1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package graphical;
25 
26 import java.io.File;
27 import java.io.FileWriter;
28 // import util.utils;
29 // import helper.OSHelper;
30 
31 public class HTMLResult
32 {
33     private FileWriter m_aOut;
34     // private String m_sFilename;
35     // private String m_sNamePrefix;              // the HTML files used a suffix to build it's right name
36 
37     /**
38      * ls is the current line separator (carridge return)
39      */
40     private String ls;
41 
HTMLResult( String _sOutputPath, String _sHTMLFilename )42     public HTMLResult( String _sOutputPath, String _sHTMLFilename )
43         {
44             FileHelper.makeDirectories("", _sOutputPath);
45             // HTMLResult a = new HTMLResult();
46             String sFilename = FileHelper.appendPath(_sOutputPath, _sHTMLFilename);
47 
48             try
49             {
50                 File outputFile = new File(sFilename);
51                 m_aOut = new FileWriter(outputFile.toString());
52                 ls = System.getProperty("line.separator");
53             }
54             catch (java.io.IOException e)
55             {
56                 e.printStackTrace();
57                 GlobalLogWriter.println("ERROR: Can't create HTML Outputter");
58                 // return null;
59             }
60             // m_sFilename = sFilename;
61             // a.m_sNamePrefix = _sNamePrefix;
62             // return a;
63         }
64 
65     // public String getFilename() {return m_sFilename;}
66 
writeln(String _sStr)67     private void writeln(String _sStr)
68     {
69             try
70             {
71                 m_aOut.write( _sStr );
72                 m_aOut.write ( ls );
73             }
74             catch (java.io.IOException e)
75             {
76             }
77     }
flush()78     private void flush()
79     {
80         try
81         {
82             m_aOut.flush();
83         }
84         catch (java.io.IOException e)
85         {
86         }
87     }
88 
89 
90     /**
91      * create the HTML header
92      * @param _sTitle
93      */
header(String _sTitle)94     public void header(String _sTitle)
95         {
96                 writeln( "<HTML>");
97                 writeln( "<HEAD>" );
98                 writeln( "<TITLE>" + _sTitle + "</TITLE>");
99                 writeln( "<LINK rel=\"stylesheet\" type=\"text/css\" href=\"/gfxcmp_ui/xmloff.css\" media=\"screen\" />");
100                 writeln( "<LINK rel=\"stylesheet\" type=\"text/css\" href=\"/gfxcmp_ui/style.css\" media=\"screen\" />");
101                 writeln( "</HEAD>");
102                 writeln( "<BODY bgcolor=white>");
103                 flush();
104         }
105 
106     final static String TEST_TABLETITLE = "Document";
107     final static String VISUAL_STATUS_TABLETITLE = "Visual status";
108     final static String VISUAL_STATUS_MESSAGE_TABLETITLE = "Message";
109     final static String FIRSTGFX_TABLETITLE = "Original print file as jpeg";
110 
indexSection(String _sOfficeInfo)111     public void indexSection(String _sOfficeInfo)
112         {
113                 writeln( "<H2>Results for " + _sOfficeInfo + "</H2>");
114                 writeln( "<P>This result was created at: " + DateHelper.getDateTimeForHumanreadableLog());
115                 writeln( "<P>Legend:<BR>");
116                 writeln( stronghtml(FIRSTGFX_TABLETITLE) + " contains the output printed via 'ghostscript' as a jpeg picture.<BR>");
117 
118                 writeln( "<TABLE class=\"infotable\">");
119                 writeln( "<TR>");
120                 writeln( tableHeaderCell(TEST_TABLETITLE));
121                 writeln( tableHeaderCell(""));
122                 writeln( tableHeaderCell(VISUAL_STATUS_TABLETITLE));
123                 writeln( tableHeaderCell(VISUAL_STATUS_MESSAGE_TABLETITLE));
124                 writeln( "</TR>");
125                 flush();
126         }
127 /**
128  * Returns the given _sHREF & _sPathInfo as a HTML String
129  * <A HREF="_sHREF">_sPathInfo</A>
130  * @param _sHREF
131  * @param _sPathInfo
132  * @return
133  */
getHREF(String _sHREF, String _sPathInfo)134     private String getHREF(String _sHREF, String _sPathInfo)
135         {
136             StringBuffer a = new StringBuffer();
137             a.append("<A HREF=\"");
138             a.append(_sHREF);
139             a.append("\">");
140             a.append(_sPathInfo);
141             a.append("</A>");
142             return a.toString();
143         }
144 
145     /**
146      * Returns the given _sValue as a HTML Table cell with _sValue as content
147      * @param _sValue
148      * @return
149      */
tableDataCell(String _sValue)150     private String tableDataCell(String _sValue)
151         {
152             StringBuffer a = new StringBuffer();
153             a.append("<TD>");
154             a.append(_sValue);
155             a.append("</TD>");
156             return a.toString();
157         }
158 
159     /**
160      * Returns the given _sValue as a HTML Table header cell with _sValue as content
161      * @param _sValue
162      * @return
163      */
tableHeaderCell(String _sValue)164     private String tableHeaderCell(String _sValue)
165         {
166             StringBuffer a = new StringBuffer();
167             a.append("<TH>");
168             a.append(_sValue);
169             a.append("</TH>");
170             return a.toString();
171         }
172 
indexLine(String _sHTMLFile, String _sHTMLName, String _sStatusRunThrough, String _sStatusMessage)173     public void indexLine(String _sHTMLFile, String _sHTMLName, String _sStatusRunThrough, String _sStatusMessage)
174         {
175                 writeln( "<TR>");
176                 writeln(tableDataCell( getHREF(_sHTMLFile, _sHTMLName) ) );
177                 writeln(tableDataCell( "" ) );
178                 writeln( tableDataCell(_sStatusRunThrough) );
179                 writeln( tableDataCell(_sStatusMessage) );
180                 writeln( "</TR>");
181                 flush();
182         }
183 
close()184     public void close()
185         {
186             writeln( "</TABLE>");
187             writeln( "</BODY></HTML>");
188             try
189             {
190                 m_aOut.close();
191             }
192             catch (java.io.IOException e)
193             {
194             }
195         }
196 
197 // -----------------------------------------------------------------------------
stronghtml(String _sValue)198     private String stronghtml(String _sValue)
199         {
200             StringBuffer a = new StringBuffer();
201             a.append("<STRONG>");
202             a.append(_sValue);
203             a.append("</STRONG>");
204             return a.toString();
205         }
206 
207 }
208