List of usage examples for javax.xml.namespace QName getNamespaceURI
public String getNamespaceURI()
Get the Namespace URI of this QName
.
From source file:com.amalto.core.history.accessor.AttributeAccessor.java
private Attr createAttribute(Node parentNode, Document domDocument) { // Ensure xsi prefix is declared if (attributeName.indexOf(':') > 0) { String attributePrefix = StringUtils.substringBefore(attributeName, ":"); //$NON-NLS-1$ String namespaceURI = domDocument.lookupNamespaceURI(attributePrefix); if (namespaceURI == null) { if ("xsi".equals(attributePrefix)) { //$NON-NLS-1$ domDocument.getDocumentElement().setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:xsi", XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI); //$NON-NLS-1$ } else if ("tmdm".equals(attributePrefix)) { //$NON-NLS-1$ domDocument.getDocumentElement().setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:tmdm", SkipAttributeDocumentBuilder.TALEND_NAMESPACE); //$NON-NLS-1$ } else { throw new IllegalArgumentException("Unrecognized attribute prefix: '" + attributePrefix + "'."); //$NON-NLS-1$ //$NON-NLS-2$ }/*from w w w . ja va 2s .c o m*/ } } QName qName = getQName(domDocument); Attr newAttribute = domDocument.createAttributeNS(qName.getNamespaceURI(), qName.getLocalPart()); String prefix = qName.getPrefix(); newAttribute.setPrefix(prefix); parentNode.getAttributes().setNamedItemNS(newAttribute); return newAttribute; }
From source file:microsoft.exchange.webservices.data.core.EwsXmlReader.java
/** * Check end element.//from www . ja v a 2s. c om * * @param startEvent the start event * @param endEvent the end event * @return true, if successful */ public static boolean checkEndElement(XMLEvent startEvent, XMLEvent endEvent) { boolean isEndElement = false; if (endEvent.isEndElement()) { QName qEName = endEvent.asEndElement().getName(); QName qSName = startEvent.asStartElement().getName(); isEndElement = qEName.getLocalPart().equals(qSName.getLocalPart()) && (qEName.getPrefix().equals(qSName.getPrefix()) || qEName.getNamespaceURI().equals(qSName.getNamespaceURI())); } return isEndElement; }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static QName getQNameWithoutPrefix(Node node) { QName qname = getQName(node); return new QName(qname.getNamespaceURI(), qname.getLocalPart()); }
From source file:com.centeractive.ws.builder.soap.SampleXmlUtil.java
private static final String formatQName(XmlCursor xmlc, QName qName) { XmlCursor parent = xmlc.newCursor(); parent.toParent();/*from w ww. ja va 2s . c o m*/ String prefix = parent.prefixForNamespace(qName.getNamespaceURI()); parent.dispose(); String name; if (prefix == null || prefix.length() == 0) name = qName.getLocalPart(); else name = prefix + ":" + qName.getLocalPart(); return name; }
From source file:net.bpelunit.util.XMLUtilTest.java
@Test public void testResolveQName_DefaultNamespace() throws Exception { Document xml = XMLUtil.parseXML("<a xmlns=\"ns1\">b</a>"); QName qname = XMLUtil.resolveQName("a", xml.getDocumentElement()); assertEquals("ns1", qname.getNamespaceURI()); assertEquals("a", qname.getLocalPart()); }
From source file:net.bpelunit.util.XMLUtilTest.java
@Test public void testResolveQName_NormalPrefix() throws Exception { Document xml = XMLUtil.parseXML("<ns:a xmlns:ns=\"ns1\">ns:b</ns:a>"); QName qname = XMLUtil.resolveQName("ns:a", xml.getDocumentElement()); assertEquals("ns1", qname.getNamespaceURI()); assertEquals("a", qname.getLocalPart()); }
From source file:com.streamsets.pipeline.lib.xml.StreamingXmlParser.java
private String getNameAndTrackNs(QName name) { final String uri = name.getNamespaceURI(); if (!Strings.isNullOrEmpty(uri)) { String prefix;//from w ww . j a v a2 s . c o m if (!namespaceUriToPrefix.containsKey(uri)) { prefix = name.getPrefix(); if (Strings.isNullOrEmpty(prefix)) { //generate a new namespace prefix for it prefix = GENERATED_NAMESPACE_PREFIX + generatedNsPrefixCount++; } //else the element already came with a prefix, so just use that namespaceUriToPrefix.put(uri, prefix); } else { prefix = namespaceUriToPrefix.get(uri); } return prefix + ":" + name.getLocalPart(); } else { // element is in no namespace return name.getLocalPart(); } }
From source file:ddf.security.pep.interceptor.PEPAuthorizingInterceptor.java
/** * This method is an implementation of the WSA-M and WSA-W specs for determining the action URI.<br> * <ul>//from ww w. j ava 2 s. c o m * <li>http://www.w3.org/TR/ws-addr-metadata/#actioninwsdl</li> * <li>http://www.w3.org/TR/ws-addr-wsdl/#actioninwsdl</li> * </ul> * Adapted from {@link org.apache.cxf.ws.addressing.impl.MAPAggregatorImpl} and * {@link org.apache.cxf.ws.addressing.impl.InternalContextUtils} * * @param message * @return */ private String getActionUri(Message message) { String actionURI = null; /** * See if the action is explicitly defined in the WSDL message service model. Retrieves one * of the Action attribute in the wsdl:input message. */ MessageInfo msgInfo = (MessageInfo) message.get(MessageInfo.class.getName()); if (msgInfo != null && msgInfo.getExtensionAttributes() != null) { // wsaw:Action Object attr = msgInfo.getExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME); // wsam:Action if (attr == null) { attr = msgInfo.getExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME); } // support for older usages if (attr == null) { attr = msgInfo.getExtensionAttributes() .get(new QName(JAXWSAConstants.NS_WSA, Names.WSAW_ACTION_NAME)); } if (attr == null) { attr = msgInfo.getExtensionAttributes() .get(new QName(Names.WSA_NAMESPACE_WSDL_NAME_OLD, Names.WSAW_ACTION_NAME)); } if (attr instanceof QName) { actionURI = ((QName) attr).getLocalPart(); } else { actionURI = attr == null ? null : attr.toString(); } } /** * See if the action is explicitly defined in the WSDL operation service model. Retrieves * the operation soap:soapAction property. */ if (StringUtils.isEmpty(actionURI)) { BindingOperationInfo bindingOpInfo = message.getExchange().get(BindingOperationInfo.class); SoapOperationInfo soi = bindingOpInfo.getExtensor(SoapOperationInfo.class); if (soi == null && bindingOpInfo.isUnwrapped()) { soi = bindingOpInfo.getWrappedOperation().getExtensor(SoapOperationInfo.class); } actionURI = soi == null ? null : soi.getAction(); actionURI = StringUtils.isEmpty(actionURI) ? null : actionURI; } /** * If the service model doesn't explicitly defines the action, we'll construct the default * URI string. */ if (StringUtils.isEmpty(actionURI)) { QName op = (QName) message.get(MessageContext.WSDL_OPERATION); QName port = (QName) message.get(MessageContext.WSDL_PORT); if (op != null && port != null) { actionURI = port.getNamespaceURI(); actionURI = addPath(actionURI, port.getLocalPart()); actionURI = addPath(actionURI, op.getLocalPart() + "Request"); } } return actionURI; }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static String getAttribute(Element element, QName attrQname) { String attr = element.getAttributeNS(attrQname.getNamespaceURI(), attrQname.getLocalPart()); if (StringUtils.isEmpty(attr)) { // also try without the namespace attr = element.getAttribute(attrQname.getLocalPart()); }//from w w w . ja v a2 s . com return attr; }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static QName getQNameAttribute(Element element, QName attributeName) { String attrContent = element.getAttributeNS(attributeName.getNamespaceURI(), attributeName.getLocalPart()); if (StringUtils.isBlank(attrContent)) { return null; }//from www .j a v a 2 s . co m return resolveQName(element, attrContent); }