Example usage for org.w3c.dom Attr getValue

List of usage examples for org.w3c.dom Attr getValue

Introduction

In this page you can find the example usage for org.w3c.dom Attr getValue.

Prototype

public String getValue();

Source Link

Document

On retrieval, the value of the attribute is returned as a string.

Usage

From source file:org.apache.cxf.systest.aegis.mtom.MtomTest.java

@Test
public void testMtomSchema() throws Exception {
    testUtilities.setBus((Bus) applicationContext.getBean("cxf"));
    testUtilities.addDefaultNamespaces();
    testUtilities.addNamespace("xmime", "http://www.w3.org/2005/05/xmlmime");
    Server s = testUtilities.getServerForService(
            new QName("http://fortest.mtom.aegis.systest.cxf.apache.org/", "MtomTestService"));
    Document wsdl = testUtilities.getWSDLDocument(s);
    Assert.assertNotNull(wsdl);/*from w  w  w  . j a va 2s .c o  m*/
    NodeList typeAttrList = testUtilities.assertValid("//xsd:complexType[@name='inputDhBean']/xsd:sequence/"
            + "xsd:element[@name='dataHandler']/" + "@type", wsdl);
    Attr typeAttr = (Attr) typeAttrList.item(0);
    String typeAttrValue = typeAttr.getValue();
    // now, this thing is a qname with a :, and we have to work out if it's correct.
    String[] pieces = typeAttrValue.split(":");
    Assert.assertEquals("base64Binary", pieces[1]);
    Node elementNode = typeAttr.getOwnerElement();
    String url = testUtilities.resolveNamespacePrefix(pieces[0], elementNode);
    Assert.assertEquals(Constants.URI_2001_SCHEMA_XSD, url);

    s = testUtilities.getServerForAddress("http://localhost:" + PORT + "/mtomXmime");
    wsdl = testUtilities.getWSDLDocument(s);
    Assert.assertNotNull(wsdl);
    typeAttrList = testUtilities.assertValid("//xsd:complexType[@name='inputDhBean']/xsd:sequence/"
            + "xsd:element[@name='dataHandler']/" + "@type", wsdl);
    typeAttr = (Attr) typeAttrList.item(0);
    typeAttrValue = typeAttr.getValue();
    // now, this thing is a qname with a :, and we have to work out if it's correct.
    pieces = typeAttrValue.split(":");
    Assert.assertEquals("base64Binary", pieces[1]);
    elementNode = typeAttr.getOwnerElement();
    url = testUtilities.resolveNamespacePrefix(pieces[0], elementNode);
    Assert.assertEquals(AbstractXOPType.XML_MIME_NS, url);

    /* when I add a test for a custom mapping.
    testUtilities.assertValid("//xsd:complexType[@name='inputDhBean']/xsd:sequence/"
                          + "xsd:element[@name='dataHandler']/"
                          + "@xmime:expectedContentType/text()",
                          wsdl);
                          */
}

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.xml.XmlFilterReader.java

private void processBufferedElement(Level level, UrlRewriteFilterGroupDescriptor config)
        throws XPathExpressionException {
    for (UrlRewriteFilterPathDescriptor selector : config.getSelectors()) {
        if (selector instanceof UrlRewriteFilterApplyDescriptor) {
            XPathExpression path = (XPathExpression) selector.compiledPath(XPATH_COMPILER);
            Object node = path.evaluate(level.scopeNode, XPathConstants.NODE);
            if (node != null) {
                UrlRewriteFilterApplyDescriptor apply = (UrlRewriteFilterApplyDescriptor) selector;
                if (node instanceof Element) {
                    Element element = (Element) node;
                    String value = element.getTextContent();
                    value = filterText(extractQName(element), value, apply.rule());
                    element.setTextContent(value);
                } else if (node instanceof Text) {
                    Text text = (Text) node;
                    String value = text.getWholeText();
                    value = filterText(extractQName(text.getParentNode()), value, apply.rule());
                    text.replaceWholeText(value);
                } else if (node instanceof Attr) {
                    Attr attr = (Attr) node;
                    String value = attr.getValue();
                    value = filterAttribute(extractQName(attr.getOwnerElement()), extractQName(attr), value,
                            apply.rule());
                    attr.setValue(value);
                } else {
                    throw new IllegalArgumentException(RES.unexpectedSelectedNodeType(node));
                }//  w  w  w  . j ava 2 s . co  m
            }
        } else if (selector instanceof UrlRewriteFilterDetectDescriptor) {
            XPathExpression path = (XPathExpression) selector.compiledPath(XPATH_COMPILER);
            Object node = path.evaluate(level.scopeNode, XPathConstants.NODE);
            if (node != null) {
                UrlRewriteFilterDetectDescriptor detect = (UrlRewriteFilterDetectDescriptor) selector;
                String value = null;
                if (node instanceof Element) {
                    Element element = (Element) node;
                    value = element.getTextContent();
                } else if (node instanceof Text) {
                    Text text = (Text) node;
                    value = text.getWholeText();
                } else if (node instanceof Attr) {
                    Attr attr = (Attr) node;
                    value = attr.getValue();
                } else {
                    throw new IllegalArgumentException(RES.unexpectedSelectedNodeType(node));
                }
                if (detect.compiledValue(REGEX_COMPILER).matcher(value).matches()) {
                    processBufferedElement(level, detect);
                }
            }
        } else {
            throw new IllegalArgumentException(RES.unexpectedRewritePathSelector(selector));
        }
    }
}

From source file:org.apache.jackrabbit.core.query.lucene.IndexingConfigurationImpl.java

/**
 * Returns the namespaces declared on the <code>node</code>.
 *
 * @param node a DOM node.//w  w  w  . j  a va 2  s  .com
 * @return the namespaces
 */
private Properties getNamespaces(Node node) {
    Properties namespaces = new Properties();
    NamedNodeMap attributes = node.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attribute = (Attr) attributes.item(i);
        if (attribute.getName().startsWith("xmlns:")) {
            namespaces.setProperty(attribute.getName().substring(6), attribute.getValue());
        }
    }
    return namespaces;
}

From source file:org.apache.jcp.xml.dsig.internal.dom.DOMReference.java

/**
 * Creates a <code>DOMReference</code> from an element.
 *
 * @param refElem a Reference element//w w  w.j av  a  2 s.  co m
 */
public DOMReference(Element refElem, XMLCryptoContext context, Provider provider) throws MarshalException {
    Boolean secureValidation = (Boolean) context.getProperty("org.apache.jcp.xml.dsig.secureValidation");
    boolean secVal = false;
    if (secureValidation != null && secureValidation.booleanValue()) {
        secVal = true;
    }

    // unmarshal Transforms, if specified
    Element nextSibling = DOMUtils.getFirstChildElement(refElem);
    List<Transform> transforms = new ArrayList<Transform>(5);
    if (nextSibling.getLocalName().equals("Transforms")) {
        Element transformElem = DOMUtils.getFirstChildElement(nextSibling);

        int transformCount = 0;
        while (transformElem != null) {
            transforms.add(new DOMTransform(transformElem, context, provider));
            transformElem = DOMUtils.getNextSiblingElement(transformElem);

            transformCount++;
            if (secVal && (transformCount > MAXIMUM_TRANSFORM_COUNT)) {
                String error = "A maxiumum of " + MAXIMUM_TRANSFORM_COUNT + " "
                        + "transforms per Reference are allowed with secure validation";
                throw new MarshalException(error);
            }
        }
        nextSibling = DOMUtils.getNextSiblingElement(nextSibling);
    }

    // unmarshal DigestMethod
    Element dmElem = nextSibling;
    this.digestMethod = DOMDigestMethod.unmarshal(dmElem);
    String digestMethodAlgorithm = this.digestMethod.getAlgorithm();
    if (secVal && MessageDigestAlgorithm.ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5.equals(digestMethodAlgorithm)) {
        throw new MarshalException(
                "It is forbidden to use algorithm " + digestMethod + " when secure validation is enabled");
    }

    // unmarshal DigestValue
    try {
        Element dvElem = DOMUtils.getNextSiblingElement(dmElem);
        this.digestValue = Base64.decode(dvElem);
    } catch (Base64DecodingException bde) {
        throw new MarshalException(bde);
    }

    // unmarshal attributes
    this.uri = DOMUtils.getAttributeValue(refElem, "URI");

    Attr attr = refElem.getAttributeNodeNS(null, "Id");
    if (attr != null) {
        this.id = attr.getValue();
        refElem.setIdAttributeNode(attr, true);
    } else {
        this.id = null;
    }

    this.type = DOMUtils.getAttributeValue(refElem, "Type");
    this.here = refElem.getAttributeNodeNS(null, "URI");
    this.refElem = refElem;
    this.transforms = transforms;
    this.allTransforms = transforms;
    this.appliedTransformData = null;
    this.provider = provider;
}

From source file:org.apache.ode.bpel.rtrep.v1.ASSIGN.java

private Element replaceElement(Element lval, Element ptr, Element src, boolean keepSrcElement) {
    Document doc = ptr.getOwnerDocument();
    Node parent = ptr.getParentNode();
    if (keepSrcElement) {
        Element replacement = (Element) doc.importNode(src, true);
        parent.replaceChild(replacement, ptr);
        return (lval == ptr) ? replacement : lval;
    }/*from  w  ww .  j a v  a  2  s  .c o m*/

    Element replacement = doc.createElementNS(ptr.getNamespaceURI(), ptr.getLocalName());
    NodeList nl = src.getChildNodes();
    for (int i = 0; i < nl.getLength(); ++i)
        replacement.appendChild(doc.importNode(nl.item(i), true));
    NamedNodeMap attrs = src.getAttributes();
    for (int i = 0; i < attrs.getLength(); ++i) {
        Attr attr = (Attr) attrs.item(i);
        if (!attr.getName().startsWith("xmlns")) {
            replacement.setAttributeNodeNS((Attr) doc.importNode(attrs.item(i), true));
            // Case of qualified attribute values, we're forced to add corresponding namespace declaration manually
            int colonIdx = attr.getValue().indexOf(":");
            if (colonIdx > 0) {
                String prefix = attr.getValue().substring(0, colonIdx);
                String attrValNs = src.lookupPrefix(prefix);
                if (attrValNs != null)
                    replacement.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + prefix, attrValNs);
            }
        }
    }
    parent.replaceChild(replacement, ptr);
    DOMUtils.copyNSContext(ptr, replacement);

    return (lval == ptr) ? replacement : lval;
}

From source file:org.apache.ode.bpel.rtrep.v2.ASSIGN.java

private Element replaceElement(Element lval, Element ptr, Element src, boolean keepSrcElement) {
    Document doc = ptr.getOwnerDocument();
    Node parent = ptr.getParentNode();
    if (keepSrcElement) {
        Element replacement = (Element) doc.importNode(src, true);
        parent.replaceChild(replacement, ptr);
        return (lval == ptr) ? replacement : lval;
    }//  www .ja v  a  2 s  . c om

    Element replacement = doc.createElementNS(ptr.getNamespaceURI(), ptr.getLocalName());
    if (ptr.getPrefix() != null) {
        replacement.setPrefix(ptr.getPrefix());
    }
    NodeList nl = src.getChildNodes();
    for (int i = 0; i < nl.getLength(); ++i)
        replacement.appendChild(doc.importNode(nl.item(i), true));
    NamedNodeMap attrs = src.getAttributes();
    for (int i = 0; i < attrs.getLength(); ++i) {
        Attr attr = (Attr) attrs.item(i);
        if (!attr.getName().startsWith("xmlns")) {
            replacement.setAttributeNodeNS((Attr) doc.importNode(attrs.item(i), true));
            // Case of qualified attribute values, we're forced to add corresponding namespace declaration manually
            int colonIdx = attr.getValue().indexOf(":");
            if (colonIdx > 0) {
                String prefix = attr.getValue().substring(0, colonIdx);
                String attrValNs = src.lookupPrefix(prefix);
                if (attrValNs != null)
                    replacement.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + prefix, attrValNs);
            }
        }
    }
    parent.replaceChild(replacement, ptr);
    DOMUtils.copyNSContext(ptr, replacement);

    return (lval == ptr) ? replacement : lval;
}

From source file:org.apache.ode.bpel.rtrep.v2.AssignHelper.java

/**
 * madars.vitolins _at gmail.com - 2009.04.17 - moved from ASSIGN here
 *//*from  w ww  . j  a  v a  2  s.  c  om*/
public Element replaceElement(Element lval, Element ptr, Element src, boolean keepSrcElement) {
    Document doc = ptr.getOwnerDocument();
    Node parent = ptr.getParentNode();
    if (keepSrcElement) {
        Element replacement = (Element) doc.importNode(src, true);
        parent.replaceChild(replacement, ptr);
        return (lval == ptr) ? replacement : lval;
    }

    Element replacement = doc.createElementNS(ptr.getNamespaceURI(), ptr.getLocalName());
    NodeList nl = src.getChildNodes();
    for (int i = 0; i < nl.getLength(); ++i)
        replacement.appendChild(doc.importNode(nl.item(i), true));
    NamedNodeMap attrs = src.getAttributes();
    for (int i = 0; i < attrs.getLength(); ++i) {
        Attr attr = (Attr) attrs.item(i);
        if (!attr.getName().startsWith("xmlns")) {
            replacement.setAttributeNodeNS((Attr) doc.importNode(attrs.item(i), true));
            // Case of qualified attribute values, we're forced to add corresponding namespace declaration manually
            int colonIdx = attr.getValue().indexOf(":");
            if (colonIdx > 0) {
                String prefix = attr.getValue().substring(0, colonIdx);
                String attrValNs = src.lookupPrefix(prefix);
                if (attrValNs != null)
                    replacement.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + prefix, attrValNs);
            }
        }
    }
    parent.replaceChild(replacement, ptr);
    DOMUtils.copyNSContext(ptr, replacement);

    return (lval == ptr) ? replacement : lval;
}

From source file:org.apache.ode.bpel.runtime.AssignHelper.java

private Element replaceElement(Element lval, Element ptr, Element src, boolean keepSrcElement) {
    Document doc = ptr.getOwnerDocument();
    Node parent = ptr.getParentNode();
    if (keepSrcElement) {
        Element replacement = (Element) doc.importNode(src, true);
        parent.replaceChild(replacement, ptr);
        return (lval == ptr) ? replacement : lval;
    }//w w  w.j  ava 2s.c om

    Element replacement = doc.createElementNS(ptr.getNamespaceURI(), ptr.getTagName());
    NodeList nl = src.getChildNodes();
    for (int i = 0; i < nl.getLength(); ++i)
        replacement.appendChild(doc.importNode(nl.item(i), true));
    NamedNodeMap attrs = src.getAttributes();
    for (int i = 0; i < attrs.getLength(); ++i) {
        Attr attr = (Attr) attrs.item(i);
        if (!attr.getName().startsWith("xmlns")) {
            replacement.setAttributeNodeNS((Attr) doc.importNode(attrs.item(i), true));
            // Case of qualified attribute values, we're forced to add corresponding namespace declaration manually
            int colonIdx = attr.getValue().indexOf(":");
            if (colonIdx > 0) {
                String prefix = attr.getValue().substring(0, colonIdx);
                String attrValNs = src.lookupPrefix(prefix);
                if (attrValNs != null)
                    replacement.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + prefix, attrValNs);
            }
        }
    }
    parent.replaceChild(replacement, ptr);
    DOMUtils.copyNSContext(ptr, replacement);

    return (lval == ptr) ? replacement : lval;
}

From source file:org.apache.ode.il.OMUtils.java

public static OMElement toOM(Element src, OMFactory omf, OMContainer parent) {
    OMElement omElement = parent == null ? omf.createOMElement(src.getLocalName(), null)
            : omf.createOMElement(src.getLocalName(), null, parent);
    if (src.getNamespaceURI() != null) {
        if (src.getPrefix() != null)
            omElement.setNamespace(omf.createOMNamespace(src.getNamespaceURI(), src.getPrefix()));
        else//  w  ww.  j  a  v a2  s . co m
            omElement.declareDefaultNamespace(src.getNamespaceURI());
    }

    if (parent == null) {
        NSContext nscontext = DOMUtils.getMyNSContext(src);
        injectNamespaces(omElement, nscontext.toMap());
    } else {
        Map<String, String> nss = DOMUtils.getMyNamespaces(src);
        injectNamespaces(omElement, nss);
    }

    NamedNodeMap attrs = src.getAttributes();
    for (int i = 0; i < attrs.getLength(); ++i) {
        Attr attr = (Attr) attrs.item(i);
        if (attr.getLocalName().equals("xmlns")
                || (attr.getNamespaceURI() != null && attr.getNamespaceURI().equals(DOMUtils.NS_URI_XMLNS)))
            continue;
        OMNamespace attrOmNs = null;
        String attrNs = attr.getNamespaceURI();
        String attrPrefix = attr.getPrefix();
        if (attrNs != null)
            attrOmNs = omElement.findNamespace(attrNs, null);
        if (attrOmNs == null && attrPrefix != null)
            attrOmNs = omElement.findNamespace(null, attrPrefix);
        omElement.addAttribute(attr.getLocalName(), attr.getValue(), attrOmNs);
    }

    NodeList children = src.getChildNodes();
    for (int i = 0; i < children.getLength(); ++i) {
        Node n = children.item(i);

        switch (n.getNodeType()) {
        case Node.CDATA_SECTION_NODE:
            omElement.addChild(omf.createOMText(((CDATASection) n).getTextContent(), XMLStreamConstants.CDATA));
            break;
        case Node.TEXT_NODE:
            omElement.addChild(omf.createOMText(((Text) n).getTextContent(), XMLStreamConstants.CHARACTERS));
            break;
        case Node.ELEMENT_NODE:
            toOM((Element) n, omf, omElement);
            break;
        }

    }

    return omElement;
}

From source file:org.apache.ode.utils.DOMUtils.java

/**
 * Returns the value of an attribute of an element. Returns null if the
 * attribute is not found (whereas Element.getAttribute returns "" if an
 * attrib is not found).//  w ww  .  j  ava 2s  .  co  m
 *
 * @param el Element whose attrib is looked for
 * @param attrName name of attribute to look for
 *
 * @return the attribute value
 */
static public String getAttribute(Element el, String attrName) {
    String sRet = null;
    Attr attr = el.getAttributeNode(attrName);
    if (attr != null) {
        sRet = attr.getValue();
    }
    return sRet;
}