FileDocCategorySizeDatePackage
XNI2SAX.javaAPI DocJava SE 5 API7885Fri Aug 26 14:55:54 BST 2005com.sun.org.apache.xerces.internal.jaxp

XNI2SAX

public class XNI2SAX extends DefaultXMLDocumentHandler
Converts {@link XNI} events to {@link ContentHandler} events.

Deriving from {@link DefaultXMLDocumentHandler} to reuse its default {@link com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler} implementation.

author
Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)

Fields Summary
private ContentHandler
fContentHandler
private String
fVersion
protected NamespaceContext
fNamespaceContext
Namespace context
private final AttributesProxy
fAttributesProxy
For efficiency, we reuse one instance.
Constructors Summary
Methods Summary
public voidcharacters(com.sun.org.apache.xerces.internal.xni.XMLString text, com.sun.org.apache.xerces.internal.xni.Augmentations augs)

        try {
            fContentHandler.characters(text.ch,text.offset,text.length);
        } catch (SAXException e) {
            throw new XNIException(e);
        }
    
public voidemptyElement(com.sun.org.apache.xerces.internal.xni.QName element, com.sun.org.apache.xerces.internal.xni.XMLAttributes attributes, com.sun.org.apache.xerces.internal.xni.Augmentations augs)

        startElement(element,attributes,augs);
        endElement(element,augs);
    
public voidendDocument(com.sun.org.apache.xerces.internal.xni.Augmentations augs)

        try {
            fContentHandler.endDocument();
        } catch (SAXException e) {
            throw new XNIException(e);
        }
    
public voidendElement(com.sun.org.apache.xerces.internal.xni.QName element, com.sun.org.apache.xerces.internal.xni.Augmentations augs)

        try {
            String uri = element.uri != null ? element.uri : "";
            String localpart = element.localpart;
            fContentHandler.endElement(uri, localpart, element.rawname);
            
            // send endPrefixMapping events
            int count = fNamespaceContext.getDeclaredPrefixCount();
            if (count > 0) {
                for (int i = 0; i < count; i++) {
                    fContentHandler.endPrefixMapping(fNamespaceContext.getDeclaredPrefixAt(i));
                }
            }
        } catch( SAXException e ) {
            throw new XNIException(e);
        }
    
public org.xml.sax.ContentHandlergetContentHandler()

        return fContentHandler;
    
public voidignorableWhitespace(com.sun.org.apache.xerces.internal.xni.XMLString text, com.sun.org.apache.xerces.internal.xni.Augmentations augs)

        try {
            fContentHandler.ignorableWhitespace(text.ch,text.offset,text.length);
        } catch (SAXException e) {
            throw new XNIException(e);
        }
    
public voidprocessingInstruction(java.lang.String target, com.sun.org.apache.xerces.internal.xni.XMLString data, com.sun.org.apache.xerces.internal.xni.Augmentations augs)

        try {
            fContentHandler.processingInstruction(target,data.toString());
        } catch (SAXException e) {
            throw new XNIException(e);
        }
    
public voidsetContentHandler(org.xml.sax.ContentHandler handler)


          
        this.fContentHandler = handler;
    
public voidstartDocument(com.sun.org.apache.xerces.internal.xni.XMLLocator locator, java.lang.String encoding, com.sun.org.apache.xerces.internal.xni.NamespaceContext namespaceContext, com.sun.org.apache.xerces.internal.xni.Augmentations augs)

        fNamespaceContext = namespaceContext;
        fContentHandler.setDocumentLocator(new LocatorProxy(locator,fVersion));
        try {
            fContentHandler.startDocument();
        } catch (SAXException e) {
            throw new XNIException(e);
        }
    
public voidstartElement(com.sun.org.apache.xerces.internal.xni.QName element, com.sun.org.apache.xerces.internal.xni.XMLAttributes attributes, com.sun.org.apache.xerces.internal.xni.Augmentations augs)

        try {
            // start namespace prefix mappings
            int count = fNamespaceContext.getDeclaredPrefixCount();
            if (count > 0) {
                String prefix = null;
                String uri = null;
                for (int i = 0; i < count; i++) {
                    prefix = fNamespaceContext.getDeclaredPrefixAt(i);
                    uri = fNamespaceContext.getURI(prefix);
                    fContentHandler.startPrefixMapping(prefix, (uri == null)?"":uri);
                }
            }
                    
            String uri = element.uri != null ? element.uri : "";
            String localpart = element.localpart;
            fAttributesProxy.setAttributes(attributes);
            fContentHandler.startElement(uri, localpart, element.rawname, fAttributesProxy);
        } catch( SAXException e ) {
            throw new XNIException(e);
        }
    
public voidxmlDecl(java.lang.String version, java.lang.String encoding, java.lang.String standalone, com.sun.org.apache.xerces.internal.xni.Augmentations augs)

        this.fVersion = version;