- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Tue, 08 Aug 2006 15:17:51 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/css In directory hutz:/tmp/cvs-serv24170/org/w3c/css/css Modified Files: format.properties StyleReportFactory.java Added Files: StyleReportUCN.java ucn.properties.en Log Message: UCN temporary output added (by Jean-Guilhem Rouel) Index: format.properties =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/css/format.properties,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- format.properties 12 Jul 2005 15:19:40 -0000 1.4 +++ format.properties 8 Aug 2006 15:17:48 -0000 1.5 @@ -21,3 +21,5 @@ text: text.properties soap12.en: soap12.properties.en soap12: soap12.properties.en +ucn.en: ucn.properties.en +ucn: ucn.properties.en \ No newline at end of file --- NEW FILE: StyleReportUCN.java --- // $Id: StyleReportUCN.java,v 1.1 2006/08/08 15:17:49 ylafon Exp $ // Author: Yves Lafon <ylafon@w3.org> // (c) COPYRIGHT MIT, ERCIM and Keio, 2003. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.css.css; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import java.net.URL; 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.TimeZone; import java.util.Vector; import org.w3c.css.parser.CssError; import org.w3c.css.parser.CssErrorToken; import org.w3c.css.parser.CssParseException; import org.w3c.css.parser.CssPrinterStyle; import org.w3c.css.parser.CssSelectors; import org.w3c.css.parser.Errors; import org.w3c.css.properties.css1.CssProperty; import org.w3c.css.util.ApplContext; import org.w3c.css.util.InvalidParamException; import org.w3c.css.util.Utf8Properties; import org.w3c.css.util.Util; import org.w3c.css.util.Warning; import org.w3c.css.util.Warnings; /** * @version $Revision: 1.1 $ */ public final class StyleReportUCN extends StyleReport implements CssPrinterStyle { StyleSheet style; Vector items; Warnings warnings; Errors errors; ApplContext ac; private CssSelectors selector; private PrintWriter out; private int warningLevel; private Utf8Properties general; private static Utf8Properties availableFormat; private static Utf8Properties availablePropertiesURL; private static Hashtable formats = new Hashtable(); int counter = 0; /** * 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) */ public StyleReportUCN(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); } this.ac = ac; this.style = style; general = new Utf8Properties(setDocumentBase(getDocumentName(ac, document))); general.put("file-title", title); warnings = style.getWarnings(); errors = style.getErrors(); items = style.newGetRules(); 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"); if (ac.getContentEncoding() != null) { general.put("encoding", " encoding=\"" + ac.getContentEncoding() + "\" "); } else { general.put("encoding", " "); } if (errors.getErrorCount() == 0) { desactivateError(); } if ((errors.getErrorCount() != 0) || (!title.startsWith("http://"))) { general.put("no-errors", ""); } if (style.charset == null) { general.put("charset-rule", ""); } if (warnings.getWarningCount() == 0 || warningLevel == -1) { general.put("go-warnings", ""); // remove go-warnings general.put("warnings", ""); // remove warnings } if (items.size() == 0) { general.put("go-rules", ""); // remove go-rules general.put("rules", ""); // remove rules general.put("no-errors", ""); } else { general.put("no-rules", ""); // remove no-rules } if (errors.getErrorCount() != 0 || warnings.getWarningCount() != 0) { // remove no-error-or-warning general.put("no-error-or-warning", ""); } 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")); } catch (Exception e) { df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.US); } } if (df != null) { general.put("today", df.format(new Date())); } else { general.put("today", new Date().toString()); } SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd'T'hh:mss'Z'"); formatter.setTimeZone(TimeZone.getTimeZone("UTC")); general.put("currentdate", formatter.format(new Date())); } public void desactivateError() { general.put("go-errors", ""); // remove go-errors general.put("errors", ""); // remove errors } /** * Returns a string representation of the object. */ public void print(PrintWriter out) { this.out = out; // must be in first ! String output = processSimple("document"); if (output != null) { out.println(output); } else { out.println(ac.getMsg().getGeneratorString("request")); } out.flush(); } // prints the stylesheet at the screen public void produceStyleSheet() { } public void print(CssProperty property) { Utf8Properties prop = new Utf8Properties(general); prop.put("property-name", property.getPropertyName().toString()); prop.put("property-value", property.toString()); if (!property.getImportant()) { prop.put("important-style", ""); } out.print(processStyle(prop.getProperty("declaration"), prop)); } 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();) { Object t = e.nextElement(); if (t != null) { buf.append(t); if (e.hasMoreElements()) buf.append(", "); } } if (buf.length() != 0) { out.print("parse-error</errortype>\n <context>"); out.print(buf); out.print("</context>\n"); } } else { out.print("parse-error</errortype>\n"); } String name = error.getProperty(); if ((name != null) && (getURLProperty(name) != null)) { /*out.print(" <property>"); out.print(name); out.print("</property>\n");*/ } if ((error.getException() != null) && (error.getMessage() != null)) { if (error.isParseException()) { out.print(" <message>"); out.print(queryReplace(error.getMessage())); out.print("</message>\n"); } else { Exception ex = error.getException(); if (ex instanceof NumberFormatException) { /*out.print(" <errorsubtype>invalid-number" + "</error-subtype>\n");*/ } else { out.print(" <message>"); out.print(queryReplace(ex.getMessage())); out.print("</message>\n"); } } /*if (error.getSkippedString() != null) { out.print(" <skippedstring>"); out.print(queryReplace(error.getSkippedString())); out.print("</skippedstring>\n"); } else if (error.getExp() != null) { out.print(" <expression>\n <start>"); out.print(queryReplace(error.getExp().toStringFromStart())); out.print("</start>\n <end>"); out.print(queryReplace(error.getExp().toString())); out.print("</end>\n </expression>\n"); }*/ } else { /*out.print(" <errorsubtype>unrecognized</errorsubtype>\n"); out.print(" <skippedstring>"); out.print(queryReplace(error.getSkippedString())); out.print("</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; try { if (errors.getErrorCount() != 0) { int i = 0; for (CssError[] error = errors.getErrors(); i < error.length; i++) { Exception ex = error[i].getException(); String file = error[i].getSourceFile(); if (!file.equals(oldSourceFile)) { oldSourceFile = file; if (open) { out.print(" </errorlist>\n"); } out.print(" <errorlist>\n"); out.print(" <uri>" + file + "</uri>\n"); open = true; } out.print(" <error>\n <line>"); out.print(error[i].getLine()); out.print("</line>\n <errortype>"); if (ex instanceof FileNotFoundException) { out.print("not-found"); out.print("</errortype>\n <message>"); out.print(ex.getMessage()); out.print("</message>\n"); } else if (ex instanceof CssParseException) { produceParseException((CssParseException) ex); } else if (ex instanceof InvalidParamException) { out.print("invalid-parameter"); out.print("</errortype>\n <message>"); out.print(queryReplace(ex.getMessage())); out.print(" </message>\n"); } else if (ex instanceof IOException) { out.print("IOException</errortype>\n"); out.print(" <message>"); out.print(queryReplace(ex.getMessage())); out.print(" </message>\n"); } else if (error[i] instanceof CssErrorToken) { out.print("csserror</errortype>"); CssErrorToken terror = (CssErrorToken) error[i]; out.print("\n <description>"); out.print(terror.getErrorDescription()); out.print("</description>\n"); // out.print(" <skippedstring>"); // out.print(terror.getSkippedString()); // out.print(" </skippedstring>\n"); } else { out.print("uncaught"); out.print("</errortype>\n <message>"); out.print(queryReplace(ex.getMessage())); out.print("</message>\n"); if (ex instanceof NullPointerException) { // ohoh, a bug out.print("nullpointer"); out.print("</errortype>\n <message>"); ex.printStackTrace(out); out.print("</message>\n"); } } out.print(" </error>\n"); } out.print(" </errorlist>"); } } catch (Exception e) { out.print("<processingerror>"); out.println(ac.getMsg().getGeneratorString("request")); e.printStackTrace(out); out.print("</processingerror>\n"); } } /** * Produce SOAP elements for all the warnings found * in the StyleSheet <i>style</i> */ public void produceWarning() { boolean open = false; String oldSourceFile = ""; int oldLine = -1; String oldMessage = ""; try { if (warnings.getWarningCount() != 0) { int i = 0; warnings.sort(); for (Warning[] warning = warnings.getWarnings(); i < warning.length; i++) { Warning warn = warning[i]; if (!warn.getSourceFile().equals(oldSourceFile)) { if (open) { out.print(" </warninglist>\n"); } oldSourceFile = warn.getSourceFile(); out.print(" <warninglist>\n"); out.print(" <uri>" + oldSourceFile + "</uri>\n"); open = true; } if (warn.getLevel() <= warningLevel) { // if (warn.getLine() != oldLine // || !warn.getWarningMessage().equals(oldMessage)) { oldLine = warn.getLine(); oldMessage = warn.getWarningMessage(); out.print(" <warning>\n <line>"); out.print(oldLine); out.print("</line>\n"); // if (warn.getLevel() != 0) { // ret.append(" Level : "); // ret.append(warn.getLevel()); // } out.print(" <level>"); out.print(warn.getLevel()); out.print("</level>\n"); out.print(" <message>"); out.print(oldMessage); out.print("</message>\n"); if (warn.getContext() != null) { out.print(" <context>"); out.print(warn.getContext()); out.print("</context>\n"); } out.print(" </warning>\n"); // } } } out.print(" </warninglist>"); } } catch (Exception e) { out.print("<processingerror>"); out.println(ac.getMsg().getGeneratorString("request")); e.printStackTrace(out); out.print("</processingerror>\n"); } } /* * Replace all occurences of <, >, &, ' and " in a String with * their html values: <, >, &, &aps; and " * @param s the String with < and > * @return the corresponding String with <, > ... replacing <, > ... */ private String queryReplace(String s) { if (s != null) { int len = s.length(); StringBuffer ret = new StringBuffer(len); for (int i = 0; i < len; i++) { char c = s.charAt(i); if (c == '<') { ret.append("<"); } else if (c == '>') { ret.append(">"); } else if (c == '&') { ret.append("&"); } else if (c == '\'') { ret.append("'"); } else if (c == '"') { ret.append("""); } else { ret.append(c); } } return ret.toString(); } else { return "[empty string]"; } } private final String processSimple(String s) { return processStyle(general.getProperty(s), general); } 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(); if (entity.equals("rule")) { out.print(str.substring(0, i)); str = str.substring(lastIndexOfEntity + 3); i = 0; produceStyleSheet(); } else if (entity.equals("selectors")) { if (selector.getNext() != null) { // contextuals selectors String value = prop.getProperty(entity); if (value != null) { str = str.substring(0, i) + value + str.substring(lastIndexOfEntity + 3); } else { i += 6; // skip this unknown entity } } else { str = str.substring(lastIndexOfEntity + 3); i = 0; } } else if (entity.equals("selector")) { str = str.substring(lastIndexOfEntity + 3); i = 0; } else if (entity.equals("charset")) { out.print(str.substring(0, i)); str = str.substring(lastIndexOfEntity + 3); i = 0; out.print(ac.getContentEncoding()); } else if (entity.equals("declaration")) { str = str.substring(lastIndexOfEntity + 3); i = 0; } else if (entity.equals("warning")) { out.print(str.substring(0, i)); str = str.substring(lastIndexOfEntity + 3); i = 0; produceWarning(); } else if (entity.equals("error")) { out.print(str.substring(0, i)); str = str.substring(lastIndexOfEntity + 3); i = 0; produceError(); } else if (entity.equals("info")) { out.print(str.substring(0, i)); str = str.substring(lastIndexOfEntity + 3); i = 0; produceMisc(); } else if (entity.equals("hook-html-validator")) { out.print(str.substring(0, i)); 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())); } else { out.println(ac.getMsg().getGeneratorString("doc")); } } else if(entity.equals("lang")) { out.print(str.substring(0, i)); str = str.substring(lastIndexOfEntity + 3); i = 0; String lang = ac.getContentLanguage(); if(lang == null || lang.equals("")) { lang = "en"; } out.print(lang); } else { String value = prop.getProperty(entity); if (value != null) { str = str.substring(0, i) + value + str.substring(lastIndexOfEntity + 3); } else { i += 6; // skip this unknown entity } } } return str; } catch (Exception e) { e.printStackTrace(); return str; } } /** * */ private void produceMisc() { if(errors.getErrorCount() == 0) { out.println("<informations xml:lang=\"" + ac.getContentLanguage() + "\">"); out.println(" <infocount>1</infocount>"); out.println(" <infolist>"); out.println(" <uri>" + general.get("file-title").toString() + "</uri>"); out.println(" <info>"); out.println(" <message> This document validates as " + ac.getCssVersion() + "!</message>"); out.println(" <longmessage><a href=\"http://jigsaw.w3.org/css-validator/\">"); out.println(" <img src=\"http://jigsaw.w3.org/css-validator/images/vcss\" alt=\"Valid CSS!\" /></a></longmessage>"); out.println(" <longmessage>To show your readers that you've taken the care to create an interoperable Web page, you may display this icon on any page that validates. Here is the XHTML you could use to add this icon to your Web page:</longmessage>"); out.println(" <longmessage>"); out.println(" <code>"); out.println("<p>"); out.println(" <a href="http://jigsaw.w3.org/css-validator/">"); out.println(" <img style="border:0;width:88px;height:31px""); out.println(" src="http://jigsaw.w3.org/css-validator/images/vcss""); out.println(" alt="Valid CSS!" />"); out.println(" </a>"); out.println("</p>"); out.println("</code>(close the img tag with > instead of /gt; if using HTML <= 4.01)</longmessage>"); out.println(" <longmessage>If you like, you can download a copy of this image to keep in your local web directory, and change the XHTML fragment above to reference your local image rather than the one on this server.</longmessage>"); out.println(" <longmessage>If you would like to create a link to this page (i.e., this validation result) to make it easier to re-validate this page in the future or to allow others to validate your page, the URI is:</longmessage>"); out.println(" <longmessage><code>"+ "http://jigsaw.w3.org/css-validator/validator?uri=http://www.w3.org "+ "or http://jigsaw.w3.org/css-validator/check/referer</code> (for HTML/XML document only)"+ "</longmessage>"); out.println(" <longmessage>(Or, you can just add the current page to your bookmarks or hotlist.)</longmessage>"); out.println(" <longmessage>To work as intended, your CSS style sheet needs a correct document parse tree. This means you should use <a href=\"http://validator.w3.org/\">valid HTML</a>.</longmessage>"); out.println(" </info>"); out.println(" </infolist>"); out.println("</informations>"); } } /** * 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 --"); while (e.hasMoreElements()) { String key = ((String) e.nextElement()).toLowerCase(); out.println("Format : " + key); out.println(" File : " + getDocumentName(null, key)); } out.flush(); } private Utf8Properties setDocumentBase(String document) { Utf8Properties properties = (Utf8Properties) formats.get(document); if (properties == null) { URL url; 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-email", "Email.html"); } catch (Exception e) { System.err.println("org.w3c.css.css.StyleSheetGenerator: " + "couldn't load properties " + document); System.err.println(" " + e.toString()); printAvailableFormat(new PrintWriter(System.err)); } formats.put(document, properties); } return new Utf8Properties(properties); } private final static String getDocumentName(ApplContext ac, String documentName) { documentName = documentName.toLowerCase(); String document = null; if (ac != null && ac.getLang() != null) { StringTokenizer tokens = new StringTokenizer(ac.getLang(), ","); while (tokens.hasMoreTokens()) { String l = tokens.nextToken().trim().toLowerCase(); document = availableFormat.getProperty(documentName + "." + l); if (document != null) { break; } int minusIndex = l.indexOf('-'); if (minusIndex != -1) { // suppressed -cn in zh-cn (example) l = l.substring(0, minusIndex); document = availableFormat.getProperty(documentName + "." + l); } if (document != null) { break; } } } if (document == null) { document = availableFormat.getProperty(documentName); } if (document == null) { System.err.println("Unable to find " + documentName + " output format"); return documentName; } else { return document; } } private final static String getURLProperty(String name) { return availablePropertiesURL.getProperty(name); } static { URL url; // the different available output formats availableFormat = new Utf8Properties(); try { url = StyleSheetGenerator.class.getResource("format.properties"); java.io.InputStream f = url.openStream(); availableFormat.load(f); f.close(); } catch (Exception e) { System.err.println("org.w3c.css.css.StyleSheetGenerator: " + "couldn't load format properties "); System.err.println(" " + e.toString()); } // links to properties documentation availablePropertiesURL = new Utf8Properties(); try { url = StyleSheetGenerator.class.getResource("urls.properties"); java.io.InputStream f = url.openStream(); availablePropertiesURL.load(f); f.close(); } catch (Exception e) { System.err.println("org.w3c.css.css.StyleSheetGenerator: " + "couldn't load URLs properties "); System.err.println(" " + e.toString()); } } } --- NEW FILE: ucn.properties.en --- # used by StyleSheet2HTML # entites used by the HTML generator # You have some predefined entities : # file-title : the name of the style sheet # today : the date of this day # errors-count : number of errors # warnings-count : number of warnings # items-count : number of rules in your style sheet # author : my name :-) # author-email : my e-mail :-)) # you can add newlines like this : \n # # How to write all rules # # be careful, use only : # - selector and declaration entities in the entity rule # - element, class, id, pseudo-class and pseudo-element entities in the entity selector # - property-name, property-value, important-style and not-css1-style entities in the entity declaration # FIXME - lots of stuff to add here, it is only a skeleton to test things. # the beginning of the document document: \ <?xml version='1.0' encoding="<!-- #charset -->"?>\n\ \ \ \ \ <observationresponse xmlns="http://www.w3.org/unicorn/observationresponse"\n\ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n\ xsi:schemaLocation="http://www.w3.org/unicorn/observationresponse file:/home/jean/observer-response.xsd"> \n\ \ \ \ \ \ \ <uri><!-- #file-title --></uri> \n\ \ \ \ \ \ \ <checkedby>http://jigsaw.w3.org/css-validator/</checkedby>\n\ \ \ \ \ \ \ <version><!-- #cssversion --></version>\n\ \ \ \ \ \ \ <date><!-- #currentdate --></date>\n\ \ \ \ \ \ \ <passed><!-- #isvalid --></passed>\n\ \ \ \ \ \ \ <result>\n\ \ \ \ \ \ \ \ \ <errors xml:lang="<!-- #lang -->">\n\ \ \ \ \ \ \ \ \ \ \ <errorcount><!-- #errors-count --></errorcount>\n\ <!-- #error -->\n\ \ \ \ \ \ \ \ \ </errors>\n\ \ \ \ \ \ \ \ \ <warnings xml:lang="<!-- #lang -->">\n\ \ \ \ \ \ \ \ \ \ \ <warningcount><!-- #warnings-count --></warningcount>\n\ <!-- #warning -->\n\ \ \ \ \ \ \ \ \ </warnings>\n\ \ \ \ \ \ \ \ \ <!-- #info -->\n\ \ \ \ \ \ \ </result>\n\ \ \ \ \ </observationresponse> Index: StyleReportFactory.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/css/StyleReportFactory.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- StyleReportFactory.java 26 Apr 2006 12:44:14 -0000 1.6 +++ StyleReportFactory.java 8 Aug 2006 15:17:48 -0000 1.7 @@ -32,7 +32,10 @@ if(document.equals("text")) { return new StyleSheetGenerator2(title, style, document, - warningLevel); + warningLevel); + } + if(document.equals("ucn")) { + return new StyleReportUCN(ac, title, style, document, warningLevel); } return new StyleSheetGeneratorHTML2(ac, title, style, "html",
Received on Tuesday, 8 August 2006 15:18:00 UTC