elena 2002/12/15 17:27:43 Modified: java/samples/xni DocumentTracer.java PSVIWriter.java PassThroughFilter.java Log: Modify samples following the changes to XNI (removing start/end Prefix mappings) Revision Changes Path 1.20 +49 -48 xml-xerces/java/samples/xni/DocumentTracer.java Index: DocumentTracer.java =================================================================== RCS file: /home/cvs/xml-xerces/java/samples/xni/DocumentTracer.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- DocumentTracer.java 24 Sep 2002 23:07:52 -0000 1.19 +++ DocumentTracer.java 16 Dec 2002 01:27:43 -0000 1.20 @@ -62,16 +62,16 @@ import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.io.Writer; +import java.util.Enumeration; -import org.apache.xerces.impl.Constants; -import org.apache.xerces.util.ObjectFactory; import org.apache.xerces.parsers.XMLDocumentParser; -import org.apache.xerces.xni.NamespaceContext; +import org.apache.xerces.util.ObjectFactory; 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.XMLDTDHandler; import org.apache.xerces.xni.XMLDTDContentModelHandler; +import org.apache.xerces.xni.XMLDTDHandler; import org.apache.xerces.xni.XMLLocator; import org.apache.xerces.xni.XMLResourceIdentifier; import org.apache.xerces.xni.XMLString; @@ -82,8 +82,6 @@ import org.apache.xerces.xni.parser.XMLParseException; import org.apache.xerces.xni.parser.XMLParserConfiguration; -import org.apache.xerces.xni.psvi.ElementPSVI; - /** * Provides a complete trace of XNI document and DTD events for * files parsed. @@ -156,6 +154,8 @@ /** Indent level. */ protected int fIndent; + + protected NamespaceContext fNamespaceContext; // // Constructors @@ -218,7 +218,7 @@ public void startDocument(XMLLocator locator, String encoding, NamespaceContext namespaceContext, Augmentations augs) throws XNIException { - + fNamespaceContext = namespaceContext; fIndent = 0; printIndent(); fOut.print("startDocument("); @@ -305,29 +305,11 @@ } // doctypeDecl(String,String,String) - /** Start prefix mapping. */ - public void startPrefixMapping(String prefix, String uri, Augmentations augs) - throws XNIException { - - printIndent(); - fOut.print("startPrefixMapping("); - fOut.print("prefix="); - printQuotedString(prefix); - fOut.print(','); - fOut.print("uri="); - printQuotedString(uri); - if (augs != null) { - fOut.print(','); - printAugmentations(augs); - } - fOut.println(')'); - fOut.flush(); - - } // startPrefixMapping(String,String) - /** Start element. */ public void startElement(QName element, XMLAttributes attributes, Augmentations augs) - throws XNIException { + throws XNIException { + + printInScopeNamespaces(); printIndent(); fOut.print("startElement("); @@ -345,7 +327,7 @@ /** Empty element. */ public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException { - + printInScopeNamespaces(); printIndent(); fOut.print("emptyElement("); printElement(element, attributes); @@ -355,7 +337,7 @@ } fOut.println(')'); fOut.flush(); - + printEndNamespaceMapping(); } // emptyElement(QName,XMLAttributes) @@ -424,26 +406,13 @@ printAugmentations(augs); } fOut.println(')'); - fOut.flush(); - - } // endElement(QName) + fOut.flush(); - /** End prefix mapping. */ - public void endPrefixMapping(String prefix, Augmentations augs) throws XNIException { + printEndNamespaceMapping(); - printIndent(); - fOut.print("endPrefixMapping("); - fOut.print("prefix="); - printQuotedString(prefix); - if (augs != null) { - fOut.print(','); - printAugmentations(augs); - } - fOut.println(')'); - fOut.flush(); - - } // endPrefixMapping(String) + } // endElement(QName) + /** Start CDATA section. */ public void startCDATA(Augmentations augs) throws XNIException { @@ -1215,7 +1184,39 @@ // // Protected methods // + protected void printInScopeNamespaces(){ + int count = fNamespaceContext.getDeclaredPrefixCount(); + if (count>0){ + for (int i = 0; i < count; i++) { + printIndent(); + fOut.print("declaredPrefix("); + fOut.print("prefix="); + String prefix = fNamespaceContext.getDeclaredPrefixAt(i); + printQuotedString(prefix); + fOut.print(','); + fOut.print("uri="); + printQuotedString(fNamespaceContext.getURI(prefix)); + fOut.println(')'); + fOut.flush(); + } + } + } + + protected void printEndNamespaceMapping(){ + int count = fNamespaceContext.getDeclaredPrefixCount(); + if (count > 0) { + for (int i = 0; i < count; i++) { + printIndent(); + fOut.print("endPrefix("); + fOut.print("prefix="); + String prefix = fNamespaceContext.getDeclaredPrefixAt(i); + printQuotedString(prefix); + fOut.println(')'); + fOut.flush(); + } + } + } /** Prints an element. */ protected void printElement(QName element, XMLAttributes attributes) { 1.15 +26 -60 xml-xerces/java/samples/xni/PSVIWriter.java Index: PSVIWriter.java =================================================================== RCS file: /home/cvs/xml-xerces/java/samples/xni/PSVIWriter.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- PSVIWriter.java 8 Nov 2002 20:09:10 -0000 1.14 +++ PSVIWriter.java 16 Dec 2002 01:27:43 -0000 1.15 @@ -186,8 +186,8 @@ /** Symbol table. */ protected SymbolTable fSymbolTable; - /** NamespaceBinder*/ - protected XMLNamespaceBinder fNamespaceBinder; + /** Namespace Context*/ + protected NamespaceContext fNamespaceContext; /** Attribute QName. */ private QName fAttrQName = new QName(); @@ -230,8 +230,6 @@ catch (XMLConfigurationException e) { fPSVInfoset = false; } - - fNamespaceBinder = (XMLNamespaceBinder)componentManager.getProperty(NAMESPACE_BINDER); fSymbolTable = (SymbolTable)componentManager.getProperty(SYMBOL_TABLE); fIncludeIgnorableWhitespace = componentManager.getFeature(INCLUDE_IGNORABLE_WHITESPACE); @@ -447,6 +445,7 @@ public void startDocument(XMLLocator locator, String encoding, NamespaceContext namespaceContext, Augmentations augs) throws XNIException { + fNamespaceContext = namespaceContext; if (fPSVInfoset) { printIndentTag("<document"+ " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+ @@ -564,21 +563,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. - * - * @throws XNIException Thrown by handler to signal an error. - */ - public void startPrefixMapping(String prefix, String uri, Augmentations augs) - throws XNIException { - if (fDocumentHandler != null) { - fDocumentHandler.startPrefixMapping(prefix, uri, augs); - } - } // startPrefixMapping(String,String) /** * Binds the namespaces. This method will handle calling the @@ -608,6 +592,7 @@ printElement("localName" , element.localpart); printElement("prefix" , element.prefix); printAttributes(attributes); + printInScopeNamespaces(); printPSVIStartElement(augs); } if (fDocumentHandler != null) { @@ -633,6 +618,7 @@ printElement("localName" , element.localpart); printElement("prefix" , element.prefix); printAttributes(attributes); + printInScopeNamespaces(); printTag("<children/>"); printPSVIStartElement(augs); printPSVIEndElement(augs); @@ -721,7 +707,6 @@ printUnIndentTag("</children>"); } _elementState.pop(); - printinScopeNamespaces(); printPSVIEndElement(augs); printUnIndentTag("</element>"); } @@ -731,23 +716,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 { - if (fDocumentHandler != null) { - fDocumentHandler.endPrefixMapping(prefix, augs); - } - - } // endPrefixMapping(String) - - /** * The start of a CDATA section. * * @param augs Additional information that may include infoset augmentations @@ -1182,28 +1150,26 @@ * form xmlns="", which does not declare a namespace but rather undeclares * the default namespace */ - private void printinScopeNamespaces() { - NamespaceContext namespaceContext = fNamespaceBinder.getNamespaceContext(); - NamespaceContext temp; - String prefix; - - printIndentTag("<inScopeNamespaces>"); - while (namespaceContext!=null) { - temp = namespaceContext.getParentContext(); - if (temp == null) { - int prefixCount = namespaceContext.getDeclaredPrefixCount(); - for (int i=0;i<prefixCount;i++) { - printIndentTag("<namespace>"); - prefix=namespaceContext.getDeclaredPrefixAt(i); - printElement("prefix",prefix); - printElement("namespaceName",namespaceContext.getURI(prefix)); - printUnIndentTag("</namespace>"); - } - } - namespaceContext = temp; - } - printUnIndentTag("</inScopeNamespaces>"); - }//printinScopeNamespaces() + private void printInScopeNamespaces() { + printIndentTag("<inScopeNamespaces>"); + printIndentTag("<namespace>"); + // print 'xml' binding + printElement("prefix", "xml"); + printElement("namespaceName", NamespaceContext.XML_URI); + printUnIndentTag("</namespace>"); + Enumeration enum = fNamespaceContext.getAllPrefixes(); + while (enum.hasMoreElements()) { + printIndentTag("<namespace>"); + + String prefix = (String) enum.nextElement(); + String uri = fNamespaceContext.getURI(prefix); + printElement("prefix", prefix); + printElement("namespaceName", uri); + printUnIndentTag("</namespace>"); + + } + printUnIndentTag("</inScopeNamespaces>"); + } //printinScopeNamespaces() /** * Check whether the calling event is first in children list , 1.8 +1 -31 xml-xerces/java/samples/xni/PassThroughFilter.java Index: PassThroughFilter.java =================================================================== RCS file: /home/cvs/xml-xerces/java/samples/xni/PassThroughFilter.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- PassThroughFilter.java 24 Sep 2002 23:07:52 -0000 1.7 +++ PassThroughFilter.java 16 Dec 2002 01:27:43 -0000 1.8 @@ -211,36 +211,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. - * - * @throws XNIException Thrown by handler to signal an error. - */ - public void startPrefixMapping(String prefix, String uri, Augmentations augs) - throws XNIException { - if (fDocumentHandler != null) { - fDocumentHandler.startPrefixMapping(prefix, uri, augs); - } - } // 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. - * - * @throws XNIException Thrown by handler to signal an error. - */ - public void endPrefixMapping(String prefix, Augmentations augs) throws XNIException { - if (fDocumentHandler != null) { - fDocumentHandler.endPrefixMapping(prefix, augs); - } - } // endPrefixMapping(String) - - /** * The start of an element. * * @param element The name of the element.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]