Java Code Examples for com.sun.org.apache.xerces.internal.xni.XMLAttributes#getLength()

The following examples show how to use com.sun.org.apache.xerces.internal.xni.XMLAttributes#getLength() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DOMParserImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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.
 * Overriding the parent to handle DOM_NAMESPACE_DECLARATIONS=false.
 *
 * @param element    The name of the element.
 * @param attributes The element attributes.
 * @param augs     Additional information that may include infoset augmentations
 *
 * @throws XNIException Thrown by handler to signal an error.
 */
public void startElement (QName element, XMLAttributes attributes, Augmentations augs) {
    // namespace declarations parameter has no effect if namespaces is false.
    if (!fNamespaceDeclarations && fNamespaceAware) {
        int len = attributes.getLength();
        for (int i = len - 1; i >= 0; --i) {
            if (XMLSymbols.PREFIX_XMLNS == attributes.getPrefix(i) ||
                XMLSymbols.PREFIX_XMLNS == attributes.getQName(i)) {
                attributes.removeAttributeAt(i);
            }
        }
    }
    super.startElement(element, attributes, augs);
}
 
Example 2
Source File: XPointerElementHandler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public boolean checkStringToken(QName element, XMLAttributes attributes){
    QName cacheQName = null;
    String id =null;
    String rawname =null;
    QName attrName = new QName();
    String attrType = null;
    String attrValue = null;
    int attrCount = attributes.getLength();
    for (int i = 0; i < attrCount; i++) {
        Augmentations aaugs = attributes.getAugmentations(i);
        attributes.getName(i,attrName);
        attrType = attributes.getType(i);
        attrValue = attributes.getValue(i);
        if(attrType != null && attrValue!= null && isIdAttribute(attributes,aaugs,i) && attrValue.equals(fCurrentTokenString)){
            if(hasMoreToken()){
                fCurrentTokenType = 0;
                fCurrentTokenString = null;
                return true;
            }
            else{
                foundElement = element;
                includeElement = true;
                fCurrentTokenType = 0;
                fCurrentTokenString = null;
                fSubResourceIdentified = true;
                return true;
            }
        }
    }
    return false;
}
 
Example 3
Source File: DOMParserImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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.
 * Overriding the parent to handle DOM_NAMESPACE_DECLARATIONS=false.
 *
 * @param element    The name of the element.
 * @param attributes The element attributes.
 * @param augs     Additional information that may include infoset augmentations
 *
 * @throws XNIException Thrown by handler to signal an error.
 */
public void startElement (QName element, XMLAttributes attributes, Augmentations augs) {
    // namespace declarations parameter has no effect if namespaces is false.
    if (!fNamespaceDeclarations && fNamespaceAware) {
        int len = attributes.getLength();
        for (int i = len - 1; i >= 0; --i) {
            if (XMLSymbols.PREFIX_XMLNS == attributes.getPrefix(i) ||
                XMLSymbols.PREFIX_XMLNS == attributes.getQName(i)) {
                attributes.removeAttributeAt(i);
            }
        }
    }
    super.startElement(element, attributes, augs);
}
 
Example 4
Source File: DOMParserImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * 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.
 * Overriding the parent to handle DOM_NAMESPACE_DECLARATIONS=false.
 *
 * @param element    The name of the element.
 * @param attributes The element attributes.
 * @param augs     Additional information that may include infoset augmentations
 *
 * @throws XNIException Thrown by handler to signal an error.
 */
public void startElement (QName element, XMLAttributes attributes, Augmentations augs) {
    // namespace declarations parameter has no effect if namespaces is false.
    if (!fNamespaceDeclarations && fNamespaceAware) {
        int len = attributes.getLength();
        for (int i = len - 1; i >= 0; --i) {
            if (XMLSymbols.PREFIX_XMLNS == attributes.getPrefix(i) ||
                XMLSymbols.PREFIX_XMLNS == attributes.getQName(i)) {
                attributes.removeAttributeAt(i);
            }
        }
    }
    super.startElement(element, attributes, augs);
}
 
Example 5
Source File: SchemaDOM.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void startAnnotationElement(String elemRawName, XMLAttributes attributes) {
    fAnnotationBuffer.append("<").append(elemRawName);
    for(int i=0; i<attributes.getLength(); i++) {
        String aValue = attributes.getValue(i);
        fAnnotationBuffer.append(" ").append(attributes.getQName(i)).append("=\"").append(processAttValue(aValue)).append("\"");
    }
    fAnnotationBuffer.append(">");
}
 
Example 6
Source File: SchemaDOMParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param attributes
 * @return
 */
private boolean hasNonSchemaAttributes(QName element, XMLAttributes attributes) {
    final int length = attributes.getLength();
    for (int i = 0; i < length; ++i) {
        String uri = attributes.getURI(i);
        if (uri != null && uri != SchemaSymbols.URI_SCHEMAFORSCHEMA &&
                uri != NamespaceContext.XMLNS_URI &&
                !(uri == NamespaceContext.XML_URI &&
                        attributes.getQName(i) == SchemaSymbols.ATT_XML_LANG && element.localpart == SchemaSymbols.ELT_SCHEMA)) {
            return true;
        }
    }
    return false;
}
 
Example 7
Source File: SchemaDOM.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void startAnnotationElement(String elemRawName, XMLAttributes attributes) {
    fAnnotationBuffer.append("<").append(elemRawName);
    for(int i=0; i<attributes.getLength(); i++) {
        String aValue = attributes.getValue(i);
        fAnnotationBuffer.append(" ").append(attributes.getQName(i)).append("=\"").append(processAttValue(aValue)).append("\"");
    }
    fAnnotationBuffer.append(">");
}
 
Example 8
Source File: SchemaDOMParser.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * @param attributes
 * @return
 */
private boolean hasNonSchemaAttributes(QName element, XMLAttributes attributes) {
    final int length = attributes.getLength();
    for (int i = 0; i < length; ++i) {
        String uri = attributes.getURI(i);
        if (uri != null && uri != SchemaSymbols.URI_SCHEMAFORSCHEMA &&
                uri != NamespaceContext.XMLNS_URI &&
                !(uri == NamespaceContext.XML_URI &&
                        attributes.getQName(i) == SchemaSymbols.ATT_XML_LANG && element.localpart == SchemaSymbols.ELT_SCHEMA)) {
            return true;
        }
    }
    return false;
}
 
Example 9
Source File: DOMResultBuilder.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void startElement(QName element, XMLAttributes attributes,
        Augmentations augs) throws XNIException {
    Element elem;
    int attrCount = attributes.getLength();
    if (fDocumentImpl == null) {
        elem = fDocument.createElementNS(element.uri, element.rawname);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            elem.setAttributeNS(fAttributeQName.uri, fAttributeQName.rawname, attributes.getValue(i));
        }
    }
    // If it's a Xerces DOM store type information for attributes, set idness, etc..
    else {
        elem = fDocumentImpl.createElementNS(element.uri, element.rawname, element.localpart);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            AttrImpl attr = (AttrImpl) fDocumentImpl.createAttributeNS(fAttributeQName.uri,
                    fAttributeQName.rawname, fAttributeQName.localpart);
            attr.setValue(attributes.getValue(i));

            // write type information to this attribute
            AttributePSVI attrPSVI = (AttributePSVI) attributes.getAugmentations(i).getItem (Constants.ATTRIBUTE_PSVI);
            if (attrPSVI != null) {
                if (fStorePSVI) {
                    ((PSVIAttrNSImpl) attr).setPSVI(attrPSVI);
                }
                Object type = attrPSVI.getMemberTypeDefinition();
                if (type == null) {
                    type = attrPSVI.getTypeDefinition();
                    if (type != null) {
                        attr.setType (type);
                        if (((XSSimpleType) type).isIDType()) {
                            ((ElementImpl) elem).setIdAttributeNode (attr, true);
                        }
                    }
                }
                else {
                    attr.setType (type);
                    if (((XSSimpleType) type).isIDType()) {
                        ((ElementImpl) elem).setIdAttributeNode (attr, true);
                    }
                }
            }
            attr.setSpecified(attributes.isSpecified(i));
            elem.setAttributeNode(attr);
        }
    }
    append(elem);
    fCurrentNode = elem;
    if (fFragmentRoot == null) {
        fFragmentRoot = elem;
    }
}
 
Example 10
Source File: ShortHandPointer.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 * @param element
 * @param attributes
 * @param augs
 * @param event
 * @return
 * @throws XNIException
 */
private boolean hasMatchingIdentifier(QName element,
        XMLAttributes attributes, Augmentations augs, int event)
throws XNIException {
    String normalizedValue = null;

    // The identifiers of an element are determined by the
    // ShortHand Pointer as follows:

    if (attributes != null) {
        for (int i = 0; i < attributes.getLength(); i++) {

            // 1. If an element information item has an attribute information item
            // among its [attributes] that is a schema-determined ID, then it is
            // identified by the value of that attribute information item's
            // [schema normalized value] property;
            normalizedValue = getSchemaDeterminedID(attributes, i);
            if (normalizedValue != null) {
                break;
            }

            // 2. If an element information item has an element information item among
            // its [children] that is a schema-determined ID, then it is identified by
            // the value of that element information item's [schema normalized value] property;
            // ???
            normalizedValue = getChildrenSchemaDeterminedID(attributes, i);
            if (normalizedValue != null) {
                break;
            }

            // 3. If an element information item has an attribute information item among
            // its [attributes] that is a DTD-determined ID, then it is identified by the
            // value of that attribute information item's [normalized value] property.
            // An attribute information item is a DTD-determined ID if and only if it has
            // a [type definition] property whose value is equal to ID.
            normalizedValue = getDTDDeterminedID(attributes, i);
            if (normalizedValue != null) {
                break;
            }
            // 4. No externally determined ID's
        }
    }

    if (normalizedValue != null
            && normalizedValue.equals(fShortHandPointer)) {
        return true;
    }

    return false;
}
 
Example 11
Source File: SchemaDOM.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
void startAnnotation(String elemRawName, XMLAttributes attributes,
        NamespaceContext namespaceContext) {
    if(fAnnotationBuffer == null) fAnnotationBuffer = new StringBuffer(256);
    fAnnotationBuffer.append("<").append(elemRawName).append(" ");

    // attributes are a bit of a pain.  To get this right, we have to keep track
    // of the namespaces we've seen declared, then examine the namespace context
    // for other namespaces so that we can also include them.
    // optimized for simplicity and the case that not many
    // namespaces are declared on this annotation...
    List<String> namespaces = new ArrayList<>();
    for (int i = 0; i < attributes.getLength(); ++i) {
        String aValue = attributes.getValue(i);
        String aPrefix = attributes.getPrefix(i);
        String aQName = attributes.getQName(i);
        // if it's xmlns:* or xmlns, must be a namespace decl
        if (aPrefix == XMLSymbols.PREFIX_XMLNS || aQName == XMLSymbols.PREFIX_XMLNS) {
            namespaces.add(aPrefix == XMLSymbols.PREFIX_XMLNS ?
                    attributes.getLocalName(i) : XMLSymbols.EMPTY_STRING);
        }
        fAnnotationBuffer.append(aQName).append("=\"").append(processAttValue(aValue)).append("\" ");
    }
    // now we have to look through currently in-scope namespaces to see what
    // wasn't declared here
    Enumeration<String> currPrefixes = namespaceContext.getAllPrefixes();
    while(currPrefixes.hasMoreElements()) {
        String prefix = currPrefixes.nextElement();
        String uri = namespaceContext.getURI(prefix);
        if (uri == null) {
            uri = XMLSymbols.EMPTY_STRING;
        }
        if (!namespaces.contains(prefix)) {
            // have to declare this one
            if(prefix == XMLSymbols.EMPTY_STRING) {
                fAnnotationBuffer.append("xmlns").append("=\"").append(processAttValue(uri)).append("\" ");
            }
            else {
                fAnnotationBuffer.append("xmlns:").append(prefix).append("=\"").append(processAttValue(uri)).append("\" ");
            }
        }
    }
    fAnnotationBuffer.append(">\n");
}
 
Example 12
Source File: ShortHandPointer.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 * @param element
 * @param attributes
 * @param augs
 * @param event
 * @return
 * @throws XNIException
 */
private boolean hasMatchingIdentifier(QName element,
        XMLAttributes attributes, Augmentations augs, int event)
throws XNIException {
    String normalizedValue = null;

    // The identifiers of an element are determined by the
    // ShortHand Pointer as follows:

    if (attributes != null) {
        for (int i = 0; i < attributes.getLength(); i++) {

            // 1. If an element information item has an attribute information item
            // among its [attributes] that is a schema-determined ID, then it is
            // identified by the value of that attribute information item's
            // [schema normalized value] property;
            normalizedValue = getSchemaDeterminedID(attributes, i);
            if (normalizedValue != null) {
                break;
            }

            // 2. If an element information item has an element information item among
            // its [children] that is a schema-determined ID, then it is identified by
            // the value of that element information item's [schema normalized value] property;
            // ???
            normalizedValue = getChildrenSchemaDeterminedID(attributes, i);
            if (normalizedValue != null) {
                break;
            }

            // 3. If an element information item has an attribute information item among
            // its [attributes] that is a DTD-determined ID, then it is identified by the
            // value of that attribute information item's [normalized value] property.
            // An attribute information item is a DTD-determined ID if and only if it has
            // a [type definition] property whose value is equal to ID.
            normalizedValue = getDTDDeterminedID(attributes, i);
            if (normalizedValue != null) {
                break;
            }
            // 4. No externally determined ID's
        }
    }

    if (normalizedValue != null
            && normalizedValue.equals(fShortHandPointer)) {
        return true;
    }

    return false;
}
 
Example 13
Source File: DOMResultBuilder.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void startElement(QName element, XMLAttributes attributes,
        Augmentations augs) throws XNIException {
    Element elem;
    int attrCount = attributes.getLength();
    if (fDocumentImpl == null) {
        elem = fDocument.createElementNS(element.uri, element.rawname);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            elem.setAttributeNS(fAttributeQName.uri, fAttributeQName.rawname, attributes.getValue(i));
        }
    }
    // If it's a Xerces DOM store type information for attributes, set idness, etc..
    else {
        elem = fDocumentImpl.createElementNS(element.uri, element.rawname, element.localpart);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            AttrImpl attr = (AttrImpl) fDocumentImpl.createAttributeNS(fAttributeQName.uri,
                    fAttributeQName.rawname, fAttributeQName.localpart);
            attr.setValue(attributes.getValue(i));

            // write type information to this attribute
            AttributePSVI attrPSVI = (AttributePSVI) attributes.getAugmentations(i).getItem (Constants.ATTRIBUTE_PSVI);
            if (attrPSVI != null) {
                if (fStorePSVI) {
                    ((PSVIAttrNSImpl) attr).setPSVI(attrPSVI);
                }
                Object type = attrPSVI.getMemberTypeDefinition();
                if (type == null) {
                    type = attrPSVI.getTypeDefinition();
                    if (type != null) {
                        attr.setType (type);
                        if (((XSSimpleType) type).isIDType()) {
                            ((ElementImpl) elem).setIdAttributeNode (attr, true);
                        }
                    }
                }
                else {
                    attr.setType (type);
                    if (((XSSimpleType) type).isIDType()) {
                        ((ElementImpl) elem).setIdAttributeNode (attr, true);
                    }
                }
            }
            attr.setSpecified(attributes.isSpecified(i));
            elem.setAttributeNode(attr);
        }
    }
    append(elem);
    fCurrentNode = elem;
    if (fFragmentRoot == null) {
        fFragmentRoot = elem;
    }
}
 
Example 14
Source File: DOMResultBuilder.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void startElement(QName element, XMLAttributes attributes,
        Augmentations augs) throws XNIException {
    Element elem;
    int attrCount = attributes.getLength();
    if (fDocumentImpl == null) {
        elem = fDocument.createElementNS(element.uri, element.rawname);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            elem.setAttributeNS(fAttributeQName.uri, fAttributeQName.rawname, attributes.getValue(i));
        }
    }
    // If it's a Xerces DOM store type information for attributes, set idness, etc..
    else {
        elem = fDocumentImpl.createElementNS(element.uri, element.rawname, element.localpart);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            AttrImpl attr = (AttrImpl) fDocumentImpl.createAttributeNS(fAttributeQName.uri,
                    fAttributeQName.rawname, fAttributeQName.localpart);
            attr.setValue(attributes.getValue(i));

            // write type information to this attribute
            AttributePSVI attrPSVI = (AttributePSVI) attributes.getAugmentations(i).getItem (Constants.ATTRIBUTE_PSVI);
            if (attrPSVI != null) {
                if (fStorePSVI) {
                    ((PSVIAttrNSImpl) attr).setPSVI(attrPSVI);
                }
                Object type = attrPSVI.getMemberTypeDefinition();
                if (type == null) {
                    type = attrPSVI.getTypeDefinition();
                    if (type != null) {
                        attr.setType (type);
                        if (((XSSimpleType) type).isIDType()) {
                            ((ElementImpl) elem).setIdAttributeNode (attr, true);
                        }
                    }
                }
                else {
                    attr.setType (type);
                    if (((XSSimpleType) type).isIDType()) {
                        ((ElementImpl) elem).setIdAttributeNode (attr, true);
                    }
                }
            }
            attr.setSpecified(attributes.isSpecified(i));
            elem.setAttributeNode(attr);
        }
    }
    append(elem);
    fCurrentNode = elem;
    if (fFragmentRoot == null) {
        fFragmentRoot = elem;
    }
}
 
Example 15
Source File: ShortHandPointer.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 *
 * @param element
 * @param attributes
 * @param augs
 * @param event
 * @return
 * @throws XNIException
 */
private boolean hasMatchingIdentifier(QName element,
        XMLAttributes attributes, Augmentations augs, int event)
throws XNIException {
    String normalizedValue = null;

    // The identifiers of an element are determined by the
    // ShortHand Pointer as follows:

    if (attributes != null) {
        for (int i = 0; i < attributes.getLength(); i++) {

            // 1. If an element information item has an attribute information item
            // among its [attributes] that is a schema-determined ID, then it is
            // identified by the value of that attribute information item's
            // [schema normalized value] property;
            normalizedValue = getSchemaDeterminedID(attributes, i);
            if (normalizedValue != null) {
                break;
            }

            // 2. If an element information item has an element information item among
            // its [children] that is a schema-determined ID, then it is identified by
            // the value of that element information item's [schema normalized value] property;
            // ???
            normalizedValue = getChildrenSchemaDeterminedID(attributes, i);
            if (normalizedValue != null) {
                break;
            }

            // 3. If an element information item has an attribute information item among
            // its [attributes] that is a DTD-determined ID, then it is identified by the
            // value of that attribute information item's [normalized value] property.
            // An attribute information item is a DTD-determined ID if and only if it has
            // a [type definition] property whose value is equal to ID.
            normalizedValue = getDTDDeterminedID(attributes, i);
            if (normalizedValue != null) {
                break;
            }
            // 4. No externally determined ID's
        }
    }

    if (normalizedValue != null
            && normalizedValue.equals(fShortHandPointer)) {
        return true;
    }

    return false;
}
 
Example 16
Source File: XMLDocumentFragmentScannerImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Scans an attribute name value pair.
 * <p>
 * <pre>
 * [41] Attribute ::= Name Eq AttValue
 * </pre>
 * <p>
 * <strong>Note:</strong> This method assumes that the next
 * character on the stream is the first character of the attribute
 * name.
 * <p>
 * <strong>Note:</strong> This method uses the fAttributeQName and
 * fQName variables. The contents of these variables will be
 * destroyed.
 *
 * @param attributes The attributes list for the scanned attribute.
 */

protected void scanAttribute(XMLAttributes attributes)
throws IOException, XNIException {
    if (DEBUG_START_END_ELEMENT) System.out.println(this.getClass().toString() +">>> scanAttribute()");

    // name
    if (fNamespaces) {
        fEntityScanner.scanQName(fAttributeQName);
    } else {
        String name = fEntityScanner.scanName();
        fAttributeQName.setValues(null, name, name, null);
    }

    // equals
    fEntityScanner.skipSpaces();
    if (!fEntityScanner.skipChar('=')) {
        reportFatalError("EqRequiredInAttribute",
            new Object[] {fCurrentElement.rawname, fAttributeQName.rawname});
    }
    fEntityScanner.skipSpaces();

    int attIndex = 0 ;
    //REVISIT: one more case needs to be included: external PE and standalone is no
    boolean isVC =  fHasExternalDTD && !fStandalone;
    //fTempString would store attribute value
    ///fTempString2 would store attribute non-normalized value

    //this function doesn't use 'attIndex'. We are adding the attribute later
    //after we have figured out that current attribute is not namespace declaration
    //since scanAttributeValue doesn't use attIndex parameter therefore we
    //can safely add the attribute later..
    XMLString tmpStr = getString();

    scanAttributeValue(tmpStr, fTempString2,
            fAttributeQName.rawname, attributes,
            attIndex, isVC, fCurrentElement.rawname);

    // content
    int oldLen = attributes.getLength();
    //if the attribute name already exists.. new value is replaced with old value
    attIndex = attributes.addAttribute(fAttributeQName, XMLSymbols.fCDATASymbol, null);

    // WFC: Unique Att Spec
    //attributes count will be same if the current attribute  name already exists for this element name.
    //this means there are two duplicate attributes.
    if (oldLen == attributes.getLength()) {
        reportFatalError("AttributeNotUnique",
                new Object[]{fCurrentElement.rawname,
                        fAttributeQName.rawname});
    }

    //tmpString contains attribute value
    //we are passing null as the attribute value
    attributes.setValue(attIndex, null, tmpStr);

    ///xxx: nonNormalizedValue is not being set as it is not required by SAX & DOM
    //attributes.setNonNormalizedValue(oldLen, fTempString2.toString());
    attributes.setSpecified(attIndex, true);

    if (DEBUG_START_END_ELEMENT) System.out.println(this.getClass().toString() +"<<< scanAttribute()");

}
 
Example 17
Source File: DOMNormalizer.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
* The start of an element.
*
* @param element    The name of the element.
* @param attributes The element attributes.
* @param augs       Additional information that may include infoset augmentations
*
* @exception XNIException
*                   Thrown by handler to signal an error.
*/
   public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
           throws XNIException {
           Element currentElement = (Element) fCurrentNode;
           int attrCount = attributes.getLength();
   if (DEBUG_EVENTS) {
       System.out.println("==>startElement: " +element+
       " attrs.length="+attrCount);
   }

           for (int i = 0; i < attrCount; i++) {
                   attributes.getName(i, fAttrQName);
                   Attr attr = null;

                   attr = currentElement.getAttributeNodeNS(fAttrQName.uri, fAttrQName.localpart);
       AttributePSVI attrPSVI =
                           (AttributePSVI) attributes.getAugmentations(i).getItem(Constants.ATTRIBUTE_PSVI);

                   if (attrPSVI != null) {
           //REVISIT: instead we should be using augmentations:
           // to set/retrieve Id attributes
           XSTypeDefinition decl = attrPSVI.getMemberTypeDefinition();
           boolean id = false;
           if (decl != null){
               id = ((XSSimpleType)decl).isIDType();
           } else{
               decl = attrPSVI.getTypeDefinition();
               if (decl !=null){
                  id = ((XSSimpleType)decl).isIDType();
               }
           }
           if (id){
               ((ElementImpl)currentElement).setIdAttributeNode(attr, true);
           }

                           if (fPSVI) {
                                   ((PSVIAttrNSImpl) attr).setPSVI(attrPSVI);
                           }
                           if ((fConfiguration.features & DOMConfigurationImpl.DTNORMALIZATION) != 0) {
                                   // datatype-normalization
                                   // NOTE: The specified value MUST be set after we set
                                   //       the node value because that turns the "specified"
                                   //       flag to "true" which may overwrite a "false"
                                   //       value from the attribute list.
                                   boolean specified = attr.getSpecified();
                                   attr.setValue(attrPSVI.getSchemaNormalizedValue());
                                   if (!specified) {
                                           ((AttrImpl) attr).setSpecified(specified);
                                   }
                           }
                   }
           }
   }
 
Example 18
Source File: DOMNormalizer.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * The start of an element.
 *
 * @param element    The name of the element.
 * @param attributes The element attributes.
 * @param augs       Additional information that may include infoset augmentations
 *
 * @exception XNIException
 *                   Thrown by handler to signal an error.
 */
public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
    throws XNIException {
    Element currentElement = (Element) fCurrentNode;
    int attrCount = attributes.getLength();
    if (DEBUG_EVENTS) {
        System.out.println("==>startElement: " +element+
                " attrs.length="+attrCount);
    }

    for (int i = 0; i < attrCount; i++) {
        attributes.getName(i, fAttrQName);
        Attr attr = null;

        attr = currentElement.getAttributeNodeNS(fAttrQName.uri, fAttrQName.localpart);
        if (attr == null) {
            // Must be a non-namespace aware DOM Level 1 node.
            attr = currentElement.getAttributeNode(fAttrQName.rawname);
        }
        AttributePSVI attrPSVI =
            (AttributePSVI) attributes.getAugmentations(i).getItem(Constants.ATTRIBUTE_PSVI);

        if (attrPSVI != null) {
            //REVISIT: instead we should be using augmentations:
            // to set/retrieve Id attributes
            XSTypeDefinition decl = attrPSVI.getMemberTypeDefinition();
            boolean id = false;
            if (decl != null) {
                id = ((XSSimpleType)decl).isIDType();
            }
            else {
                decl = attrPSVI.getTypeDefinition();
                if (decl != null) {
                    id = ((XSSimpleType)decl).isIDType();
                }
            }
            if (id) {
                ((ElementImpl)currentElement).setIdAttributeNode(attr, true);
            }

            if (fPSVI) {
                ((PSVIAttrNSImpl) attr).setPSVI(attrPSVI);
            }

            // Updating the TypeInfo for this attribute.
            ((AttrImpl) attr).setType(decl);

            if ((fConfiguration.features & DOMConfigurationImpl.DTNORMALIZATION) != 0) {
                // datatype-normalization
                // NOTE: The specified value MUST be set after we set
                //       the node value because that turns the "specified"
                //       flag to "true" which may overwrite a "false"
                //       value from the attribute list.
                final String normalizedValue = attrPSVI.getSchemaValue().getNormalizedValue();
                if (normalizedValue != null) {
                    boolean specified = attr.getSpecified();
                    attr.setValue(normalizedValue);
                    if (!specified) {
                        ((AttrImpl) attr).setSpecified(specified);
                    }
                }
            }
        }
        else { // DTD
            String type = null;
            boolean isDeclared = Boolean.TRUE.equals(attributes.getAugmentations(i).getItem (Constants.ATTRIBUTE_DECLARED));
            // For DOM Level 3 TypeInfo, the type name must
            // be null if this attribute has not been declared
            // in the DTD.
            if (isDeclared) {
                type = attributes.getType(i);
                if ("ID".equals (type)) {
                    ((ElementImpl) currentElement).setIdAttributeNode(attr, true);
                }
            }
            // Updating the TypeInfo for this attribute.
            ((AttrImpl) attr).setType(type);
        }
    }
}
 
Example 19
Source File: DOMResultBuilder.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
public void startElement(QName element, XMLAttributes attributes,
        Augmentations augs) throws XNIException {
    Element elem;
    int attrCount = attributes.getLength();
    if (fDocumentImpl == null) {
        elem = fDocument.createElementNS(element.uri, element.rawname);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            elem.setAttributeNS(fAttributeQName.uri, fAttributeQName.rawname, attributes.getValue(i));
        }
    }
    // If it's a Xerces DOM store type information for attributes, set idness, etc..
    else {
        elem = fDocumentImpl.createElementNS(element.uri, element.rawname, element.localpart);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            AttrImpl attr = (AttrImpl) fDocumentImpl.createAttributeNS(fAttributeQName.uri,
                    fAttributeQName.rawname, fAttributeQName.localpart);
            attr.setValue(attributes.getValue(i));

            // write type information to this attribute
            AttributePSVI attrPSVI = (AttributePSVI) attributes.getAugmentations(i).getItem (Constants.ATTRIBUTE_PSVI);
            if (attrPSVI != null) {
                if (fStorePSVI) {
                    ((PSVIAttrNSImpl) attr).setPSVI(attrPSVI);
                }
                Object type = attrPSVI.getMemberTypeDefinition();
                if (type == null) {
                    type = attrPSVI.getTypeDefinition();
                    if (type != null) {
                        attr.setType (type);
                        if (((XSSimpleType) type).isIDType()) {
                            ((ElementImpl) elem).setIdAttributeNode (attr, true);
                        }
                    }
                }
                else {
                    attr.setType (type);
                    if (((XSSimpleType) type).isIDType()) {
                        ((ElementImpl) elem).setIdAttributeNode (attr, true);
                    }
                }
            }
            attr.setSpecified(attributes.isSpecified(i));
            elem.setAttributeNode(attr);
        }
    }
    append(elem);
    fCurrentNode = elem;
    if (fFragmentRoot == null) {
        fFragmentRoot = elem;
    }
}
 
Example 20
Source File: DOMResultBuilder.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
public void startElement(QName element, XMLAttributes attributes,
        Augmentations augs) throws XNIException {
    Element elem;
    int attrCount = attributes.getLength();
    if (fDocumentImpl == null) {
        elem = fDocument.createElementNS(element.uri, element.rawname);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            elem.setAttributeNS(fAttributeQName.uri, fAttributeQName.rawname, attributes.getValue(i));
        }
    }
    // If it's a Xerces DOM store type information for attributes, set idness, etc..
    else {
        elem = fDocumentImpl.createElementNS(element.uri, element.rawname, element.localpart);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            AttrImpl attr = (AttrImpl) fDocumentImpl.createAttributeNS(fAttributeQName.uri,
                    fAttributeQName.rawname, fAttributeQName.localpart);
            attr.setValue(attributes.getValue(i));

            // write type information to this attribute
            AttributePSVI attrPSVI = (AttributePSVI) attributes.getAugmentations(i).getItem (Constants.ATTRIBUTE_PSVI);
            if (attrPSVI != null) {
                if (fStorePSVI) {
                    ((PSVIAttrNSImpl) attr).setPSVI(attrPSVI);
                }
                Object type = attrPSVI.getMemberTypeDefinition();
                if (type == null) {
                    type = attrPSVI.getTypeDefinition();
                    if (type != null) {
                        attr.setType (type);
                        if (((XSSimpleType) type).isIDType()) {
                            ((ElementImpl) elem).setIdAttributeNode (attr, true);
                        }
                    }
                }
                else {
                    attr.setType (type);
                    if (((XSSimpleType) type).isIDType()) {
                        ((ElementImpl) elem).setIdAttributeNode (attr, true);
                    }
                }
            }
            attr.setSpecified(attributes.isSpecified(i));
            elem.setAttributeNode(attr);
        }
    }
    append(elem);
    fCurrentNode = elem;
    if (fFragmentRoot == null) {
        fFragmentRoot = elem;
    }
}