org.w3c.dom.Attr#getSpecified ( )源码实例Demo

下面列出了org.w3c.dom.Attr#getSpecified ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk1.8-source-analysis   文件: DOMNormalizer.java
final String normalizeAttributeValue(String value, Attr attr) {
    if (!attr.getSpecified()){
        // specified attributes should already have a normalized form
        // since those were added by validator
        return value;
    }
    int end = value.length();
    // ensure capacity
    if (fNormalizedValue.ch.length < end) {
        fNormalizedValue.ch = new char[end];
    }
    fNormalizedValue.length = 0;
    boolean normalized = false;
    for (int i = 0; i < end; i++) {
        char c = value.charAt(i);
        if (c==0x0009 || c==0x000A) {
           fNormalizedValue.ch[fNormalizedValue.length++] = ' ';
           normalized = true;
        }
        else if(c==0x000D){
           normalized = true;
           fNormalizedValue.ch[fNormalizedValue.length++] = ' ';
           int next = i+1;
           if (next < end && value.charAt(next)==0x000A) i=next; // skip following xA
        }
        else {
            fNormalizedValue.ch[fNormalizedValue.length++] = c;
        }
    }
    if (normalized){
       value = fNormalizedValue.toString();
       attr.setValue(value);
    }
    return value;
}
 
源代码2 项目: jdk1.8-source-analysis   文件: DOM2DTM.java
/**
 *     5. [specified] A flag indicating whether this attribute was actually
 *        specified in the start-tag of its element, or was defaulted from the
 *        DTD.
 *
 * @param attributeHandle the attribute handle
 * @return <code>true</code> if the attribute was specified;
 *         <code>false</code> if it was defaulted.
 */
public boolean isAttributeSpecified(int attributeHandle)
{
  int type = getNodeType(attributeHandle);

  if (DTM.ATTRIBUTE_NODE == type)
  {
    Attr attr = (Attr)getNode(attributeHandle);
    return attr.getSpecified();
  }
  return false;
}
 
源代码3 项目: openjdk-jdk8u   文件: DOM2DTM.java
/**
 *     5. [specified] A flag indicating whether this attribute was actually
 *        specified in the start-tag of its element, or was defaulted from the
 *        DTD.
 *
 * @param attributeHandle the attribute handle
 * @return <code>true</code> if the attribute was specified;
 *         <code>false</code> if it was defaulted.
 */
public boolean isAttributeSpecified(int attributeHandle)
{
  int type = getNodeType(attributeHandle);

  if (DTM.ATTRIBUTE_NODE == type)
  {
    Attr attr = (Attr)getNode(attributeHandle);
    return attr.getSpecified();
  }
  return false;
}
 
源代码4 项目: j2objc   文件: DOM2DTM.java
/**
 *     5. [specified] A flag indicating whether this attribute was actually
 *        specified in the start-tag of its element, or was defaulted from the
 *        DTD.
 *
 * @param attributeHandle the attribute handle
 * @return <code>true</code> if the attribute was specified;
 *         <code>false</code> if it was defaulted.
 */
public boolean isAttributeSpecified(int attributeHandle)
{
  int type = getNodeType(attributeHandle);

  if (DTM.ATTRIBUTE_NODE == type)
  {
    Attr attr = (Attr)getNode(attributeHandle);
    return attr.getSpecified();
  }
  return false;
}
 
源代码5 项目: cxf   文件: ServerFactoryBeanDefinitionParser.java
protected boolean parseAttribute(Element element, Attr node,
                                 ParserContext ctx, BeanDefinitionBuilder bean) {
    if (!node.getSpecified() && "start".equals(node.getLocalName())) {
        return false;
    }
    return super.parseAttribute(element, node, ctx, bean);
}
 
源代码6 项目: hottub   文件: DOMNormalizer.java
final String normalizeAttributeValue(String value, Attr attr) {
    if (!attr.getSpecified()){
        // specified attributes should already have a normalized form
        // since those were added by validator
        return value;
    }
    int end = value.length();
    // ensure capacity
    if (fNormalizedValue.ch.length < end) {
        fNormalizedValue.ch = new char[end];
    }
    fNormalizedValue.length = 0;
    boolean normalized = false;
    for (int i = 0; i < end; i++) {
        char c = value.charAt(i);
        if (c==0x0009 || c==0x000A) {
           fNormalizedValue.ch[fNormalizedValue.length++] = ' ';
           normalized = true;
        }
        else if(c==0x000D){
           normalized = true;
           fNormalizedValue.ch[fNormalizedValue.length++] = ' ';
           int next = i+1;
           if (next < end && value.charAt(next)==0x000A) i=next; // skip following xA
        }
        else {
            fNormalizedValue.ch[fNormalizedValue.length++] = c;
        }
    }
    if (normalized){
       value = fNormalizedValue.toString();
       attr.setValue(value);
    }
    return value;
}
 
源代码7 项目: Bytecoder   文件: DOMNormalizer.java
final String normalizeAttributeValue(String value, Attr attr) {
    if (!attr.getSpecified()){
        // specified attributes should already have a normalized form
        // since those were added by validator
        return value;
    }
    int end = value.length();
    // ensure capacity
    if (fNormalizedValue.ch.length < end) {
        fNormalizedValue.ch = new char[end];
    }
    fNormalizedValue.length = 0;
    boolean normalized = false;
    for (int i = 0; i < end; i++) {
        char c = value.charAt(i);
        if (c==0x0009 || c==0x000A) {
           fNormalizedValue.ch[fNormalizedValue.length++] = ' ';
           normalized = true;
        }
        else if(c==0x000D){
           normalized = true;
           fNormalizedValue.ch[fNormalizedValue.length++] = ' ';
           int next = i+1;
           if (next < end && value.charAt(next)==0x000A) i=next; // skip following xA
        }
        else {
            fNormalizedValue.ch[fNormalizedValue.length++] = c;
        }
    }
    if (normalized){
       value = fNormalizedValue.toString();
       attr.setValue(value);
    }
    return value;
}
 
源代码8 项目: openjdk-8   文件: DOM2DTM.java
/**
 *     5. [specified] A flag indicating whether this attribute was actually
 *        specified in the start-tag of its element, or was defaulted from the
 *        DTD.
 *
 * @param attributeHandle the attribute handle
 * @return <code>true</code> if the attribute was specified;
 *         <code>false</code> if it was defaulted.
 */
public boolean isAttributeSpecified(int attributeHandle)
{
  int type = getNodeType(attributeHandle);

  if (DTM.ATTRIBUTE_NODE == type)
  {
    Attr attr = (Attr)getNode(attributeHandle);
    return attr.getSpecified();
  }
  return false;
}
 
源代码9 项目: JDKSourceCode1.8   文件: DOM2DTM.java
/**
 *     5. [specified] A flag indicating whether this attribute was actually
 *        specified in the start-tag of its element, or was defaulted from the
 *        DTD.
 *
 * @param attributeHandle the attribute handle
 * @return <code>true</code> if the attribute was specified;
 *         <code>false</code> if it was defaulted.
 */
public boolean isAttributeSpecified(int attributeHandle)
{
  int type = getNodeType(attributeHandle);

  if (DTM.ATTRIBUTE_NODE == type)
  {
    Attr attr = (Attr)getNode(attributeHandle);
    return attr.getSpecified();
  }
  return false;
}
 
源代码10 项目: openjdk-jdk8u   文件: DOMNormalizer.java
final String normalizeAttributeValue(String value, Attr attr) {
    if (!attr.getSpecified()){
        // specified attributes should already have a normalized form
        // since those were added by validator
        return value;
    }
    int end = value.length();
    // ensure capacity
    if (fNormalizedValue.ch.length < end) {
        fNormalizedValue.ch = new char[end];
    }
    fNormalizedValue.length = 0;
    boolean normalized = false;
    for (int i = 0; i < end; i++) {
        char c = value.charAt(i);
        if (c==0x0009 || c==0x000A) {
           fNormalizedValue.ch[fNormalizedValue.length++] = ' ';
           normalized = true;
        }
        else if(c==0x000D){
           normalized = true;
           fNormalizedValue.ch[fNormalizedValue.length++] = ' ';
           int next = i+1;
           if (next < end && value.charAt(next)==0x000A) i=next; // skip following xA
        }
        else {
            fNormalizedValue.ch[fNormalizedValue.length++] = c;
        }
    }
    if (normalized){
       value = fNormalizedValue.toString();
       attr.setValue(value);
    }
    return value;
}
 
源代码11 项目: jdk1.8-source-analysis   文件: DOMNormalizer.java
/**
* 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);
                                   }
                           }
                   }
           }
   }
 
源代码12 项目: openjdk-8   文件: DOMUtil.java
/**
 * Copies the source tree into the specified place in a destination
 * tree. The source node and its children are appended as children
 * of the destination node.
 * <p>
 * <em>Note:</em> This is an iterative implementation.
 */
public static void copyInto(Node src, Node dest) throws DOMException {

    // get node factory
    Document factory = dest.getOwnerDocument();
    boolean domimpl = factory instanceof DocumentImpl;

    // placement variables
    Node start  = src;
    Node parent = src;
    Node place  = src;

    // traverse source tree
    while (place != null) {

        // copy this node
        Node node = null;
        int  type = place.getNodeType();
        switch (type) {
        case Node.CDATA_SECTION_NODE: {
            node = factory.createCDATASection(place.getNodeValue());
            break;
        }
        case Node.COMMENT_NODE: {
            node = factory.createComment(place.getNodeValue());
            break;
        }
        case Node.ELEMENT_NODE: {
            Element element = factory.createElement(place.getNodeName());
            node = element;
            NamedNodeMap attrs  = place.getAttributes();
            int attrCount = attrs.getLength();
            for (int i = 0; i < attrCount; i++) {
                Attr attr = (Attr)attrs.item(i);
                String attrName = attr.getNodeName();
                String attrValue = attr.getNodeValue();
                element.setAttribute(attrName, attrValue);
                if (domimpl && !attr.getSpecified()) {
                    ((AttrImpl)element.getAttributeNode(attrName)).setSpecified(false);
                }
            }
            break;
        }
        case Node.ENTITY_REFERENCE_NODE: {
            node = factory.createEntityReference(place.getNodeName());
            break;
        }
        case Node.PROCESSING_INSTRUCTION_NODE: {
            node = factory.createProcessingInstruction(place.getNodeName(),
                    place.getNodeValue());
            break;
        }
        case Node.TEXT_NODE: {
            node = factory.createTextNode(place.getNodeValue());
            break;
        }
        default: {
            throw new IllegalArgumentException("can't copy node type, "+
                    type+" ("+
                    place.getNodeName()+')');
        }
        }
        dest.appendChild(node);

        // iterate over children
        if (place.hasChildNodes()) {
            parent = place;
            place  = place.getFirstChild();
            dest   = node;
        }

        // advance
        else {
            place = place.getNextSibling();
            while (place == null && parent != start) {
                place  = parent.getNextSibling();
                parent = parent.getParentNode();
                dest   = dest.getParentNode();
            }
        }

    }

}
 
源代码13 项目: Bytecoder   文件: DOMUtil.java
/**
 * Copies the source tree into the specified place in a destination
 * tree. The source node and its children are appended as children
 * of the destination node.
 * <p>
 * <em>Note:</em> This is an iterative implementation.
 */
public static void copyInto(Node src, Node dest) throws DOMException {

    // get node factory
    Document factory = dest.getOwnerDocument();
    boolean domimpl = factory instanceof DocumentImpl;

    // placement variables
    Node start  = src;
    Node parent = src;
    Node place  = src;

    // traverse source tree
    while (place != null) {

        // copy this node
        Node node = null;
        int  type = place.getNodeType();
        switch (type) {
        case Node.CDATA_SECTION_NODE: {
            node = factory.createCDATASection(place.getNodeValue());
            break;
        }
        case Node.COMMENT_NODE: {
            node = factory.createComment(place.getNodeValue());
            break;
        }
        case Node.ELEMENT_NODE: {
            Element element = factory.createElement(place.getNodeName());
            node = element;
            NamedNodeMap attrs  = place.getAttributes();
            int attrCount = attrs.getLength();
            for (int i = 0; i < attrCount; i++) {
                Attr attr = (Attr)attrs.item(i);
                String attrName = attr.getNodeName();
                String attrValue = attr.getNodeValue();
                element.setAttribute(attrName, attrValue);
                if (domimpl && !attr.getSpecified()) {
                    ((AttrImpl)element.getAttributeNode(attrName)).setSpecified(false);
                }
            }
            break;
        }
        case Node.ENTITY_REFERENCE_NODE: {
            node = factory.createEntityReference(place.getNodeName());
            break;
        }
        case Node.PROCESSING_INSTRUCTION_NODE: {
            node = factory.createProcessingInstruction(place.getNodeName(),
                    place.getNodeValue());
            break;
        }
        case Node.TEXT_NODE: {
            node = factory.createTextNode(place.getNodeValue());
            break;
        }
        default: {
            throw new IllegalArgumentException("can't copy node type, "+
                    type+" ("+
                    place.getNodeName()+')');
        }
        }
        dest.appendChild(node);

        // iterate over children
        if (place.hasChildNodes()) {
            parent = place;
            place  = place.getFirstChild();
            dest   = node;
        }

        // advance
        else {
            place = place.getNextSibling();
            while (place == null && parent != start) {
                place  = parent.getNextSibling();
                parent = parent.getParentNode();
                dest   = dest.getParentNode();
            }
        }

    }

}
 
源代码14 项目: openjdk-8   文件: DOMNormalizer.java
/**
* 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);
                                   }
                           }
                   }
           }
   }
 
源代码15 项目: openjdk-8-source   文件: DOMNormalizer.java
/**
* 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);
                                   }
                           }
                   }
           }
   }
 
源代码16 项目: openjdk-8-source   文件: DOMUtil.java
/**
 * Copies the source tree into the specified place in a destination
 * tree. The source node and its children are appended as children
 * of the destination node.
 * <p>
 * <em>Note:</em> This is an iterative implementation.
 */
public static void copyInto(Node src, Node dest) throws DOMException {

    // get node factory
    Document factory = dest.getOwnerDocument();
    boolean domimpl = factory instanceof DocumentImpl;

    // placement variables
    Node start  = src;
    Node parent = src;
    Node place  = src;

    // traverse source tree
    while (place != null) {

        // copy this node
        Node node = null;
        int  type = place.getNodeType();
        switch (type) {
        case Node.CDATA_SECTION_NODE: {
            node = factory.createCDATASection(place.getNodeValue());
            break;
        }
        case Node.COMMENT_NODE: {
            node = factory.createComment(place.getNodeValue());
            break;
        }
        case Node.ELEMENT_NODE: {
            Element element = factory.createElement(place.getNodeName());
            node = element;
            NamedNodeMap attrs  = place.getAttributes();
            int attrCount = attrs.getLength();
            for (int i = 0; i < attrCount; i++) {
                Attr attr = (Attr)attrs.item(i);
                String attrName = attr.getNodeName();
                String attrValue = attr.getNodeValue();
                element.setAttribute(attrName, attrValue);
                if (domimpl && !attr.getSpecified()) {
                    ((AttrImpl)element.getAttributeNode(attrName)).setSpecified(false);
                }
            }
            break;
        }
        case Node.ENTITY_REFERENCE_NODE: {
            node = factory.createEntityReference(place.getNodeName());
            break;
        }
        case Node.PROCESSING_INSTRUCTION_NODE: {
            node = factory.createProcessingInstruction(place.getNodeName(),
                    place.getNodeValue());
            break;
        }
        case Node.TEXT_NODE: {
            node = factory.createTextNode(place.getNodeValue());
            break;
        }
        default: {
            throw new IllegalArgumentException("can't copy node type, "+
                    type+" ("+
                    place.getNodeName()+')');
        }
        }
        dest.appendChild(node);

        // iterate over children
        if (place.hasChildNodes()) {
            parent = place;
            place  = place.getFirstChild();
            dest   = node;
        }

        // advance
        else {
            place = place.getNextSibling();
            while (place == null && parent != start) {
                place  = parent.getNextSibling();
                parent = parent.getParentNode();
                dest   = dest.getParentNode();
            }
        }

    }

}
 
源代码17 项目: JDKSourceCode1.8   文件: DOMUtil.java
/**
 * Copies the source tree into the specified place in a destination
 * tree. The source node and its children are appended as children
 * of the destination node.
 * <p>
 * <em>Note:</em> This is an iterative implementation.
 */
public static void copyInto(Node src, Node dest) throws DOMException {

    // get node factory
    Document factory = dest.getOwnerDocument();
    boolean domimpl = factory instanceof DocumentImpl;

    // placement variables
    Node start  = src;
    Node parent = src;
    Node place  = src;

    // traverse source tree
    while (place != null) {

        // copy this node
        Node node = null;
        int  type = place.getNodeType();
        switch (type) {
        case Node.CDATA_SECTION_NODE: {
            node = factory.createCDATASection(place.getNodeValue());
            break;
        }
        case Node.COMMENT_NODE: {
            node = factory.createComment(place.getNodeValue());
            break;
        }
        case Node.ELEMENT_NODE: {
            Element element = factory.createElement(place.getNodeName());
            node = element;
            NamedNodeMap attrs  = place.getAttributes();
            int attrCount = attrs.getLength();
            for (int i = 0; i < attrCount; i++) {
                Attr attr = (Attr)attrs.item(i);
                String attrName = attr.getNodeName();
                String attrValue = attr.getNodeValue();
                element.setAttribute(attrName, attrValue);
                if (domimpl && !attr.getSpecified()) {
                    ((AttrImpl)element.getAttributeNode(attrName)).setSpecified(false);
                }
            }
            break;
        }
        case Node.ENTITY_REFERENCE_NODE: {
            node = factory.createEntityReference(place.getNodeName());
            break;
        }
        case Node.PROCESSING_INSTRUCTION_NODE: {
            node = factory.createProcessingInstruction(place.getNodeName(),
                    place.getNodeValue());
            break;
        }
        case Node.TEXT_NODE: {
            node = factory.createTextNode(place.getNodeValue());
            break;
        }
        default: {
            throw new IllegalArgumentException("can't copy node type, "+
                    type+" ("+
                    place.getNodeName()+')');
        }
        }
        dest.appendChild(node);

        // iterate over children
        if (place.hasChildNodes()) {
            parent = place;
            place  = place.getFirstChild();
            dest   = node;
        }

        // advance
        else {
            place = place.getNextSibling();
            while (place == null && parent != start) {
                place  = parent.getNextSibling();
                parent = parent.getParentNode();
                dest   = dest.getParentNode();
            }
        }

    }

}
 
源代码18 项目: htmlunit   文件: XmlUtils.java
private static DomNode createFrom(final SgmlPage page, final Node source, final boolean handleXHTMLAsHTML,
        final Map<Integer, List<String>> attributesOrderMap) {
    if (source.getNodeType() == Node.TEXT_NODE) {
        return new DomText(page, source.getNodeValue());
    }
    if (source.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
        return new DomProcessingInstruction(page, source.getNodeName(), source.getNodeValue());
    }
    if (source.getNodeType() == Node.COMMENT_NODE) {
        return new DomComment(page, source.getNodeValue());
    }
    if (source.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
        final DocumentType documentType = (DocumentType) source;
        return new DomDocumentType(page, documentType.getName(), documentType.getPublicId(),
                documentType.getSystemId());
    }
    final String ns = source.getNamespaceURI();
    String localName = source.getLocalName();
    if (handleXHTMLAsHTML && Html.XHTML_NAMESPACE.equals(ns)) {
        final ElementFactory factory = page.getWebClient().getPageCreator().getHtmlParser().getFactory(localName);
        return factory.createElementNS(page, ns, localName,
                namedNodeMapToSaxAttributes(source.getAttributes(), attributesOrderMap, source));
    }
    final NamedNodeMap nodeAttributes = source.getAttributes();
    if (page != null && page.isHtmlPage()) {
        localName = localName.toUpperCase(Locale.ROOT);
    }
    final String qualifiedName;
    if (source.getPrefix() == null) {
        qualifiedName = localName;
    }
    else {
        qualifiedName = source.getPrefix() + ':' + localName;
    }

    final String namespaceURI = source.getNamespaceURI();
    if (Html.SVG_NAMESPACE.equals(namespaceURI)) {
        return page.getWebClient().getPageCreator().getHtmlParser().getSvgFactory()
                .createElementNS(page, namespaceURI, qualifiedName,
                        namedNodeMapToSaxAttributes(nodeAttributes, attributesOrderMap, source));
    }

    final Map<String, DomAttr> attributes = new LinkedHashMap<>();
    for (int i = 0; i < nodeAttributes.getLength(); i++) {
        final int orderedIndex = getIndex(nodeAttributes, attributesOrderMap, source, i);
        final Attr attribute = (Attr) nodeAttributes.item(orderedIndex);
        final String attributeNamespaceURI = attribute.getNamespaceURI();
        final String attributeQualifiedName;
        if (attribute.getPrefix() != null) {
            attributeQualifiedName = attribute.getPrefix() + ':' + attribute.getLocalName();
        }
        else {
            attributeQualifiedName = attribute.getLocalName();
        }
        final String value = attribute.getNodeValue();
        final boolean specified = attribute.getSpecified();
        final DomAttr xmlAttribute =
                new DomAttr(page, attributeNamespaceURI, attributeQualifiedName, value, specified);
        attributes.put(attribute.getNodeName(), xmlAttribute);
    }
    return new DomElement(namespaceURI, qualifiedName, page, attributes);
}
 
源代码19 项目: HtmlUnit-Android   文件: XmlUtil.java
private static DomNode createFrom(final SgmlPage page, final Node source, final boolean handleXHTMLAsHTML,
        final Map<Integer, List<String>> attributesOrderMap) {
    if (source.getNodeType() == Node.TEXT_NODE) {
        return new DomText(page, source.getNodeValue());
    }
    if (source.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
        return new DomProcessingInstruction(page, source.getNodeName(), source.getNodeValue());
    }
    if (source.getNodeType() == Node.COMMENT_NODE) {
        return new DomComment(page, source.getNodeValue());
    }
    if (source.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
        final DocumentType documentType = (DocumentType) source;
        return new DomDocumentType(page, documentType.getName(), documentType.getPublicId(),
                documentType.getSystemId());
    }
    final String ns = source.getNamespaceURI();
    String localName = source.getLocalName();
    if (handleXHTMLAsHTML && HTMLParser.XHTML_NAMESPACE.equals(ns)) {
        final ElementFactory factory = HTMLParser.getFactory(localName);
        return factory.createElementNS(page, ns, localName,
                namedNodeMapToSaxAttributes(source.getAttributes(), attributesOrderMap, source));
    }
    final NamedNodeMap nodeAttributes = source.getAttributes();
    if (page != null && page.isHtmlPage()) {
        localName = localName.toUpperCase(Locale.ROOT);
    }
    final String qualifiedName;
    if (source.getPrefix() == null) {
        qualifiedName = localName;
    }
    else {
        qualifiedName = source.getPrefix() + ':' + localName;
    }

    final String namespaceURI = source.getNamespaceURI();
    if (HTMLParser.SVG_NAMESPACE.equals(namespaceURI)) {
        return HTMLParser.SVG_FACTORY.createElementNS(page, namespaceURI, qualifiedName,
                namedNodeMapToSaxAttributes(nodeAttributes, attributesOrderMap, source));
    }

    final Map<String, DomAttr> attributes = new LinkedHashMap<>();
    for (int i = 0; i < nodeAttributes.getLength(); i++) {
        final int orderedIndex = getIndex(nodeAttributes, attributesOrderMap, source, i);
        final Attr attribute = (Attr) nodeAttributes.item(orderedIndex);
        final String attributeNamespaceURI = attribute.getNamespaceURI();
        final String attributeQualifiedName;
        if (attribute.getPrefix() != null) {
            attributeQualifiedName = attribute.getPrefix() + ':' + attribute.getLocalName();
        }
        else {
            attributeQualifiedName = attribute.getLocalName();
        }
        final String value = attribute.getNodeValue();
        final boolean specified = attribute.getSpecified();
        final DomAttr xmlAttribute =
                new DomAttr(page, attributeNamespaceURI, attributeQualifiedName, value, specified);
        attributes.put(attribute.getNodeName(), xmlAttribute);
    }
    return new DomElement(namespaceURI, qualifiedName, page, attributes);
}
 
源代码20 项目: Bytecoder   文件: DOMNormalizer.java
/**
 * 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);
        }
    }
}