changeset 784:61cadaf2583d draft

Updated comments in the class HtmlStructureWriter.
author Pavel Tisnovsky <ptisnovs@redhat.com>
date Mon, 04 Jan 2016 11:04:54 +0100
parents fd109a931f89
children e9bbfa68cc70
files ChangeLog src/org/gfxtest/ImageDiffer/ResultWriters/HtmlStructureWriter.java
diffstat 2 files changed, 47 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Nov 13 13:26:05 2015 +0100
+++ b/ChangeLog	Mon Jan 04 11:04:54 2016 +0100
@@ -1,3 +1,8 @@
+2016-01-04  Pavel Tisnovsky  <ptisnovs@redhat.com>
+
+	* src/org/gfxtest/ImageDiffer/ResultWriters/HtmlStructureWriter.java:
+	Updated comments in the class HtmlStructureWriter.
+
 2015-11-13  Pavel Tisnovsky  <ptisnovs@redhat.com>
 
 	* src/org/gfxtest/testsuites/BitBltUsingBgColor.java:
--- a/src/org/gfxtest/ImageDiffer/ResultWriters/HtmlStructureWriter.java	Fri Nov 13 13:26:05 2015 +0100
+++ b/src/org/gfxtest/ImageDiffer/ResultWriters/HtmlStructureWriter.java	Mon Jan 04 11:04:54 2016 +0100
@@ -1,7 +1,7 @@
 /*
   Java gfx-test framework
 
-   Copyright (C) 2010, 2011, 2012  Red Hat
+   Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016  Red Hat
 
 This file is part of IcedTea.
 
@@ -62,8 +62,10 @@
 import org.gfxtest.ImageDiffer.Configuration;
 import org.gfxtest.framework.Log;
 
+
+
 /**
- * 
+ * Helper class for writting result(s) into an HTML page.
  *
  * @author Pavel Tisnovsky
  */
@@ -74,19 +76,31 @@
      */
     private static final String DEFAULT_ENCODING = "UTF-8";
 
+    /**
+     * Directory that contains HTML templates.
+     */
     private static final String TEMPLATE_DIR = "templates";
 
+    /**
+     * Initialization of the logger used during HTML generation.
+     */
     static Log log = new Log(HtmlStructureWriter.class.getName(), true);
 
+    /**
+     * Create directory where the results should be placed.
+     */
     public static void createAndFillResultDirectory(Configuration configuration, BufferedImage[] sourceImages,
             ComparisonResult comparisonResult, String dirName) throws IOException
     {
         File newDir = new File(configuration.getOutputDirectory(), dirName);
         log.logProcess("creating directory %s", newDir.getAbsolutePath());
+        // create directory to store results (this directory might exists)
         if (!newDir.mkdir())
         {
             log.logError("error creating directory %s", newDir.getAbsolutePath());
         }
+        // write images according to computed diff
+        // but only when at least one diff have been found
         if (!comparisonResult.isEqualsImages())
         {
             log.logProcess("writing source and diff images to directory %s", dirName);
@@ -102,11 +116,16 @@
         createHtmlFile(newDir, comparisonResult);
     }
 
+    /**
+     * Create HTML file containing result(s).
+     */
     private static void createHtmlFile(File newDir, ComparisonResult cr) throws IOException
     {
+        // get the appropriate template
         String templateName = cr.isEqualsImages() ? "template_same_images.html" : "template_different_images.html";
         BufferedWriter writer = null;
         BufferedReader template = null;
+        // read the template and write the resulting HTML by using this template
         try
         {
             writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(newDir, "result.html")), DEFAULT_ENCODING));
@@ -119,21 +138,26 @@
         }
         catch (UnsupportedEncodingException e)
         {
+            // print stack trace in case of exception
             e.printStackTrace();
             throw e;
         }
         catch (FileNotFoundException e)
         {
+            // print stack trace in case of exception
             e.printStackTrace();
             throw e;
         }
         catch (IOException e)
         {
+            // print stack trace in case of exception
             e.printStackTrace();
             throw e;
         }
+        // try to close template & the resulting HTML file
         finally
         {
+            // close the template
             if (template != null)
             {
                 try
@@ -145,6 +169,7 @@
                     e.printStackTrace();
                 }
             }
+            // close the HTML file with results
             if (writer != null)
             {
                 try
@@ -159,12 +184,17 @@
         }
     }
 
+    /**
+     * Replace placeholder name with the appropriate value.
+     */
     private static String replacePlaceholders(ComparisonResult cr, File newDir, String line)
     {
         StringBuffer out = new StringBuffer();
+        // placeholder is written as ${IDENTIFIER}
         Pattern pattern = Pattern.compile("\\$\\{(.*?)\\}", Pattern.CASE_INSENSITIVE);
         Matcher matcher = pattern.matcher(line);
 
+        // each placeholder is processed in one iteration
         while (matcher.find())
         {
             matcher.appendReplacement(out, getPlaceholderValue(cr, matcher.group(1)));
@@ -173,41 +203,45 @@
         return out.toString() + "\n";
     }
 
+    /**
+     * Try to read the value of getter with the same name as placeholder.
+     */
     private static String getPlaceholderValue(ComparisonResult cr, String group)
     {
         Method method;
         try
         {
-            // call appropriate getter
+            // try to call appropriate getter
             method = cr.getClass().getDeclaredMethod("get" + group, (Class<?>[]) null);
             return "" + method.invoke(cr, (Object[]) null);
         }
         catch (IllegalAccessException e)
         {
-            // print ST in case of exception
+            // print stack trace in case of exception
             e.printStackTrace();
         }
         catch (SecurityException e)
         {
-            // print ST in case of exception
+            // print stack trace in case of exception
             e.printStackTrace();
         }
         catch (NoSuchMethodException e)
         {
-            // print ST in case of exception
+            // print stack trace in case of exception
             e.printStackTrace();
         }
         catch (IllegalArgumentException e)
         {
-            // print ST in case of exception
+            // print stack trace in case of exception
             e.printStackTrace();
         }
         catch (InvocationTargetException e)
         {
-            // print ST in case of exception
+            // print stack trace in case of exception
             e.printStackTrace();
         }
         return group;
     }
 
 }
+