Example usage for org.w3c.dom Node getPrefix

List of usage examples for org.w3c.dom Node getPrefix

Introduction

In this page you can find the example usage for org.w3c.dom Node getPrefix.

Prototype

public String getPrefix();

Source Link

Document

The namespace prefix of this node, or null if it is unspecified.

Usage

From source file:org.regenstrief.util.XMLUtil.java

/**
 * Retrieves the prefix of the given Node
 * /*w ww . j  a  va 2s.c o m*/
 * @param n the Node
 * @return the prefix String
 **/
public final static String getPrefix(final Node n) {
    if (n == null) {
        return null;
    }

    final String prefix = n.getPrefix();
    if (prefix != null) {
        return prefix;
    }

    return getPrefix(n.getNodeName());
}

From source file:org.wso2.carbon.apimgt.impl.soaptorest.WSDL11SOAPOperationExtractor.java

private void setNamespaceDetails(ModelImpl model, Node currentNode) {

    Xml xml = new Xml();
    xml.setNamespace(currentNode.getNamespaceURI());
    xml.setPrefix(currentNode.getPrefix());
    model.setXml(xml);//from  w w  w  . j  a v a2 s .com
}

From source file:org.wso2.carbon.apimgt.impl.soaptorest.WSDL11SOAPOperationExtractor.java

private void setNamespaceDetails(Property property, Node currentNode) {

    Xml xml = new Xml();
    xml.setNamespace(currentNode.getNamespaceURI());
    xml.setPrefix(currentNode.getPrefix());
    property.setXml(xml);/* ww  w. jav  a 2s  .  c o  m*/
}

From source file:org.wso2.developerstudio.eclipse.esb.mediators.impl.HeaderMediatorImpl.java

/**
 * {@inheritDoc}//w ww  .ja  va  2  s .  co  m
 */

protected void doLoad(Element self) throws Exception {
    String headerNamePrefix = null;
    if (self.hasAttribute("name")) {
        getHeaderName().load(self);

        // Extract header name and the corresponding namespace.
        String headerNameWithPrefix = getHeaderName().getPropertyValue();
        String headerName = null;
        String headerNameNamespaceURI = null;
        int colon = headerNameWithPrefix.indexOf(':');
        if (colon > 0) {
            headerNamePrefix = headerNameWithPrefix.substring(0, colon);
            headerName = headerNameWithPrefix.substring(colon + 1);
            headerNameNamespaceURI = getHeaderName().getNamespaces().get(headerNamePrefix);
            if (headerNameNamespaceURI == null) {
                Map<String, String> nsMap = new HashMap<String, String>();
                NamedNodeMap nsList = self.getOwnerDocument().getChildNodes().item(0).getAttributes();
                if (nsList.getLength() > 0) {
                    for (int i = 0; i < nsList.getLength(); i++) {
                        Node item = nsList.item(i);
                        if (null != item.getPrefix() && "xmlns".equals(item.getPrefix())) {
                            nsMap.put(item.getLocalName(), item.getNodeValue());
                        }
                    }
                }
                headerNameNamespaceURI = (String) nsMap.get(headerNamePrefix);
            }
        }

        // Clear all other namespaces.
        getHeaderName().getNamespaces().clear();

        // Set the extracted header name.
        if (!StringUtils.isBlank(headerName)) {
            getHeaderName().setPropertyValue(headerName);
        }

        // Add the namespace corresponding to header name.
        if (!StringUtils.isBlank(headerNamePrefix) && (!StringUtils.isBlank(headerNameNamespaceURI))) {
            getHeaderName().getNamespaces().put(headerNamePrefix, headerNameNamespaceURI);
        }
    } else {
        throw new Exception("Expected header name.");
    }

    // Header action.
    HeaderAction action = HeaderAction.get(self.getAttribute("action"));
    if (null != action) {
        setHeaderAction(action);
    }
    // removed exception throwing due to optionality of action

    // Header value.
    if (getHeaderAction().equals(HeaderAction.SET)) {
        if (self.hasAttribute("value")) {
            setValueType(HeaderValueType.LITERAL);
            setValueLiteral(self.getAttribute("value"));
        } else if (self.hasAttribute("expression")) {
            setValueType(HeaderValueType.EXPRESSION);
            getValueExpression().load(self);

            // Remove the namespace corresponding to header name.
            if (!StringUtils.isBlank(headerNamePrefix)) {
                getValueExpression().getNamespaces().remove(headerNamePrefix);
            }
        } else {
            throw new Exception("Expected either a header value or an expression.");
        }
    }
    super.doLoad(self);
}

From source file:org.xsystem.bpmn2.formats.xml.XMLParser3.java

protected void setNameSpace(Element elem) {
    NamedNodeMap atts = elem.getAttributes();
    for (int i = 0; i < atts.getLength(); i++) {
        Node currentAttribute = atts.item(i);
        String currentPrefix = currentAttribute.getPrefix();
        if (currentPrefix != null && currentPrefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
            String prfx = currentAttribute.getLocalName();
            String uri = currentAttribute.getNodeValue();
            definitions.setNamespaceURI(prfx, uri);
        }/*  ww w.ja v a 2  s .co m*/
    }
}

From source file:wsattacker.library.signatureFaking.SignatureFakingOracle.java

private void appendCertificate(Node keyInfo, String certificate) {
    keyInfo.setTextContent("");
    String prefix = keyInfo.getPrefix();
    if (prefix == null) {
        prefix = "";
    } else {/*from w w w.j av a2 s  .  c  om*/
        prefix = prefix + ":";
    }
    Node data = keyInfo.getOwnerDocument().createElementNS(NamespaceConstants.URI_NS_DS, prefix + "X509Data");
    keyInfo.appendChild(data);
    Node cert = keyInfo.getOwnerDocument().createElementNS(NamespaceConstants.URI_NS_DS,
            prefix + "X509Certificate");
    data.appendChild(cert);
    cert.setTextContent(certificate);
    log.debug("Appending Certificate \r\n" + certificate + "\r\nto the" + prefix + "X509Certificate element");
}