Example usage for org.w3c.dom Element getNamespaceURI

List of usage examples for org.w3c.dom Element getNamespaceURI

Introduction

In this page you can find the example usage for org.w3c.dom Element getNamespaceURI.

Prototype

public String getNamespaceURI();

Source Link

Document

The namespace URI of this node, or null if it is unspecified (see ).

Usage

From source file:org.dhatim.delivery.dom.serialize.ContextObjectSerializationUnit.java

public static boolean isContextObjectElement(Element element) {
    if (DomUtils.getName(element).equals("context-object")
            && Namespace.SMOOKS_URI.equals(element.getNamespaceURI())) {
        return true;
    }//from ww w.j  a  va 2s  .co m

    return false;
}

From source file:org.dhatim.delivery.dom.serialize.TextSerializationUnit.java

public static boolean isTextElement(Element element) {
    if (DomUtils.getName(element).equals("text") && Namespace.SMOOKS_URI.equals(element.getNamespaceURI())) {
        return true;
    }//from   ww w . j  a  v a 2s.  c  o m

    return false;
}

From source file:org.dhatim.templating.xslt.XslTemplateProcessor.java

private boolean isTemplatelet(boolean inlineXSL, String templateCode) {
    try {//from   w  ww.j  a  va2  s. c o  m
        Document xslDoc = XmlUtil.parseStream(new StringReader(templateCode), logErrorHandler);
        Element rootElement = xslDoc.getDocumentElement();
        String rootElementNS = rootElement.getNamespaceURI();

        return (inlineXSL
                && !(rootElementNS != null && rootElementNS.equals("http://www.w3.org/1999/XSL/Transform")
                        && DomUtils.getName(rootElement).equals("stylesheet")));
    } catch (ParserConfigurationException e) {
        throw new SmooksConfigurationException("Unable to parse XSL Document (Stylesheet/Templatelet).", e);
    } catch (IOException e) {
        throw new SmooksConfigurationException("Unable to parse XSL Document (Stylesheet/Templatelet).", e);
    } catch (SAXException e) {
        return inlineXSL;
    }
}

From source file:org.dhatim.xml.DomUtils.java

/**
 * Get the parent element of the supplied element having the
 * specified tag name./* w  ww.  java2  s . c  om*/
 * @param child Child element. 
 * @param parentLocalName Parent element local name.
 * @param namespaceURI Namespace URI of the required parent element,
 * or null if a non-namespaced get is to be performed.
 * @return The first parent element of "child" having the tagname "parentName",
 * or null if no such parent element exists.
 */
public static Element getParentElement(Element child, String parentLocalName, String namespaceURI) {
    AssertArgument.isNotNull(child, "child");
    AssertArgument.isNotNullAndNotEmpty(parentLocalName, "parentLocalName");

    Node parentNode = child.getParentNode();

    while (parentNode != null && parentNode.getNodeType() == Node.ELEMENT_NODE) {
        Element parentElement = (Element) parentNode;

        if (getName(parentElement).equalsIgnoreCase(parentLocalName)) {
            if (namespaceURI == null) {
                return parentElement;
            } else if (parentElement.getNamespaceURI().equals(namespaceURI)) {
                return parentElement;
            }
        }
        parentNode = parentNode.getParentNode();
    }

    return null;
}

From source file:org.dhatim.xml.DomUtils.java

/**
 * Get the child elements having the supplied localname and namespace.
 * <p/>/* w ww .j  a  v  a 2  s . com*/
 * Can be used instead of XPath.
 * @param nodeList List of DOM nodes on which to perform the search.
 * @param localname Localname of the element required.  Supports "*" wildcards.
 * @param namespaceURI Namespace URI of the required element, or null
 * if a namespace comparison is not to be performed.
 * @return A list of W3C DOM {@link Element}s.  An empty list if no such
 * child elements exist on the parent element.
 */
public static List getElements(NodeList nodeList, String localname, String namespaceURI) {
    AssertArgument.isNotNull(nodeList, "nodeList");
    AssertArgument.isNotNullAndNotEmpty(localname, "localname");
    AssertArgument.isNotEmpty(namespaceURI, "namespaceURI");

    int count = nodeList.getLength();
    Vector<Element> elements = new Vector<Element>();

    for (int i = 0; i < count; i++) {
        Node node = nodeList.item(i);

        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element) node;
            if (localname.equals("*") || getName(element).equals(localname)) {
                // The local name matches the element we're after...
                if (namespaceURI == null || namespaceURI.equals(element.getNamespaceURI())) {
                    elements.add(element);
                }
            }
        }
    }

    return elements;
}

From source file:org.dita.dost.writer.ConrefPushParser.java

/**
 * /*from   w w w .j  a  v a2s  .c om*/
 * @param targetClassAttribute targetClassAttribute
 * @param content string
 * @return string
 */
private DocumentFragment replaceElementName(final DitaClass targetClassAttribute,
        final DocumentFragment content) {
    try {
        if (content.hasChildNodes()) {
            final NodeList nodeList = content.getChildNodes();
            for (int i = 0; i < nodeList.getLength(); i++) {
                final Node node = nodeList.item(i);
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    final Element elem = (Element) node;
                    final DitaClass clazz = DitaClass.getInstance(elem);
                    // get type of the target element
                    final String type = targetClassAttribute.toString()
                            .substring(1, targetClassAttribute.toString().indexOf("/")).trim();
                    if (!clazz.equals(targetClassAttribute) && targetClassAttribute.matches(clazz)) {
                        // Specializing the pushing content is not handled here
                        // but we can catch such a situation to emit a warning by comparing the class values.
                        final String targetElementName = targetClassAttribute.toString()
                                .substring(targetClassAttribute.toString().indexOf("/") + 1).trim();
                        if (elem.getAttributeNode(ATTRIBUTE_NAME_CONREF) != null) {
                            hasConref = true;
                        }
                        if (elem.getAttributeNode(ATTRIBUTE_NAME_KEYREF) != null) {
                            hasKeyref = true;
                        }
                        elem.getOwnerDocument().renameNode(elem, elem.getNamespaceURI(), targetElementName);
                        // process the child nodes of the current node
                        final NodeList nList = elem.getChildNodes();
                        for (int j = 0; j < nList.getLength(); j++) {
                            final Node subNode = nList.item(j);
                            if (subNode.getNodeType() == Node.ELEMENT_NODE) {
                                //replace the subElement Name
                                replaceSubElementName(type, (Element) subNode);
                            }
                        }
                    } else {
                        replaceSubElementName(STRING_BLANK, elem);
                    }
                }
            }
        }
    } catch (final Exception e) {
        e.printStackTrace();
    }
    return content;
}

From source file:org.dita.dost.writer.ConrefPushParser.java

/**
 * //from  w ww .jav  a  2s .c  om
 * @param type pushtype
 * @param elem element
 * @return string
 */
private void replaceSubElementName(final String type, final Element elem) {
    final DitaClass classValue = DitaClass.getInstance(elem);
    if (elem.getAttributeNode(ATTRIBUTE_NAME_CONREF) != null) {
        hasConref = true;
    }
    if (elem.getAttributeNode(ATTRIBUTE_NAME_KEYREF) != null) {
        hasKeyref = true;
    }
    String generalizedElemName = elem.getNodeName();
    if (classValue != null) {
        if (classValue.toString().contains(type) && !type.equals(STRING_BLANK)) {
            generalizedElemName = classValue.toString()
                    .substring(classValue.toString().indexOf("/") + 1,
                            classValue.toString().indexOf(STRING_BLANK, classValue.toString().indexOf("/")))
                    .trim();
        }
    }
    elem.getOwnerDocument().renameNode(elem, elem.getNamespaceURI(), generalizedElemName);
    final NodeList nodeList = elem.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        final Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            replaceSubElementName(type, (Element) node);
        }
    }
}

From source file:org.dita.dost.writer.ConrefPushParser.java

private void writeNode(final Node node) throws SAXException {
    switch (node.getNodeType()) {
    case Node.DOCUMENT_FRAGMENT_NODE: {
        final NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            writeNode(children.item(i));
        }/*from   w ww. ja v  a2 s  . c  o  m*/
        break;
    }
    case Node.ELEMENT_NODE:
        final Element e = (Element) node;
        final AttributesBuilder b = new AttributesBuilder();
        final NamedNodeMap atts = e.getAttributes();
        for (int i = 0; i < atts.getLength(); i++) {
            b.add((Attr) atts.item(i));
        }
        final String ns = e.getNamespaceURI() != null ? e.getNamespaceURI() : NULL_NS_URI;
        getContentHandler().startElement(ns, e.getTagName(), e.getNodeName(), b.build());
        final NodeList children = e.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            writeNode(children.item(i));
        }
        getContentHandler().endElement(ns, e.getTagName(), e.getNodeName());
        break;
    case Node.TEXT_NODE:
        final char[] data = node.getNodeValue().toCharArray();
        getContentHandler().characters(data, 0, data.length);
        break;
    case Node.PROCESSING_INSTRUCTION_NODE:
        getContentHandler().processingInstruction(node.getNodeName(), node.getNodeValue());
        break;
    default:
        throw new UnsupportedOperationException();
    }
}

From source file:org.eclipse.gemini.blueprint.blueprint.config.internal.BlueprintParser.java

/**
 * Parse a value, ref or collection sub-element of a property or constructor-arg element. This method is called from
 * several places to handle reusable elements such as idref, ref, null, value and so on.
 * //  www .j ava2s  .c  o  m
 * In fact, this method is the main reason why the BeanDefinitionParserDelegate is not used in full since the
 * element namespace becomes important as mixed rfc124/bean content can coexist.
 * 
 * @param ele subelement of property element; we don't know which yet
 * @param defaultValueType the default type (class name) for any <code>&lt;value&gt;</code> tag that might be
 * created
 */
private Object parsePropertySubElement(Element ele, BeanDefinition bd, String defaultValueType) {
    // skip other namespace
    String namespaceUri = ele.getNamespaceURI();

    // check Spring own namespace
    if (parserContext.getDelegate().isDefaultNamespace(namespaceUri)) {
        return parserContext.getDelegate().parsePropertySubElement(ele, bd);
    }
    // let the delegate handle other ns
    else if (!NAMESPACE_URI.equals(namespaceUri)) {
        return parserContext.getDelegate().parseCustomElement(ele);
    }

    // 
    else {
        if (DomUtils.nodeNameEquals(ele, BEAN)) {
            BeanDefinitionHolder bdHolder = parseComponentDefinitionElement(ele, bd);
            if (bdHolder != null) {
                bdHolder = ParsingUtils.decorateBeanDefinitionIfRequired(ele, bdHolder, parserContext);
            }
            return bdHolder;
        }

        if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.REF_ELEMENT)) {
            return parseRefElement(ele);
        } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.IDREF_ELEMENT)) {
            return parseIdRefElement(ele);
        } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.VALUE_ELEMENT)) {
            return parseValueElement(ele, defaultValueType);
        } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.NULL_ELEMENT)) {
            // It's a distinguished null value. Let's wrap it in a TypedStringValue
            // object in order to preserve the source location.
            TypedStringValue nullHolder = new TypedStringValue(null);
            nullHolder.setSource(parserContext.extractSource(ele));
            return nullHolder;
        } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.ARRAY_ELEMENT)) {
            return parseArrayElement(ele, bd);
        } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.LIST_ELEMENT)) {
            return parseListElement(ele, bd);
        } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.SET_ELEMENT)) {
            return parseSetElement(ele, bd);
        } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.MAP_ELEMENT)) {
            return parseMapElement(ele, bd);
        } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.PROPS_ELEMENT)) {
            return parsePropsElement(ele);
        }

        // maybe it's a nested service/reference/ref-list/ref-set
        return parserContext.getDelegate().parseCustomElement(ele, bd);
    }
}

From source file:org.eclipse.swordfish.plugins.planner.policy.PolicyAssertionHintExtractor.java

@SuppressWarnings("unchecked")
private Policy getPolicy(MessageExchange messageExchange) {
    Policy policy = null;//  w  ww .  j  a v a 2  s.  com
    try {
        NormalizedMessage message = getNormalizedMessage(messageExchange);

        Map<QName, Node> headers = (Map<QName, Node>) message.getProperty(JbiConstants.SOAP_HEADERS);
        if (headers == null) {
            return null;
        }

        DocumentFragment policyFragment = (DocumentFragment) headers.get(POLICY_HEADER);
        if (policyFragment == null) {
            return null;
        }

        Element policyElement = (Element) policyFragment.getFirstChild();
        if (!Constants.ELEM_POLICY.equals(policyElement.getLocalName())
                || !Constants.URI_POLICY_NS.equals(policyElement.getNamespaceURI())) {
            return null;
        }
        return policyExtractor.extractPolicy(policyElement);
    } catch (Exception ex) {
        LOG.warn(ex.getMessage(), ex);
    }
    return policy;
}