001/*
002 * JPPF.
003 * Copyright (C) 2005-2019 JPPF Team.
004 * http://www.jppf.org
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.jppf.utils;
020
021
022/**
023 * Implementation of a formatter that print the contents of a {@link java.util.Properties Properties} object as HTML.
024 * @author Laurent Cohen
025 */
026public class HTMLPropertiesTableFormat extends PropertiesTableFormat {
027  /**
028   * 
029   */
030  private final boolean fullHtml;
031
032  /**
033   * Initialize this formatter with the specified title.
034   * @param docTitle the title of the whole document.
035   */
036  public HTMLPropertiesTableFormat(final String docTitle) {
037    this(docTitle, true);
038  }
039
040  /**
041   * Initialize this formatter with the specified title.
042   * @param docTitle the title of the whole document.
043   * @param fullHtml .
044   */
045  public HTMLPropertiesTableFormat(final String docTitle, final boolean fullHtml) {
046    super(docTitle);
047    this.fullHtml = fullHtml;
048  }
049
050  /**
051   * Write the prologue for the formatted text.
052   */
053  @Override
054  public void start() {
055    if (fullHtml) sb.append("<html><head></head><body style=\"font-family: Arial; font-size: 12pt\">");
056    sb.append("<h1><font color=\"#2D3876\">").append(docTitle).append("</font></h1>");
057  }
058
059  /**
060   * Write the epilogue for the formatted text.
061   */
062  @Override
063  public void end() {
064    if (fullHtml) sb.append("</body></html>");
065  }
066
067  /**
068   * Write the prologue of a table.
069   * @param title the title for the table.
070   */
071  @Override
072  public void tableStart(final String title) {
073    sb.append("<h2><font color=\"#2D3876\">").append(title).append("</font></h2>");
074    sb.append("<table cellspacing=\"0\" cellpadding=\"1\" style=\"border: 0px\">");
075  }
076
077  /**
078   * Write the prologue of a table.
079   */
080  @Override
081  public void tableEnd() {
082    sb.append("</table>");
083  }
084
085  /**
086   * Write the prologue of a table row.
087   */
088  @Override
089  public void rowStart() {
090    sb.append("<tr>");
091  }
092
093  /**
094   * Write the prologue of a table row.
095   */
096  @Override
097  public void rowEnd() {
098    sb.append("</tr>");
099  }
100
101  /**
102   * Write the prologue of a table cell.
103   */
104  @Override
105  public void cellStart() {
106    sb.append("<td valign=\"top\">");
107  }
108
109  /**
110   * Write the prologue of a table cell.
111   */
112  @Override
113  public void cellEnd() {
114    sb.append("</td>");
115  }
116
117  /**
118   * Write the separator between 2 cells.
119   */
120  @Override
121  public void cellSeparator() {
122    //sb.append("<td width=\"5\"/>");
123    sb.append("<td valign=\"top\"><font color=\"red\"> = </font></td>");
124  }
125
126  @Override
127  public String formatName(final String name) {
128    return "<font color=\"#2D3876\">" + name + "</font>";
129  }
130}