FileDocCategorySizeDatePackage
SAX2XNI.javaAPI DocJava SE 5 API8909Fri Aug 26 14:55:56 BST 2005com.sun.org.apache.xerces.internal.util

SAX2XNI

public class SAX2XNI extends Object implements XMLDocumentSource, ContentHandler
Receves SAX {@link ContentHandler} events and produces the equivalent {@link XMLDocumentHandler} events.
author
Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)

Fields Summary
private XMLDocumentHandler
fCore
private final NamespaceSupport
nsContext
private final SymbolTable
symbolTable
private Locator
locator
private final XMLAttributes
xa
only one instance of XMLAttributes is used.
Constructors Summary
public SAX2XNI(XMLDocumentHandler core)

        this.fCore = core;
    
Methods Summary
public voidcharacters(char[] buf, int offset, int len)

        try {
            fCore.characters(new XMLString(buf,offset,len),null);
        } catch( WrappedSAXException e ) {
            throw e.exception;
        }
    
private com.sun.org.apache.xerces.internal.xni.XMLAttributescreateAttributes(org.xml.sax.Attributes att)
Creates an XMLAttributes object.

    
         
        
        xa.removeAllAttributes();
        int len = att.getLength();
        for (int i = 0; i < len; i++)
            xa.addAttribute(
                    createQName(att.getURI(i), att.getLocalName(i), att.getQName(i)),
                    att.getType(i),
                    att.getValue(i));
        return xa;
    
private com.sun.org.apache.xerces.internal.xni.QNamecreateQName(java.lang.String uri, java.lang.String local, java.lang.String raw)
Creates a QName object.


        int idx = raw.indexOf(':");
        
        if( local.length()==0 ) {
            // if naemspace processing is turned off, local could be "".
            // in that case, treat everything to be in the no namespace.
            uri = "";
            if(idx<0)
                local = raw;
            else
                local = raw.substring(idx+1);
        }
        
        String prefix;
        if (idx < 0)
            prefix = null;
        else
            prefix = raw.substring(0, idx);
        
        if (uri != null && uri.length() == 0)
            uri = null; // XNI uses null whereas SAX uses the empty string
        
        return new QName(symbolize(prefix), symbolize(local), symbolize(raw), symbolize(uri));
    
private com.sun.org.apache.xerces.internal.xni.XMLStringcreateXMLString(java.lang.String str)

        // with my patch
        // return new XMLString(str);
        
        // for now
        return new XMLString(str.toCharArray(), 0, str.length());
    
public voidendDocument()

        try {
            fCore.endDocument(null);
        } catch( WrappedSAXException e ) {
            throw e.exception;
        }
    
public voidendElement(java.lang.String uri, java.lang.String local, java.lang.String qname)

        try {
            fCore.endElement(createQName(uri,local,qname),null);
        } catch( WrappedSAXException e ) {
            throw e.exception;
        }
    
public voidendPrefixMapping(java.lang.String prefix)

        nsContext.popContext();
    
public com.sun.org.apache.xerces.internal.xni.XMLDocumentHandlergetDocumentHandler()

        return fCore;
    
public voidignorableWhitespace(char[] buf, int offset, int len)

        try {
            fCore.ignorableWhitespace(new XMLString(buf,offset,len),null);
        } catch( WrappedSAXException e ) {
            throw e.exception;
        }
    
public voidprocessingInstruction(java.lang.String target, java.lang.String data)

        try {
            fCore.processingInstruction(
                    symbolize(target),createXMLString(data),null);
        } catch( WrappedSAXException e ) {
            throw e.exception;
        }
    
public voidsetDocumentHandler(com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler handler)

    

        
        fCore = handler;
    
public voidsetDocumentLocator(org.xml.sax.Locator _loc)

        this.locator = _loc;
    
public voidskippedEntity(java.lang.String name)

    
public voidstartDocument()

        try {
            nsContext.reset();
            
            XMLLocator xmlLocator;
            if(locator==null)
                // some SAX source doesn't provide a locator,
                // in which case we assume no line information is available
                // and use a dummy locator. With this, downstream components
                // can always assume that they will get a non-null Locator.
                xmlLocator=new SimpleLocator(null,null,-1,-1);
            else
                xmlLocator=new LocatorWrapper(locator);
            
            fCore.startDocument(
                    xmlLocator,
                    null,
                    nsContext,
                    null);
        } catch( WrappedSAXException e ) {
            throw e.exception;
        }
    
public voidstartElement(java.lang.String uri, java.lang.String local, java.lang.String qname, org.xml.sax.Attributes att)

        try {
            fCore.startElement(createQName(uri,local,qname),createAttributes(att),null);
        } catch( WrappedSAXException e ) {
            throw e.exception;
        }
    
public voidstartPrefixMapping(java.lang.String prefix, java.lang.String uri)

        nsContext.pushContext();
        nsContext.declarePrefix(prefix,uri);
    
private java.lang.Stringsymbolize(java.lang.String s)
Symbolizes the specified string.

        if (s == null)
            return null;
        else
            return symbolTable.addSymbol(s);