1 /* 2 ************************************************************************ 3 * 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * Copyright 2000, 2010 Oracle and/or its affiliates. 7 * 8 * OpenOffice.org - a multi-platform office productivity suite 9 * 10 * This file is part of OpenOffice.org. 11 * 12 * OpenOffice.org is free software: you can redistribute it and/or modify 13 * it under the terms of the GNU Lesser General Public License version 3 14 * only, as published by the Free Software Foundation. 15 * 16 * OpenOffice.org is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU Lesser General Public License version 3 for more details 20 * (a copy is included in the LICENSE file that accompanied this code). 21 * 22 * You should have received a copy of the GNU Lesser General Public License 23 * version 3 along with OpenOffice.org. If not, see 24 * <http://www.openoffice.org/license.html> 25 * for a copy of the LGPLv3 License. 26 * 27 ************************************************************************/ 28 29 package graphical; 30 31 import java.io.File; 32 import java.io.FileWriter; 33 // import util.utils; 34 // import helper.OSHelper; 35 36 public class HTMLResult 37 { 38 private FileWriter m_aOut; 39 // private String m_sFilename; 40 // private String m_sNamePrefix; // the HTML files used a suffix to build it's right name 41 42 /** 43 * ls is the current line separator (carridge return) 44 */ 45 private String ls; 46 47 public HTMLResult( String _sOutputPath, String _sHTMLFilename ) 48 { 49 FileHelper.makeDirectories("", _sOutputPath); 50 // HTMLResult a = new HTMLResult(); 51 String sFilename = FileHelper.appendPath(_sOutputPath, _sHTMLFilename); 52 53 try 54 { 55 File outputFile = new File(sFilename); 56 m_aOut = new FileWriter(outputFile.toString()); 57 ls = System.getProperty("line.separator"); 58 } 59 catch (java.io.IOException e) 60 { 61 e.printStackTrace(); 62 GlobalLogWriter.println("ERROR: Can't create HTML Outputter"); 63 // return null; 64 } 65 // m_sFilename = sFilename; 66 // a.m_sNamePrefix = _sNamePrefix; 67 // return a; 68 } 69 70 // public String getFilename() {return m_sFilename;} 71 72 private void writeln(String _sStr) 73 { 74 try 75 { 76 m_aOut.write( _sStr ); 77 m_aOut.write ( ls ); 78 } 79 catch (java.io.IOException e) 80 { 81 } 82 } 83 private void flush() 84 { 85 try 86 { 87 m_aOut.flush(); 88 } 89 catch (java.io.IOException e) 90 { 91 } 92 } 93 94 95 /** 96 * create the HTML header 97 * @param _sTitle 98 */ 99 public void header(String _sTitle) 100 { 101 writeln( "<HTML>"); 102 writeln( "<HEAD>" ); 103 writeln( "<TITLE>" + _sTitle + "</TITLE>"); 104 writeln( "<LINK rel=\"stylesheet\" type=\"text/css\" href=\"/gfxcmp_ui/xmloff.css\" media=\"screen\" />"); 105 writeln( "<LINK rel=\"stylesheet\" type=\"text/css\" href=\"/gfxcmp_ui/style.css\" media=\"screen\" />"); 106 writeln( "</HEAD>"); 107 writeln( "<BODY bgcolor=white>"); 108 flush(); 109 } 110 111 final static String TEST_TABLETITLE = "Document"; 112 final static String VISUAL_STATUS_TABLETITLE = "Visual status"; 113 final static String VISUAL_STATUS_MESSAGE_TABLETITLE = "Message"; 114 final static String FIRSTGFX_TABLETITLE = "Original print file as jpeg"; 115 116 public void indexSection(String _sOfficeInfo) 117 { 118 writeln( "<H2>Results for " + _sOfficeInfo + "</H2>"); 119 writeln( "<P>This result was created at: " + DateHelper.getDateTimeForHumanreadableLog()); 120 writeln( "<P>Legend:<BR>"); 121 writeln( stronghtml(FIRSTGFX_TABLETITLE) + " contains the output printed via 'ghostscript' as a jpeg picture.<BR>"); 122 123 writeln( "<TABLE class=\"infotable\">"); 124 writeln( "<TR>"); 125 writeln( tableHeaderCell(TEST_TABLETITLE)); 126 writeln( tableHeaderCell("")); 127 writeln( tableHeaderCell(VISUAL_STATUS_TABLETITLE)); 128 writeln( tableHeaderCell(VISUAL_STATUS_MESSAGE_TABLETITLE)); 129 writeln( "</TR>"); 130 flush(); 131 } 132 /** 133 * Returns the given _sHREF & _sPathInfo as a HTML String 134 * <A HREF="_sHREF">_sPathInfo</A> 135 * @param _sHREF 136 * @param _sPathInfo 137 * @return 138 */ 139 private String getHREF(String _sHREF, String _sPathInfo) 140 { 141 StringBuffer a = new StringBuffer(); 142 a.append("<A HREF=\""); 143 a.append(_sHREF); 144 a.append("\">"); 145 a.append(_sPathInfo); 146 a.append("</A>"); 147 return a.toString(); 148 } 149 150 /** 151 * Returns the given _sValue as a HTML Table cell with _sValue as content 152 * @param _sValue 153 * @return 154 */ 155 private String tableDataCell(String _sValue) 156 { 157 StringBuffer a = new StringBuffer(); 158 a.append("<TD>"); 159 a.append(_sValue); 160 a.append("</TD>"); 161 return a.toString(); 162 } 163 164 /** 165 * Returns the given _sValue as a HTML Table header cell with _sValue as content 166 * @param _sValue 167 * @return 168 */ 169 private String tableHeaderCell(String _sValue) 170 { 171 StringBuffer a = new StringBuffer(); 172 a.append("<TH>"); 173 a.append(_sValue); 174 a.append("</TH>"); 175 return a.toString(); 176 } 177 178 public void indexLine(String _sHTMLFile, String _sHTMLName, String _sStatusRunThrough, String _sStatusMessage) 179 { 180 writeln( "<TR>"); 181 writeln(tableDataCell( getHREF(_sHTMLFile, _sHTMLName) ) ); 182 writeln(tableDataCell( "" ) ); 183 writeln( tableDataCell(_sStatusRunThrough) ); 184 writeln( tableDataCell(_sStatusMessage) ); 185 writeln( "</TR>"); 186 flush(); 187 } 188 189 public void close() 190 { 191 writeln( "</TABLE>"); 192 writeln( "</BODY></HTML>"); 193 try 194 { 195 m_aOut.close(); 196 } 197 catch (java.io.IOException e) 198 { 199 } 200 } 201 202 // ----------------------------------------------------------------------------- 203 private String stronghtml(String _sValue) 204 { 205 StringBuffer a = new StringBuffer(); 206 a.append("<STRONG>"); 207 a.append(_sValue); 208 a.append("</STRONG>"); 209 return a.toString(); 210 } 211 212 } 213