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:Main.java

/**
 * Static utility method that throws an exception if the supplied reader's
 * cursor doesn't point to a START_ELEMENT with the given name.
 * /*from   ww w  . j  a  v a2  s .  co m*/
 * @param reader The reader to test.
 * @param name The name of the element to require.
 * @throws XMLStreamException If the reader state is an element with the
 *             specified name.
 */
public static final void requireElement(XMLStreamReader reader, QName name) throws XMLStreamException {

    reader.require(XMLStreamReader.START_ELEMENT, name.getNamespaceURI(), name.getLocalPart());

}

From source file:Main.java

public static String getAttributeNSOrNull(Element e, QName name) {
    Attr a = e.getAttributeNodeNS(name.getNamespaceURI(), name.getLocalPart());
    if (a == null)
        return null;
    return a.getValue();
}

From source file:Main.java

public static Element getFirstChildElementNS(Element domNode, QName name) {
    return getFirstChildElementNS(domNode, name.getNamespaceURI(), name.getLocalPart());
}

From source file:Main.java

/**
 * Compare an attribute's tag name to a given name.
 *
 * @param attribute The attribute to get the tag name from.
 * @param qname The qname to compare to.
 * @return True if the attribute's tag name and namespace URI match those of the qname.
 *///from   w ww . j a va 2s  . c om
public static boolean attributeHasQname(Attr attribute, QName qname) {
    return qname.getLocalPart().equals(attribute.getLocalName())
            && qname.getNamespaceURI().equals(getNamespaceUri(attribute));
}

From source file:Main.java

/**
 * Return a string for a particular QName, mapping a new prefix
 * if necessary./* w  ww . j av a2s.  c  o m*/
 */
public static String getStringForQName(QName qname, Element e) {
    String uri = qname.getNamespaceURI();
    String prefix = getPrefix(uri, e);
    if (prefix == null) {
        int i = 1;
        prefix = "ns" + i;
        while (getNamespace(prefix, e) != null) {
            i++;
            prefix = "ns" + i;
        }
        e.setAttributeNS(NS_URI_XMLNS, "xmlns:" + prefix, uri);
    }
    return prefix + ":" + qname.getLocalPart();
}

From source file:eu.esdihumboldt.hale.common.instance.orient.internal.ONamespaceMap.java

/**
 * Encode a {@link QName} for runtime use with OrientDB.
 * // w ww.ja v  a2  s  .co  m
 * @param org the qualified name
 * @return the encoded name
 */
public static String encode(QName org) {
    String ns = org.getNamespaceURI();
    if (!XMLConstants.NULL_NS_URI.equals(ns)) {
        ns = IDS.getId(org.getNamespaceURI());
    }

    return ns + "_" + ONameUtil.encodeName(org.getLocalPart());
}

From source file:eu.esdihumboldt.hale.common.instance.orient.internal.ONamespaceMap.java

/**
 * Map the namespace of the given qualified name to a short identifier and
 * return the adapted name.//  w ww .j  av  a  2 s.c  o  m
 * 
 * @param org the original qualified name
 * @return the adapted qualified name
 */
public static QName map(QName org) {
    if (XMLConstants.NULL_NS_URI.equals(org.getNamespaceURI())) {
        return org;
    }

    return new QName(IDS.getId(org.getNamespaceURI()), org.getLocalPart());
}

From source file:eu.esdihumboldt.hale.common.instance.orient.internal.ONamespaceMap.java

/**
 * Determine the original namespace of the given qualified name with a
 * namespace previously mapped with {@link #map(QName)} and return the
 * original name./*from w w  w  .j a  va2s . c  o m*/
 * 
 * @param mapped the adapted qualified name
 * @return the original qualified name
 */
public static QName unmap(QName mapped) {
    if (XMLConstants.NULL_NS_URI.equals(mapped.getNamespaceURI())) {
        return mapped;
    }

    return new QName(IDS.getObject(mapped.getNamespaceURI()), mapped.getLocalPart());
}

From source file:Main.java

/**
 * Constructs a new StartElement that merges the attributes and namespaces
 * found in the specified StartElement, with the provided attributes. The
 * returned StartElement will contain all the attributes and namespaces of
 * the original, plus those defined in the map.
 * /*from  w  w  w.  jav  a  2 s.co m*/
 * @param tag The original StartElement
 * @param attrs An iterator of Atributes to add to the element.
 * @return A new StartElement that contains all the original attributes and
 *         namespaces, plus the provided attributes.
 */
public static StartElement mergeAttributes(StartElement tag, Iterator attrs, XMLEventFactory factory) {

    // create Attribute map
    Map attributes = new HashMap();

    // iterate through start tag's attributes
    for (Iterator i = tag.getAttributes(); i.hasNext();) {

        Attribute attr = (Attribute) i.next();
        attributes.put(attr.getName(), attr);

    }

    // iterate through new attributes
    while (attrs.hasNext()) {

        Attribute attr = (Attribute) attrs.next();
        attributes.put(attr.getName(), attr);

    }

    factory.setLocation(tag.getLocation());

    QName tagName = tag.getName();
    return factory.createStartElement(tagName.getPrefix(), tagName.getNamespaceURI(), tagName.getLocalPart(),
            attributes.values().iterator(), tag.getNamespaces(), tag.getNamespaceContext());

}

From source file:no.digipost.api.interceptors.WsSecurityInterceptor.java

private static String partFromQName(final QName qname) {
    return "{}{" + qname.getNamespaceURI() + "}" + qname.getLocalPart();
}