Java Code Examples for org.w3c.dom.Attr#getPrefix()

The following examples show how to use org.w3c.dom.Attr#getPrefix() . 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: DOMXPathTransform.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void unmarshalParams(Element paramsElem) {
    String xPath = paramsElem.getFirstChild().getNodeValue();
    // create a Map of namespace prefixes
    NamedNodeMap attributes = paramsElem.getAttributes();
    if (attributes != null) {
        int length = attributes.getLength();
        Map<String, String> namespaceMap =
            new HashMap<String, String>(length);
        for (int i = 0; i < length; i++) {
            Attr attr = (Attr)attributes.item(i);
            String prefix = attr.getPrefix();
            if (prefix != null && prefix.equals("xmlns")) {
                namespaceMap.put(attr.getLocalName(), attr.getValue());
            }
        }
        this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
    } else {
        this.params = new XPathFilterParameterSpec(xPath);
    }
}
 
Example 2
Source File: DOMPrinter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected void visitAttr(Attr node)
    throws XMLStreamException {
    String name = node.getLocalName();
    if (name.equals("xmlns")) {
        out.writeDefaultNamespace(node.getNamespaceURI());
    } else {
        String prefix = node.getPrefix();
        if (prefix != null && prefix.equals("xmlns")) {
            out.writeNamespace(prefix, node.getNamespaceURI());
        } else if (prefix != null) {
            out.writeAttribute(prefix
                , node.getNamespaceURI()
                , name
                , node.getNodeValue()
            );
        } else {
            out.writeAttribute(node.getNamespaceURI()
                    , name
                    , node.getNodeValue());
        }
    }
}
 
Example 3
Source File: DOMXPathTransform.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void unmarshalParams(Element paramsElem) {
    String xPath = paramsElem.getFirstChild().getNodeValue();
    // create a Map of namespace prefixes
    NamedNodeMap attributes = paramsElem.getAttributes();
    if (attributes != null) {
        int length = attributes.getLength();
        Map<String, String> namespaceMap =
            new HashMap<String, String>(length);
        for (int i = 0; i < length; i++) {
            Attr attr = (Attr)attributes.item(i);
            String prefix = attr.getPrefix();
            if (prefix != null && prefix.equals("xmlns")) {
                namespaceMap.put(attr.getLocalName(), attr.getValue());
            }
        }
        this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
    } else {
        this.params = new XPathFilterParameterSpec(xPath);
    }
}
 
Example 4
Source File: DOMPrinter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected void visitAttr(Attr node)
    throws XMLStreamException {
    String name = node.getLocalName();
    if (name.equals("xmlns")) {
        out.writeDefaultNamespace(node.getNamespaceURI());
    } else {
        String prefix = node.getPrefix();
        if (prefix != null && prefix.equals("xmlns")) {
            out.writeNamespace(prefix, node.getNamespaceURI());
        } else if (prefix != null) {
            out.writeAttribute(prefix
                , node.getNamespaceURI()
                , name
                , node.getNodeValue()
            );
        } else {
            out.writeAttribute(node.getNamespaceURI()
                    , name
                    , node.getNodeValue());
        }
    }
}
 
Example 5
Source File: DOMPrinter.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
protected void visitAttr(Attr node)
    throws XMLStreamException {
    String name = node.getLocalName();
    if (name.equals("xmlns")) {
        out.writeDefaultNamespace(node.getNamespaceURI());
    } else {
        String prefix = node.getPrefix();
        if (prefix != null && prefix.equals("xmlns")) {
            out.writeNamespace(prefix, node.getNamespaceURI());
        } else if (prefix != null) {
            out.writeAttribute(prefix
                , node.getNamespaceURI()
                , name
                , node.getNodeValue()
            );
        } else {
            out.writeAttribute(node.getNamespaceURI()
                    , name
                    , node.getNodeValue());
        }
    }
}
 
Example 6
Source File: DomUtils.java    From teamengine with Apache License 2.0 6 votes vote down vote up
static public Map<QName, String> getAttributes(Node node) {
    Map<QName, String> atts = new HashMap<QName, String>();
    NamedNodeMap nnm = node.getAttributes();
    if (nnm != null) {
        for (int i = 0; i < nnm.getLength(); i++) {
            Attr att = (Attr) nnm.item(i);
            String uri = att.getBaseURI();
            String localname = att.getLocalName();
            String prefix = att.getPrefix();
            QName name;
            if (uri == null) {
                name = new QName(localname);
            } else if (prefix == null) {
                name = new QName(uri, localname);
            } else {
                name = new QName(uri, localname, prefix);
            }
            if (prefix == null
                    || !(prefix.equals("xmlns") || prefix.equals("xml"))) {
                atts.put(name, att.getValue());
            }
        }
    }
    return atts;
}
 
Example 7
Source File: DOMPrinter.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected void visitAttr(Attr node)
    throws XMLStreamException {
    String name = node.getLocalName();
    if (name.equals("xmlns")) {
        out.writeDefaultNamespace(node.getNamespaceURI());
    } else {
        String prefix = node.getPrefix();
        if (prefix != null && prefix.equals("xmlns")) {
            out.writeNamespace(prefix, node.getNamespaceURI());
        } else if (prefix != null) {
            out.writeAttribute(prefix
                , node.getNamespaceURI()
                , name
                , node.getNodeValue()
            );
        } else {
            out.writeAttribute(node.getNamespaceURI()
                    , name
                    , node.getNodeValue());
        }
    }
}
 
Example 8
Source File: DOMWriter.java    From java-client-api with Apache License 2.0 6 votes vote down vote up
public void serializeAttributes(NamedNodeMap attributes) throws XMLStreamException {
  for (int i=0; i < attributes.getLength(); i++) {
    Attr attribute = (Attr) attributes.item(i);
    String namespaceURI = attribute.getNamespaceURI();
    String prefix       = (namespaceURI != null) ? attribute.getPrefix() : null;
    String localName    = (namespaceURI != null) ? attribute.getLocalName() : attribute.getName();
    String value        = attribute.getValue();
    if ("http://www.w3.org/2000/xmlns/".equals(namespaceURI)) {
      //TODO: Seems there should be a better way to prevent redundant namespaces.
    } else if (prefix != null) {
      serializer.writeAttribute(prefix, namespaceURI, localName, value);
    } else if (namespaceURI != null) {
      serializer.writeAttribute(namespaceURI, localName, value);
    } else {
      serializer.writeAttribute(localName, value);
    }
  }
}
 
Example 9
Source File: DomToGroovy.java    From groovy with Apache License 2.0 6 votes vote down vote up
protected boolean printAttributeWithoutPrefix(Attr attribute, boolean hasAttribute) {
    String prefix = attribute.getPrefix();
    if (prefix == null || prefix.length() == 0) {
        if (!hasAttribute) {
            hasAttribute = true;
        } else {
            print(", ");
        }
        String localName = getLocalName(attribute);
        boolean needsEscaping = checkEscaping(localName);
        if (needsEscaping) print(qt);
        print(localName);
        if (needsEscaping) print(qt);
        print(":");
        printQuoted(getAttributeValue(attribute));
    }
    return hasAttribute;
}
 
Example 10
Source File: DOMPrinter.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
protected void visitAttr(Attr node)
    throws XMLStreamException {
    String name = node.getLocalName();
    if (name.equals("xmlns")) {
        out.writeDefaultNamespace(node.getNamespaceURI());
    } else {
        String prefix = node.getPrefix();
        if (prefix != null && prefix.equals("xmlns")) {
            out.writeNamespace(prefix, node.getNamespaceURI());
        } else if (prefix != null) {
            out.writeAttribute(prefix
                , node.getNamespaceURI()
                , name
                , node.getNodeValue()
            );
        } else {
            out.writeAttribute(node.getNamespaceURI()
                    , name
                    , node.getNodeValue());
        }
    }
}
 
Example 11
Source File: DOMXPathTransform.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void unmarshalParams(Element paramsElem) {
    String xPath = paramsElem.getFirstChild().getNodeValue();
    // create a Map of namespace prefixes
    NamedNodeMap attributes = paramsElem.getAttributes();
    if (attributes != null) {
        int length = attributes.getLength();
        Map<String, String> namespaceMap =
            new HashMap<String, String>(length);
        for (int i = 0; i < length; i++) {
            Attr attr = (Attr)attributes.item(i);
            String prefix = attr.getPrefix();
            if (prefix != null && prefix.equals("xmlns")) {
                namespaceMap.put(attr.getLocalName(), attr.getValue());
            }
        }
        this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
    } else {
        this.params = new XPathFilterParameterSpec(xPath);
    }
}
 
Example 12
Source File: DOMXPathTransform.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void unmarshalParams(Element paramsElem) {
    String xPath = paramsElem.getFirstChild().getNodeValue();
    // create a Map of namespace prefixes
    NamedNodeMap attributes = paramsElem.getAttributes();
    if (attributes != null) {
        int length = attributes.getLength();
        Map<String, String> namespaceMap =
            new HashMap<String, String>(length);
        for (int i = 0; i < length; i++) {
            Attr attr = (Attr)attributes.item(i);
            String prefix = attr.getPrefix();
            if (prefix != null && prefix.equals("xmlns")) {
                namespaceMap.put(attr.getLocalName(), attr.getValue());
            }
        }
        this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
    } else {
        this.params = new XPathFilterParameterSpec(xPath);
    }
}
 
Example 13
Source File: DOMPrinter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected void visitAttr(Attr node)
    throws XMLStreamException {
    String name = node.getLocalName();
    if (name.equals("xmlns")) {
        out.writeDefaultNamespace(node.getNamespaceURI());
    } else {
        String prefix = node.getPrefix();
        if (prefix != null && prefix.equals("xmlns")) {
            out.writeNamespace(prefix, node.getNamespaceURI());
        } else if (prefix != null) {
            out.writeAttribute(prefix
                , node.getNamespaceURI()
                , name
                , node.getNodeValue()
            );
        } else {
            out.writeAttribute(node.getNamespaceURI()
                    , name
                    , node.getNodeValue());
        }
    }
}
 
Example 14
Source File: AbstractBPBeanDefinitionParser.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected boolean parseAttributes(Element element, ParserContext ctx, MutableBeanMetadata bean) {
    NamedNodeMap atts = element.getAttributes();
    boolean setBus = false;
    for (int i = 0; i < atts.getLength(); i++) {
        Attr node = (Attr) atts.item(i);
        String val = node.getValue();
        String pre = node.getPrefix();
        String name = node.getLocalName();
        String prefix = node.getPrefix();

        // Don't process namespaces
        if (isNamespace(name, prefix)) {
            continue;
        }

        if ("createdFromAPI".equals(name) || "abstract".equals(name)) {
            bean.setScope(BeanMetadata.SCOPE_PROTOTYPE);
        } else {
            if ("depends-on".equals(name)) {
                bean.addDependsOn(val);
            } else if ("name".equals(name)) {
                processNameAttribute(element, ctx, bean, val);
            } else if ("bus".equals(name)) {
                processBusAttribute(element, ctx, bean, val);
            } else if (!"id".equals(name) && isAttribute(pre, name)) {
                mapAttribute(bean, element, name, val, ctx);
            }
        }
    }
    return setBus; // 'setBus' is always false
}
 
Example 15
Source File: W3CDOMStreamReader.java    From cxf with Apache License 2.0 5 votes vote down vote up
public QName getAttributeName(int i) {
    Attr at = getAttribute(i);

    String prefix = at.getPrefix();
    String ln = getLocalName(at);
    // at.getNodeName();
    String ns = at.getNamespaceURI();

    if (prefix == null) {
        return new QName(ns, ln);
    }
    return new QName(ns, ln, prefix);
}
 
Example 16
Source File: DOMXPathFilter2Transform.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void unmarshalParams(Element curXPathElem) throws MarshalException
{
    List<XPathType> list = new ArrayList<XPathType>();
    while (curXPathElem != null) {
        String xPath = curXPathElem.getFirstChild().getNodeValue();
        String filterVal = DOMUtils.getAttributeValue(curXPathElem,
                                                      "Filter");
        if (filterVal == null) {
            throw new MarshalException("filter cannot be null");
        }
        XPathType.Filter filter = null;
        if (filterVal.equals("intersect")) {
            filter = XPathType.Filter.INTERSECT;
        } else if (filterVal.equals("subtract")) {
            filter = XPathType.Filter.SUBTRACT;
        } else if (filterVal.equals("union")) {
            filter = XPathType.Filter.UNION;
        } else {
            throw new MarshalException("Unknown XPathType filter type" +
                                       filterVal);
        }
        NamedNodeMap attributes = curXPathElem.getAttributes();
        if (attributes != null) {
            int length = attributes.getLength();
            Map<String, String> namespaceMap =
                new HashMap<String, String>(length);
            for (int i = 0; i < length; i++) {
                Attr attr = (Attr)attributes.item(i);
                String prefix = attr.getPrefix();
                if (prefix != null && prefix.equals("xmlns")) {
                    namespaceMap.put(attr.getLocalName(), attr.getValue());
                }
            }
            list.add(new XPathType(xPath, filter, namespaceMap));
        } else {
            list.add(new XPathType(xPath, filter));
        }

        curXPathElem = DOMUtils.getNextSiblingElement(curXPathElem);
    }
    this.params = new XPathFilter2ParameterSpec(list);
}
 
Example 17
Source File: DOMXPathFilter2Transform.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void unmarshalParams(Element curXPathElem) throws MarshalException
{
    List<XPathType> list = new ArrayList<XPathType>();
    while (curXPathElem != null) {
        String xPath = curXPathElem.getFirstChild().getNodeValue();
        String filterVal = DOMUtils.getAttributeValue(curXPathElem,
                                                      "Filter");
        if (filterVal == null) {
            throw new MarshalException("filter cannot be null");
        }
        XPathType.Filter filter = null;
        if (filterVal.equals("intersect")) {
            filter = XPathType.Filter.INTERSECT;
        } else if (filterVal.equals("subtract")) {
            filter = XPathType.Filter.SUBTRACT;
        } else if (filterVal.equals("union")) {
            filter = XPathType.Filter.UNION;
        } else {
            throw new MarshalException("Unknown XPathType filter type" +
                                       filterVal);
        }
        NamedNodeMap attributes = curXPathElem.getAttributes();
        if (attributes != null) {
            int length = attributes.getLength();
            Map<String, String> namespaceMap =
                new HashMap<String, String>(length);
            for (int i = 0; i < length; i++) {
                Attr attr = (Attr)attributes.item(i);
                String prefix = attr.getPrefix();
                if (prefix != null && prefix.equals("xmlns")) {
                    namespaceMap.put(attr.getLocalName(), attr.getValue());
                }
            }
            list.add(new XPathType(xPath, filter, namespaceMap));
        } else {
            list.add(new XPathType(xPath, filter));
        }

        curXPathElem = DOMUtils.getNextSiblingElement(curXPathElem);
    }
    this.params = new XPathFilter2ParameterSpec(list);
}
 
Example 18
Source File: DOMXPathFilter2Transform.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private void unmarshalParams(Element curXPathElem) throws MarshalException
{
    List<XPathType> list = new ArrayList<XPathType>();
    while (curXPathElem != null) {
        String xPath = curXPathElem.getFirstChild().getNodeValue();
        String filterVal = DOMUtils.getAttributeValue(curXPathElem,
                                                      "Filter");
        if (filterVal == null) {
            throw new MarshalException("filter cannot be null");
        }
        XPathType.Filter filter = null;
        if (filterVal.equals("intersect")) {
            filter = XPathType.Filter.INTERSECT;
        } else if (filterVal.equals("subtract")) {
            filter = XPathType.Filter.SUBTRACT;
        } else if (filterVal.equals("union")) {
            filter = XPathType.Filter.UNION;
        } else {
            throw new MarshalException("Unknown XPathType filter type" +
                                       filterVal);
        }
        NamedNodeMap attributes = curXPathElem.getAttributes();
        if (attributes != null) {
            int length = attributes.getLength();
            Map<String, String> namespaceMap =
                new HashMap<String, String>(length);
            for (int i = 0; i < length; i++) {
                Attr attr = (Attr)attributes.item(i);
                String prefix = attr.getPrefix();
                if (prefix != null && prefix.equals("xmlns")) {
                    namespaceMap.put(attr.getLocalName(), attr.getValue());
                }
            }
            list.add(new XPathType(xPath, filter, namespaceMap));
        } else {
            list.add(new XPathType(xPath, filter));
        }

        curXPathElem = DOMUtils.getNextSiblingElement(curXPathElem);
    }
    this.params = new XPathFilter2ParameterSpec(list);
}
 
Example 19
Source File: DOMXPathFilter2Transform.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private void unmarshalParams(Element curXPathElem) throws MarshalException
{
    List<XPathType> list = new ArrayList<XPathType>();
    while (curXPathElem != null) {
        String xPath = curXPathElem.getFirstChild().getNodeValue();
        String filterVal = DOMUtils.getAttributeValue(curXPathElem,
                                                      "Filter");
        if (filterVal == null) {
            throw new MarshalException("filter cannot be null");
        }
        XPathType.Filter filter = null;
        if (filterVal.equals("intersect")) {
            filter = XPathType.Filter.INTERSECT;
        } else if (filterVal.equals("subtract")) {
            filter = XPathType.Filter.SUBTRACT;
        } else if (filterVal.equals("union")) {
            filter = XPathType.Filter.UNION;
        } else {
            throw new MarshalException("Unknown XPathType filter type" +
                                       filterVal);
        }
        NamedNodeMap attributes = curXPathElem.getAttributes();
        if (attributes != null) {
            int length = attributes.getLength();
            Map<String, String> namespaceMap =
                new HashMap<String, String>(length);
            for (int i = 0; i < length; i++) {
                Attr attr = (Attr)attributes.item(i);
                String prefix = attr.getPrefix();
                if (prefix != null && prefix.equals("xmlns")) {
                    namespaceMap.put(attr.getLocalName(), attr.getValue());
                }
            }
            list.add(new XPathType(xPath, filter, namespaceMap));
        } else {
            list.add(new XPathType(xPath, filter));
        }

        curXPathElem = DOMUtils.getNextSiblingElement(curXPathElem);
    }
    this.params = new XPathFilter2ParameterSpec(list);
}
 
Example 20
Source File: XMLUtils.java    From xcurator with Apache License 2.0 2 votes vote down vote up
/**
 * Check if the attribute node is a namespace definition.
 *
 * @param attr
 * @return
 */
public static boolean isNamespaceDef(Attr attr) {
    String prefix = attr.getPrefix();
    return (prefix != null && prefix.equals(XMLConstants.XMLNS_ATTRIBUTE))
            || attr.getNodeName().equals(XMLConstants.XMLNS_ATTRIBUTE);
}