neilg 2002/12/11 07:11:41
Modified: java/src/org/apache/xerces/impl XMLVersionDetector.java
XMLNamespaceBinder.java
Added: java/src/org/apache/xerces/impl XML11NamespaceBinder.java
Log:
add support for namespace 1.1 when XML 1.1 documents are being parsed.
Revision Changes Path
1.2 +33 -8
xml-xerces/java/src/org/apache/xerces/impl/XMLVersionDetector.java
Index: XMLVersionDetector.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLVersionDetector.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLVersionDetector.java 7 Dec 2002 00:15:58 -0000 1.1
+++ XMLVersionDetector.java 11 Dec 2002 15:11:40 -0000 1.2
@@ -143,20 +143,21 @@
protected static final String DTD_PROCESSOR_PROPERTY =
Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_PROCESSOR_PROPERTY;
+ /** Property identifier: namespace binder. */
+ protected static final String NAMESPACE_BINDER_PROPERTY =
+ Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY;
+
// recognized properties
private static final String[] RECOGNIZED_PROPERTIES = {
SYMBOL_TABLE,
ERROR_REPORTER,
ENTITY_MANAGER,
- DTD_SCANNER_PROPERTY, DTD_VALIDATOR_PROPERTY,
+ DTD_SCANNER_PROPERTY,
+ DTD_VALIDATOR_PROPERTY,
DTD_PROCESSOR_PROPERTY,
+ NAMESPACE_BINDER_PROPERTY,
};
- private static final String[] PROPERTY_DEFAULTS = {null, null, null, null,
null, null};
-
- // debugging
-
- /** Debug attribute normalization. */
- protected static final boolean DEBUG_ATTR_NORMALIZATION = false;
+ private static final String[] PROPERTY_DEFAULTS = {null, null, null, null,
null, null, null};
//
// Data
@@ -215,6 +216,9 @@
// the XML 1.1 DTD processor
protected XML11DTDProcessor fXML11DTDProcessor = null;
+ // the XML 1.1 namespace binder
+ protected XML11NamespaceBinder fXML11NamespaceBinder = null;
+
// symbols
/** Symbol: "version". */
@@ -560,6 +564,27 @@
if(val.getDocumentHandler() != null) {
val.getDocumentHandler().setDocumentSource(fXML11DTDValidator);
fXML11DTDValidator.setDocumentHandler(val.getDocumentHandler());
+ }
+ }
+ // is there a namespace binder in the pipeline?
+ // if so, it'll be XML 1.0; need to replace
+ // it... (REVISIT: does it make more sense here just to
+ // have a feature???)
+ XMLDocumentFilter nsb = null;
+ if((nsb = (XMLDocumentFilter
)fComponentManager.getProperty(NAMESPACE_BINDER_PROPERTY)) != null) {
+ // do we need to new up a replacement?
+ if(fXML11NamespaceBinder == null) {
+ fXML11NamespaceBinder = new XML11NamespaceBinder();
+ }
+ fXML11NamespaceBinder.reset(fComponentManager);
+ // now take nsb out of the picture...
+ if(nsb.getDocumentSource() != null) {
+
nsb.getDocumentSource().setDocumentHandler(fXML11NamespaceBinder);
+
fXML11NamespaceBinder.setDocumentSource(nsb.getDocumentSource());
+ }
+ if(nsb.getDocumentHandler() != null) {
+
nsb.getDocumentHandler().setDocumentSource(fXML11NamespaceBinder);
+
fXML11NamespaceBinder.setDocumentHandler(nsb.getDocumentHandler());
}
}
// now do the same to the DTD pipeline.
1.26 +12 -2
xml-xerces/java/src/org/apache/xerces/impl/XMLNamespaceBinder.java
Index: XMLNamespaceBinder.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLNamespaceBinder.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- XMLNamespaceBinder.java 24 Sep 2002 23:16:03 -0000 1.25
+++ XMLNamespaceBinder.java 11 Dec 2002 15:11:40 -0000 1.26
@@ -854,7 +854,11 @@
// http://www.w3.org/TR/1999/REC-xml-names-19990114/#dt-prefix
// We should only report an error if there is a prefix,
// that is, the local part is not "xmlns". -SG
- if (uri == XMLSymbols.EMPTY_STRING && localpart !=
XMLSymbols.PREFIX_XMLNS) {
+ // Since this is an error condition in XML 1.0,
+ // and should be relatively uncommon in XML 1.1,
+ // making this test into a method call to reuse code
+ // should be acceptable. - NG
+ if(prefixBoundToNullURI(uri, localpart)) {
fErrorReporter.reportError(XMLMessageFormatter.XMLNS_DOMAIN,
"EmptyPrefixedAttName",
new Object[]{attributes.getQName(i)},
@@ -970,5 +974,11 @@
fNamespaceSupport.popContext();
} // handleEndElement(QName,boolean)
+
+ // returns true iff the given prefix is bound to "" *and*
+ // this is disallowed by the version of XML namespaces in use.
+ protected boolean prefixBoundToNullURI(String uri, String localpart) {
+ return (uri == XMLSymbols.EMPTY_STRING && localpart !=
XMLSymbols.PREFIX_XMLNS);
+ } // prefixBoundToNullURI(String, String): boolean
} // class XMLNamespaceBinder
1.1
xml-xerces/java/src/org/apache/xerces/impl/XML11NamespaceBinder.java
Index: XML11NamespaceBinder.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xerces.impl;
import java.util.Enumeration;
import org.apache.xerces.impl.XMLErrorReporter;
import org.apache.xerces.impl.msg.XMLMessageFormatter;
import org.apache.xerces.util.NamespaceSupport;
import org.apache.xerces.util.SymbolTable;
import org.apache.xerces.util.XMLSymbols;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.NamespaceContext;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;
import org.apache.xerces.xni.XMLDocumentHandler;
import org.apache.xerces.xni.XMLLocator;
import org.apache.xerces.xni.XMLResourceIdentifier;
import org.apache.xerces.xni.XMLString;
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.parser.XMLComponent;
import org.apache.xerces.xni.parser.XMLComponentManager;
import org.apache.xerces.xni.parser.XMLConfigurationException;
import org.apache.xerces.xni.parser.XMLDocumentSource;
import org.apache.xerces.xni.parser.XMLDocumentFilter;
/**
* This class performs namespace binding on the startElement and endElement
* method calls in accordance with Namespaces in XML 1.1. It extends the standard,
* Namespace-1.0-compliant binder in order to do this.
*
* @author Neil Graham, IBM
*
* @version $Id: XML11NamespaceBinder.java,v 1.1 2002/12/11 15:11:40 neilg Exp $
*/
public class XML11NamespaceBinder extends XMLNamespaceBinder {
//
// Constants
//
//
// Data
//
//
// Constructors
//
/** Default constructor. */
public XML11NamespaceBinder() {
this(null);
} // <init>()
/**
* Constructs a namespace binder that shares the specified namespace
* context during each parse.
*
* @param namespaceContext The shared context.
*/
public XML11NamespaceBinder(NamespaceContext namespaceContext) {
super(namespaceContext);
} // <init>(NamespaceContext)
//
// Public methods
//
//
// Protected methods
//
// returns true iff the given prefix is bound to "" *and*
// this is disallowed by the version of XML namespaces in use.
protected boolean prefixBoundToNullURI(String uri, String localpart) {
return false;
} // prefixBoundToNullURI(String, String): boolean
} // class XML11NamespaceBinder
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]