W3C home > Mailing lists > Public > www-validator-cvs@w3.org > February 2009

2002/css-validator/org/w3c/css/util Messages.java,1.29,1.30 Warning.java,1.9,1.10

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Wed, 25 Feb 2009 20:44:52 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1LcQce-0000sr-9Z@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/util
In directory hutz:/tmp/cvs-serv3171/org/w3c/css/util

Modified Files:
	Messages.java Warning.java 
Log Message:
Fixes http://www.w3.org/Bugs/Public/show_bug.cgi?id=5770
Added accessors to get X/HTML escaped versions of differents String
(like URL representation, selectors, warning messages, etc).
The markup-based output were modified accordingly.



Index: Warning.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/Warning.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- Warning.java	22 Feb 2009 15:16:18 -0000	1.9
+++ Warning.java	25 Feb 2009 20:44:50 -0000	1.10
@@ -144,6 +144,13 @@
     }
 
     /**
+     * Get the source file
+     */
+    public String getSourceFileEscaped() {
+	return Messages.escapeString(sourceFile);
+    }
+
+    /**
      * Get the line number.
      */
     public int getLine() {
@@ -158,6 +165,13 @@
     }
 
     /**
+     * Get the message.
+     */
+    public String getWarningMessageEscaped() {
+	return Messages.escapeString(warningMessage);
+    }
+
+    /**
      * Get the warning level.
      */
     public int getLevel() {

Index: Messages.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/Messages.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- Messages.java	24 Feb 2009 23:27:08 -0000	1.29
+++ Messages.java	25 Feb 2009 20:44:50 -0000	1.30
@@ -162,6 +162,30 @@
 	return getString("servlet."+message);
     }
 
+    /**
+     * escape string
+     */
+    static public String escapeString(String orig) {
+	if (orig != null) {
+            int len = orig.length();
+            StringBuilder ret = new StringBuilder(len+16);
+            char c;
+	    
+            for (int i = 0; i < len; i++) {
+                switch (c = orig.charAt(i)) {
+                case '&'  : ret.append("&amp;"); break;
+                case '\'' : ret.append("&#39;"); break;
+                case '"'  : ret.append("&quot;"); break;
+                case '<'  : ret.append("&lt;"); break;
+                case '>'  : ret.append("&gt;"); break;
+                default   : ret.append(c);
+                }
+            }
+            return ret.toString();
+        }
+        return "[empty string]";
+    }
+
     public String getString(String message, Vector<String> params) {
 	if ((params == null) || params.size() == 0) {
 	    return getString(message);
Received on Wednesday, 25 February 2009 20:45:01 GMT

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