Example usage for org.dom4j Namespace getURI

List of usage examples for org.dom4j Namespace getURI

Introduction

In this page you can find the example usage for org.dom4j Namespace getURI.

Prototype

public String getURI() 

Source Link

Document

DOCUMENT ME!

Usage

From source file:org.arquillian.graphene.visual.testing.impl.JCRMaskHandler.java

private void deleteMaskFromTest(String maskID, Document doc) {
    Namespace ns = Namespace.get(RushEye.NAMESPACE_VISUAL_SUITE);
    String xPath = "/*[namespace-uri()=\"" + ns.getURI()
            + "\" and name()=\"visual-suite\"]/*[namespace-uri()=\"" + ns.getURI()
            + "\" and name()=\"test\"]/*[namespace-uri()=\"" + ns.getURI() + "\" and name()=\"mask\" and @id=\""
            + maskID + "\"]";
    Node maskElement = doc.selectSingleNode(xPath);
    maskElement.detach();/* w  w  w  .  j  a  va 2 s .  co  m*/
}

From source file:org.arquillian.graphene.visual.testing.impl.JCRMaskHandler.java

private void addMasksToTest(List<MaskFromREST> masks, Document doc) {
    Namespace ns = Namespace.get(RushEye.NAMESPACE_VISUAL_SUITE);
    for (MaskFromREST mask : masks) {
        String testName = mask.getName().split(":")[1].replaceAll("/", ".");
        testName = testName.substring(0, testName.lastIndexOf(".png"));
        String xPath = "/*[namespace-uri()=\"" + ns.getURI()
                + "\" and name()=\"visual-suite\"]/*[namespace-uri()=\"" + ns.getURI()
                + "\" and name()=\"test\" and @name=\"" + testName + "\"]";
        Element testElement = (Element) doc.selectSingleNode(xPath);
        Element patternElement = testElement.element(QName.get("pattern", ns));
        patternElement.detach();/* w  w  w. java 2s .  c  om*/
        Element maskElement = testElement.addElement(QName.get("mask", ns));
        maskElement.addAttribute("id", mask.getId());
        maskElement.addAttribute("source", mask.getSourceUrl());
        maskElement.addAttribute("type", mask.getMaskType().value());
        testElement.add(patternElement);
    }
}

From source file:org.collectionspace.chain.util.xtmpl.XTmplTmpl.java

License:Educational Community License

@SuppressWarnings("unchecked")
private void removeNamespaces(Element e) {
    for (Namespace ns : (List<Namespace>) e.declaredNamespaces()) {
        if (!XTMPL_URI.equals(ns.getURI()))
            continue;
        e.remove(ns);//from www. ja  va  2s .  c  o m
    }
    for (Element k : (List<Element>) e.elements()) {
        removeNamespaces(k);
    }
}

From source file:org.firesoa.common.jxpath.model.dom4j.Dom4JNodePointer.java

License:Open Source License

public String getNamespaceURI(String prefix) {
    if (prefix.equals("xml")) {
        return Namespace.XML_NAMESPACE.getURI();
    }//  w  ww.  java2  s. co  m
    if (prefix.equals(Constants.DEFAULT_NS_PREFIX)) {//context??
        return getDefaultNamespaceURI();
    }
    Element element = null;
    if (node instanceof Document) {
        element = ((Document) node).getRootElement();
    }
    if (node instanceof Element) {
        element = (Element) node;
    }
    if (element == null) {
        return null;
    }
    Namespace ns = element.getNamespaceForPrefix(prefix);
    return ns == null ? null : ns.getURI();
}

From source file:org.hudsonci.xpath.impl.Dom2Dom.java

License:Open Source License

private org.w3c.dom.Node createChild(Node child, org.w3c.dom.Node wparent) {
    int type = child.getNodeType();

    // Collapse multiple consecutive text nodes to a single text node
    // with trimmed value.
    if (type != Node.TEXT_NODE)
        endText(wparent);//from  w  ww . j a  v  a 2s  .c  o  m

    Name name;
    org.w3c.dom.Node node = null;

    switch (type) {
    case Node.ATTRIBUTE_NODE:
        break;
    case Node.CDATA_SECTION_NODE:
        CDATA cd = (CDATA) child;
        wparent.appendChild(node = wdoc.createCDATASection(cd.getText()));
        break;
    case Node.COMMENT_NODE:
        Comment co = (Comment) child;
        wparent.appendChild(node = wdoc.createComment(co.getText()));
        break;
    case Node.DOCUMENT_TYPE_NODE:
        DocumentType dt = (DocumentType) child;
        wparent.appendChild(new XDocumentType(dt, wparent));
        break;
    case Node.ELEMENT_NODE:
        Element el = (Element) child;
        name = new Name(el);
        org.w3c.dom.Element e = name.namespaceURI == null ? wdoc.createElement(name.qualifiedName)
                : wdoc.createElementNS(name.namespaceURI, name.qualifiedName);
        wparent.appendChild(e);
        node = currentElement = e;

        for (int i = 0, n = el.attributeCount(); i < n; i++) {
            Attribute at = el.attribute(i);
            name = new Name(at);
            if (name.namespaceURI == null)
                e.setAttribute(name.qualifiedName, at.getValue());
            else
                e.setAttributeNS(name.namespaceURI, name.qualifiedName, at.getValue());
        }
        return e;
    case Node.ENTITY_REFERENCE_NODE:
        break;
    case Node.PROCESSING_INSTRUCTION_NODE:
        ProcessingInstruction p = (ProcessingInstruction) child;
        wparent.appendChild(node = wdoc.createProcessingInstruction(p.getTarget(), p.getText()));
        break;
    case Node.TEXT_NODE:
        textBuilder.append(child.getText());
        lastText = (Text) child;
        break;
    case Node.NAMESPACE_NODE:
        Namespace ns = (Namespace) child;
        name = new Name(ns);
        currentElement.setAttribute(name.qualifiedName, ns.getURI());
        break;
    default:
        throw new IllegalStateException("Unknown node type");
    }
    if (node != null)
        reverseMap.put(node, child);
    return null;
}

From source file:org.jamppa.component.XMPPComponent.java

License:Apache License

private IQ handle(IQ iq, Map<String, QueryHandler> handlers) {
    Element queryElement = iq.getElement().element("query");
    if (queryElement == null) {
        return XMPPUtils.error(iq, "IQ does not contain query element.", LOGGER);
    }/* w w  w .  j  av a2  s.  c  o  m*/

    Namespace namespace = queryElement.getNamespace();

    QueryHandler queryHandler = handlers.get(namespace.getURI());
    if (queryHandler == null) {
        return XMPPUtils.error(iq, "QueryHandler not found for namespace: " + namespace, LOGGER);
    }

    return queryHandler.handle(iq);
}

From source file:org.jboss.rusheye.CommandCrawl.java

License:Open Source License

private void addDocumentRoot() {
    ns = Namespace.get(RushEye.NAMESPACE_VISUAL_SUITE);

    Element root = document.addElement(QName.get("visual-suite", ns));

    Namespace xsi = Namespace.get("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    QName schemaLocation = QName.get("schemaLocation", xsi);

    root.addNamespace("", ns.getURI());
    root.addNamespace(xsi.getPrefix(), xsi.getURI());
    root.addAttribute(schemaLocation, ns.getURI() + " " + RushEye.SCHEMA_LOCATION_VISUAL_SUITE);

    Element globalConfiguration = root.addElement(QName.get("global-configuration", ns));
    addSuiteListener(globalConfiguration);
    addRetrievers(globalConfiguration);/*from   ww  w . j a va2s  .  c  om*/
    addPerception(globalConfiguration);
    addMasksByType(base, globalConfiguration);
    addTests(base, root);
}

From source file:org.jboss.tools.jbpm.convert.bpmnto.util.DomXmlWriter.java

License:Open Source License

public static Document createDomTree(boolean useNamespace, String url, String rootElementName) {
    Document document = DocumentHelper.createDocument();
    Element root = null;/*from w w w  . j av a  2 s .  co  m*/

    if (useNamespace) {
        Namespace jbpmNamespace = new Namespace(null, url);
        root = document.addElement(rootElementName, jbpmNamespace.getURI());
    } else {
        root = document.addElement(rootElementName);
    }
    root.addText(System.getProperty("line.separator"));

    return document;
}

From source file:org.nuxeo.ecm.jsf2.migration.parser.GenericParser.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from w w w  .  ja v  a 2  s .com
public void parse(Document input, FileReport report) throws Exception {
    XPath xpathExpr = new Dom4jXPath(xpath);

    // Check if a namespace is needed
    List<String> prefixesInXpath = getPrefix(xpath);
    if (prefixesInXpath.size() > 0) {
        for (String prefixInXpath : prefixesInXpath) {
            // Check if the prefix is in the list of prefixes
            EnumPrefixes enumPrefix = EnumPrefixes.getPrefix(prefixInXpath);
            if (enumPrefix != EnumPrefixes.UNKNOWN) {
                Namespace namespace = input.getRootElement().getNamespaceForPrefix(prefixInXpath);
                // If the namespace is not present in the root element, we
                // use the one defined in the enum to avoid errors while
                // executing the XPath expression.
                // Specific rules are used to check the validity of the
                // namespaces
                String nsURI = namespace != null ? namespace.getURI() : enumPrefix.getNamespace();
                SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
                nsContext.addNamespace(prefixInXpath, nsURI);
                xpathExpr.setNamespaceContext(nsContext);
            } else {
                // Add an error in the file report for the unknown
                // namespace
                report.getListMigrations().put(EnumTypeMigration.NAMESPACE_RULE_2, Integer.valueOf(1));
                List<String> params = new ArrayList<String>();
                params.add(prefixInXpath);
                report.getListParams().put(EnumTypeMigration.NAMESPACE_RULE_2, params);
            }
        }
    }

    listElementsToMigrate = xpathExpr.selectNodes(input);
    if (listElementsToMigrate.size() > 0) {
        List<String> params = new ArrayList<String>();
        params.add("" + listElementsToMigrate.size());
        report.getListParams().put(rule, params);
        report.getListMigrations().put(rule, Integer.valueOf(listElementsToMigrate.size()));
    }
}

From source file:org.nuxeo.ecm.jsf2.migration.parser.NamespaceParser.java

License:Open Source License

@Override
public void parse(Document input, FileReport report) throws Exception {
    Element rootElement = input.getRootElement();
    // For each prefix defined, we check, when it's present in the root
    // element, that the namespace is correct
    for (EnumPrefixes prefix : EnumPrefixes.values()) {
        Namespace ns = rootElement.getNamespaceForPrefix(prefix.getPrefix());
        if (ns != null && !StringUtils.equals(prefix.getNamespace(), ns.getURI())) {
            listPrefixToMigrate.add(prefix.getPrefix());
            // Add the value for the report
            report.getListMigrations().put(EnumTypeMigration.NAMESPACE_RULE_1, Integer.valueOf(1));
            List<String> params = new ArrayList<String>();
            params.add(prefix.getPrefix());
            params.add(prefix.getNamespace());
            report.getListParams().put(EnumTypeMigration.NAMESPACE_RULE_1, params);
        }/*ww w .  j av  a  2s.  c  om*/
    }
}