mrglavas 2004/04/14 21:51:56 Modified: java/src/org/apache/xerces/xinclude XIncludeHandler.java XIncludeTextReader.java java/src/org/apache/xerces/impl/msg XIncludeMessages.properties Log: Updates for changes in latest draft:
http://www.w3.org/TR/2004/CR-xinclude-20040413/ Remove code supporting 'accept-charset' attribute. Report fatal error if 'accept' or 'accept-language' attribute values contain characters outside of the range 0x20 to 0x7E. Revision Changes Path 1.26 +34 -6 xml-xerces/java/src/org/apache/xerces/xinclude/XIncludeHandler.java Index: XIncludeHandler.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/xinclude/XIncludeHandler.java,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- XIncludeHandler.java 14 Apr 2004 19:23:53 -0000 1.25 +++ XIncludeHandler.java 15 Apr 2004 04:51:56 -0000 1.26 @@ -106,7 +106,6 @@ "org.apache.xerces.parsers.XIncludeParserConfiguration"; public final static String HTTP_ACCEPT = "Accept"; public final static String HTTP_ACCEPT_LANGUAGE = "Accept-Language"; - public final static String HTTP_ACCEPT_CHARSET = "Accept-Charset"; public final static String XPOINTER = "xpointer"; public final static String XINCLUDE_NS_URI = @@ -122,7 +121,6 @@ public final static String XINCLUDE_ATTR_ENCODING = "encoding".intern(); public final static String XINCLUDE_ATTR_ACCEPT = "accept".intern(); public final static String XINCLUDE_ATTR_ACCEPT_LANGUAGE = "accept-language".intern(); - public final static String XINCLUDE_ATTR_ACCEPT_CHARSET = "accept-charset".intern(); // Top Level Information Items have [included] property in infoset public final static String XINCLUDE_INCLUDED = "[included]".intern(); @@ -1116,15 +1114,28 @@ // TODO: figure out what section 4.1.1 of the XInclude spec is talking about // has to do with disallowed ASCII character escaping // this ties in with the above IURI section, but I suspect Java already does it + String href = attributes.getValue(XINCLUDE_ATTR_HREF); String parse = attributes.getValue(XINCLUDE_ATTR_PARSE); String xpointer = attributes.getValue(XPOINTER); + String accept = attributes.getValue(XINCLUDE_ATTR_ACCEPT); + String acceptLanguage = attributes.getValue(XINCLUDE_ATTR_ACCEPT_LANGUAGE); + if (href == null && xpointer == null) { reportFatalError("XpointerMissing"); } if (parse == null) { parse = XINCLUDE_PARSE_XML; } + + // Verify that if an accept and/or an accept-language attribute exist + // that the value(s) don't contain disallowed characters. + if (accept != null && !isValidInHTTPHeader(accept)) { + reportFatalError("AcceptMalformed", null); + } + if (acceptLanguage != null && !isValidInHTTPHeader(acceptLanguage)) { + reportFatalError("AcceptLanguageMalformed", null); + } XMLInputSource includedSource = null; if (fEntityResolver != null) { @@ -1253,9 +1264,7 @@ } if (includedSource.getCharacterStream() == null && includedSource.getByteStream() == null) { - reader.setHttpProperties(attributes.getValue(XINCLUDE_ATTR_ACCEPT), - attributes.getValue(XINCLUDE_ATTR_ACCEPT_CHARSET), - attributes.getValue(XINCLUDE_ATTR_ACCEPT_LANGUAGE)); + reader.setHttpProperties(accept, acceptLanguage); } reader.setErrorReporter(fErrorReporter); reader.parse(); @@ -2163,5 +2172,24 @@ // REVISIT: throw error here } } + } + + /** + * Returns <code>true</code> if the given string + * would be valid in an HTTP header. + * + * @param value string to check + * @return <code>true</code> if the given string + * would be valid in an HTTP header + */ + private boolean isValidInHTTPHeader (String value) { + char ch; + for (int i = value.length() - 1; i >= 0; --i) { + ch = value.charAt(i); + if (ch < 0x20 || ch > 0x7E) { + return false; + } + } + return true; } } 1.10 +3 -10 xml-xerces/java/src/org/apache/xerces/xinclude/XIncludeTextReader.java Index: XIncludeTextReader.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/xinclude/XIncludeTextReader.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- XIncludeTextReader.java 5 Mar 2004 22:17:00 -0000 1.9 +++ XIncludeTextReader.java 15 Apr 2004 04:51:56 -0000 1.10 @@ -65,7 +65,6 @@ // Content negotation parameters private String fAccept; - private String fAcceptCharset; private String fAcceptLanguage; /** @@ -92,16 +91,13 @@ } /** - * Sets content negotation parameters to - * be attached to an HTTP request. + * Sets content negotation parameters to be attached to an HTTP request. * * @param accept the Accept HTTP request property - * @param acceptCharset the Accept-Charset HTTP request property * @param acceptLanguage the Accept-Language HTTP request property */ - public void setHttpProperties(String accept, String acceptCharset, String acceptLanguage) { + public void setHttpProperties(String accept, String acceptLanguage) { fAccept = accept; - fAcceptCharset = acceptCharset; fAcceptLanguage = acceptLanguage; } @@ -139,9 +135,6 @@ if (urlCon instanceof HttpURLConnection) { if( fAccept != null && fAccept.length() > 0) { urlCon.setRequestProperty(XIncludeHandler.HTTP_ACCEPT, fAccept); - } - if( fAcceptCharset != null && fAcceptCharset.length() > 0) { - urlCon.setRequestProperty(XIncludeHandler.HTTP_ACCEPT_CHARSET, fAcceptCharset); } if( fAcceptLanguage != null && fAcceptLanguage.length() > 0) { urlCon.setRequestProperty(XIncludeHandler.HTTP_ACCEPT_LANGUAGE, fAcceptLanguage); 1.8 +3 -1 xml-xerces/java/src/org/apache/xerces/impl/msg/XIncludeMessages.properties Index: XIncludeMessages.properties =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/msg/XIncludeMessages.properties,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- XIncludeMessages.properties 14 Apr 2004 19:23:53 -0000 1.7 +++ XIncludeMessages.properties 15 Apr 2004 04:51:56 -0000 1.8 @@ -15,7 +15,9 @@ TextResourceError = Include operation failed, reverting to fallback. Resource error reading file as text (href=''{0}''). Reason: {1} NonDuplicateNotation = Multiple notations were used which had the name ''{0}'', but which were not determined to be duplicates. NonDuplicateUnparsedEntity = Multiple unparsed entities were used which had the name ''{0}'', but which were not determined to be duplicates. -XpointerMissing = xpointer attribute must be present when href attribute is absent +XpointerMissing = xpointer attribute must be present when href attribute is absent. +AcceptMalformed = Characters outside the range #x20 through #x7E are not allowed in the value of the 'accept' attribute of an 'include' element. +AcceptLanguageMalformed = Characters outside the range #x20 through #x7E are not allowed in the value of the 'accept-language' attribute of an 'include' element. # Messages from erroneous set-up IncompatibleNamespaceContext = The type of the NamespaceContext is incompatible with using XInclude; it must be an instance of XIncludeNamespaceSupport --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]