- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Mon, 29 Aug 2005 12:00:44 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/css
In directory hutz:/tmp/cvs-serv14471/css
Modified Files:
HTMLStyleSheetParser.java StyleSheetCom.java
XMLStyleSheetHandler.java
Log Message:
Use the MimeType class to avoid issues with case and parameters
Index: StyleSheetCom.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/css/StyleSheetCom.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- StyleSheetCom.java 23 Aug 2005 16:22:54 -0000 1.9
+++ StyleSheetCom.java 29 Aug 2005 12:00:42 -0000 1.10
@@ -6,6 +6,9 @@
// Please first read the full copyright statement in file COPYRIGHT.html
/*
* $Log$
+ * Revision 1.10 2005/08/29 12:00:42 ylafon
+ * Use the MimeType class to avoid issues with case and parameters
+ *
* Revision 1.9 2005/08/23 16:22:54 ylafon
* Patch by Jean-Guilhem Rouel
*
@@ -292,11 +295,16 @@
URLConnection urlC = HTTPURL.getConnection(style.htmlURL, null);
if (urlC.getContentType() != null) {
- if (urlC.getContentType().indexOf("text/html") != -1) {
+ MimeType mt = null;
+ try {
+ mt = new MimeType(urlC.getContentType());
+ } catch (Exception ex);
+ if (MimeType.TEXT_HTML.match(mt) == MimeType.MATCH_SPECIFIC_SUBTYPE) {
style.htmlRequest();
- } else if (urlC.getContentType().indexOf("text/xml") != -1) {
+ } else if ((MimeType.TEXT_XML.match(mt) == MimeType.MATCH_SPECIFIC_SUBTYPE) ||
+ (MimeType.APPLICATION_XHTML_XML..match(mt) == MimeType.MATCH_SPECIFIC_SUBTYPE)) {
style.xmlRequest();
- } else if (urlC.getContentType().indexOf("text/css") != -1) {
+ } else if (MimeType.TEXT_CSS.match(mt) == MimeType.MATCH_SPECIFIC_SUBTYPE) {
style.cssRequest(selector, style.defaultmedium);
}
} else {
Index: XMLStyleSheetHandler.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/css/XMLStyleSheetHandler.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- XMLStyleSheetHandler.java 23 Aug 2005 16:22:54 -0000 1.16
+++ XMLStyleSheetHandler.java 29 Aug 2005 12:00:42 -0000 1.17
@@ -30,6 +30,7 @@
import org.w3c.css.util.Util;
import org.w3c.css.util.xml.XMLCatalog;
import org.w3c.www.mime.MimeType;
+import org.w3c.www.mime.MimeTypeFormatException;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.EntityResolver;
@@ -153,37 +154,45 @@
styleSheetParser.notifyErrors(ers);
}
- if (type.equalsIgnoreCase("text/css")) {
+ if (type != null) {
+ MimeType mt = null;
+ try {
+ new MimeType(type);
+ } catch (Exception ex) { /* at worst, null */ };
+ if (MimeType.TEXT_CSS.match(mt) ==
+ MimeType.MATCH_SPECIFIC_SUBTYPE ) {
// we're dealing with a stylesheet...
- URL url;
-
- try {
- if (baseURI != null) {
- url = new URL(baseURI, href);
- } else {
- url = new URL(href);
+ URL url;
+
+ try {
+ if (baseURI != null) {
+ url = new URL(baseURI, href);
+ } else {
+ url = new URL(href);
+ }
+ } catch (MalformedURLException e) {
+ return; // Ignore errors
+ }
+
+ if (Util.onDebug) {
+ System.err.println("[XMLStyleSheetHandler::"+
+ "initialize(): "
+ + "should parse CSS url: "
+ + url.toString() + "]");
+ }
+ String media = (String) atts.get("media");
+ if (media == null) {
+ media="all";
+ }
+ styleSheetParser.parseURL(ac,
+ url,
+ (String) atts.get("title"),
+ rel,
+ media,
+ StyleSheetOrigin.AUTHOR);
+ if (Util.onDebug) {
+ System.err.println("[parsed!]");
}
- } catch (MalformedURLException e) {
- return; // Ignore errors
- }
-
- if (Util.onDebug) {
- System.err.println("[XMLStyleSheetHandler::initialize(): "
- + "should parse CSS url: "
- + url.toString() + "]");
- }
- String media = (String) atts.get("media");
- if (media == null) {
- media="all";
- }
- styleSheetParser.parseURL(ac,
- url,
- (String) atts.get("title"),
- rel,
- media,
- StyleSheetOrigin.AUTHOR);
- if (Util.onDebug) {
- System.err.println("[parsed!]");
}
}
}
@@ -231,8 +240,17 @@
+ "\" type=\"" + type
+ "\"" + " href=\"" + href + "\"");
}
- // Spif
- if ((type != null) && !type.equalsIgnoreCase("text/css")) {
+ if (type == null) {
+ return;
+ }
+ MimeType mt = null;
+ try {
+ mt = new MimeType(type);
+ } catch (MimeTypeFormatException mtfe) {
+ return;
+ }
+ if (MimeType.TEXT_CSS.match(mt) !=
+ MimeType.MATCH_SPECIFIC_SUBTYPE) {
return;
}
if (href == null) {
@@ -243,14 +261,16 @@
}
CssError er =
new CssError(baseURI.toString(), line,
- new InvalidParamException("unrecognized.link", ac));
+ new InvalidParamException(
+ "unrecognized.link", ac));
Errors ers = new Errors();
ers.addError(er);
styleSheetParser.notifyErrors(ers);
return;
}
- if ((rel != null) && rel.toLowerCase().indexOf("stylesheet") != -1) {
+ if ((rel != null) &&
+ rel.toLowerCase().indexOf("stylesheet") != -1) {
// we're dealing with a stylesheet...
// @@TODO alternate stylesheet
URL url;
@@ -306,13 +326,22 @@
}
CssError er =
new CssError(baseURI.toString(), line,
- new InvalidParamException("unrecognized.link", ac));
+ new InvalidParamException(
+ "unrecognized.link", ac));
Errors ers = new Errors();
ers.addError(er);
styleSheetParser.notifyErrors(ers);
- } else if (type.equals("text/css")) {
- text.setLength(0);
- inStyle = true;
+ } else {
+ try {
+ MimeType mt = new MimeType(type);
+ if (MimeType.TEXT_CSS.match(mt) ==
+ MimeType.MATCH_SPECIFIC_SUBTYPE) {
+ text.setLength(0);
+ inStyle = true;
+ }
+ } catch (MimeTypeFormatException ex) {
+ // do nothing
+ }
}
} else if (atts.getValue("style") != null) {
String value = atts.getValue("style");
Index: HTMLStyleSheetParser.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/css/HTMLStyleSheetParser.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- HTMLStyleSheetParser.java 8 Aug 2005 13:18:04 -0000 1.14
+++ HTMLStyleSheetParser.java 29 Aug 2005 12:00:42 -0000 1.15
@@ -21,6 +21,9 @@
import org.w3c.css.util.HTTPURL;
import org.w3c.css.util.Util;
+import org.w3c.www.mime.MimeType;
+import org.w3c.www.mime.MimeTypeFormatException;
+
/**
* @version $Revision$
*/
@@ -95,17 +98,23 @@
htmlURL = HTTPURL.getURL(htmlURL, httpCL);
}
- contentType = connection.getContentType();
- if (contentType == null) {
- contentType = "unknown";
+ cType = connection.getContentType();
+ if (cType == null) {
+ cType = "unknown/unknown";
}
- contentType = contentType.toLowerCase();
+ MimeType contentType = null;
+ try {
+ contentType = new MimeTYpe(cType());
+ } catch (MimeTypeFormatException ex) {
+ }
+
if (Util.onDebug) {
System.err.println( "[DEBUG] content type is [" +
contentType + ']');
}
- if (contentType.indexOf("text/html") != -1) {
+ if (cType.match(MimeType.TEXT_HTML) ==
+ MimeType.MATCH_SPECIFIC_SUBTYPE) {
HtmlParser htmlParser;
htmlParser = new HtmlParser(ac, "html4", urlString,
connection);
@@ -141,18 +150,24 @@
} finally {
Util.fromHTMLFile = false;
}
- } else if (contentType.indexOf("text/css") != -1) {
+ } 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.indexOf("text/xml") == -1)
- && (contentType.indexOf("application/xhtml+xml") == -1)) {
+ } else if ((contentType.match(MimeType.TEXT_XML) !=
+ MimeType.MATCH_SPECIFIC_SUBTYPE) &&
+ (contentType.match(MimeType.APPLICATION_XHTML_XML) !=
+ MimeType.MATCH_SPECIFIC_SUBTYPE)) {
throw new IOException("Unknown mime type : "+ contentType);
}
- if ((contentType.indexOf("text/xml") != -1) || isXML
- || (contentType.indexOf("application/xhtml+xml") != -1)) {
+ if (isXML ||
+ (contentType.match(MimeType.TEXT_XML) ==
+ MimeType.MATCH_SPECIFIC_SUBTYPE) ||
+ (contentType.match(MimeType.APPLICATION_XHTML_XML) ==
+ MimeType.MATCH_SPECIFIC_SUBTYPE)) {
XMLStyleSheetHandler handler;
handler = new XMLStyleSheetHandler(htmlURL, ac);
handler.parse(urlString, connection);
Received on Monday, 29 August 2005 12:00:49 UTC