001/*
002 * JPPF.
003 * Copyright (C) 2005-2016 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   * Initialize this formatter with the specified title.
029   * @param docTitle the title of the whole document.
030   */
031  public HTMLPropertiesTableFormat(final String docTitle) {
032    super(docTitle);
033  }
034
035  /**
036   * Write the prologue for the formatted text.
037   */
038  @Override
039  public void start() {
040    sb.append("<html><head></head><body style=\"font-family: Arial; font-size: 12pt\">");
041    sb.append("<h1><font color=\"#2D3876\">").append(docTitle).append("</font></h1>");
042  }
043
044  /**
045   * Write the epilogue for the formatted text.
046   */
047  @Override
048  public void end() {
049    sb.append("</body></html>");
050  }
051
052  /**
053   * Write the prologue of a table.
054   * @param title the title for the table.
055   */
056  @Override
057  public void tableStart(final String title) {
058    sb.append("<h2><font color=\"#2D3876\">").append(title).append("</font></h2>");
059    sb.append("<table cellspacing=\"0\" cellpadding=\"1\">");
060  }
061
062  /**
063   * Write the prologue of a table.
064   */
065  @Override
066  public void tableEnd() {
067    sb.append("</table>");
068  }
069
070  /**
071   * Write the prologue of a table row.
072   */
073  @Override
074  public void rowStart() {
075    sb.append("<tr>");
076  }
077
078  /**
079   * Write the prologue of a table row.
080   */
081  @Override
082  public void rowEnd() {
083    sb.append("</tr>");
084  }
085
086  /**
087   * Write the prologue of a table cell.
088   */
089  @Override
090  public void cellStart() {
091    sb.append("<td valign=\"top\">");
092  }
093
094  /**
095   * Write the prologue of a table cell.
096   */
097  @Override
098  public void cellEnd() {
099    sb.append("</td>");
100  }
101
102  /**
103   * Write the separator between 2 cells.
104   */
105  @Override
106  public void cellSeparator() {
107    //sb.append("<td width=\"5\"/>");
108    sb.append("<td valign=\"top\"><font color=\"red\"> = </font></td>");
109  }
110
111  @Override
112  public String formatName(final String name) {
113    return "<font color=\"#2D3876\">" + name + "</font>";
114  }
115}