FileDocCategorySizeDatePackage
DOMResultAugmentor.javaAPI DocApache Xerces 3.0.110206Fri Sep 14 20:33:54 BST 2007org.apache.xerces.jaxp.validation

DOMResultAugmentor

public final class DOMResultAugmentor extends Object implements DOMDocumentHandler

DOM result augmentor.

author
Michael Glavassevich, IBM
version
$Id: DOMResultAugmentor.java 542522 2007-05-29 13:59:56Z mrglavas $

Fields Summary
private final DOMValidatorHelper
fDOMValidatorHelper
private Document
fDocument
private org.apache.xerces.dom.CoreDocumentImpl
fDocumentImpl
private boolean
fStorePSVI
private boolean
fIgnoreChars
private final org.apache.xerces.xni.QName
fAttributeQName
Constructors Summary
public DOMResultAugmentor(DOMValidatorHelper helper)

    
       
        fDOMValidatorHelper = helper;
    
Methods Summary
public voidcdata(org.w3c.dom.CDATASection node)

public voidcharacters(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs)

        if (!fIgnoreChars) {
            final Element currentElement = (Element) fDOMValidatorHelper.getCurrentElement();
            currentElement.appendChild(fDocument.createTextNode(text.toString()));
        }
    
public voidcharacters(org.w3c.dom.Text node)

public voidcomment(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs)

public voidcomment(org.w3c.dom.Comment node)

public voiddoctypeDecl(java.lang.String rootElement, java.lang.String publicId, java.lang.String systemId, org.apache.xerces.xni.Augmentations augs)

public voiddoctypeDecl(org.w3c.dom.DocumentType node)

public voidemptyElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attributes, org.apache.xerces.xni.Augmentations augs)

        startElement(element, attributes, augs);
        endElement(element, augs);
    
public voidendCDATA(org.apache.xerces.xni.Augmentations augs)

public voidendDocument(org.apache.xerces.xni.Augmentations augs)

public voidendElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.Augmentations augs)

        final Node currentElement = fDOMValidatorHelper.getCurrentElement();
        // Write type information to this element
        if (augs != null && fDocumentImpl != null) {
            ElementPSVI elementPSVI = (ElementPSVI)augs.getItem(Constants.ELEMENT_PSVI);
            if (elementPSVI != null) {
                if (fStorePSVI) {
                    ((PSVIElementNSImpl) currentElement).setPSVI(elementPSVI);
                }
                XSTypeDefinition type = elementPSVI.getMemberTypeDefinition();
                if (type == null) {
                    type = elementPSVI.getTypeDefinition();
                }
                ((ElementNSImpl) currentElement).setType(type);
            }
        }
    
public voidendGeneralEntity(java.lang.String name, org.apache.xerces.xni.Augmentations augs)

public org.apache.xerces.xni.parser.XMLDocumentSourcegetDocumentSource()

        return null;
    
public voidignorableWhitespace(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs)

        characters(text, augs);
    
private booleanprocessAttributePSVI(org.apache.xerces.dom.AttrImpl attr, org.apache.xerces.xs.AttributePSVI attrPSVI)
Returns whether the given attribute is an ID type.

        if (fStorePSVI) {
            ((PSVIAttrNSImpl) attr).setPSVI (attrPSVI);
        }
        Object type = attrPSVI.getMemberTypeDefinition ();
        if (type == null) {
            type = attrPSVI.getTypeDefinition ();
            if (type != null) {
                attr.setType(type);
                return ((XSSimpleType) type).isIDType();
            }
        }
        else {
            attr.setType(type);
            return ((XSSimpleType) type).isIDType();
        }
        return false;
    
public voidprocessingInstruction(java.lang.String target, org.apache.xerces.xni.XMLString data, org.apache.xerces.xni.Augmentations augs)

public voidprocessingInstruction(org.w3c.dom.ProcessingInstruction node)

public voidsetDOMResult(javax.xml.transform.dom.DOMResult result)

        fIgnoreChars = false;
        if (result != null) {
            final Node target = result.getNode();
            fDocument = (target.getNodeType() == Node.DOCUMENT_NODE) ? (Document) target : target.getOwnerDocument();
            fDocumentImpl = (fDocument instanceof CoreDocumentImpl) ? (CoreDocumentImpl) fDocument : null;
            fStorePSVI = (fDocument instanceof PSVIDocumentImpl);
            return;
        }
        fDocument = null;
        fDocumentImpl = null;
        fStorePSVI = false;
    
public voidsetDocumentSource(org.apache.xerces.xni.parser.XMLDocumentSource source)

public voidsetIgnoringCharacters(boolean ignore)

        fIgnoreChars = ignore;
    
public voidstartCDATA(org.apache.xerces.xni.Augmentations augs)

public voidstartDocument(org.apache.xerces.xni.XMLLocator locator, java.lang.String encoding, org.apache.xerces.xni.NamespaceContext namespaceContext, org.apache.xerces.xni.Augmentations augs)

public voidstartElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attributes, org.apache.xerces.xni.Augmentations augs)

        final Element currentElement = (Element) fDOMValidatorHelper.getCurrentElement();
        final NamedNodeMap attrMap = currentElement.getAttributes();
        
        final int oldLength = attrMap.getLength();
        // If it's a Xerces DOM store type information for attributes, set idness, etc..
        if (fDocumentImpl != null) {
            AttrImpl attr;
            for (int i = 0; i < oldLength; ++i) {
                attr = (AttrImpl) attrMap.item(i);
                
                // write type information to this attribute
                AttributePSVI attrPSVI = (AttributePSVI) attributes.getAugmentations(i).getItem (Constants.ATTRIBUTE_PSVI);
                if (attrPSVI != null) {
                    if (processAttributePSVI(attr, attrPSVI)) {
                        ((ElementImpl) currentElement).setIdAttributeNode (attr, true);
                    }
                }
            }
        }
        
        final int newLength = attributes.getLength();
        // Add default/fixed attributes
        if (newLength > oldLength) {
            if (fDocumentImpl == null) {
                for (int i = oldLength; i < newLength; ++i) {
                    attributes.getName(i, fAttributeQName);
                    currentElement.setAttributeNS(fAttributeQName.uri, fAttributeQName.rawname, attributes.getValue(i));
                }
            }
            // If it's a Xerces DOM store type information for attributes, set idness, etc..
            else {
                for (int i = oldLength; i < newLength; ++i) {
                    attributes.getName(i, fAttributeQName);
                    AttrImpl attr = (AttrImpl) fDocumentImpl.createAttributeNS(fAttributeQName.uri, 
                            fAttributeQName.rawname, fAttributeQName.localpart);
                    attr.setValue(attributes.getValue(i));
                    currentElement.setAttributeNodeNS(attr);
                    
                    // write type information to this attribute
                    AttributePSVI attrPSVI = (AttributePSVI) attributes.getAugmentations(i).getItem (Constants.ATTRIBUTE_PSVI);
                    if (attrPSVI != null) {
                        if (processAttributePSVI(attr, attrPSVI)) {
                            ((ElementImpl) currentElement).setIdAttributeNode (attr, true);
                        }
                    }
                    attr.setSpecified(false);
                }
            }
        }
    
public voidstartGeneralEntity(java.lang.String name, org.apache.xerces.xni.XMLResourceIdentifier identifier, java.lang.String encoding, org.apache.xerces.xni.Augmentations augs)

public voidtextDecl(java.lang.String version, java.lang.String encoding, org.apache.xerces.xni.Augmentations augs)

public voidxmlDecl(java.lang.String version, java.lang.String encoding, java.lang.String standalone, org.apache.xerces.xni.Augmentations augs)