elena 2002/12/15 17:26:21 Modified: java/src/org/apache/xerces/dom DOMNormalizer.java java/src/org/apache/xerces/impl XML11NamespaceBinder.java XMLDocumentScannerImpl.java XMLEntityScanner.java XMLNSDocumentScannerImpl.java XMLNamespaceBinder.java java/src/org/apache/xerces/impl/dtd XMLDTDValidator.java XMLNSDTDValidator.java java/src/org/apache/xerces/impl/xs XMLSchemaValidator.java java/src/org/apache/xerces/impl/xs/util SimpleLocator.java java/src/org/apache/xerces/parsers AbstractDOMParser.java AbstractSAXParser.java AbstractXMLDocumentParser.java BasicParserConfiguration.java java/src/org/apache/xerces/util ErrorHandlerWrapper.java NamespaceSupport.java java/src/org/apache/xerces/xni NamespaceContext.java XMLDocumentFragmentHandler.java XMLDocumentHandler.java XMLLocator.java XMLResourceIdentifier.java Log: XNI modifications 1. XMLResourceIdentifier add the following methods: public void setPublicId(String publicId); public void setExpandedSystemId(String systemId); public void setLiteralSystemId(String systemId); public void setBaseSystemId(String systemId); 2. XMLLocator add the following methods: public void setLineNumber(); public void setColumnNumber(); 3. Remove startPrefixMapping/endPrefixMapping from the xni.XMLDocumentHandler and xni.XMLDocumentFragmentHandler and modify the pipeline. From now one all components that need to read or modify namespace context need to save a pointer to the namespace context that is passed in the startDocument() call. 4. NamespaceContext Add pushContext, popContext, declarePrefix, getURI, reset() methods. Revision Changes Path 1.20 +5 -36 xml-xerces/java/src/org/apache/xerces/dom/DOMNormalizer.java Index: DOMNormalizer.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DOMNormalizer.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- DOMNormalizer.java 11 Dec 2002 16:14:30 -0000 1.19 +++ DOMNormalizer.java 16 Dec 2002 01:26:19 -0000 1.20 @@ -173,11 +173,11 @@ // Update PSVI information in the tree protected boolean fPSVI = false; - /** stores namespaces in scope */ - protected final NamespaceSupport fNamespaceContext = new NamespaceSupport(); + /** The namespace context of this document: stores namespaces in scope */ + protected final NamespaceContext fNamespaceContext = new NamespaceSupport(); - /** stores all namespace bindings on the current element */ - protected final NamespaceSupport fLocalNSBinder = new NamespaceSupport(); + /** Stores all namespace bindings on the current element */ + protected final NamespaceContext fLocalNSBinder = new NamespaceSupport(); /** list of attributes */ protected final Vector fAttributeList = new Vector(5,10); @@ -612,9 +612,6 @@ fLocalNSBinder.declarePrefix(XMLSymbols.EMPTY_STRING, value); fNamespaceContext.declarePrefix(XMLSymbols.EMPTY_STRING, value); - if (fValidationHandler != null) { - fValidationHandler.startPrefixMapping(XMLSymbols.EMPTY_STRING, value, null); - } removeDefault (attr, attributes); continue; } @@ -1216,21 +1213,6 @@ } /** - * The start of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * - * @param prefix The namespace prefix. - * @param uri The URI bound to the prefix. - * @param augs Additional information that may include infoset augmentations - * - * @exception XNIException - * Thrown by handler to signal an error. - */ - public void startPrefixMapping(String prefix, String uri, Augmentations augs) - throws XNIException{ - } - - /** * The start of an element. * * @param element The name of the element. @@ -1387,19 +1369,6 @@ } } } - } - - /** - * The end of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * - * @param prefix The namespace prefix. - * @param augs Additional information that may include infoset augmentations - * - * @exception XNIException - * Thrown by handler to signal an error. - */ - public void endPrefixMapping(String prefix, Augmentations augs) throws XNIException{ } /** 1.2 +1 -14 xml-xerces/java/src/org/apache/xerces/impl/XML11NamespaceBinder.java Index: XML11NamespaceBinder.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XML11NamespaceBinder.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- XML11NamespaceBinder.java 11 Dec 2002 15:11:40 -0000 1.1 +++ XML11NamespaceBinder.java 16 Dec 2002 01:26:19 -0000 1.2 @@ -106,20 +106,7 @@ /** 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 // 1.32 +5 -18 xml-xerces/java/src/org/apache/xerces/impl/XMLDocumentScannerImpl.java Index: XMLDocumentScannerImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLDocumentScannerImpl.java,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- XMLDocumentScannerImpl.java 7 Dec 2002 00:15:59 -0000 1.31 +++ XMLDocumentScannerImpl.java 16 Dec 2002 01:26:19 -0000 1.32 @@ -59,31 +59,18 @@ import java.io.EOFException; import java.io.IOException; -import java.util.Stack; -import org.apache.xerces.impl.XMLEntityManager; -import org.apache.xerces.impl.XMLEntityScanner; -import org.apache.xerces.impl.XMLErrorReporter; -import org.apache.xerces.impl.msg.XMLMessageFormatter; import org.apache.xerces.impl.validation.ValidationManager; - import org.apache.xerces.util.NamespaceSupport; -import org.apache.xerces.util.XMLAttributesImpl; -import org.apache.xerces.util.XMLStringBuffer; -import org.apache.xerces.util.XMLResourceIdentifierImpl; -import org.apache.xerces.util.SymbolTable; import org.apache.xerces.util.XMLChar; - -import org.apache.xerces.xni.QName; -import org.apache.xerces.xni.XMLAttributes; -import org.apache.xerces.xni.XMLDocumentHandler; +import org.apache.xerces.util.XMLResourceIdentifierImpl; +import org.apache.xerces.util.XMLStringBuffer; +import org.apache.xerces.xni.NamespaceContext; 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.XMLDocumentScanner; import org.apache.xerces.xni.parser.XMLDTDScanner; import org.apache.xerces.xni.parser.XMLInputSource; @@ -214,7 +201,7 @@ protected String fDoctypeSystemId; /** Namespace support. */ - protected NamespaceSupport fNamespaceContext = new NamespaceSupport(); + protected NamespaceContext fNamespaceContext = new NamespaceSupport(); // features 1.9 +45 -1 xml-xerces/java/src/org/apache/xerces/impl/XMLEntityScanner.java Index: XMLEntityScanner.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLEntityScanner.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- XMLEntityScanner.java 7 Dec 2002 00:15:58 -0000 1.8 +++ XMLEntityScanner.java 16 Dec 2002 01:26:19 -0000 1.9 @@ -1414,6 +1414,49 @@ return -1; } // getColumnNumber():int + + /** + * @see org.apache.xerces.xni.XMLLocator#setColumnNumber(int) + */ + public void setColumnNumber(int col) { + // no-op + } + + /** + * @see org.apache.xerces.xni.XMLLocator#setLineNumber(int) + */ + public void setLineNumber(int line) { + //no-op + } + + /** + * @see org.apache.xerces.xni.XMLResourceIdentifier#setBaseSystemId(String) + */ + public void setBaseSystemId(String systemId) { + //no-op + } + + + /** + * @see org.apache.xerces.xni.XMLResourceIdentifier#setExpandedSystemId(String) + */ + public void setExpandedSystemId(String systemId) { + //no-op + } + + /** + * @see org.apache.xerces.xni.XMLResourceIdentifier#setLiteralSystemId(String) + */ + public void setLiteralSystemId(String systemId) { + //no-op + } + + /** + * @see org.apache.xerces.xni.XMLResourceIdentifier#setPublicId(String) + */ + public void setPublicId(String publicId) { + //no-op + } // allow entity manager to tell us what the current entityis: public void setCurrentEntity(XMLEntityManager.ScannedEntity ent) { @@ -1500,6 +1543,7 @@ return entityChanged; } // load(int, boolean):boolean + } // class XMLEntityScanner 1.10 +1 -14 xml-xerces/java/src/org/apache/xerces/impl/XMLNSDocumentScannerImpl.java Index: XMLNSDocumentScannerImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLNSDocumentScannerImpl.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- XMLNSDocumentScannerImpl.java 7 Dec 2002 00:15:59 -0000 1.9 +++ XMLNSDocumentScannerImpl.java 16 Dec 2002 01:26:19 -0000 1.10 @@ -300,10 +300,6 @@ if (fBindNamespaces) { int count = fNamespaceContext.getDeclaredPrefixCount(); - for (int i = count - 1; i >= 0; i--) { - String prefix = fNamespaceContext.getDeclaredPrefixAt(i); - fDocumentHandler.endPrefixMapping(prefix, null); - } fNamespaceContext.popContext(); } //pop the element off the stack.. @@ -469,10 +465,6 @@ // bind namespace attribute to a namespace attributes.setURI(oldLen, fNamespaceContext.getURI(XMLSymbols.PREFIX_XMLNS)); - // call handler - if (fDocumentHandler != null) { - fDocumentHandler.startPrefixMapping(prefix, uri, null); - } } else { // attempt to bind attribute @@ -542,11 +534,6 @@ fDocumentHandler.endElement(fElementQName, null); if (fBindNamespaces) { - int count = fNamespaceContext.getDeclaredPrefixCount(); - for (int i = count - 1; i >= 0; i--) { - String prefix = fNamespaceContext.getDeclaredPrefixAt(i); - fDocumentHandler.endPrefixMapping(prefix, null); - } fNamespaceContext.popContext(); } 1.27 +17 -112 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.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- XMLNamespaceBinder.java 11 Dec 2002 15:11:40 -0000 1.26 +++ XMLNamespaceBinder.java 16 Dec 2002 01:26:19 -0000 1.27 @@ -170,11 +170,6 @@ protected XMLDocumentSource fDocumentSource; - // namespaces - - /** Namespace support. */ - protected NamespaceSupport fNamespaceSupport = new NamespaceSupport(); - // settings /** Only pass start and end prefix mapping events. */ @@ -196,29 +191,12 @@ /** Default constructor. */ public XMLNamespaceBinder() { - this(null); } // <init>() - /** - * Constructs a namespace binder that shares the specified namespace - * context during each parse. - * - * @param namespaceContext The shared context. - */ - public XMLNamespaceBinder(NamespaceContext namespaceContext) { - fNamespaceContext = namespaceContext; - } // <init>(NamespaceContext) - - // // Public methods // - /** Returns the current namespace context. */ - public NamespaceContext getNamespaceContext() { - return fNamespaceSupport; - } // getNamespaceContext():NamespaceContext - // settings /** @@ -276,22 +254,6 @@ fSymbolTable = (SymbolTable)componentManager.getProperty(SYMBOL_TABLE); fErrorReporter = (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER); - fNamespaceSupport.reset(); - - // use shared context - NamespaceContext context = fNamespaceContext; - while (context != null) { - int count = context.getDeclaredPrefixCount(); - for (int i = 0; i < count; i++) { - String prefix = context.getDeclaredPrefixAt(i); - if (fNamespaceSupport.getURI(prefix) == null) { - String uri = context.getURI(prefix); - fNamespaceSupport.declarePrefix(prefix, uri); - } - } - context = context.getParentContext(); - } - } // reset(XMLComponentManager) /** @@ -493,16 +455,15 @@ * * @throws XNIException Thrown by handler to signal an error. */ - public void startDocument(XMLLocator locator, String encoding, - NamespaceContext namespaceContext, Augmentations augs) - throws XNIException { - // REVISIT: in the namespace binder we should be able to modify the namespace - // context object, thus for now we are dropping the namespaceContext - // Not sure this is a correct behaviour.... - if (fDocumentHandler != null && !fOnlyPassPrefixMappingEvents) { - fDocumentHandler.startDocument(locator, encoding, fNamespaceSupport, augs); - } - } // startDocument(XMLLocator,String) + public void startDocument(XMLLocator locator, String encoding, + NamespaceContext namespaceContext, Augmentations augs) + throws XNIException { + fNamespaceContext = namespaceContext; + + if (fDocumentHandler != null && !fOnlyPassPrefixMappingEvents) { + fDocumentHandler.startDocument(locator, encoding, namespaceContext, augs); + } + } // startDocument(XMLLocator,String) /** * Notifies of the presence of an XMLDecl line in the document. If @@ -582,28 +543,6 @@ } } // processingInstruction(String,XMLString) - /** - * The start of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * - * @param prefix The namespace prefix. - * @param uri The URI bound to the prefix. - * @param augs Additional information that may include infoset augmentations - * - * @throws XNIException Thrown by handler to signal an error. - */ - public void startPrefixMapping(String prefix, String uri, Augmentations augs) - throws XNIException { - - // REVISIT: Should prefix mapping from previous stage in - // the pipeline affect the namespaces? - - // call handlers - if (fDocumentHandler != null) { - fDocumentHandler.startPrefixMapping(prefix, uri, augs); - } - - } // startPrefixMapping(String,String) /** * Binds the namespaces. This method will handle calling the @@ -708,27 +647,6 @@ } // endElement(QName) /** - * The end of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * - * @param prefix The namespace prefix. - * @param augs Additional information that may include infoset augmentations - * - * @throws XNIException Thrown by handler to signal an error. - */ - public void endPrefixMapping(String prefix, Augmentations augs) throws XNIException { - - // REVISIT: Should prefix mapping from previous stage in - // the pipeline affect the namespaces? - - // call handlers - if (fDocumentHandler != null) { - fDocumentHandler.endPrefixMapping(prefix, augs); - } - - } // endPrefixMapping(String) - - /** * The start of a CDATA section. * @param augs Additional information that may include infoset augmentations * @@ -792,7 +710,7 @@ boolean isEmpty) throws XNIException { // add new namespace context - fNamespaceSupport.pushContext(); + fNamespaceContext.pushContext(); if (element.prefix == XMLSymbols.PREFIX_XMLNS) { fErrorReporter.reportError(XMLMessageFormatter.XMLNS_DOMAIN, @@ -867,19 +785,15 @@ } // declare prefix in context - fNamespaceSupport.declarePrefix(prefix, uri.length() != 0 ? uri : null); + fNamespaceContext.declarePrefix(prefix, uri.length() != 0 ? uri : null); - // call handler - if (fDocumentHandler != null) { - fDocumentHandler.startPrefixMapping(prefix, uri, augs); - } } } // bind the element String prefix = element.prefix != null ? element.prefix : XMLSymbols.EMPTY_STRING; - element.uri = fNamespaceSupport.getURI(prefix); + element.uri = fNamespaceContext.getURI(prefix); if (element.prefix == null && element.uri != null) { element.prefix = XMLSymbols.EMPTY_STRING; } @@ -897,11 +811,11 @@ ? fAttributeQName.prefix : XMLSymbols.EMPTY_STRING; String arawname = fAttributeQName.rawname; if (arawname == XMLSymbols.PREFIX_XMLNS) { - fAttributeQName.uri = fNamespaceSupport.getURI(XMLSymbols.PREFIX_XMLNS); + fAttributeQName.uri = fNamespaceContext.getURI(XMLSymbols.PREFIX_XMLNS); attributes.setName(i, fAttributeQName); } else if (aprefix != XMLSymbols.EMPTY_STRING) { - fAttributeQName.uri = fNamespaceSupport.getURI(aprefix); + fAttributeQName.uri = fNamespaceContext.getURI(aprefix); if (fAttributeQName.uri == null) { fErrorReporter.reportError(XMLMessageFormatter.XMLNS_DOMAIN, "AttributePrefixUnbound", @@ -949,7 +863,7 @@ // bind element String eprefix = element.prefix != null ? element.prefix : XMLSymbols.EMPTY_STRING; - element.uri = fNamespaceSupport.getURI(eprefix); + element.uri = fNamespaceContext.getURI(eprefix); if (element.uri != null) { element.prefix = eprefix; } @@ -961,17 +875,8 @@ } } - // end prefix mappings - if (fDocumentHandler != null) { - int count = fNamespaceSupport.getDeclaredPrefixCount(); - for (int i = count - 1; i >= 0; i--) { - String prefix = fNamespaceSupport.getDeclaredPrefixAt(i); - fDocumentHandler.endPrefixMapping(prefix, augs); - } - } - // pop context - fNamespaceSupport.popContext(); + fNamespaceContext.popContext(); } // handleEndElement(QName,boolean) 1.43 +14 -71 xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java Index: XMLDTDValidator.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- XMLDTDValidator.java 11 Dec 2002 16:14:30 -0000 1.42 +++ XMLDTDValidator.java 16 Dec 2002 01:26:20 -0000 1.43 @@ -60,43 +60,33 @@ import org.apache.xerces.impl.Constants; import org.apache.xerces.impl.XMLEntityManager; import org.apache.xerces.impl.XMLErrorReporter; -import org.apache.xerces.impl.validation.ValidationManager; -import org.apache.xerces.impl.validation.ValidationState; -import org.apache.xerces.impl.msg.XMLMessageFormatter; - -import org.apache.xerces.impl.validation.EntityState; import org.apache.xerces.impl.dtd.models.ContentModelValidator; -import org.apache.xerces.impl.dv.DatatypeValidator; import org.apache.xerces.impl.dv.DTDDVFactory; +import org.apache.xerces.impl.dv.DatatypeValidator; import org.apache.xerces.impl.dv.InvalidDatatypeValueException; - -import org.apache.xerces.util.NamespaceSupport; +import org.apache.xerces.impl.msg.XMLMessageFormatter; +import org.apache.xerces.impl.validation.ValidationManager; +import org.apache.xerces.impl.validation.ValidationState; import org.apache.xerces.util.SymbolTable; -import org.apache.xerces.util.XMLSymbols; import org.apache.xerces.util.XMLChar; - +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.XMLString; 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.grammars.XMLGrammarPool; -import org.apache.xerces.xni.grammars.XMLGrammarDescription; import org.apache.xerces.xni.grammars.Grammar; +import org.apache.xerces.xni.grammars.XMLGrammarDescription; +import org.apache.xerces.xni.grammars.XMLGrammarPool; 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; - -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; -import java.util.StringTokenizer; +import org.apache.xerces.xni.parser.XMLDocumentSource; /** * The DTD validator. The validator implements a document @@ -273,7 +263,7 @@ protected XMLResourceIdentifier fDocLocation; /** Namespace support. */ - protected NamespaceSupport fNamespaceSupport = null; + protected NamespaceContext fNamespaceContext = null; /** Datatype validator factory. */ protected DTDDVFactory fDatatypeValidatorFactory; @@ -685,20 +675,10 @@ } } fDocLocation = locator; - // REVISIT: xni.NamespaceSupport should be read/write, since some - // components might want or need to modify the namespace information - // - if (namespaceContext instanceof NamespaceSupport) { - fNamespaceSupport = (NamespaceSupport)namespaceContext; - } - else { - // REVISIT: this is a hack for the case user inserts component before - // DTD validator - fNamespaceSupport = new NamespaceSupport(); - } - + fNamespaceContext = namespaceContext; + if (fDocumentHandler != null) { - fDocumentHandler.startDocument(locator, encoding, fNamespaceSupport, augs); + fDocumentHandler.startDocument(locator, encoding, namespaceContext, augs); } } // startDocument(XMLLocator,String) @@ -774,25 +754,6 @@ } // doctypeDecl(String,String,String, Augmentations) - /** - * The start of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * - * @param prefix The namespace prefix. - * @param uri The URI bound to the prefix. - * @param augs Additional information that may include infoset augmentations - * - * @throws XNIException Thrown by handler to signal an error. - */ - public void startPrefixMapping(String prefix, String uri, Augmentations augs) - throws XNIException { - - // call handlers - if (fDocumentHandler != null) { - fDocumentHandler.startPrefixMapping(prefix, uri, augs); - } - - } // startPrefixMapping(String,String) /** * The start of an element. @@ -936,24 +897,6 @@ handleEndElement(element, augs, false); } // endElement(QName) - - /** - * The end of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * - * @param prefix The namespace prefix. - * @param augs Additional information that may include infoset augmentations - * - * @throws XNIException Thrown by handler to signal an error. - */ - public void endPrefixMapping(String prefix, Augmentations augs) throws XNIException { - - // call handlers - if (fDocumentHandler != null) { - fDocumentHandler.endPrefixMapping(prefix, augs); - } - - } // endPrefixMapping(String) /** * The start of a CDATA section. 1.5 +9 -29 xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLNSDTDValidator.java Index: XMLNSDTDValidator.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLNSDTDValidator.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- XMLNSDTDValidator.java 24 Sep 2002 23:16:03 -0000 1.4 +++ XMLNSDTDValidator.java 16 Dec 2002 01:26:20 -0000 1.5 @@ -57,20 +57,14 @@ package org.apache.xerces.impl.dtd; -import org.apache.xerces.impl.Constants; import org.apache.xerces.impl.XMLErrorReporter; import org.apache.xerces.impl.msg.XMLMessageFormatter; - import org.apache.xerces.util.XMLSymbols; - -import org.apache.xerces.xni.NamespaceContext; 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.XNIException; -import org.apache.xerces.xni.parser.XMLComponentManager; -import org.apache.xerces.xni.parser.XMLConfigurationException; /** @@ -113,7 +107,7 @@ Augmentations augs) throws XNIException { // add new namespace context - fNamespaceSupport.pushContext(); + fNamespaceContext.pushContext(); if (element.prefix == XMLSymbols.PREFIX_XMLNS) { fErrorReporter.reportError(XMLMessageFormatter.XMLNS_DOMAIN, @@ -184,19 +178,14 @@ } // declare prefix in context - fNamespaceSupport.declarePrefix(prefix, uri.length() != 0 ? uri : null); - - // call handler - if (fDocumentHandler != null) { - fDocumentHandler.startPrefixMapping(prefix, uri, augs); - } + fNamespaceContext.declarePrefix(prefix, uri.length() != 0 ? uri : null); } } // bind the element String prefix = element.prefix != null ? element.prefix : XMLSymbols.EMPTY_STRING; - element.uri = fNamespaceSupport.getURI(prefix); + element.uri = fNamespaceContext.getURI(prefix); if (element.prefix == null && element.uri != null) { element.prefix = XMLSymbols.EMPTY_STRING; } @@ -214,11 +203,11 @@ ? fAttributeQName.prefix : XMLSymbols.EMPTY_STRING; String arawname = fAttributeQName.rawname; if (arawname == XMLSymbols.PREFIX_XMLNS) { - fAttributeQName.uri = fNamespaceSupport.getURI(XMLSymbols.PREFIX_XMLNS); + fAttributeQName.uri = fNamespaceContext.getURI(XMLSymbols.PREFIX_XMLNS); attributes.setName(i, fAttributeQName); } else if (aprefix != XMLSymbols.EMPTY_STRING) { - fAttributeQName.uri = fNamespaceSupport.getURI(aprefix); + fAttributeQName.uri = fNamespaceContext.getURI(aprefix); if (fAttributeQName.uri == null) { fErrorReporter.reportError(XMLMessageFormatter.XMLNS_DOMAIN, "AttributePrefixUnbound", @@ -257,7 +246,7 @@ // bind element String eprefix = element.prefix != null ? element.prefix : XMLSymbols.EMPTY_STRING; - element.uri = fNamespaceSupport.getURI(eprefix); + element.uri = fNamespaceContext.getURI(eprefix); if (element.uri != null) { element.prefix = eprefix; } @@ -269,17 +258,8 @@ } } - // end prefix mappings - if (fDocumentHandler != null) { - int count = fNamespaceSupport.getDeclaredPrefixCount(); - for (int i = count - 1; i >= 0; i--) { - String prefix = fNamespaceSupport.getDeclaredPrefixAt(i); - fDocumentHandler.endPrefixMapping(prefix, augs); - } - } - // pop context - fNamespaceSupport.popContext(); + fNamespaceContext.popContext(); } // endNamespaceScope(QName,boolean) 1.125 +2 -46 xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java Index: XMLSchemaValidator.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java,v retrieving revision 1.124 retrieving revision 1.125 diff -u -r1.124 -r1.125 --- XMLSchemaValidator.java 11 Dec 2002 16:14:31 -0000 1.124 +++ XMLSchemaValidator.java 16 Dec 2002 01:26:20 -0000 1.125 @@ -663,29 +663,6 @@ } // doctypeDecl(String,String,String) /** - * The start of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * - * @param prefix The namespace prefix. - * @param uri The URI bound to the prefix. - * @param augs Additional information that may include infoset augmentations - * - * @throws XNIException Thrown by handler to signal an error. - */ - public void startPrefixMapping(String prefix, String uri, Augmentations augs) - throws XNIException { - if (DEBUG) { - System.out.println("startPrefixMapping("+prefix+","+uri+")"); - } - - // call handlers - if (fDocumentHandler != null) { - fDocumentHandler.startPrefixMapping(prefix, uri, augs); - } - - } // startPrefixMapping(String,String) - - /** * The start of an element. * * @param element The name of the element. @@ -816,28 +793,7 @@ } } // endElement(QName, Augmentations) - /** - * The end of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * - * @param prefix The namespace prefix. - * @param augs Additional information that may include infoset augmentations - * - * @throws XNIException Thrown by handler to signal an error. - */ - public void endPrefixMapping(String prefix, Augmentations augs) throws XNIException { - - if (DEBUG) { - System.out.println("endPrefixMapping("+prefix+")"); - } - // call handlers - if (fDocumentHandler != null) { - fDocumentHandler.endPrefixMapping(prefix, augs); - } - - } // endPrefixMapping(String) - - /** + /** * The start of a CDATA section. * * @param augs Additional information that may include infoset augmentations 1.2 +39 -1 xml-xerces/java/src/org/apache/xerces/impl/xs/util/SimpleLocator.java Index: SimpleLocator.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/util/SimpleLocator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SimpleLocator.java 18 Feb 2002 22:30:26 -0000 1.1 +++ SimpleLocator.java 16 Dec 2002 01:26:20 -0000 1.2 @@ -109,4 +109,42 @@ public String getBaseSystemId() { return null; } + /** + * @see org.apache.xerces.xni.XMLLocator#setColumnNumber(int) + */ + public void setColumnNumber(int col) { + this.column = col; + } + + /** + * @see org.apache.xerces.xni.XMLLocator#setLineNumber(int) + */ + public void setLineNumber(int line) { + this.line = line; + } + + /** + * @see org.apache.xerces.xni.XMLResourceIdentifier#setBaseSystemId(String) + */ + public void setBaseSystemId(String systemId) {} + + /** + * @see org.apache.xerces.xni.XMLResourceIdentifier#setExpandedSystemId(String) + */ + public void setExpandedSystemId(String systemId) { + esid = systemId; + } + + /** + * @see org.apache.xerces.xni.XMLResourceIdentifier#setLiteralSystemId(String) + */ + public void setLiteralSystemId(String systemId) { + lsid = systemId; + } + + /** + * @see org.apache.xerces.xni.XMLResourceIdentifier#setPublicId(String) + */ + public void setPublicId(String publicId) {} + } 1.78 +1 -28 xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java Index: AbstractDOMParser.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java,v retrieving revision 1.77 retrieving revision 1.78 diff -u -r1.77 -r1.78 --- AbstractDOMParser.java 20 Nov 2002 20:55:39 -0000 1.77 +++ AbstractDOMParser.java 16 Dec 2002 01:26:20 -0000 1.78 @@ -900,33 +900,6 @@ } // doctypeDecl(String,String,String) /** - * The start of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * - * @param prefix The namespace prefix. - * @param uri The URI bound to the prefix. - * @param augs Additional information that may include infoset augmentations - * - * @throws XNIException Thrown by handler to signal an error. - */ - public void startPrefixMapping(String prefix, String uri, Augmentations augs) - throws XNIException { - } // startPrefixMapping(String,String) - - - /** - * The end of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * - * @param prefix The namespace prefix. - * @param augs Additional information that may include infoset augmentations - * - * @throws XNIException Thrown by handler to signal an error. - */ - public void endPrefixMapping(String prefix, Augmentations augs) throws XNIException { - } // endPrefixMapping(String) - - /** * The start of an element. If the document specifies the start element * by using an empty tag, then the startElement method will immediately * be followed by the endElement method, with no intervening methods. 1.35 +37 -51 xml-xerces/java/src/org/apache/xerces/parsers/AbstractSAXParser.java Index: AbstractSAXParser.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/AbstractSAXParser.java,v retrieving revision 1.34 retrieving revision 1.35 diff -u -r1.34 -r1.35 --- AbstractSAXParser.java 11 Dec 2002 16:14:31 -0000 1.34 +++ AbstractSAXParser.java 16 Dec 2002 01:26:20 -0000 1.35 @@ -186,6 +186,9 @@ /** Document handler. */ protected DocumentHandler fDocumentHandler; + + /** Namespace context */ + protected NamespaceContext fNamespaceContext; /** DTD handler. */ protected org.xml.sax.DTDHandler fDTDHandler; @@ -263,7 +266,8 @@ public void startDocument(XMLLocator locator, String encoding, NamespaceContext namespaceContext, Augmentations augs) throws XNIException { - + + fNamespaceContext = namespaceContext; try { // SAX1 if (fDocumentHandler != null) { @@ -373,32 +377,7 @@ } // endEntity(String) - /** - * The start of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * - * @param prefix The namespace prefix. - * @param uri The URI bound to the prefix. - * @param augs Additional information that may include infoset augmentations - * - * @throws XNIException Thrown by handler to signal an error. - */ - public void startPrefixMapping(String prefix, String uri, Augmentations augs) - throws XNIException { - - try { - // SAX2 - if (fContentHandler != null) { - fContentHandler.startPrefixMapping(prefix, uri); - } - } - catch (SAXException e) { - throw new XNIException(e); - } - - } // startPrefixMapping(String prefix, String uri) - - /** + /** * The start of an element. If the document specifies the start element * by using an empty tag, then the startElement method will immediately * be followed by the endElement method, with no intervening methods. @@ -423,6 +402,10 @@ // SAX2 if (fContentHandler != null) { + + // send prefix mapping events + startNamespaceMapping(); + fAugmentations = augs; int len = attributes.getLength(); @@ -551,6 +534,7 @@ String localpart = fNamespaces ? element.localpart : ""; fContentHandler.endElement(uri, localpart, element.rawname); + endNamespaceMapping(); } } catch (SAXException e) { @@ -559,29 +543,6 @@ } // endElement(QName) - /** - * The end of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * - * @param prefix The namespace prefix. - * @param augs Additional information that may include infoset augmentations - * - * @throws XNIException Thrown by handler to signal an error. - */ - public void endPrefixMapping(String prefix, Augmentations augs) throws XNIException { - - try { - // SAX2 - if (fContentHandler != null) { - fContentHandler.endPrefixMapping(prefix); - } - } - catch (SAXException e) { - throw new XNIException(e); - } - - } // endPrefixMapping(String) - /** * The start of a CDATA section. * @param augs Additional information that may include infoset augmentations @@ -1855,6 +1816,31 @@ return fLexicalHandler; } // getLexicalHandler():LexicalHandler + /** + * Send startPrefixMapping events + */ + protected final void startNamespaceMapping() throws SAXException{ + int count = fNamespaceContext.getDeclaredPrefixCount(); + if (count > 0) { + String prefix = null; + for (int i = 0; i < count; i++) { + prefix = fNamespaceContext.getDeclaredPrefixAt(i); + fContentHandler.startPrefixMapping(prefix, + fNamespaceContext.getURI(prefix)); + } + } + } + /** + * Send endPrefixMapping events + */ + protected final void endNamespaceMapping() throws SAXException { + int count = fNamespaceContext.getDeclaredPrefixCount(); + if (count > 0) { + for (int i = 0; i < count; i++) { + fContentHandler.endPrefixMapping(fNamespaceContext.getDeclaredPrefixAt(i)); + } + } + } // // XMLDocumentParser methods // 1.16 +1 -27 xml-xerces/java/src/org/apache/xerces/parsers/AbstractXMLDocumentParser.java Index: AbstractXMLDocumentParser.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/AbstractXMLDocumentParser.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- AbstractXMLDocumentParser.java 7 Dec 2002 00:25:52 -0000 1.15 +++ AbstractXMLDocumentParser.java 16 Dec 2002 01:26:20 -0000 1.16 @@ -196,20 +196,6 @@ } // doctypeDecl(String,String,String) /** - * The start of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * - * @param prefix The namespace prefix. - * @param uri The URI bound to the prefix. - * @param augs Additional information that may include infoset augmentations - * - * @throws XNIException Thrown by handler to signal an error. - */ - public void startPrefixMapping(String prefix, String uri, Augmentations augs) - throws XNIException { - } // startPrefixMapping(String,String) - - /** * The start of an element. If the document specifies the start element * by using an empty tag, then the startElement method will immediately * be followed by the endElement method, with no intervening methods. @@ -278,18 +264,6 @@ */ public void endElement(QName element, Augmentations augs) throws XNIException { } // endElement(QName) - - /** - * The end of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * - * @param prefix The namespace prefix. - * @param augs Additional information that may include infoset augmentations - * - * @throws XNIException Thrown by handler to signal an error. - */ - public void endPrefixMapping(String prefix, Augmentations augs) throws XNIException { - } // endPrefixMapping(String) /** * The start of a CDATA section. 1.14 +1 -2 xml-xerces/java/src/org/apache/xerces/parsers/BasicParserConfiguration.java Index: BasicParserConfiguration.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/BasicParserConfiguration.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- BasicParserConfiguration.java 24 Sep 2002 23:05:18 -0000 1.13 +++ BasicParserConfiguration.java 16 Dec 2002 01:26:20 -0000 1.14 @@ -68,7 +68,6 @@ import org.apache.xerces.impl.msg.XMLMessageFormatter; import org.apache.xerces.util.ParserConfigurationSettings; import org.apache.xerces.util.SymbolTable; -import org.apache.xerces.util.NamespaceSupport; import org.apache.xerces.xni.XMLDocumentHandler; import org.apache.xerces.xni.XMLDTDHandler; import org.apache.xerces.xni.XMLDTDContentModelHandler; 1.6 +7 -1 xml-xerces/java/src/org/apache/xerces/util/ErrorHandlerWrapper.java Index: ErrorHandlerWrapper.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/util/ErrorHandlerWrapper.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ErrorHandlerWrapper.java 29 Jan 2002 01:15:18 -0000 1.5 +++ ErrorHandlerWrapper.java 16 Dec 2002 01:26:21 -0000 1.6 @@ -244,12 +244,18 @@ final int fLineNumber = exception.getLineNumber(); final int fColumnNumber = exception.getColumnNumber(); XMLLocator location = new XMLLocator() { + public void setPublicId(String id) {} public String getPublicId() { return fPublicId; } + public void setExpandedSystemId( String id) {} public String getExpandedSystemId() { return fExpandedSystemId; } + public void setBaseSystemId(String id) {} public String getBaseSystemId() { return null; } + public void setLiteralSystemId(String id) {} public String getLiteralSystemId() { return null; } public int getColumnNumber() { return fColumnNumber; } + public void setColumnNumber(int col) {} public int getLineNumber() { return fLineNumber; } + public void setLineNumber(int line) {} }; return new XMLParseException(location, exception.getMessage(), exception.getException()); 1.14 +98 -231 xml-xerces/java/src/org/apache/xerces/util/NamespaceSupport.java Index: NamespaceSupport.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/util/NamespaceSupport.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- NamespaceSupport.java 18 Oct 2002 02:22:05 -0000 1.13 +++ NamespaceSupport.java 16 Dec 2002 01:26:21 -0000 1.14 @@ -57,8 +57,10 @@ package org.apache.xerces.util; +import java.util.Enumeration; +import java.util.NoSuchElementException; + import org.apache.xerces.xni.NamespaceContext; -import org.apache.xerces.util.XMLSymbols; /** * Namespace support for XML document handlers. This class doesn't @@ -70,8 +72,7 @@ * * @version $Id$ */ -public class NamespaceSupport - implements NamespaceContext { +public class NamespaceSupport implements NamespaceContext { // // Data @@ -106,7 +107,9 @@ /** The current context. */ protected int fCurrentContext; - + + protected String[] fPrefixes = new String[16]; + // // Constructors // @@ -121,32 +124,23 @@ */ public NamespaceSupport(NamespaceContext context) { pushContext(); - while (context != null) { - int count = context.getDeclaredPrefixCount(); - for (int i = 0; i < count; i++) { - String prefix = context.getDeclaredPrefixAt(i); - String uri = getURI(prefix); - if (uri == null) { - uri = context.getURI(prefix); - declarePrefix(prefix, uri); - } - } - context = context.getParentContext(); + // copy declaration in the context + Enumeration enum = context.getAllPrefixes(); + while (enum.hasMoreElements()){ + String prefix = (String)enum.nextElement(); + String uri = context.getURI(prefix); + declarePrefix(prefix, uri); } - } // <init>(NamespaceContext) + } // <init>(NamespaceContext) + // // Public methods // - - // context management - /** - * Reset this Namespace support object for reuse. - * - * <p>It is necessary to invoke this method before reusing the - * Namespace support object for a new session.</p> - */ + /** + * @see org.apache.xerces.xni.NamespaceContext#reset() + */ public void reset() { // reset namespace and context info @@ -164,20 +158,10 @@ } // reset(SymbolTable) - /** - * Start a new Namespace context. - * <p> - * Normally, you should push a new context at the beginning - * of each XML element: the new context will automatically inherit - * the declarations of its parent context, but it will also keep - * track of which declarations were made within this context. - * <p> - * The Namespace support object always starts with a base context - * already in force: in this context, only the "xml" prefix is - * declared. - * - * @see #popContext - */ + + /** + * @see org.apache.xerces.xni.NamespaceContext#pushContext() + */ public void pushContext() { // extend the array, if necessary @@ -193,49 +177,17 @@ } // pushContext() - /** - * Revert to the previous Namespace context. - * <p> - * Normally, you should pop the context at the end of each - * XML element. After popping the context, all Namespace prefix - * mappings that were previously in force are restored. - * <p> - * You must not attempt to declare additional Namespace - * prefixes after popping a context, unless you push another - * context first. - * - * @see #pushContext - */ + /** + * @see org.apache.xerces.xni.NamespaceContext#popContext() + */ public void popContext() { fNamespaceSize = fContext[fCurrentContext--]; } // popContext() - // operations within a context. - - /** - * Declare a Namespace prefix. - * <p> - * This method declares a prefix in the current Namespace - * context; the prefix will remain in force until this context - * is popped, unless it is shadowed in a descendant context. - * <p> - * To declare a default Namespace, use the empty string. The - * prefix must not be "xml" or "xmlns". - * <p> - * Note that you must <em>not</em> declare a prefix after - * you've pushed and popped another Namespace. - * - * @param prefix The prefix to declare, or null for the empty - * string. - * @param uri The Namespace URI to associate with the prefix. - * - * @return true if the prefix was legal, false otherwise - * - * @see #getURI - * @see #getDeclaredPrefixAt - */ + /** + * @see org.apache.xerces.xni.NamespaceContext#declarePrefix(String, String) + */ public boolean declarePrefix(String prefix, String uri) { - // ignore "xml" and "xmlns" prefixes if (prefix == XMLSymbols.PREFIX_XML || prefix == XMLSymbols.PREFIX_XMLNS) { return false; @@ -270,21 +222,11 @@ } // declarePrefix(String,String):boolean - /** - * Look up a prefix and get the currently-mapped Namespace URI. - * <p> - * This method looks up the prefix in the current context. - * Use the empty string ("") for the default Namespace. - * - * @param prefix The prefix to look up. - * - * @return The associated Namespace URI, or null if the prefix - * is undeclared in this context. - * - * @see #getDeclaredPrefixAt - */ + /** + * @see org.apache.xerces.xni.NamespaceContext#getURI(String) + */ public String getURI(String prefix) { - + // find prefix in current context for (int i = fNamespaceSize; i > 0; i -= 2) { if (fNamespace[i - 2] == prefix) { @@ -298,19 +240,9 @@ } // getURI(String):String - - /** - * Look up a namespace URI and get one of the mapped prefix. - * <p> - * This method looks up the namespace URI in the current context. - * - * @param uri The namespace URI to look up. - * - * @return one of the associated prefixes, or null if the uri - * does not map to any prefix. - * - * @see #getPrefix - */ + /** + * @see org.apache.xerces.xni.NamespaceContext#getPrefix(String) + */ public String getPrefix(String uri) { // find uri in current context @@ -324,146 +256,81 @@ // uri not found return null; - } // getURI(String):String + } // getPrefix(String):String - /** - * Return a count of all prefixes currently declared, including - * the default prefix if bound. - */ + /** + * @see org.apache.xerces.xni.NamespaceContext#getDeclaredPrefixCount() + */ public int getDeclaredPrefixCount() { return (fNamespaceSize - fContext[fCurrentContext]) / 2; } // getDeclaredPrefixCount():int - /** - * Returns the prefix at the specified index in the current context. - */ + /** + * @see org.apache.xerces.xni.NamespaceContext#getDeclaredPrefixAt(int) + */ public String getDeclaredPrefixAt(int index) { return fNamespace[fContext[fCurrentContext] + index * 2]; } // getDeclaredPrefixAt(int):String - /** - * Returns the parent namespace context or null if there is no - * parent context. The total depth of the namespace contexts - * matches the element depth in the document. - * <p> - * <strong>Note:</strong> This method <em>may</em> return the same - * NamespaceContext object reference. The caller is responsible for - * saving the declared prefix mappings before calling this method. - */ - public NamespaceContext getParentContext() { - if (fCurrentContext == 1) { - return null; + /** + * @see org.apache.xerces.xni.NamespaceContext#getAllPrefixes() + */ + public Enumeration getAllPrefixes() { + int count = 0; + if (fPrefixes.length < (fNamespace.length/2)) { + // resize prefix array + String[] prefixes = new String[fNamespaceSize]; + fPrefixes = prefixes; } - return new Context(fCurrentContext - 1); - } // getParentContext():NamespaceContext - - // - // Classes - // - - /** - * Namespace context information. The current context is always - * handled directly by the NamespaceSupport class. This class is - * used when a user queries the parent context. - * - * @author Andy Clark, IBM - */ - final class Context - implements NamespaceContext { - - // - // Data - // - - /** The current context. */ - private int fCurrentContext; - - // - // Constructors - // - - /** - * Constructs a new context. Once constructed, this object will - * be re-used when the application calls <code>getParentContext</code. - */ - public Context(int currentContext) { - setCurrentContext(currentContext); - } // <init>(int) - - // - // Public methods - // - - /** Sets the current context. */ - public void setCurrentContext(int currentContext) { - fCurrentContext = currentContext; - } // setCurrentContext(int) - - // - // NamespaceContext methods - // - - /** - * Look up a prefix and get the currently-mapped Namespace URI. - * <p> - * This method looks up the prefix in the current context. - * Use the empty string ("") for the default Namespace. - * - * @param prefix The prefix to look up. - * - * @return The associated Namespace URI, or null if the prefix - * is undeclared in this context. - * - * @see #getPrefix - */ - public String getURI(String prefix) { - - // find prefix in current context - for (int i = fNamespaceSize; i > 0; i -= 2) { - if (fNamespace[i - 2] == prefix) { - return fNamespace[i - 1]; - } + String prefix = null; + boolean unique = true; + for (int i = 2; i < (fNamespaceSize-2); i += 2) { + prefix = fNamespace[i + 2]; + for (int k=0;k<count;k++){ + if (fPrefixes[k]==prefix){ + unique = false; + break; + } } - - // prefix not found - return null; - - } // getURI(String):String - - /** - * Return a count of all prefixes currently declared, including - * the default prefix if bound. - */ - public int getDeclaredPrefixCount() { - return (fNamespaceSize - fContext[fCurrentContext]) / 2; - } // getDeclaredPrefixCount():int - - /** - * Returns the prefix at the specified index in the current context. - */ - public String getDeclaredPrefixAt(int index) { - return fNamespace[fContext[fCurrentContext] + index * 2]; - } // getDeclaredPrefixAt(int):String - - /** - * Returns the parent namespace context or null if there is no - * parent context. The total depth of the namespace contexts - * matches the element depth in the document. - * <p> - * <strong>Note:</strong> This method <em>may</em> return the same - * NamespaceContext object reference. The caller is responsible for - * saving the declared prefix mappings before calling this method. - */ - public NamespaceContext getParentContext() { - if (fCurrentContext == 1) { - return null; + if (unique){ + fPrefixes[count++] = prefix; } - setCurrentContext(fCurrentContext - 1); - return this; - } // getParentContext():NamespaceContext - - } // class Context + unique = true; + } + return new Prefixes(fPrefixes, count); + } + + final class Prefixes implements Enumeration { + private String[] prefixes; + private int counter = 0; + private int size = 0; + + /** + * Constructor for Prefixes. + */ + public Prefixes(String [] prefixes, int size) { + this.prefixes = prefixes; + this.size = size; + } + + /** + * @see java.util.Enumeration#hasMoreElements() + */ + public boolean hasMoreElements() { + return (counter< size); + } + + /** + * @see java.util.Enumeration#nextElement() + */ + public Object nextElement() { + if (counter< size){ + return fPrefixes[counter++]; + } + throw new NoSuchElementException("Illegal access to Namespace prefixes enumeration."); + } +} } // class NamespaceSupport 1.9 +100 -12 xml-xerces/java/src/org/apache/xerces/xni/NamespaceContext.java Index: NamespaceContext.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/xni/NamespaceContext.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- NamespaceContext.java 24 Sep 2002 23:05:18 -0000 1.8 +++ NamespaceContext.java 16 Dec 2002 01:26:21 -0000 1.9 @@ -57,8 +57,17 @@ package org.apache.xerces.xni; +import java.util.Enumeration; + /** * Represents an interface to query namespace information. + * <p> + * The prefix and namespace must be identical references for equal strings, thus + * each string should be internalized (@see String.intern()) + * or added to the <code>SymbolTable</code> + * + * @see <a href="../../../../../xerces2/org/apache/xerces/util/SymbolTable.html"> + * org.apache.xerces.util.SymbolTable</a> * * @author Andy Clark, IBM * @@ -86,20 +95,92 @@ // // NamespaceContext methods // + + /** + * Start a new Namespace context. + * <p> + * A new context should be pushed at the beginning + * of each XML element: the new context will automatically inherit + * the declarations of its parent context, but it will also keep + * track of which declarations were made within this context. + * <p> + * + * @see #popContext + */ + public void pushContext(); + + /** + * Revert to the previous Namespace context. + * <p> + * The context should be popped at the end of each + * XML element. After popping the context, all Namespace prefix + * mappings that were previously in force are restored. + * <p> + * Users must not attempt to declare additional Namespace + * prefixes after popping a context, unless you push another + * context first. + * + * @see #pushContext + */ + public void popContext(); + + /** + * Declare a Namespace prefix. + * <p> + * This method declares a prefix in the current Namespace + * context; the prefix will remain in force until this context + * is popped, unless it is shadowed in a descendant context. + * <p> + * Note that to declare a default Namespace, use the empty string. + * The prefixes "xml" and "xmlns" can't be rebound. + * <p> + * Note that you must <em>not</em> declare a prefix after + * you've pushed and popped another Namespace. + * + * @param prefix The prefix to declare, or null for the empty + * string. + * @param uri The Namespace URI to associate with the prefix. + * + * @return true if the prefix was legal, false otherwise + * + * @see #getURI + * @see #getDeclaredPrefixAt + */ + public boolean declarePrefix(String prefix, String uri); + /** * Look up a prefix and get the currently-mapped Namespace URI. * <p> - * This method looks up the prefix in the current context. + * This method looks up the prefix in the current context. If no mapping + * is found, this methods will continue lookup in the parent context(s). * Use the empty string ("") for the default Namespace. * - * @param prefix The prefix to look up. + * @param prefix The prefix to look up. * * @return The associated Namespace URI, or null if the prefix * is undeclared in this context. */ public String getURI(String prefix); - + + /** + * Look up a namespace URI and get one of the mapped prefix. + * <p> + * This method looks up the namespace URI in the current context. + * If more than one prefix is currently mapped to the same URI, + * this method will make an arbitrary selection + * If no mapping is found, this methods will continue lookup in the + * parent context(s). + * + * @param uri The namespace URI to look up. + * + * @return One of the associated prefixes, or null if the uri + * does not map to any prefix. + * + * @see #getPrefix + */ + public String getPrefix(String uri); + /** * Return a count of locally declared prefixes, including * the default prefix if bound. @@ -111,15 +192,22 @@ */ public String getDeclaredPrefixAt(int index); + /** + * Return an enumeration of all prefixes whose declarations are active + * in the current context. This includes declarations from parent contexts + * that have not been overridden. + * @return Enumeration + */ + public Enumeration getAllPrefixes(); + /** - * Returns the parent namespace context or null if there is no - * parent context. The total depth of the namespace contexts - * matches the element depth in the document. - * <p> - * <strong>Note:</strong> This method <em>may</em> return the same - * NamespaceContext object reference. The caller is responsible for - * saving the declared prefix mappings before calling this method. + * Reset this Namespace support object for reuse. + * + * <p>It is necessary to invoke this method before reusing the + * Namespace support object for a new session.</p> */ - public NamespaceContext getParentContext(); + public void reset(); + + } // interface NamespaceContext 1.6 +1 -29 xml-xerces/java/src/org/apache/xerces/xni/XMLDocumentFragmentHandler.java Index: XMLDocumentFragmentHandler.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/xni/XMLDocumentFragmentHandler.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- XMLDocumentFragmentHandler.java 29 Jan 2002 01:15:19 -0000 1.5 +++ XMLDocumentFragmentHandler.java 16 Dec 2002 01:26:21 -0000 1.6 @@ -196,21 +196,6 @@ throws XNIException; /** - * The start of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * - * @param prefix The namespace prefix. - * @param uri The URI bound to the prefix. - * @param augmentations Additional information that may include infoset - * augmentations. - * - * @throws XNIException Thrown by handler to signal an error. - */ - public void startPrefixMapping(String prefix, String uri, - Augmentations augmentations) - throws XNIException; - - /** * The start of an element. * * @param element The name of the element. @@ -276,19 +261,6 @@ * @throws XNIException Thrown by handler to signal an error. */ public void endElement(QName element, Augmentations augmentations) - throws XNIException; - - /** - * The end of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * - * @param prefix The namespace prefix. - * @param augmentations Additional information that may include infoset - * augmentations. - * - * @throws XNIException Thrown by handler to signal an error. - */ - public void endPrefixMapping(String prefix, Augmentations augmentations) throws XNIException; /** 1.10 +1 -27 xml-xerces/java/src/org/apache/xerces/xni/XMLDocumentHandler.java Index: XMLDocumentHandler.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/xni/XMLDocumentHandler.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- XMLDocumentHandler.java 25 Sep 2002 20:13:51 -0000 1.9 +++ XMLDocumentHandler.java 16 Dec 2002 01:26:21 -0000 1.10 @@ -174,20 +174,6 @@ throws XNIException; /** - * The start of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * @deprecated Use <code>xni.NamespaceContext</code> in <code>startDocument()</code>. - * @param prefix The namespace prefix. - * @param uri The URI bound to the prefix. - * @param augs Additional information that may include infoset augmentations - * - * @exception XNIException - * Thrown by handler to signal an error. - */ - public void startPrefixMapping(String prefix, String uri, Augmentations augs) - throws XNIException; - - /** * The start of an element. * * @param element The name of the element. @@ -306,18 +292,6 @@ * Thrown by handler to signal an error. */ public void endElement(QName element, Augmentations augs) throws XNIException; - - /** - * The end of a namespace prefix mapping. This method will only be - * called when namespace processing is enabled. - * - * @param prefix The namespace prefix. - * @param augs Additional information that may include infoset augmentations - * @deprecated Use <code>xni.NamespaceContext</code> in <code>startDocument()</code>. - * @exception XNIException - * Thrown by handler to signal an error. - */ - public void endPrefixMapping(String prefix, Augmentations augs) throws XNIException; /** * The start of a CDATA section. 1.5 +8 -2 xml-xerces/java/src/org/apache/xerces/xni/XMLLocator.java Index: XMLLocator.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/xni/XMLLocator.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- XMLLocator.java 29 Jan 2002 01:15:19 -0000 1.4 +++ XMLLocator.java 16 Dec 2002 01:26:21 -0000 1.5 @@ -71,10 +71,16 @@ // // XMLLocator methods // + + /** Sets the line number. */ + public void setLineNumber(int line); /** Returns the line number. */ public int getLineNumber(); - + + /** Sets the column number. */ + public void setColumnNumber(int col); + /** Returns the column number. */ public int getColumnNumber(); 1.2 +17 -4 xml-xerces/java/src/org/apache/xerces/xni/XMLResourceIdentifier.java Index: XMLResourceIdentifier.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/xni/XMLResourceIdentifier.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- XMLResourceIdentifier.java 17 Jan 2002 23:54:59 -0000 1.1 +++ XMLResourceIdentifier.java 16 Dec 2002 01:26:21 -0000 1.2 @@ -66,16 +66,29 @@ */ public interface XMLResourceIdentifier { + + /** Sets the public identifier. */ + public void setPublicId(String publicId); /** Returns the public identifier. */ public String getPublicId(); - + + /** Sets the expanded system identifier. */ + public void setExpandedSystemId(String systemId); + /** Returns the expanded system identifier. */ public String getExpandedSystemId(); - + + /** Sets the literal system identifier. */ + public void setLiteralSystemId(String systemId); + /** Returns the literal system identifier. */ public String getLiteralSystemId(); - + + /** Setsthe base URI against which the literal SystemId is to be + resolved.*/ + public void setBaseSystemId(String systemId); + /** <p> Returns the base URI against which the literal SystemId is to be resolved. </p> */ public String getBaseSystemId();
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]