W3C home > Mailing lists > Public > www-validator-cvs@w3.org > August 2011

2002/css-validator/org/w3c/css/util ApplContext.java,1.18,1.19 Messages.java,1.40,1.41 Util.java,1.6,1.7

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Mon, 29 Aug 2011 07:21:04 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1Qxw9Y-0004oC-41@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/util
In directory hutz:/tmp/cvs-serv18238/css/util

Modified Files:
	ApplContext.java Messages.java Util.java 
Log Message:
genericity + updated code to 5.0 stds

Index: ApplContext.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/ApplContext.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- ApplContext.java	12 Jan 2011 15:01:56 -0000	1.18
+++ ApplContext.java	29 Aug 2011 07:21:01 -0000	1.19
@@ -9,49 +9,47 @@
 package org.w3c.css.util;
 
 
+import org.apache.velocity.io.UnicodeInputStream;
+import org.w3c.css.parser.Frame;
+import org.w3c.www.http.HttpAcceptCharset;
+import org.w3c.www.http.HttpAcceptCharsetList;
+import org.w3c.www.http.HttpFactory;
+
 import java.io.ByteArrayInputStream;
-import java.io.InputStream;
 import java.io.IOException;
-
-import java.util.HashMap;
+import java.io.InputStream;
 import java.net.URL;
 import java.nio.charset.Charset;
 import java.nio.charset.IllegalCharsetNameException;
 import java.nio.charset.UnsupportedCharsetException;
-
-import org.w3c.css.parser.Frame;
-import org.w3c.www.http.HttpAcceptCharset;
-import org.w3c.www.http.HttpAcceptCharsetList;
-import org.w3c.www.http.HttpFactory;
-
-import org.apache.velocity.io.UnicodeInputStream;
+import java.util.HashMap;
 
 /**
- * @version $Revision$
  * @author Philippe Le Hegaret
+ * @version $Revision$
  */
 public class ApplContext {
 
     // the charset of the first source (url/uploaded/text)
-    public static Charset defaultCharset;  
+    public static Charset defaultCharset;
     public static Charset utf8Charset;
 
     static {
-	try {
-	    defaultCharset = Charset.forName("iso-8859-1");
-	    utf8Charset = Charset.forName("utf-8");
-	} catch (Exception ex) {
-	    // we are in deep trouble here
-	    defaultCharset = null;
-	    utf8Charset    = null;
-	}
+        try {
+            defaultCharset = Charset.forName("iso-8859-1");
+            utf8Charset = Charset.forName("utf-8");
+        } catch (Exception ex) {
+            // we are in deep trouble here
+            defaultCharset = null;
+            utf8Charset = null;
+        }
     }
 
     // charset definition of traversed URLs
-    private HashMap<URL,Charset> uricharsets = null;
+    private HashMap<URL, Charset> uricharsets = null;
 
     // namespace definitions
-    private HashMap<URL,HashMap<String,String>> namespaces = null;
+    private HashMap<URL, HashMap<String, String>> namespaces = null;
 
     // default prefix
     public static String defaultPrefix = "*defaultprefix*";
@@ -72,143 +70,143 @@
     boolean treatVendorExtensionsAsWarnings = false;
 
     FakeFile fakefile = null;
-    String   faketext = null;
-    URL      fakeurl  = null;
+    String faketext = null;
+    URL fakeurl = null;
 
     /**
      * Creates a new ApplContext
      */
     public ApplContext(String lang) {
-	this.lang = lang;
-	msgs = new Messages(lang);
+        this.lang = lang;
+        msgs = new Messages(lang);
     }
 
     public int getWarningLevel() {
-	return warningLevel;
+        return warningLevel;
     }
 
     public void setWarningLevel(int warningLevel) {
-	this.warningLevel = warningLevel;
+        this.warningLevel = warningLevel;
     }
 
     // as ugly as everything else
     public String getCredential() {
-	return credential;
+        return credential;
     }
 
     public void setCredential(String credential) {
-	this.credential = credential;
+        this.credential = credential;
     }
 
     public void setFrame(Frame frame) {
-	this.frame = frame;
-	frame.ac = this;
+        this.frame = frame;
+        frame.ac = this;
     }
 
     public Frame getFrame() {
-	return frame;
+        return frame;
     }
 
     public Class getCssSelectorsStyle() {
-	return cssselectorstyle;
+        return cssselectorstyle;
     }
 
     public void setCssSelectorsStyle(Class s) {
-	cssselectorstyle = s;
+        cssselectorstyle = s;
     }
 
     public Messages getMsg() {
-	return msgs;
+        return msgs;
     }
 
     public String getContentType() {
-	return (msgs != null) ? msgs.getString("content-type") : null;
+        return (msgs != null) ? msgs.getString("content-type") : null;
     }
 
     public String getContentLanguage() {
-	return (msgs != null) ? msgs.getString("content-language") : null;
+        return (msgs != null) ? msgs.getString("content-language") : null;
     }
 
     /**
      * Searches the properties list for a content-encoding one. If it does not
      * exist, searches for output-encoding-name. If it still does not exists,
      * the method returns the default utf-8 value
-     * 
+     *
      * @return the output encoding of this ApplContext
      */
     public String getContentEncoding() {
-	// return (msgs != null) ? msgs.getString("content-encoding") : null;
-	String res = null;
-	if (msgs != null) {
-	    res = msgs.getString("content-encoding");
-	    if (res == null) {
-		res = msgs.getString("output-encoding-name");
-	    }
-	    if (res != null) {
-		// if an encoding has been found, return it
-		return res;
-	    }
-	}
-	// default encoding
-	return Utf8Properties.ENCODING;
+        // return (msgs != null) ? msgs.getString("content-encoding") : null;
+        String res = null;
+        if (msgs != null) {
+            res = msgs.getString("content-encoding");
+            if (res == null) {
+                res = msgs.getString("output-encoding-name");
+            }
+            if (res != null) {
+                // if an encoding has been found, return it
+                return res;
+            }
+        }
+        // default encoding
+        return Utf8Properties.ENCODING;
     }
-    
+
     public String getLang() {
-	return lang;
+        return lang;
     }
-    
+
     public void setCssVersion(String cssversion) {
-	this.cssversion = cssversion;
+        this.cssversion = cssversion;
     }
 
     public String getCssVersion() {
-	if (cssversion == null) {
-	    cssversion = "css2";
-	}
-	return cssversion;
+        if (cssversion == null) {
+            cssversion = "css2";
+        }
+        return cssversion;
     }
 
     public void setProfile(String profile) {
-	this.profile = profile;
+        this.profile = profile;
     }
 
     public String getProfile() {
-	if (profile == null) {
-	    return "";
-	}
-	return profile;
+        if (profile == null) {
+            return "";
+        }
+        return profile;
     }
 
     public void setOrigin(int origin) {
-	this.origin = origin;
+        this.origin = origin;
     }
 
     public int getOrigin() {
-	return origin;
+        return origin;
     }
 
     public void setMedium(String medium) {
-	this.medium = medium;
+        this.medium = medium;
     }
 
     public String getMedium() {
-	return medium;
+        return medium;
     }
 
     public String getInput() {
-	return input;
+        return input;
     }
 
     public void setInput(String input) {
-	this.input = input;
+        this.input = input;
     }
-	
+
     public String getLink() {
-	return link;
+        return link;
     }
 
     public void setLink(String queryString) {
-	this.link = queryString;
+        this.link = queryString;
     }
 
     public boolean getTreatVendorExtensionsAsWarnings() {
@@ -216,7 +214,7 @@
     }
 
     public void setTreatVendorExtensionsAsWarnings(
-        boolean treatVendorExtensionsAsWarnings) {
+            boolean treatVendorExtensionsAsWarnings) {
         this.treatVendorExtensionsAsWarnings = treatVendorExtensionsAsWarnings;
     }
 
@@ -224,233 +222,231 @@
      * Sets the content encoding to the first charset that appears in
      * <i>acceptCharset</i>. If the charset is not supported, the content
      * encoding will be utf-8
-     * 
-     * @param acceptCharset
-     *            a String representing the Accept-Charset request parameter
+     *
+     * @param acceptCharset a String representing the Accept-Charset request parameter
      */
     public void setContentEncoding(String acceptCharset) {
-	if (acceptCharset != null) {
-	    // uses some Jigsaw classes to parse the Accept-Charset
-	    // these classes need to load a lot of stuff, so it may be quite
-	    // long the first time
-	    HttpAcceptCharsetList charsetList;
-	    HttpAcceptCharset[] charsets;
+        if (acceptCharset != null) {
+            // uses some Jigsaw classes to parse the Accept-Charset
+            // these classes need to load a lot of stuff, so it may be quite
+            // long the first time
+            HttpAcceptCharsetList charsetList;
+            HttpAcceptCharset[] charsets;
 
-	    charsetList = HttpFactory.parseAcceptCharsetList(acceptCharset);
-	    charsets = (HttpAcceptCharset[]) charsetList.getValue();
+            charsetList = HttpFactory.parseAcceptCharsetList(acceptCharset);
+            charsets = (HttpAcceptCharset[]) charsetList.getValue();
 
-	    String encoding = null;
-	    double quality = 0.0;
+            String encoding = null;
+            double quality = 0.0;
 
-	    String biasedcharset = getMsg().getString("output-encoding-name");
+            String biasedcharset = getMsg().getString("output-encoding-name");
 
-	    for (int i = 0; i < charsets.length && quality < 1.0; i++) {
-		HttpAcceptCharset charset = charsets[i];
+            for (int i = 0; i < charsets.length && quality < 1.0; i++) {
+                HttpAcceptCharset charset = charsets[i];
 
-		String currentCharset = charset.getCharset();
+                String currentCharset = charset.getCharset();
 
-		// checks that the charset is supported by Java
+                // checks that the charset is supported by Java
 
-		if (isCharsetSupported(currentCharset)) {
-		    double currentQuality = charset.getQuality();
+                if (isCharsetSupported(currentCharset)) {
+                    double currentQuality = charset.getQuality();
 
-		    // we prefer utf-8
-		    // FIXME (the bias value and the biased charset
-		    // should be dependant on the language)
-		    if ((biasedcharset != null) && 
-			!biasedcharset.equalsIgnoreCase(currentCharset)) {
-			currentQuality = currentQuality * 0.5;
-		    }
-		    if (currentQuality > quality) {
-			quality = currentQuality;
-			encoding = charset.getCharset();
-		    }
-		}
-	    }
-	    if (encoding != null) {
-		getMsg().properties.setProperty("content-encoding", encoding);
-	    } else {
-		// no valid charset
-		getMsg().properties.remove("content-encoding");
-	    }
-	} else {
-	    // no Accept-Charset given
-	    getMsg().properties.remove("content-encoding");
-	}
+                    // we prefer utf-8
+                    // FIXME (the bias value and the biased charset
+                    // should be dependant on the language)
+                    if ((biasedcharset != null) &&
+                            !biasedcharset.equalsIgnoreCase(currentCharset)) {
+                        currentQuality = currentQuality * 0.5;
+                    }
+                    if (currentQuality > quality) {
+                        quality = currentQuality;
+                        encoding = charset.getCharset();
+                    }
+                }
+            }
+            if (encoding != null) {
+                getMsg().properties.setProperty("content-encoding", encoding);
+            } else {
+                // no valid charset
+                getMsg().properties.remove("content-encoding");
+            }
+        } else {
+            // no Accept-Charset given
+            getMsg().properties.remove("content-encoding");
+        }
     }
 
     private boolean isCharsetSupported(String charset) {
-	if ("*".equals(charset)) {
-	    return true;
-	}
-	try {
-	    return Charset.isSupported(charset);
-	} catch (Exception e) {
-	    return false;
-	}
+        if ("*".equals(charset)) {
+            return true;
+        }
+        try {
+            return Charset.isSupported(charset);
+        } catch (Exception e) {
+            return false;
+        }
     }
 
     /**
      * used for storing the charset of the document in use
-     *  and its update by a @charset statement, or through 
-     *  automatic discovery
+     * and its update by a @charset statement, or through
+     * automatic discovery
      */
     public void setCharsetForURL(URL url, String charset) {
-	if (uricharsets == null) {
-	    uricharsets = new HashMap<URL,Charset>();
-	}
-	Charset c = null;
-	try {
-	    c = Charset.forName(charset);
-	} catch (IllegalCharsetNameException icex) {
-	    // FIXME add a warning in the CSS
-	} catch (UnsupportedCharsetException ucex) {
-	    // FIXME inform about lack of support
-	}
-	if (c != null) {
-	    uricharsets.put(url, c);
-	}
+        if (uricharsets == null) {
+            uricharsets = new HashMap<URL, Charset>();
+        }
+        Charset c = null;
+        try {
+            c = Charset.forName(charset);
+        } catch (IllegalCharsetNameException icex) {
+            // FIXME add a warning in the CSS
+        } catch (UnsupportedCharsetException ucex) {
+            // FIXME inform about lack of support
+        }
+        if (c != null) {
+            uricharsets.put(url, c);
+        }
     }
 
     /**
      * used for storing the charset of the document in use
-     *  and its update by a @charset statement, or through 
-     *  automatic discovery
+     * and its update by a @charset statement, or through
+     * automatic discovery
      */
     public void setCharsetForURL(URL url, Charset charset) {
-	if (uricharsets == null) {
-	    uricharsets = new HashMap<URL,Charset>();
-	}
-	uricharsets.put(url, charset);
+        if (uricharsets == null) {
+            uricharsets = new HashMap<URL, Charset>();
+        }
+        uricharsets.put(url, charset);
     }
-  
+
     /**
      * used for storing the charset of the document in use
-     *  and its update by a @charset statement, or through 
-     *  automatic discovery
+     * and its update by a @charset statement, or through
+     * automatic discovery
      */
     public String getCharsetForURL(URL url) {
-	Charset c;
-	if (uricharsets == null) {
-	    return null;
-	}
-	c = uricharsets.get(url);
-	if (c != null) {
-	    return c.toString();
-	}
-	return null;
+        Charset c;
+        if (uricharsets == null) {
+            return null;
+        }
+        c = uricharsets.get(url);
+        if (c != null) {
+            return c.toString();
+        }
+        return null;
     }
-    
+
     /**
      * used for storing the charset of the document in use
-     *  and its update by a @charset statement, or through 
-     *  automatic discovery
+     * and its update by a @charset statement, or through
+     * automatic discovery
      */
     public Charset getCharsetObjForURL(URL url) {
-	Charset c;
-	if (uricharsets == null) {
-	    return null;
-	}
-	return uricharsets.get(url);
+        Charset c;
+        if (uricharsets == null) {
+            return null;
+        }
+        return uricharsets.get(url);
     }
 
     /**
-     * store content of uploaded file 
+     * store content of uploaded file
      */
     public void setFakeFile(FakeFile fakefile) {
-	this.fakefile = fakefile;
+        this.fakefile = fakefile;
     }
 
     /**
      * store content of entered text
      */
     public void setFakeText(String faketext) {
-	this.faketext = faketext;
+        this.faketext = faketext;
     }
 
-    public InputStream getFakeInputStream(URL source) 
-	throws IOException 
-    {
-	InputStream is = null;
-	if (fakefile != null) {
-	    is = fakefile.getInputStream();
-	}
-	if (faketext != null) {
-	    is = new ByteArrayInputStream(faketext.getBytes());
-	}
-	if (is == null) {
-	    return null;
-	}
-	Charset c = getCharsetObjForURL(source);
-	if (c == null) {
-	    UnicodeInputStream uis = new UnicodeInputStream(is);
-	    String guessedCharset = uis.getEncodingFromStream();
-	    if (guessedCharset != null) {
-		setCharsetForURL(source, guessedCharset);
-	    }
-	    return uis;
-	} else {
-	    if (utf8Charset.compareTo(c) == 0) {
-		return new UnicodeInputStream(is);
-	    }
-	}
-	return is;
+    public InputStream getFakeInputStream(URL source)
+            throws IOException {
+        InputStream is = null;
+        if (fakefile != null) {
+            is = fakefile.getInputStream();
+        }
+        if (faketext != null) {
+            is = new ByteArrayInputStream(faketext.getBytes());
+        }
+        if (is == null) {
+            return null;
+        }
+        Charset c = getCharsetObjForURL(source);
+        if (c == null) {
+            UnicodeInputStream uis = new UnicodeInputStream(is);
+            String guessedCharset = uis.getEncodingFromStream();
+            if (guessedCharset != null) {
+                setCharsetForURL(source, guessedCharset);
+            }
+            return uis;
+        } else {
+            if (utf8Charset.compareTo(c) == 0) {
+                return new UnicodeInputStream(is);
+            }
+        }
+        return is;
     }
-    
+
     public boolean isInputFake() {
-	return ((faketext != null) || (fakefile != null));
+        return ((faketext != null) || (fakefile != null));
     }
 
     public void setFakeURL(String fakeurl) {
-	try {
-	    this.fakeurl = new URL(fakeurl);
-	} catch (Exception ex) {
-	}
+        try {
+            this.fakeurl = new URL(fakeurl);
+        } catch (Exception ex) {
+        }
     }
 
     public URL getFakeURL() {
-	return fakeurl;
+        return fakeurl;
     }
-	
+
     /**
      * support for namespaces
      */
     public void setNamespace(URL url, String prefix, String nsname) {
-	if (namespaces == null) {
-	    namespaces = new HashMap<URL,HashMap<String,String>>();
-	}
-	// reformat the prefix if null.
-	if ((prefix == null) || "".equals(prefix)) {
-	    prefix = defaultPrefix;
-	}
+        if (namespaces == null) {
+            namespaces = new HashMap<URL, HashMap<String, String>>();
+        }
+        // reformat the prefix if null.
+        if ((prefix == null) || prefix.length() == 0) {
+            prefix = defaultPrefix;
+        }
 
-	HashMap<String,String> nsdefs = namespaces.get(url);
-	if (nsdefs == null) {
-	    nsdefs =  new HashMap<String,String>();
-	    nsdefs.put(prefix, nsname);
-	    namespaces.put(url, nsdefs);
-	} else {
-	    // do we need to check if we have a redefinition ?
-	    nsdefs.put(prefix, nsname);
-	}
+        HashMap<String, String> nsdefs = namespaces.get(url);
+        if (nsdefs == null) {
+            nsdefs = new HashMap<String, String>();
+            nsdefs.put(prefix, nsname);
+            namespaces.put(url, nsdefs);
+        } else {
+            // do we need to check if we have a redefinition ?
+            nsdefs.put(prefix, nsname);
+        }
     }
 
     // true if a namespace is defined in the document (CSS fragment)
     // defined by the URL, with prefix "prefix"
     public boolean isNamespaceDefined(URL url, String prefix) {
-	if (prefix == null) { // no prefix, always match
-	    return true;
-	}
-	if (prefix.equals("*")) { // any ns, always true
-	    return true;
-	}
-	if ("".equals(prefix)) {
-	    prefix = "*defaultprefix*";
-	}
-	HashMap<String,String> nsdefs = namespaces.get(url);
-	if (nsdefs == null) {
-	    return false;
-	}
-	return nsdefs.containsKey(prefix);
+        if (prefix == null) { // no prefix, always match
+            return true;
+        }
+        if (prefix.equals("*")) { // any ns, always true
+            return true;
+        }
+        if (prefix.length() == 0) {
+            prefix = "*defaultprefix*";
+        }
+        HashMap<String, String> nsdefs = namespaces.get(url);
+        if (nsdefs == null) {
+            return false;
+        }
+        return nsdefs.containsKey(prefix);
     }
 }

Index: Util.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/Util.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- Util.java	17 Mar 2008 17:52:54 -0000	1.6
+++ Util.java	29 Aug 2011 07:21:02 -0000	1.7
@@ -380,5 +380,8 @@
      */
     public static boolean onDebug = Boolean.getBoolean("CSS.debug");
     //    public static boolean onDebug = false;
+
+    // default maximum size for checked entities
+    public static long maxEntitySize = 1048576L ;
 }
 

Index: Messages.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/Messages.java,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- Messages.java	7 Apr 2011 14:37:41 -0000	1.40
+++ Messages.java	29 Aug 2011 07:21:01 -0000	1.41
@@ -11,7 +11,6 @@
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.StringTokenizer;
-import java.util.Vector;
 
 /**
  * @version $Revision$
@@ -21,10 +20,10 @@
     /**
      * Message properties
      */
-    public Utf8Properties<String, String> properties;
+    public Utf8Properties<String, String> properties = null;
 
-    public static Hashtable<String, Utf8Properties<String, String>> languages;
-    public static ArrayList<String> languages_name;
+    public static final Hashtable<String, Utf8Properties<String, String>> languages;
+    public static final ArrayList<String> languages_name;
 
     /**
      * Creates a new Messages
@@ -189,7 +188,7 @@
         return "[empty string]";
     }
 
-    public String getString(String message, Vector<String> params) {
+    public String getString(String message, ArrayList<String> params) {
         if ((params == null) || params.size() == 0) {
             return getString(message);
         }
Received on Monday, 29 August 2011 07:21:06 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:17:46 UTC