W3C home > Mailing lists > Public > www-validator-cvs@w3.org > July 2005

2002/css-validator/org/w3c/css/css StyleReportSOAP12.java,1.5,1.6

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Tue, 12 Jul 2005 13:44:55 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1DsL4B-0001OX-Vy@lionel-hutz.w3.org>

Update of /sources/public/2002/css-validator/org/w3c/css/css
In directory hutz:/tmp/cvs-serv5353

Modified Files:
	StyleReportSOAP12.java 
Log Message:
Fixed bug 750
http://www.w3.org/Bugs/Public/show_bug.cgi?id=750
Solved lots of encoding issues.


Index: StyleReportSOAP12.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/css/StyleReportSOAP12.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- StyleReportSOAP12.java	4 Dec 2003 19:12:05 -0000	1.5
+++ StyleReportSOAP12.java	12 Jul 2005 13:44:53 -0000	1.6
@@ -5,91 +5,94 @@
 
 package org.w3c.css.css;
 
-import java.io.PrintWriter;
-import java.io.IOException;
 import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintWriter;
 import java.net.URL;
-import java.util.Hashtable;
-import java.util.Properties;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Locale;
 import java.util.StringTokenizer;
-import java.util.Date;
 import java.util.TimeZone;
-import java.util.Locale;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
 import java.util.Vector;
 
-import org.w3c.css.parser.analyzer.ParseException;
-import org.w3c.css.parser.CssParseException;
-import org.w3c.css.parser.Errors;
 import org.w3c.css.parser.CssError;
 import org.w3c.css.parser.CssErrorToken;
-import org.w3c.css.parser.CssFouffa;
+import org.w3c.css.parser.CssParseException;
 import org.w3c.css.parser.CssPrinterStyle;
 import org.w3c.css.parser.CssSelectors;
-import org.w3c.css.parser.CssSelectorsConstant;
-import org.w3c.css.parser.AtRule;
-import org.w3c.css.parser.AtRulePage;
-import org.w3c.css.parser.AtRuleMedia;
-import org.w3c.css.parser.AtRuleFontFace;
+import org.w3c.css.parser.Errors;
 import org.w3c.css.properties.CssProperty;
+import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
-import org.w3c.css.util.SortedHashtable;
-import org.w3c.css.util.Warnings;
-import org.w3c.css.util.Warning;
+import org.w3c.css.util.Utf8Properties;
 import org.w3c.css.util.Util;
-import org.w3c.css.util.ApplContext;
+import org.w3c.css.util.Warning;
+import org.w3c.css.util.Warnings;
 
 /**
  * @version $Revision$
  */
-public final class StyleReportSOAP12 extends StyleReport
-    implements CssPrinterStyle {
+public final class StyleReportSOAP12 extends StyleReport implements
+CssPrinterStyle {
 
     StyleSheet style;
+
     Vector items;
+
     Warnings warnings;
+
     Errors errors;
+
     ApplContext ac;
     
     private CssSelectors selector;
+
     private CssProperty property;
+
     private PrintWriter out;
+
     private int warningLevel;
-    private Properties general;
     
-    private static Properties availableFormat;    
-    private static Properties availablePropertiesURL;
+    private Utf8Properties general;
+
+    private static Utf8Properties availableFormat;
+
+    private static Utf8Properties availablePropertiesURL;
+
     private static Hashtable formats = new Hashtable();
+
     int counter = 0;
 
+    private final static String DEFAULT_CHARSET = "utf-8";
+
     /**
      * Create a new StyleSheetGenerator
      *
-     * @param title        The title for the generated document
-     * @param style        The style sheet
-     * @param document     The name of the source file
-     * @param warningLevel If you want to reduce warning output.
-     *                     (-1 means no warnings)
+     * @param title
+     *            The title for the generated document
+     * @param style
+     *            The style sheet
+     * @param document
+     *            The name of the source file
+     * @param warningLevel
+     *            If you want to reduce warning output. (-1 means no warnings)
      */
-    public StyleReportSOAP12(ApplContext ac, 
-			     String title, 
-			     StyleSheet style,
-			     String document,
-			     int warningLevel) {
-
+    public StyleReportSOAP12(ApplContext ac, String title, StyleSheet style,
+			     String document, int warningLevel) {
 
 	if (document == null) {
 	    document = "soap12.en";
 	}
 	if (Util.onDebug) {
-	    System.err.println( "document format is " + document );
+	    System.err.println("document format is " + document);
 	}
 	this.ac = ac;
 	this.style = style;
-	general = new Properties(setDocumentBase(getDocumentName(ac,
-								 document)));
+	general = new Utf8Properties(setDocumentBase(getDocumentName(ac, document)));
 	general.put("file-title", title);
 	warnings = style.getWarnings();
 	errors = style.getErrors();
@@ -98,25 +101,23 @@
 	this.warningLevel = warningLevel;
 	
 	general.put("cssversion", ac.getCssVersion());
-	general.put("errors-count", 
-		    Integer.toString(errors.getErrorCount()));
-	general.put("warnings-count", 
-		    Integer.toString(warnings.getWarningCount()));
-	general.put("rules-count", 
-		    Integer.toString(items.size()));
-	general.put("isvalid",(errors.getErrorCount() == 0) ? "true":"false");
+	general.put("errors-count", Integer.toString(errors.getErrorCount()));
+	general.put("warnings-count", Integer.toString(warnings
+						       .getWarningCount()));
+	general.put("rules-count", Integer.toString(items.size()));
+	general.put("isvalid", (errors.getErrorCount() == 0) ? "true"
+		    : "false");
 	
 	if (ac.getContentEncoding() != null) {
-	    general.put("encoding",
-			" encoding=\""+ac.getContentEncoding()+"\" ");
+	    general.put("encoding", " encoding=\"" + ac.getContentEncoding()
+			+ "\" ");
 	} else {
-	    general.put("encoding"," ");
+	    general.put("encoding", " ");
 	}
 	if (errors.getErrorCount() == 0) {
 	    desactivateError();
 	}
-	if ((errors.getErrorCount() != 0) 
-	        || (!title.startsWith("http://"))) {
+	if ((errors.getErrorCount() != 0) || (!title.startsWith("http://"))) {
 	    general.put("no-errors", "");
 	}
 	if (style.charset == null) {
@@ -139,21 +140,19 @@
 	    general.put("no-error-or-warning", ""); 
 	}
 
-	if (Util.onDebug) general.list(System.err);
+	if (Util.onDebug)
+	    general.list(System.err);
 
 	DateFormat df = null;
 
 	if (ac.getLang() != null) {
 	    try {
-		df = DateFormat
-		    .getDateTimeInstance(DateFormat.FULL, 
-					 DateFormat.FULL,
-				       new Locale(ac.getLang().substring(0, 2),
-						    "US"));
+		df = DateFormat.getDateTimeInstance(DateFormat.FULL,
+						    DateFormat.FULL, new Locale(ac.getLang()
+										.substring(0, 2), "US"));
 	    } catch (Exception e) {
 		df = DateFormat.getDateTimeInstance(DateFormat.FULL, 
-						    DateFormat.FULL,
-						    Locale.US);
+						    DateFormat.FULL, Locale.US);
 	    }
 	}
 	if (df != null) {
@@ -161,8 +160,8 @@
 	} else {
 	    general.put("today", new Date().toString());
 	}
-	SimpleDateFormat formatter
-	    = new SimpleDateFormat ("yyyy.MM.dd'T'hh:mm:ss'Z'");
+	SimpleDateFormat formatter = new SimpleDateFormat(
+	    "yyyy.MM.dd'T'hh:mm:ss'Z'");
 	formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
 	general.put("currentdate", formatter.format(new Date()));
     }
@@ -193,7 +192,7 @@
     }
     
     public void print(CssProperty property) {
-	Properties prop = new Properties(general); 
+	Utf8Properties prop = new Utf8Properties(general);
 	prop.put("property-name", property.getPropertyName().toString());
 	prop.put("property-value", property.toString());
 	
@@ -206,8 +205,8 @@
     public void produceParseException(CssParseException error) {
 	if (error.getContexts() != null && error.getContexts().size() != 0) {
 	    StringBuffer buf = new StringBuffer();
-	    for (Enumeration e = error.getContexts().elements(); 
-		 e.hasMoreElements();) {
+	    for (Enumeration e = error.getContexts().elements(); e
+		     .hasMoreElements();) {
 		Object t = e.nextElement();
 		if (t != null) {
 		    buf.append(t);
@@ -216,52 +215,59 @@
 		}
 	    }
 	    if (buf.length() != 0) {
-		out.print("parse-error</m:errortype>\n<m:context>");
+		out.print("parse-error</m:errortype>\n\t\t\t<m:context>");
 		out.print(buf);
 		out.print("</m:context>\n");
 	    }
 	}
+	else {
+	    out.print("parse-error</m:errortype>\n");
+	}
 	String name = error.getProperty();
 	if ((name != null) && (getURLProperty(name) != null)) {
-	    out.print("<m:property>");
+	    out.print("\t\t\t<m:property>");
 	    out.print(name);
 	    out.print("</m:property>\n");
 	}
 	if ((error.getException() != null) && (error.getMessage() != null)) {
 	    if (error.isParseException()) {
-		out.print("<m:message>");
+		out.print("\t\t\t<m:message>");
 		out.print(queryReplace(error.getMessage()));
 		out.print("</m:message>\n");
 	    } else {
 		Exception ex = error.getException();
 		if (ex instanceof NumberFormatException) {
-		    out.print("<m:errorsubtype>invalid-number"+
-			      "</m:error-subtype>\n");
+		    out.print("\t\t\t<m:errorsubtype>invalid-number"
+			      + "</m:error-subtype>\n");
 		} else {
-		    out.print("<m:message>");
+		    out.print("\t\t\t<m:message>");
 		    out.print(queryReplace(ex.getMessage()));
 		    out.print("</m:message>\n");
 		}
 	    }
 	    if (error.getSkippedString() != null) {
-		out.print("<m:skippedstring>");
+		out.print("\t\t\t<m:skippedstring>");
 		out.print(queryReplace(error.getSkippedString()));
 		out.print("</m:skippedstring>\n");
 	    } else if (error.getExp() != null) {
-		out.print("<m:expression>\n<m:start>");
+		out.print("\t\t\t<m:expression>\n\t\t\t\t<m:start>");
 		out.print(queryReplace(error.getExp().toStringFromStart()));
-		out.print("</m:start>\n<m:end>");
+		out.print("</m:start>\n\t\t\t\t<m:end>");
 		out.print(queryReplace(error.getExp().toString()));
-		out.print("</m:end>\n</m:expression>\n");		
+		out.print("</m:end>\n\t\t\t</m:expression>\n");
 	    }
 	} else {
-	    out.print("<m:errorsubtype>unrecognized</m:errorsubtype>\n");
-	    out.print("<m:skippedstring>");
+	    out.print("\t\t\t<m:errorsubtype>unrecognized</m:errorsubtype>\n");
+	    out.print("\t\t\t<m:skippedstring>");
 	    out.print(queryReplace(error.getSkippedString()));
 	    out.print("</m:skippedstring>\n");
 	}
     }
 
+    /**
+     * Produce SOAP elements for all the errors found
+     *  in the StyleSheet <i>style</i>	 
+     */
     public void produceError() {
 	String oldSourceFile = null;
 	boolean open = false;
@@ -269,8 +275,7 @@
 	try {
 	    if (errors.getErrorCount() != 0) {
 		int i = 0;
-		for (CssError[] error = errors.getErrors(); 
-		          i < error.length; i++) {
+		for (CssError[] error = errors.getErrors(); i < error.length; i++) {
 		    Exception ex = error[i].getException();
 		    String file = error[i].getSourceFile();
 		    if (!file.equals(oldSourceFile)) {
@@ -281,51 +286,51 @@
 			out.print("<m:errorlist>\n");
 			open = true;
 		    }
-		    out.print("<m:error>\n<m:line>\n");
+		    out.print("\t\t<m:error>\n\t\t\t<m:line>");
 		    out.print(error[i].getLine());
-		    out.print("</m:line>\n<m:errortype>");
+		    out.print("</m:line>\n\t\t\t<m:errortype>");						
 		    if (ex instanceof FileNotFoundException) {
 			out.print("not-found");
-			out.print("</m:errortype>\n<m:message>");
+			out.print("</m:errortype>\n\t\t\t<m:message>");
 			out.print(ex.getMessage());
 			out.print("</m:message>\n");			
 		    } else if (ex instanceof CssParseException) {
 			produceParseException((CssParseException) ex);
 		    } else if (ex instanceof InvalidParamException) {
 			out.print("invalid-parameter");
-			out.print("</m:errortype>\n<m:message>");
+			out.print("</m:errortype>\n\t\t\t<m:message>");
 			out.print(queryReplace(ex.getMessage()));
-			out.print("</m:message>\n");
+			out.print("\t\t\t</m:message>\n");
 		    } else if (ex instanceof IOException) {
 			out.print("IOException</m:errortype>\n");
-			out.print("<m:message>");
+			out.print("\t\t\t<m:message>");
 			out.print(queryReplace(ex.getMessage()));
-			out.print("</m:message>\n");
+			out.print("\t\t\t</m:message>\n");
 		    } else if (error[i] instanceof CssErrorToken) {
 			out.print("csserror</m:errortype>");
 			CssErrorToken terror = (CssErrorToken) error[i];
-			out.print("\n<m:description>");
+			out.print("\n\t\t\t\t<m:description>");
 			out.print(terror.getErrorDescription());
 			out.print("</m:description>\n");
-			out.print("<m:skippedstring>");
+			out.print("\t\t\t\t<m:skippedstring>");
 			out.print(terror.getSkippedString());
 			out.print("</m:skippedstring>\n");
 		    } else {
 			out.print("uncaught");
-			out.print("</m:errortype>\n<m:message>");
+			out.print("</m:errortype>\n\t\t\t<m:message>");
 			out.print(queryReplace(ex.getMessage()));
 			out.print("</m:message>\n");
 			if (ex instanceof NullPointerException) {
 			    // ohoh, a bug
 			    out.print("nullpointer");
-			    out.print("</m:errortype>\n<m:message>");
+			    out.print("</m:errortype>\n\t\t\t<m:message>");
 			    ex.printStackTrace(out);
 			    out.print("</m:message>\n");
 			}
 		    }
-		    out.print("</m:error>\n");
+		    out.print("\t\t</m:error>\n");
 		}
-		out.print("</m:errorlist>");
+		out.print("\t</m:errorlist>");
 	    }
 	} catch (Exception e) {
 	    out.print("<m:processingerror>");
@@ -335,6 +340,10 @@
 	}
     }
     
+    /**
+     * Produce SOAP elements for all the warnings found
+     *  in the StyleSheet <i>style</i>	 
+     */
     public void produceWarning() {
 	boolean open = false;
 	String oldSourceFile = "";
@@ -344,8 +353,7 @@
 	    if (warnings.getWarningCount() != 0) {
 		int i = 0;
 		warnings.sort();
-		for (Warning[] warning = warnings.getWarnings(); 
-		     i < warning.length; i++) {
+		for (Warning[] warning = warnings.getWarnings(); i < warning.length; i++) {
 		    
 		    Warning warn = warning[i];
 		    if (warn.getLevel() <= warningLevel) {
@@ -357,8 +365,8 @@
 			    out.print("<m:warninglist>\n");
 			    open = true;
 			}
-			if (warn.getLine() != oldLine || 
-			    !warn.getWarningMessage().equals(oldMessage)) {
+			if (warn.getLine() != oldLine
+			    || !warn.getWarningMessage().equals(oldMessage)) {
 			    oldLine = warn.getLine();
 			    oldMessage = warn.getWarningMessage();
 			    out.print("<m:warning>\n<m:line>");
@@ -368,13 +376,13 @@
 			    //    if (warn.getLevel() != 0) {
 			    //	ret.append(" Level : ");
 			    //	ret.append(warn.getLevel());
-			    //}
+			    // }
 			    out.print("<m:level>");
 			    out.print(warn.getLevel());
 			    out.print("</m:level>\n");
-//			    out.print("<message>");
-//			    out.print(oldMessage);
-//			    out.print("</message>\n");
+			    // out.print("<message>");
+			    // out.print(oldMessage);
+			    // out.print("</message>\n");
 			    if (warn.getContext() != null) {
 				out.print("<m:context>");
 				out.print(warn.getContext());
@@ -394,6 +402,12 @@
 	}
     }
     
+    /*
+     * Replace all occurences of < and > in a String with
+     *  their html values: &lt; and &gt;
+     * @param s the String with < and >
+     * @return the corresponding String with &lt; and &gt; replacing < and >
+     */
     private String queryReplace(String s) {
 	if (s != null) {
 	    int len = s.length();
@@ -419,18 +433,17 @@
 	return processStyle(general.getProperty(s), general);
     }
     
-    private String processStyle(String str, Properties prop) {
+    private String processStyle(String str, Utf8Properties prop) {
 	try {
 	    int i = 0;
 	    while ((i = str.indexOf("<!-- #", i)) >= 0) {
 		int lastIndexOfEntity = str.indexOf("-->", i);
-		String entity = 
-		    str.substring(i+6, 
-				  lastIndexOfEntity - 1).toLowerCase();
+		String entity = str.substring(i + 6, lastIndexOfEntity - 1)
+		    .toLowerCase();
 
 		if (entity.equals("rule")) {
                     out.print(str.substring(0, i));
-		    str = str.substring(lastIndexOfEntity+3);
+		    str = str.substring(lastIndexOfEntity + 3);
 		    i = 0;
 		    produceStyleSheet();
 		} else if (entity.equals("selectors")) {
@@ -438,50 +451,51 @@
 			// contextuals selectors
 			String value = prop.getProperty(entity);
 			if (value != null) {
-			    str = str.substring(0, i) + value + 
-				str.substring(lastIndexOfEntity+3);
+			    str = str.substring(0, i) + value
+				+ str.substring(lastIndexOfEntity + 3);
 			} else {
 			    i += 6; // skip this unknown entity
 			}
 		    } else {
-			str = str.substring(lastIndexOfEntity+3);
+			str = str.substring(lastIndexOfEntity + 3);
 			i = 0;
 		    }
 		} else if (entity.equals("selector")) {
-		    str = str.substring(lastIndexOfEntity+3);
+		    str = str.substring(lastIndexOfEntity + 3);
 		    i = 0;
 		} else if (entity.equals("charset")) {
-		    str = str.substring(lastIndexOfEntity+3);
+		    out.print(str.substring(0, i));
+		    str = str.substring(lastIndexOfEntity + 3);
 		    i = 0;
-		    out.print(style.charset);
+		    out.print(ac.getContentEncoding());
 		} else if (entity.equals("declaration")) {
-		    str = str.substring(lastIndexOfEntity+3);
+		    str = str.substring(lastIndexOfEntity + 3);
 		    i = 0;
 		} else if (entity.equals("warning")) {
 		    out.print(str.substring(0, i));
-		    str = str.substring(lastIndexOfEntity+3);
+		    str = str.substring(lastIndexOfEntity + 3);
 		    i = 0;
 		    produceWarning();
 		} else if (entity.equals("error")) {
 		    out.print(str.substring(0, i));
-		    str = str.substring(lastIndexOfEntity+3);
+		    str = str.substring(lastIndexOfEntity + 3);
 		    i = 0;
 		    produceError();
 		} else if (entity.equals("hook-html-validator")) {
 		    out.print(str.substring(0, i));
-		    str = str.substring(lastIndexOfEntity+3);
+		    str = str.substring(lastIndexOfEntity + 3);
 		    i = 0;
 		    if (style.getType().equals("text/html")) { 
 			out.println(ac.getMsg().getGeneratorString("doc-html",
-                                    general.get("file-title").toString()));
+								   general.get("file-title").toString()));
 		    } else {
 			out.println(ac.getMsg().getGeneratorString("doc"));
 		    }
 		} else {
 		    String value = prop.getProperty(entity);
 		    if (value != null) {
-			str = str.substring(0, i) + value + 
-			    str.substring(lastIndexOfEntity+3);
+			str = str.substring(0, i) + value
+			    + str.substring(lastIndexOfEntity + 3);
 		    } else {
 			i += 6; // skip this unknown entity
 		    }
@@ -495,39 +509,43 @@
 	}
     }
     
+    /**
+     * List the available output formats on a PrintWriter
+     * @param out the PrintWriter used to write the listing
+     */
     public final static void printAvailableFormat(PrintWriter out) {
 	Enumeration e = availableFormat.propertyNames();
-	out.println( " -- listing available output format --" );
+	out.println(" -- listing available output format --");
 	while (e.hasMoreElements()) {
 	    String key = ((String) e.nextElement()).toLowerCase();
-	    out.println( "Format : " + key );
-	    out.println( "   File : " + getDocumentName(null, key) );
+	    out.println("Format : " + key);
+	    out.println("   File : " + getDocumentName(null, key));
 	}
 	out.flush();
     }
     
-    private Properties setDocumentBase(String document) {
-	Properties properties = (Properties) formats.get(document);
+    private Utf8Properties setDocumentBase(String document) {
+	Utf8Properties properties = (Utf8Properties) formats.get(document);
 	if (properties == null) {
 	    URL url;
-	    properties = new Properties();
+	    properties = new Utf8Properties();
 	    try {
 		url = StyleSheetGenerator.class.getResource(document);
 		java.io.InputStream f = url.openStream();
 		properties.load(f);
 		f.close();
-		properties.put("author","www-validator-css");
+		properties.put("author", "www-validator-css");
 		properties.put("author-email", "Email.html");
 	    } catch (Exception e) {
 		System.err.println("org.w3c.css.css.StyleSheetGenerator: "
 				   + "couldn't load properties " + document);
-		System.err.println("  " + e.toString() );
+		System.err.println("  " + e.toString());
 		printAvailableFormat(new PrintWriter(System.err));
 	    }
 	    formats.put(document, properties);
 	}
 
-	return new Properties(properties);
+	return new Utf8Properties(properties);
     }
     
     private final static String getDocumentName(ApplContext ac, 
@@ -547,8 +565,8 @@
 		if (minusIndex != -1) {
 		    // suppressed -cn in zh-cn (example)
 		    l = l.substring(0, minusIndex);
-		    document = availableFormat.getProperty(documentName 
-							   + "." + l);
+		    document = availableFormat.getProperty(documentName + "."
+							   + l);
 		}
 		if (document != null) {
 		    break;
@@ -559,8 +577,8 @@
 	    document = availableFormat.getProperty(documentName);
 	}
 	if (document == null) {
-	    System.err.println( "Unable to find " + 
-				documentName + " output format" );
+	    System.err.println("Unable to find " + documentName
+			       + " output format");
 	    return documentName;
 	} else {
 	    return document;
@@ -573,7 +591,8 @@
     
     static {
 	URL url;
-	availableFormat = new Properties();
+	// the different available output formats
+	availableFormat = new Utf8Properties();
 	try {
 	    url = StyleSheetGenerator.class.getResource("format.properties");
 	    java.io.InputStream f = url.openStream();
@@ -582,10 +601,10 @@
 	} catch (Exception e) {
 	    System.err.println("org.w3c.css.css.StyleSheetGenerator: "
 			       + "couldn't load format properties ");
-	    System.err.println("  " + e.toString() );
+	    System.err.println("  " + e.toString());
 	}
-
-	availablePropertiesURL = new Properties();
+	// links to properties documentation
+	availablePropertiesURL = new Utf8Properties();
 	try {
 	    url = StyleSheetGenerator.class.getResource("urls.properties");
 	    java.io.InputStream f = url.openStream();
@@ -594,7 +613,7 @@
 	} catch (Exception e) {
 	    System.err.println("org.w3c.css.css.StyleSheetGenerator: "
 			       + "couldn't load URLs properties ");
-	    System.err.println("  " + e.toString() );
+	    System.err.println("  " + e.toString());
 	}
     }
 }
Received on Tuesday, 12 July 2005 13:45:49 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 26 April 2012 12:54:48 GMT