Example usage for javax.xml.namespace QName getNamespaceURI

List of usage examples for javax.xml.namespace QName getNamespaceURI

Introduction

In this page you can find the example usage for javax.xml.namespace QName getNamespaceURI.

Prototype

public String getNamespaceURI() 

Source Link

Document

Get the Namespace URI of this QName.

Usage

From source file:org.apache.ddlutils.io.DatabaseIO.java

/**
 * Compares the given qnames. This specifically ignores the namespace
 * uri of the other qname if the namespace of the current element is
 * empty.//from  ww w  .j a  v a2 s . c o  m
 * 
 * @param curElemQName The qname of the current element
 * @param qName        The qname to compare to
 * @return <code>true</code> if they are the same
 */
private boolean isSameAs(QName curElemQName, QName qName) {
    if (StringUtils.isEmpty(curElemQName.getNamespaceURI())) {
        return qName.getLocalPart().equals(curElemQName.getLocalPart());
    } else {
        return qName.equals(curElemQName);
    }
}

From source file:org.apache.ddlutils.io.DatabaseIO.java

/**
 * Writes the start of the specified XML element to the given XML writer.
 * //from   w  ww  . jav  a  2 s  .  com
 * @param xmlWriter The xml writer
 * @param qName     The qname of the XML element
 */
private void writeElementStart(PrettyPrintingXmlWriter xmlWriter, QName qName) throws DdlUtilsXMLException {
    xmlWriter.writeElementStart(qName.getNamespaceURI(), qName.getLocalPart());
}

From source file:org.apache.falcon.lifecycle.engine.oozie.utils.OozieBuilderUtils.java

public static Path marshalDefaultConfig(Cluster cluster, WORKFLOWAPP workflowapp, Properties properties,
        Path outPath) throws FalconException {
    QName workflowQName = new org.apache.falcon.oozie.workflow.ObjectFactory().createWorkflowApp(workflowapp)
            .getName();/*  w  w  w. j a  va 2s. c  om*/
    org.apache.falcon.oozie.workflow.CONFIGURATION config = getWorkflowConfig(properties);
    JAXBElement<org.apache.falcon.oozie.workflow.CONFIGURATION> configJaxbElement = new JAXBElement(
            new QName(workflowQName.getNamespaceURI(), "configuration", workflowQName.getPrefix()),
            org.apache.falcon.oozie.workflow.CONFIGURATION.class, config);

    Path defaultConfigPath = new Path(outPath, "config-default.xml");
    return marshal(cluster, configJaxbElement, CONFIG_JAXB_CONTEXT, defaultConfigPath);
}

From source file:org.apache.falcon.oozie.OozieOrchestrationWorkflowBuilder.java

protected Path marshal(Cluster cluster, WORKFLOWAPP workflowapp, CONFIGURATION config, Path outPath)
        throws FalconException {
    QName workflowQName = new org.apache.falcon.oozie.workflow.ObjectFactory().createWorkflowApp(workflowapp)
            .getName();//from  ww  w.  jav  a  2  s .c  o m
    JAXBElement<CONFIGURATION> configJaxbElement = new JAXBElement(
            new QName(workflowQName.getNamespaceURI(), "configuration", workflowQName.getPrefix()),
            CONFIGURATION.class, config);

    return marshal(cluster, configJaxbElement, OozieUtils.CONFIG_JAXB_CONTEXT,
            new Path(outPath, "config-default.xml"));
}

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

private Element bufferElement(StartElement event) {
    QName qname = event.getName();
    String prefix = qname.getPrefix();
    String uri = qname.getNamespaceURI();
    Element element;/*from   w w w.  ja  va  2  s . c  o m*/
    if (uri == null || uri.isEmpty()) {
        element = document.createElement(qname.getLocalPart());
    } else {
        element = document.createElementNS(qname.getNamespaceURI(), qname.getLocalPart());
        if (prefix != null && !prefix.isEmpty()) {
            element.setPrefix(prefix);
        }
    }
    // Always need to buffer the namespaces regardless of what else happens so that XPath will work on attributes
    // namespace qualified attributes.
    bufferNamespaces(event, element);
    return element;
}

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

private Attr bufferAttribute(Element element, Attribute attribute) {
    QName name = attribute.getName();
    String prefix = name.getPrefix();
    String uri = name.getNamespaceURI();
    Attr node;//w w  w .jav  a  2  s.  co  m
    if (uri == null || uri.isEmpty()) {
        node = document.createAttribute(name.getLocalPart());
        element.setAttributeNode(node);
    } else {
        node = document.createAttributeNS(uri, name.getLocalPart());
        if (prefix != null && !prefix.isEmpty()) {
            node.setPrefix(prefix);
        }
        element.setAttributeNodeNS(node);
    }
    node.setTextContent(attribute.getValue());
    return node;
}

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

private void streamAttribute(Element element, Attribute attribute) throws XPathExpressionException {
    Attr node;/*w  w  w. j a v a 2  s .  c o  m*/
    QName name = attribute.getName();
    String prefix = name.getPrefix();
    String uri = name.getNamespaceURI();
    if (uri == null || uri.isEmpty()) {
        node = document.createAttribute(name.getLocalPart());
        element.setAttributeNode(node);
    } else {
        node = document.createAttributeNS(uri, name.getLocalPart());
        if (prefix != null && !prefix.isEmpty()) {
            node.setPrefix(prefix);
        }
        element.setAttributeNodeNS(node);
    }

    String value = attribute.getValue();
    Level level = stack.peek();
    if ((level.scopeConfig) == null || (level.scopeConfig.getSelectors().isEmpty())) {
        value = filterAttribute(null, attribute.getName(), value, null);
        node.setValue(value);
    } else {
        UrlRewriteFilterPathDescriptor path = pickFirstMatchingPath(level);
        if (path instanceof UrlRewriteFilterApplyDescriptor) {
            String rule = ((UrlRewriteFilterApplyDescriptor) path).rule();
            value = filterAttribute(null, attribute.getName(), value, rule);
            node.setValue(value);
        }
    }

    //dump( document );

    if (prefix == null || prefix.isEmpty()) {
        writer.write(" ");
        writer.write(name.getLocalPart());
    } else {
        writer.write(" ");
        writer.write(prefix);
        writer.write(":");
        writer.write(name.getLocalPart());
    }
    writer.write("=\"");
    writer.write(value);
    writer.write("\"");
    element.removeAttributeNode(node);
}

From source file:org.apache.hise.engine.HISEEngineImpl.java

public static QName getCanonicalQName(QName q) {
    String ns = q.getNamespaceURI();
    ns = ns.endsWith("/") ? ns.substring(0, ns.length() - 1) : ns;
    return new QName(ns, q.getLocalPart());
}

From source file:org.apache.hise.runtime.Task.java

static Map<String, Node> findInputParts(TaskDefinition taskDefinition, Node requestXml) {
    Map<String, Node> inputParts = new HashMap<String, Node>();

    Operation operation = taskDefinition.getPortType()
            .getOperation(taskDefinition.getTaskInterface().getOperation(), null, null);
    if (operation == null) {
        LogFactory.getLog(Task.class).error("Operation: " + taskDefinition.getTaskInterface().getOperation()
                + " not found in port type definition.");
        return inputParts;
    }// w w  w.  ja  v a2  s  .co  m

    Map<String, Part> partsMap = operation.getInput().getMessage().getParts();
    Node messagePart = null;
    for (Part part : partsMap.values()) {
        String name = part.getName();
        QName element = part.getElementName();
        QName type = part.getTypeName();
        Element root = (Element) requestXml;
        XPath xPath = XPathFactory.newInstance().newXPath();
        try {
            if (element != null) {
                Map namespaceMap = new HashMap(1);
                namespaceMap.put("prefix", element.getNamespaceURI());
                NamespaceContext nc = new NamespaceMap(namespaceMap);
                xPath.setNamespaceContext(nc);
                messagePart = (Node) xPath.evaluate("prefix:" + element.getLocalPart(), root,
                        XPathConstants.NODE);
            } else if (type != null) {
                messagePart = (Node) xPath.evaluate("child::*/" + part.getName(), root, XPathConstants.NODE);
            }
        } catch (XPathExpressionException ex) {
            LogFactory.getLog(Task.class).error("Can not get message part.", ex);
        }
        inputParts.put(name, messagePart);
    }

    return inputParts;
}

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

public static QName uniqueQName(QName q) {
    String s = q.getNamespaceURI();
    while (s.endsWith("/")) {
        s = s.substring(0, s.length() - 1);
    }//from   w ww  . j  av a 2  s  .c om
    return new QName(s, q.getLocalPart());
}