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 convwatch;
25 
26 import java.io.File;
27 import java.io.FileWriter;
28 import helper.OSHelper;
29 
30 public class HTMLOutputter
31 {
32     FileWriter m_aOut;
33     String m_sFilename;
34     String m_sNamePrefix;              // the HTML files used a suffix to build it's right name
35 
36     /**
37      * ls is the current line separator (carridge return)
38      */
39     String ls;
40 
HTMLOutputter()41     HTMLOutputter() {}
create( String _sOutputPath, String _sHTMLFilename, String _sNamePrefix, String _sTitle )42     public static HTMLOutputter create( String _sOutputPath, String _sHTMLFilename, String _sNamePrefix, String _sTitle )
43         {
44             FileHelper.makeDirectories("", _sOutputPath);
45             HTMLOutputter a = new HTMLOutputter();
46             String fs = System.getProperty("file.separator");
47             String sFilename = _sOutputPath + fs + _sHTMLFilename;
48 
49             try
50             {
51                 File outputFile = new File(sFilename);
52                 a.m_aOut = new FileWriter(outputFile.toString());
53                 a.ls = System.getProperty("line.separator");
54             }
55             catch (java.io.IOException e)
56             {
57                 e.printStackTrace();
58                 GlobalLogWriter.get().println("ERROR: Can't create HTML Outputter");
59                 return null;
60             }
61             a.m_sFilename = sFilename;
62             a.m_sNamePrefix = _sNamePrefix;
63             return a;
64         }
getFilename()65     public String getFilename() {return m_sFilename;}
66 
header(String _sTitle)67     public void header(String _sTitle)
68         {
69             try
70             {
71                 m_aOut.write( "<html>" + ls);
72                 m_aOut.write( "<head>"  + ls);
73                 m_aOut.write( "<title>" + _sTitle + "</title>" + ls);
74                 m_aOut.write( "<link rel=\"stylesheet\" type=\"text/css\" href=\"/gfxcmp_ui/xmloff.css\" media=\"screen\" />" + ls);
75                 m_aOut.write( "<link rel=\"stylesheet\" type=\"text/css\" href=\"/gfxcmp_ui/style.css\" media=\"screen\" />" + ls);
76                 m_aOut.write( "</head>" + ls);
77                 m_aOut.write( "<body bgcolor=white>" + ls);
78                 m_aOut.flush();
79             }
80             catch (java.io.IOException e)
81             {
82             }
83         }
84 
85     final static String TEST_TABLETITLE = "Test";
86     final static String VISUAL_STATUS_TABLETITLE = "Visual status";
87     final static String VISUAL_STATUS_MESSAGE_TABLETITLE = "Message";
88 
indexSection(String _sOfficeInfo)89     public void indexSection(String _sOfficeInfo)
90         {
91             try
92             {
93                 m_aOut.write( "<h2>Results for " + _sOfficeInfo + "</h2>" + ls);
94                 m_aOut.write( "<p>Legend:<br>");
95                 m_aOut.write( stronghtml(FIRSTGFX_TABLETITLE) + " contains the output printed via 'ghostscript' as a jpeg picture.<br>");
96 
97                 m_aOut.write( "<table class=\"infotable\">" + ls);
98                 m_aOut.write( "<TR>");
99                 m_aOut.write( tableHeaderCell(TEST_TABLETITLE));
100                 m_aOut.write( tableHeaderCell(TEST_TABLETITLE));
101                 m_aOut.write( tableHeaderCell(VISUAL_STATUS_TABLETITLE));
102                 m_aOut.write( tableHeaderCell(VISUAL_STATUS_MESSAGE_TABLETITLE));
103                 m_aOut.write( "</TR>" + ls);
104                 m_aOut.flush();
105             }
106             catch (java.io.IOException e)
107             {
108             }
109         }
110 
getHREF(String _sHREF, String _sPathInfo)111     String getHREF(String _sHREF, String _sPathInfo)
112         {
113             StringBuffer a = new StringBuffer();
114             if (! OSHelper.isWindows())
115             {
116                 // System.out.println("Tu'nix system.");
117                 a.append("<A HREF=\"");
118                 a.append(_sHREF);
119                 a.append("\">");
120                 a.append(_sPathInfo);
121                 a.append("</A>");
122             }
123             else
124             {
125                 // System.out.println("Windows system.");
126                 //! this should be replaced by a better method
127                 //! name(WIN|UNIX)
128                 a.append("<A HREF=\"");
129                 a.append(_sHREF);
130                 a.append("\">");
131                 a.append(_sPathInfo);
132                 // a.append("(first)");
133                 a.append("</A>");
134                 // if (_sHREF.charAt(1) == ':' && (_sHREF.charAt(0) == 'x' || _sHREF.charAt(0) == 'X'))
135                 // int index = 0;
136                 // index = _sHREF.indexOf("X:");
137                 // if (index == -1)
138                 // {
139                 //     index = _sHREF.indexOf("x:");
140                 // }
141                 // if (index >= 0)
142                 // {
143                 //     // int index = 0;
144                 //     // remove "X:" and insert "/tausch"
145                 //     StringBuffer sbUNIXPath = new StringBuffer( _sHREF.substring(0, index) );
146                 //     sbUNIXPath.append("/tausch");
147                 //     sbUNIXPath.append(_sHREF.substring(index + 2));
148                 //     String sUNIXPath = sbUNIXPath.toString();
149                 //     sUNIXPath = utils.replaceAll13(sUNIXPath, "\\", "/");
150                 //
151                 //     a.append("<A HREF=\"");
152                 //     a.append(sUNIXPath);
153                 //     a.append("\">");
154                 //     a.append("(second)");
155                 //     a.append("</A>");
156                 // }
157                 // else
158                 // {
159                 //     System.out.println("Path is '" + _sHREF + "'");
160                 // }
161 
162             }
163             return a.toString();
164         }
165 
tableDataCell(String _sValue)166     String tableDataCell(String _sValue)
167         {
168             StringBuffer a = new StringBuffer();
169             a.append("<TD>");
170             a.append(_sValue);
171             a.append("</TD>");
172             return a.toString();
173         }
174 
tableHeaderCell(String _sValue)175     String tableHeaderCell(String _sValue)
176         {
177             StringBuffer a = new StringBuffer();
178             a.append("<TH>");
179             a.append(_sValue);
180             a.append("</TH>");
181             return a.toString();
182         }
183 
indexLine(String _sHTMLFile, String _sHTMLName, String _sHTMLFile2, String _sHTMLName2, String _sStatusRunThrough, String _sStatusMessage)184     public void indexLine(String _sHTMLFile, String _sHTMLName, String _sHTMLFile2, String _sHTMLName2, String _sStatusRunThrough, String _sStatusMessage)
185         {
186             try
187             {
188                 m_aOut.write( "<TR>");
189                 m_aOut.write(tableDataCell( getHREF(_sHTMLFile, _sHTMLName) ) );
190                 if (_sHTMLFile2.length() > 0)
191                 {
192                     m_aOut.write(tableDataCell( getHREF(_sHTMLFile2, _sHTMLName2) ) );
193                 }
194                 else
195                 {
196                     m_aOut.write(tableDataCell( "" ) );
197                 }
198 
199                 m_aOut.write( tableDataCell(_sStatusRunThrough) );
200                 m_aOut.write( tableDataCell(_sStatusMessage) );
201                 m_aOut.write( "</TR>" + ls);
202 
203                 m_aOut.flush();
204             }
205             catch (java.io.IOException e)
206             {
207             }
208         }
209 
close()210     public void close()
211         {
212             try
213             {
214                 m_aOut.write( "</TABLE>" + ls);
215                 m_aOut.write( "</BODY></HTML>" + ls);
216                 m_aOut.flush();
217                 m_aOut.close();
218             }
219             catch (java.io.IOException e)
220             {
221             }
222         }
223 
224 // -----------------------------------------------------------------------------
stronghtml(String _sValue)225     String stronghtml(String _sValue)
226         {
227             StringBuffer a = new StringBuffer();
228             a.append("<STRONG>");
229             a.append(_sValue);
230             a.append("</STRONG>");
231             return a.toString();
232         }
233 
234     final static String FIRSTGFX_TABLETITLE = "Original print file as jpeg";
235     final static String SECONDGFX_TABLETITLE = "New print file as jpeg";
236     final static String DIFFER_TABLETITLE = "Difference file";
237     final static String STATUS_TABLETITLE = "Status";
238     final static String PIXELDIFF_TABLETITLE = "Pixel difference in %";
239 
240     final static String PIXELDIFF_BM_TABLETITLE = "P.diff. in % after remove border";
241     final static String DIFFER_BM_TABLETITLE = "Diff file (RB)";
242 
243     final static String OK_TABLETITLE = "OK?";
checkSection(String _sDocumentName)244     public void checkSection(String _sDocumentName)
245         {
246             try
247             {
248                 m_aOut.write( "<H2>Results for the document " + _sDocumentName + "</H2>" + ls);
249 
250                 m_aOut.write( "<p>Legend:<br>");
251                 m_aOut.write( stronghtml(FIRSTGFX_TABLETITLE) + " contains the output printed via 'ghostscript' as a jpeg picture.<br>");
252                 m_aOut.write( stronghtml(SECONDGFX_TABLETITLE) + " contains the same document opened within OpenOffice.org also printed via ghostscript as jpeg.<br>");
253                 m_aOut.write( stronghtml(DIFFER_TABLETITLE)+" is build via composite from original and new picture. The result should be a whole black picture, if there are no differences.<br>At the moment "+stronghtml(STATUS_TABLETITLE)+" is only ok, if the difference file contains only one color (black).</p>" );
254                 m_aOut.write( stronghtml(DIFFER_BM_TABLETITLE) + " is build via composite from original and new picture after the border of both pictures are removed, so differences based on center problems may solved here");
255                 m_aOut.write( "</p>");
256                 m_aOut.write( "<p>Some words about the percentage value<br>");
257                 m_aOut.write( "If a character is on the original page (a) and on the new page this character is moved to an other position only (b) , this means the difference is 100%.<br>");
258                 m_aOut.write( "If character (b) is also bigger than character (a) the percentage is grow over the 100% mark.<br>");
259                 m_aOut.write( "This tool count only the pixels which are differ to it's background color. It makes no sense to count all pixels, or the difference percentage will most the time in a very low percentage range.");
260                 m_aOut.write( "</p>");
261 
262                 m_aOut.write( "<table class=\"infotable\">" + ls);
263 
264                 m_aOut.write( "<TR>" + ls);
265                 m_aOut.write( tableHeaderCell( FIRSTGFX_TABLETITLE) );
266                 m_aOut.write( tableHeaderCell( SECONDGFX_TABLETITLE ) );
267                 m_aOut.write( tableHeaderCell(DIFFER_TABLETITLE ) );
268                 m_aOut.write( tableHeaderCell(PIXELDIFF_TABLETITLE ) );
269 
270                 m_aOut.write( tableHeaderCell(DIFFER_BM_TABLETITLE) );
271                 m_aOut.write( tableHeaderCell(PIXELDIFF_BM_TABLETITLE ) );
272 
273                 m_aOut.write( tableHeaderCell( OK_TABLETITLE) );
274 
275                 m_aOut.write( "</TR>" + ls);
276                 m_aOut.flush();
277             }
278             catch (java.io.IOException e)
279             {
280             }
281         }
282 
checkLine(StatusHelper _aStatus, boolean _bCurrentResult)283     public void checkLine(StatusHelper _aStatus, boolean _bCurrentResult)
284         {
285             try
286             {
287                 m_aOut.write( "<TR>" + ls);
288                 String sLink = getHREF(FileHelper.getBasename(_aStatus.m_sOldGfx), FileHelper.getBasename(_aStatus.m_sOldGfx));
289                 m_aOut.write( tableDataCell(sLink) );
290 
291                 sLink = getHREF(FileHelper.getBasename(_aStatus.m_sNewGfx), FileHelper.getBasename(_aStatus.m_sNewGfx));
292                 m_aOut.write( tableDataCell(sLink) );
293 
294                 sLink = getHREF(FileHelper.getBasename(_aStatus.m_sDiffGfx), FileHelper.getBasename(_aStatus.m_sDiffGfx));
295                 m_aOut.write( tableDataCell(sLink) );
296 
297                 String sPercent = String.valueOf(_aStatus.nPercent) + "%";
298                 if (_aStatus.nPercent > 0 && _aStatus.nPercent < 5)
299                 {
300                     sPercent += " (less 5% is ok)";
301                 }
302                 m_aOut.write(tableDataCell( sPercent ) );
303 
304                 if (_aStatus.m_sDiff_BM_Gfx == null)
305                 {
306                     sLink = "No diffs, therefore no moves";
307                     m_aOut.write( tableDataCell(sLink) );
308                     m_aOut.write(tableDataCell( "" ) );
309                 }
310                 else
311                 {
312                     sLink = getHREF(FileHelper.getBasename(_aStatus.m_sDiff_BM_Gfx), FileHelper.getBasename(_aStatus.m_sDiff_BM_Gfx));
313                     m_aOut.write( tableDataCell(sLink) );
314 
315                     String sPercent2 = String.valueOf(_aStatus.nPercent2) + "%";
316                     if (_aStatus.nPercent2 > 0 && _aStatus.nPercent2 < 5)
317                     {
318                         sPercent2 += " (less 5% is ok)";
319                     }
320                     m_aOut.write(tableDataCell( sPercent2 ) );
321                 }
322 
323                 // is the check positiv, in a defined range
324                 if (_bCurrentResult)
325                 {
326                     m_aOut.write(tableDataCell( "YES" ) );
327                 }
328                 else
329                 {
330                     m_aOut.write(tableDataCell( "NO" ) );
331                 }
332 
333                 m_aOut.write( "</TR>" + ls);
334             }
335             catch (java.io.IOException e)
336             {
337             }
338         }
339 
340 // -----------------------------------------------------------------------------
checkDiffDiffSection(String _sDocumentName)341     public void checkDiffDiffSection(String _sDocumentName)
342         {
343             try
344             {
345                 m_aOut.write( "<H2>Results for the document " + _sDocumentName + "</H2>" + ls);
346 
347                 m_aOut.write( "<p>Legend:<br>");
348                 m_aOut.write( "</p>");
349 
350                 m_aOut.write( "<table class=\"infotable\">" + ls);
351 
352                 m_aOut.write( "<TR>" + ls);
353                 m_aOut.write( tableHeaderCell( "Source to actual difference" ) );
354                 m_aOut.write( tableHeaderCell( "Actual difference" ) );
355                 m_aOut.write( tableHeaderCell(DIFFER_TABLETITLE ) );
356                 m_aOut.write( tableHeaderCell(PIXELDIFF_TABLETITLE ) );
357 
358                 m_aOut.write( tableHeaderCell( OK_TABLETITLE) );
359 
360                 m_aOut.write( "</TR>" + ls);
361                 m_aOut.flush();
362             }
363             catch (java.io.IOException e)
364             {
365             }
366         }
367 
checkDiffDiffLine(StatusHelper _aStatus, boolean _bCurrentResult)368     public void checkDiffDiffLine(StatusHelper _aStatus, boolean _bCurrentResult)
369         {
370             try
371             {
372                 m_aOut.write( "<TR>" + ls);
373                 // the link to the old difference can't offer here
374                 //  String sLink = getHREF(FileHelper.getBasename(_aStatus.m_sOldGfx), FileHelper.getBasename(_aStatus.m_sOldGfx));
375                 //  m_aOut.write( tableDataCell(sLink) );
376 
377                 String sBasename = FileHelper.getBasename(m_sFilename);
378                 String sNew = sBasename.substring(m_sNamePrefix.length());
379 
380                 String sLink;
381                 sLink = getHREF(sNew, sNew);
382                 m_aOut.write( tableDataCell(sLink) );
383 
384                 sLink = getHREF(FileHelper.getBasename(_aStatus.m_sNewGfx), FileHelper.getBasename(_aStatus.m_sNewGfx));
385                 m_aOut.write( tableDataCell(sLink) );
386 
387                 sLink = getHREF(FileHelper.getBasename(_aStatus.m_sDiffGfx), FileHelper.getBasename(_aStatus.m_sDiffGfx));
388                 m_aOut.write( tableDataCell(sLink) );
389 
390                 String sPercent = String.valueOf(_aStatus.nPercent) + "%";
391                 // if (_aStatus.nPercent > 0 && _aStatus.nPercent < 5)
392                 // {
393                 //     sPercent += " (less 5% is ok)";
394                 // }
395                 m_aOut.write(tableDataCell( sPercent ) );
396 
397                 // is the check positiv, in a defined range
398                 if (_bCurrentResult)
399                 {
400                     m_aOut.write(tableDataCell( "YES" ) );
401                 }
402                 else
403                 {
404                     m_aOut.write(tableDataCell( "NO" ) );
405                 }
406 
407                 m_aOut.write( "</TR>" + ls);
408             }
409             catch (java.io.IOException e)
410             {
411             }
412         }
413 
414 }
415