- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Wed, 10 Dec 2008 15:25:54 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/css
In directory hutz:/tmp/cvs-serv3613/css
Modified Files:
DocumentParser.java XMLStyleSheetHandler.java
Log Message:
various cleanup + templating
Index: DocumentParser.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/css/DocumentParser.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- DocumentParser.java 13 Jul 2007 13:32:19 -0000 1.2
+++ DocumentParser.java 10 Dec 2008 15:25:51 -0000 1.3
@@ -24,122 +24,122 @@
*/
public final class DocumentParser {
- private StyleSheet style;
- private URL htmlURL;
- private Exception exception;
- private ApplContext ac;
+ private StyleSheet style;
+ private URL htmlURL;
+ private Exception exception;
+ private ApplContext ac;
- /**
- * Create a new DocumentParser
- *
- * @exception Exception
- * An error
- */
- public DocumentParser(ApplContext ac, String urlString) throws Exception {
- this.htmlURL = HTTPURL.getURL(urlString);
- this.ac = ac;
- urlString = htmlURL.toString();
- String urlLower = urlString.toLowerCase();
- String media = ac.getMedium();
- String urlProtocol = htmlURL.getProtocol();
+ /**
+ * Create a new DocumentParser
+ *
+ * @exception Exception
+ * An error
+ */
+ public DocumentParser(ApplContext ac, String urlString) throws Exception {
+ this.htmlURL = HTTPURL.getURL(urlString);
+ this.ac = ac;
+ urlString = htmlURL.toString();
+ String urlLower = urlString.toLowerCase();
+ String media = ac.getMedium();
+ String urlProtocol = htmlURL.getProtocol();
- if (!"http".equals(urlProtocol) && !"https".equals(urlProtocol)) {
- if (urlLower.endsWith(".css")) {
- StyleSheetParser parser = new StyleSheetParser();
- parser.parseURL(ac, htmlURL, null, null, media, StyleSheetOrigin.AUTHOR);
- style = parser.getStyleSheet();
- } else if (urlLower.endsWith(".html") || urlLower.endsWith(".shtml") || urlLower.endsWith("/")) {
- TagSoupStyleSheetHandler handler = new TagSoupStyleSheetHandler(htmlURL, ac);
- handler.parse(htmlURL);
- style = handler.getStyleSheet();
- if (style != null) {
- style.setType("text/html");
- }
- } else if (urlLower.endsWith(".xhtml") || urlLower.endsWith(".xml")) {
- // Seems like we need to use tagsout in this case as well
- XMLStyleSheetHandler handler = new XMLStyleSheetHandler(htmlURL, ac);
- handler.parse(htmlURL);
- style = handler.getStyleSheet();
- if (style != null) {
- style.setType("text/xml");
- }
- } else {
- throw new Exception("Unknown file");
- }
- } else {
- URLConnection connection = null;
+ if (!"http".equals(urlProtocol) && !"https".equals(urlProtocol)) {
+ if (urlLower.endsWith(".css")) {
+ StyleSheetParser parser = new StyleSheetParser();
+ parser.parseURL(ac, htmlURL, null, null, media, StyleSheetOrigin.AUTHOR);
+ style = parser.getStyleSheet();
+ } else if (urlLower.endsWith(".html") || urlLower.endsWith(".shtml") || urlLower.endsWith("/")) {
+ TagSoupStyleSheetHandler handler = new TagSoupStyleSheetHandler(htmlURL, ac);
+ handler.parse(htmlURL);
+ style = handler.getStyleSheet();
+ if (style != null) {
+ style.setType("text/html");
+ }
+ } else if (urlLower.endsWith(".xhtml") || urlLower.endsWith(".xml")) {
+ // Seems like we need to use tagsout in this case as well
+ XMLStyleSheetHandler handler = new XMLStyleSheetHandler(htmlURL, ac);
+ handler.parse(htmlURL);
+ style = handler.getStyleSheet();
+ if (style != null) {
+ style.setType("text/xml");
+ }
+ } else {
+ throw new Exception("Unknown file");
+ }
+ } else {
+ URLConnection connection = null;
- try {
- boolean isXML = false;
- String cType;
+ try {
+ boolean isXML = false;
+ String cType;
- // @@ hum, maybe? (plh, yes probably :-) )
- String credential = ac.getCredential();
+ // @@ hum, maybe? (plh, yes probably :-) )
+ String credential = ac.getCredential();
- connection = HTTPURL.getConnection(htmlURL, ac);
- htmlURL = connection.getURL();
+ connection = HTTPURL.getConnection(htmlURL, ac);
+ htmlURL = connection.getURL();
- String httpCL = connection.getHeaderField("Content-Location");
- if (httpCL != null) {
- htmlURL = HTTPURL.getURL(htmlURL, httpCL);
- }
+ String httpCL = connection.getHeaderField("Content-Location");
+ if (httpCL != null) {
+ htmlURL = HTTPURL.getURL(htmlURL, httpCL);
+ }
- cType = connection.getContentType();
- if (cType == null) {
- cType = "unknown/unknown";
- }
- MimeType contentType = null;
- try {
- contentType = new MimeType(cType);
- } catch (MimeTypeFormatException ex) {
- }
+ cType = connection.getContentType();
+ if (cType == null) {
+ cType = "unknown/unknown";
+ }
+ MimeType contentType = null;
+ try {
+ contentType = new MimeType(cType);
+ } catch (MimeTypeFormatException ex) {
+ }
- if (Util.onDebug) {
- System.err.println("[DEBUG] content type is [" + contentType + ']');
- }
+ if (Util.onDebug) {
+ System.err.println("[DEBUG] content type is [" + contentType + ']');
+ }
- if (contentType.match(MimeType.TEXT_HTML) == MimeType.MATCH_SPECIFIC_SUBTYPE) {
- TagSoupStyleSheetHandler handler;
- handler = new TagSoupStyleSheetHandler(htmlURL, ac);
- handler.parse(urlString, connection);
- style = handler.getStyleSheet();
+ if (contentType.match(MimeType.TEXT_HTML) == MimeType.MATCH_SPECIFIC_SUBTYPE) {
+ TagSoupStyleSheetHandler handler;
+ handler = new TagSoupStyleSheetHandler(htmlURL, ac);
+ handler.parse(urlString, connection);
+ style = handler.getStyleSheet();
- if (style != null) {
- style.setType("text/html");
- }
- } else if (contentType.match(MimeType.TEXT_CSS) == MimeType.MATCH_SPECIFIC_SUBTYPE) {
- StyleSheetParser parser = new StyleSheetParser();
- parser.parseURL(ac, htmlURL, null, null, media, StyleSheetOrigin.AUTHOR);
- style = parser.getStyleSheet();
- } else if ((contentType.match(MimeType.TEXT_XML) == MimeType.MATCH_SPECIFIC_SUBTYPE)
- || (contentType.match(MimeType.APPLICATION_XHTML_XML) == MimeType.MATCH_SPECIFIC_SUBTYPE)) {
- // TagSoup ?
- XMLStyleSheetHandler handler = new XMLStyleSheetHandler(htmlURL, ac);
- handler.parse(urlString, connection);
- style = handler.getStyleSheet();
+ if (style != null) {
+ style.setType("text/html");
+ }
+ } else if (contentType.match(MimeType.TEXT_CSS) == MimeType.MATCH_SPECIFIC_SUBTYPE) {
+ StyleSheetParser parser = new StyleSheetParser();
+ parser.parseURL(ac, htmlURL, null, null, media, StyleSheetOrigin.AUTHOR);
+ style = parser.getStyleSheet();
+ } else if ((contentType.match(MimeType.TEXT_XML) == MimeType.MATCH_SPECIFIC_SUBTYPE)
+ || (contentType.match(MimeType.APPLICATION_XHTML_XML) == MimeType.MATCH_SPECIFIC_SUBTYPE)) {
+ // TagSoup ?
+ XMLStyleSheetHandler handler = new XMLStyleSheetHandler(htmlURL, ac);
+ handler.parse(urlString, connection);
+ style = handler.getStyleSheet();
- if (style != null) {
- style.setType("text/xml");
- }
- } else {
- throw new IOException("Unknown mime type : " + contentType);
- }
- } finally {
- try {
- connection.getInputStream().close();
- } catch (Exception e) {
- }
- }
+ if (style != null) {
+ style.setType("text/xml");
+ }
+ } else {
+ throw new IOException("Unknown mime type : " + contentType);
+ }
+ } finally {
+ try {
+ connection.getInputStream().close();
+ } catch (Exception e) {
}
+ }
}
+ }
- /**
- * Returns the recognized style sheet.
- *
- * @return A style sheet.
- */
- public StyleSheet getStyleSheet() {
- return style;
- }
+ /**
+ * Returns the recognized style sheet.
+ *
+ * @return A style sheet.
+ */
+ public StyleSheet getStyleSheet() {
+ return style;
+ }
} // HTMLStyleSheetParser
Index: XMLStyleSheetHandler.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/css/XMLStyleSheetHandler.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- XMLStyleSheetHandler.java 18 Sep 2007 18:06:36 -0000 1.28
+++ XMLStyleSheetHandler.java 10 Dec 2008 15:25:52 -0000 1.29
@@ -20,7 +20,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
-import java.util.Hashtable;
+import java.util.HashMap;
import org.w3c.css.parser.CssError;
import org.w3c.css.parser.Errors;
@@ -77,7 +77,7 @@
String title = null;
- StringBuffer text = new StringBuffer(255);
+ StringBuilder text = new StringBuilder(255);
Locator locator;
@@ -136,12 +136,12 @@
public void processingInstruction(String target, String data)
throws SAXException {
- Hashtable atts = getValues(data);
+ HashMap<String,String> atts = getValues(data);
if ("xml-stylesheet".equals(target)) {
- String rel = (String) atts.get("alternate");
- String type = (String) atts.get("type");
- String href = (String) atts.get("href");
+ String rel = atts.get("alternate");
+ String type = atts.get("type");
+ String href = atts.get("href");
if (Util.onDebug) {
System.err.println("<?xml-stylesheet alternate=\"" + rel
@@ -199,12 +199,12 @@
+ "initialize(): " + "should parse CSS url: "
+ url.toString() + "]");
}
- String media = (String) atts.get("media");
+ String media = atts.get("media");
if (media == null) {
media = "all";
}
- styleSheetParser.parseURL(ac, url, (String) atts
- .get("title"), rel, media, StyleSheetOrigin.AUTHOR);
+ styleSheetParser.parseURL(ac, url, atts.get("title"), rel, media,
+ StyleSheetOrigin.AUTHOR);
if (Util.onDebug) {
System.err.println("[parsed!]");
}
@@ -384,7 +384,6 @@
title, media, documentURI, line);
}
}
-
}
}
}
@@ -392,9 +391,10 @@
public void handleStyleAttribute(String value, String id) {
if (id == null) { // but we have no id: create one.
// a normal id should NOT contain a "#" character.
- id = "#autoXML" + autoIdCount;
- // workaround a java hashcode bug.
- id += "" + autoIdCount++;
+ StringBuilder sb = new StringBuilder("#autoXML");
+ // FIXME why two times, then increment?
+ sb.append(autoIdCount).append(autoIdCount++);
+ id = sb.toString();
}
int line = 0;
if (locator != null) {
@@ -582,15 +582,15 @@
}
}
- Hashtable getValues(String data) {
+ HashMap<String,String> getValues(String data) {
int length = data.length();
int current = 0;
char c;
- StringBuffer name = new StringBuffer(10);
- StringBuffer value = new StringBuffer(128);
- StringBuffer entity_name = new StringBuffer(16);
+ StringBuilder name = new StringBuilder(10);
+ StringBuilder value = new StringBuilder(128);
+ StringBuilder entity_name = new StringBuilder(16);
int state = 0;
- Hashtable table = new Hashtable();
+ HashMap<String,String> table = new HashMap<String,String>();
while (current < length) {
c = data.charAt(current);
Received on Wednesday, 10 December 2008 15:26:04 UTC