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

2002/css-validator/org/w3c/css/parser CssFouffa.java,1.47,1.48 Frame.java,1.10,1.11

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Sat, 14 Feb 2009 09:05:05 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1LYGSP-0000hV-90@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/parser
In directory hutz:/tmp/cvs-serv2661/org/w3c/css/parser

Modified Files:
	CssFouffa.java Frame.java 
Log Message:
support of @charset (generating re-parsing using the new charset definition)

Index: Frame.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/Frame.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- Frame.java	13 Sep 2007 10:00:28 -0000	1.10
+++ Frame.java	14 Feb 2009 09:05:03 -0000	1.11
@@ -44,7 +44,9 @@
      * @param sourceFile The name of the source file.
      * @param beginLine  The begin line
      */
-    public Frame(CssFouffa cssFouffa, String sourceFile, int beginLine, int warningLevel) {
+    public Frame(CssFouffa cssFouffa, String sourceFile, int beginLine,
+		 int warningLevel)
+    {
     	this(cssFouffa, sourceFile, warningLevel);
     	line = beginLine;
     }
@@ -55,16 +57,16 @@
      * @param error The new error.
      */
     public void addError(CssError error) {
-    error.sourceFile = getSourceFile();
-    error.line = getLine();
-    errors.addError(error);
+	error.sourceFile = getSourceFile();
+	error.line = getLine();
+	errors.addError(error);
     }
 
     /**
      * Returns all errors.
      */
     public Errors getErrors() {
-    return errors;
+	return errors;
     }
 
     /**
@@ -75,8 +77,8 @@
      * @see                  org.w3c.css.util.Warning
      */
     public void addWarning(String warningMessage) {
-    warnings.addWarning(new Warning(getSourceFile(), getLine(),
-                    warningMessage, 0, ac));
+	warnings.addWarning(new Warning(getSourceFile(), getLine(),
+					warningMessage, 0, ac));
     }
 
     /**
@@ -88,8 +90,9 @@
      * @see                  org.w3c.css.util.Warning
      */
     public void addWarning(String warningMessage, String message) {
-    warnings.addWarning(new Warning(getSourceFile(), getLine(),
-                    warningMessage, 0, new String[] { message }, ac));
+	warnings.addWarning(new Warning(getSourceFile(), getLine(),
+					warningMessage, 0, 
+					new String[] { message }, ac));
     }
 
     /**
@@ -100,38 +103,38 @@
      * @param messages       Some add-on messages.
      * @see                  org.w3c.css.util.Warning
      */
-	public void addWarning(String warningMessage, String[] messages) {
-		warnings.addWarning(new Warning(getSourceFile(), getLine(),
-                warningMessage, 0, messages, ac));
-	}
+    public void addWarning(String warningMessage, String[] messages) {
+	warnings.addWarning(new Warning(getSourceFile(), getLine(),
+					warningMessage, 0, messages, ac));
+    }
 
     /**
      * Get all warnings.
      */
     public Warnings getWarnings() {
-    return warnings;
+	return warnings;
     }
 
     /**
      * Get the name of the source file.
      */
     public String getSourceFile() {
-    return sourceFile;
+	return sourceFile;
     }
 
     /**
      * Get the begin line.
      */
     public int getBeginLine() {
-    return line;
+	return line;
     }
 
     /**
      * Get the current line.
      */
     public int getLine() {
-    //return line; //+ cssFouffa.token.beginLine;
-    return line + cssFouffa.token.beginLine;
+	//return line; //+ cssFouffa.token.beginLine;
+	return line + cssFouffa.token.beginLine;
     }
 
     /**
@@ -140,8 +143,8 @@
      * @param frame The other frame for merging.
      */
     public void join(Frame frame) {
-    errors.addErrors(frame.errors);
-    warnings.addWarnings(frame.warnings);
+	errors.addErrors(frame.errors);
+	warnings.addWarnings(frame.warnings);
     }
 }
 

Index: CssFouffa.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/CssFouffa.java,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- CssFouffa.java	13 Feb 2009 21:50:15 -0000	1.47
+++ CssFouffa.java	14 Feb 2009 09:05:03 -0000	1.48
@@ -100,16 +100,19 @@
      * @exception IOException
      *                if an I/O error occurs.
      */
-    public CssFouffa(ApplContext ac, InputStream input, String charset, URL file, int beginLine) 
+    public CssFouffa(ApplContext ac, InputStream input, String charset, 
+		     URL file, int beginLine) 
 	throws IOException
     {
-	super(new InputStreamReader(input, (charset == null) ? "iso-8859-1" : charset));
+	super(new InputStreamReader(input, (charset == null) ? 
+				    "iso-8859-1" : charset));
 	if (ac.getOrigin() == -1) {
 	    setOrigin(StyleSheetOrigin.AUTHOR); // default is user
 	} else {
 	    setOrigin(ac.getOrigin()); // default is user
 	}
-	ac.setFrame(new Frame(this, file.toString(), beginLine, ac.getWarningLevel()));
+	ac.setFrame(new Frame(this, file.toString(), beginLine, 
+			      ac.getWarningLevel()));
 	setApplContext(ac);
 	// @@this is a default media ...
 	/*
@@ -123,7 +126,8 @@
 	 */
 	setURL(file);
 	if (Util.onDebug) {
-	    System.err.println("[DEBUG] CSS version " + ac.getCssVersion() + " medium " + ac.getMedium() + " at-rule "
+	    System.err.println("[DEBUG] CSS version " + ac.getCssVersion() + 
+			       " medium " + ac.getMedium() + " at-rule "
 			       + getAtRule() + " profile " + ac.getProfile());
 	}
 
@@ -144,7 +148,8 @@
 	    style = Class.forName(classStyle);
 	    ac.setCssSelectorsStyle(style);
 	} catch (ClassNotFoundException e) {
-	    System.err.println("org.w3c.css.parser.CssFouffa: couldn't" + " load the style");
+	    System.err.println("org.w3c.css.parser.CssFouffa: couldn't" + 
+			       " load the style");
 	    e.printStackTrace();
 	}
 
@@ -162,8 +167,11 @@
      * @exception IOException
      *                if an I/O error occurs.
      */
-    public CssFouffa(ApplContext ac, InputStream input, URL file) throws IOException {
-	this(ac, input, "iso-8859-1", file, 0);
+    public CssFouffa(ApplContext ac, InputStream input, URL file) 
+	throws IOException 
+    {
+	this(ac, input, (ac.getCharsetForURL(file) != null) ?
+	     ac.getCharsetForURL(file):"iso-8859-1", file, 0);
     }
 
     /**
@@ -208,7 +216,9 @@
     private CssFouffa(ApplContext ac, InputStream in, URL url, 
 		      Vector<CssValidatorListener> listeners, 
 		      Vector<String> urlvisited,
-		      CssPropertyFactory cssfactory, boolean mode) throws IOException {
+		      CssPropertyFactory cssfactory, boolean mode) 
+	throws IOException 
+    {
 	this(ac, in, ac.getCharsetForURL(url), url, 0);
 	this.visited = urlvisited;
 	setURL(url);
@@ -219,7 +229,8 @@
 	this.mode = mode;
     }
 
-    private void ReInit(ApplContext ac, InputStream input, URL file, Frame frame) {
+    private void ReInit(ApplContext ac, InputStream input, 
+			URL file, Frame frame) {
 	// reinitialize the parser with a new data input
 	// and a new frame for errors and warnings
 	super.ReInitWithAc(input, ac, ac.getCharsetForURL(file));
@@ -281,10 +292,12 @@
      * @exception IOException
      *                if an I/O error occurs.
      */
-    public void ReInit(ApplContext ac, InputStream input, URL file, int beginLine) 
+    public void ReInit(ApplContext ac, InputStream input, URL file, 
+		       int beginLine) 
 	throws IOException 
     {
-	Frame f = new Frame(this, file.toString(), beginLine, ac.getWarningLevel());
+	Frame f = new Frame(this, file.toString(), beginLine, 
+			    ac.getWarningLevel());
 	ac.setFrame(f);
 	ReInit(ac, input, file, f);
     }
@@ -299,7 +312,9 @@
      * @exception IOException
      *                if an I/O error occurs.
      */
-    public void ReInit(ApplContext ac, InputStream input, URL file) throws IOException {
+    public void ReInit(ApplContext ac, InputStream input, URL file) 
+	throws IOException 
+    {
 	Frame f = new Frame(this, file.toString(), ac.getWarningLevel());
 	ac.setFrame(f);
 	ReInit(ac, input, file, f);
@@ -447,11 +462,15 @@
 		// check that we didn't already got this URL, or that the
 		// number of imports is not exploding
 		if (visited.contains(surl)) {
-		    CssError cerr = new CssError(new Exception("Import loop" + " detected in " + surl));
+		    CssError cerr = new CssError(new Exception("Import loop" +
+							       " detected in "+
+							       surl));
 		    ac.getFrame().addError(cerr);
 		    return;
 		} else if (visited.size() > 42) {
-		    CssError cerr = new CssError(new Exception("Maximum number" + " of imports " + "reached"));
+		    CssError cerr = new CssError(new Exception("Maximum number"+
+							       " of imports " +
+							       "reached"));
 		    ac.getFrame().addError(cerr);
 		    return;
 		}
@@ -460,7 +479,8 @@
 	    newVisited.addElement(surl);
 
 	    if (Util.importSecurity) {
-		throw new FileNotFoundException("[SECURITY] You can't " + "import URL sorry.");
+		throw new FileNotFoundException("[SECURITY] You can't " +
+						"import URL sorry.");
 	    }
 
 	    URLConnection importURL = HTTPURL.getConnection(importedURL, ac);
@@ -474,7 +494,8 @@
 		}
 		String mtype = httpURL.getContentType();
 		if (mtype == null) {
-		    throw new FileNotFoundException(importURL.getURL() + "No Media Type defined");
+		    throw new FileNotFoundException(importURL.getURL() + 
+						    "No Media Type defined");
 		} else {
 		    if (mtype.toLowerCase().indexOf("text/html") != -1) {
 			throw new FileNotFoundException(importURL.getURL() + 
@@ -485,9 +506,10 @@
 	    }
 	    Frame f = ac.getFrame();
 	    try {
-		CssFouffa cssFouffa = new CssFouffa(ac, HTTPURL.getInputStream(ac, importURL),
-						    importedURL, listeners, newVisited,
-						    properties, mode);
+		CssFouffa cssFouffa = new CssFouffa(ac, 
+					  HTTPURL.getInputStream(ac, importURL),
+					  importedURL, listeners, newVisited,
+					  properties, mode);
 		cssFouffa.setOrigin(getOrigin());
 		if (!media.isEmpty()) {
 		    cssFouffa.setAtRule(media);
@@ -657,6 +679,21 @@
 	     e.hasMoreElements();) {
 	    e.nextElement().addCharSet(charset);
 	}
+	String originalCharset = ac.getCharsetForURL(getURL());
+	if (!charset.equalsIgnoreCase(originalCharset)) {
+	    if (originalCharset == null) {
+		ac.setCharsetForURL(getURL(), charset);
+		try {
+		    ReInit(ac, getURL());
+		} catch (IOException ioex) {}
+	    } else {
+		Exception ex = new Exception("Conflicting charset definition"+
+					     "between network and @charset "+
+					     originalCharset+" and "+charset);
+		CssError cerr = new CssError(ex);
+		ac.getFrame().addError(cerr);
+	    }
+	}
     }
 
     /**
Received on Saturday, 14 February 2009 09:05:16 GMT

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