List of usage examples for javax.xml.namespace QName getPrefix
public String getPrefix()
Get the prefix of this QName
.
The prefix assigned to a QName
might NOT be valid in a different context.
From source file:com.evolveum.midpoint.util.DOMUtil.java
/** * Sets QName value for a given element. * * Contrary to standard XML semantics, namespace-less QNames are specified as simple names without prefix * (regardless of default prefix used in the XML document). * * @param element Element whose text content should be set to represent QName value * @param elementValue QName value to be stored into the element *///from w ww . ja va2 s . com public static void setQNameValue(Element element, QName elementValue) { if (elementValue == null) { setElementTextContent(element, ""); } else if (XMLConstants.NULL_NS_URI.equals(elementValue.getNamespaceURI())) { if (QNameUtil.isPrefixUndeclared(elementValue.getPrefix())) { setElementTextContent(element, elementValue.getPrefix() + ":" + elementValue.getLocalPart()); } else { setElementTextContent(element, elementValue.getLocalPart()); } } else { String prefix = lookupOrCreateNamespaceDeclaration(element, elementValue.getNamespaceURI(), elementValue.getPrefix(), element, false); assert StringUtils.isNotBlank(prefix); String stringValue = prefix + ":" + elementValue.getLocalPart(); setElementTextContent(element, stringValue); } }
From source file:no.digipost.api.interceptors.Wss4jInterceptor.java
private void validateIsSigned(final Document doc, final List<WSSecurityEngineResult> results, final QName... qnamePath) { if (!wasSigned(doc, results, qnamePath)) { QName qName = qnamePath[qnamePath.length - 1]; throw new Wss4jSecurityValidationException( qName.getPrefix() + ":" + qName.getLocalPart() + " was not signed"); }/*from w ww . ja va 2s. c om*/ }
From source file:com.autentia.xml.namespace.QNameBuilder.java
private QName discoverQNameAndCachesIt(Class<?> classType, String classTypeNameSuffix, String prefixSuffix, QNamesCache cache) {/*from w w w . jav a2 s.c o m*/ QName qName = cache.getQNameFor(classType); if (qName == null) { qName = discoverQNameFromJaxb(classType); final String localPart = (isNotBlank(qName.getLocalPart()) ? qName.getLocalPart() : discoverLocalPartFor(classType)) + classTypeNameSuffix; final String namespaceUri = isNotBlank(qName.getNamespaceURI()) ? qName.getNamespaceURI() : discoverNamespaceUriFor(classType, localPart); final String prefix = isNotBlank(qName.getPrefix()) ? qName.getPrefix() : discoverPrefixFor(classType, prefixSuffix); qName = new QName(namespaceUri, localPart, prefix); cache.putQNameFor(classType, qName); } return qName; }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static void setQNameAttribute(Element element, QName attributeName, QName attributeValue) { Document doc = element.getOwnerDocument(); Attr attr = doc.createAttributeNS(attributeName.getNamespaceURI(), attributeName.getLocalPart()); String namePrefix = lookupOrCreateNamespaceDeclaration(element, attributeName.getNamespaceURI(), attributeName.getPrefix(), element, true); attr.setPrefix(namePrefix);//from www. j a v a 2s . co m setQNameAttribute(element, attr, attributeValue, element); }
From source file:com.evolveum.midpoint.util.DOMUtil.java
private static void setQNameAttribute(Element element, Attr attr, QName attributeQnameValue, Element definitionElement) { String attributeStringValue;//from ww w . j ava2 s. c o m if (attributeQnameValue == null) { attributeStringValue = ""; } else if (XMLConstants.NULL_NS_URI.equals(attributeQnameValue.getNamespaceURI())) { if (QNameUtil.isPrefixUndeclared(attributeQnameValue.getPrefix())) { attributeStringValue = attributeQnameValue.getPrefix() + ":" + attributeQnameValue.getLocalPart(); // to give user a chance to see and fix this } else { attributeStringValue = attributeQnameValue.getLocalPart(); } } else { String valuePrefix = lookupOrCreateNamespaceDeclaration(element, attributeQnameValue.getNamespaceURI(), attributeQnameValue.getPrefix(), definitionElement, false); assert StringUtils.isNotBlank(valuePrefix); attributeStringValue = valuePrefix + ":" + attributeQnameValue.getLocalPart(); } NamedNodeMap attributes = element.getAttributes(); checkValidXmlChars(attributeStringValue); attr.setValue(attributeStringValue); attributes.setNamedItem(attr); }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static void setQNameAttribute(Element element, QName attributeName, QName attributeValue, Element definitionElement) { Document doc = element.getOwnerDocument(); Attr attr = doc.createAttributeNS(attributeName.getNamespaceURI(), attributeName.getLocalPart()); String namePrefix = lookupOrCreateNamespaceDeclaration(element, attributeName.getNamespaceURI(), attributeName.getPrefix(), element, true); attr.setPrefix(namePrefix);/*from w w w. ja v a2 s . c o m*/ setQNameAttribute(element, attr, attributeValue, definitionElement); }
From source file:com.centeractive.ws.builder.core.WsdlParser.java
public SoapBuilderFinder binding() { return new SoapBuilderFinder() { private String namespaceURI; private String localPart; private String prefix; @Override//from w w w. ja v a 2s . co m public SoapBuilderFinder namespaceURI(String namespaceURI) { this.namespaceURI = namespaceURI; return this; } @Override public SoapBuilderFinder localPart(String localPart) { this.localPart = localPart; return this; } @Override public SoapBuilderFinder prefix(String prefix) { this.prefix = prefix; return this; } @Override public SoapBuilder builder() { validate(); return getBuilder(getBindingName(), SoapContext.DEFAULT); } @Override public SoapBuilder builder(SoapContext context) { validate(); return getBuilder(getBindingName(), context); } @Override public SoapOperationFinder operation() { return builder().operation(); } private QName getBindingName() { List<QName> result = new ArrayList<QName>(); for (QName bindingName : soapFacade.getBindingNames()) { if (bindingName.getLocalPart().equals(localPart)) { if (namespaceURI != null) { if (!bindingName.getNamespaceURI().equals(namespaceURI)) { continue; } } if (prefix != null) { if (!bindingName.getPrefix().equals(prefix)) { continue; } } result.add(bindingName); } } if (result.isEmpty()) { throw new SoapBuilderException("Binding not found"); } if (result.size() > 1) { throw new SoapBuilderException("Found more than one binding " + result); } return result.iterator().next(); } private void validate() { if (StringUtils.isBlank(localPart)) { throw new SoapBuilderException("Specify at least localPart of the binding's QName"); } } }; }
From source file:com.evolveum.midpoint.prism.parser.XPathHolder.java
private void addPureXpath(StringBuilder sb) { if (!absolute && segments.isEmpty()) { // Empty segment list gives a "local node" XPath sb.append("."); return;/*from w w w . j a v a 2s .co m*/ } if (absolute) { sb.append("/"); } boolean first = true; for (XPathSegment seg : segments) { if (seg.isIdValueFilter()) { sb.append("["); sb.append(seg.getValue()); sb.append("]"); } else { if (!first) { sb.append("/"); } else { first = false; } if (seg.isVariable()) { sb.append("$"); } QName qname = seg.getQName(); if (!StringUtils.isEmpty(qname.getPrefix())) { sb.append(qname.getPrefix() + ":" + qname.getLocalPart()); } else { if (StringUtils.isNotEmpty(qname.getNamespaceURI())) { String prefix = GlobalDynamicNamespacePrefixMapper .getPreferredPrefix(qname.getNamespaceURI()); seg.setQNamePrefix(prefix); // hack - we modify the path segment here (only the form, not the meaning), but nevertheless it's ugly sb.append(seg.getQName().getPrefix() + ":" + seg.getQName().getLocalPart()); } else { // no namespace, no prefix sb.append(qname.getLocalPart()); } } } } }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static Element createElement(Document document, QName qname) { Element element;//from w w w.j a v a2 s. c o m // String namespaceURI = qname.getNamespaceURI(); // if (StringUtils.isBlank(namespaceURI)) { // element = document.createElement(qname.getLocalPart()); // } else { element = document.createElementNS(qname.getNamespaceURI(), qname.getLocalPart()); // } if (StringUtils.isNotEmpty(qname.getPrefix()) && StringUtils.isNotEmpty(qname.getNamespaceURI())) { // second part of the condition is because of wrong data in tests (undeclared prefixes in XPath expressions) element.setPrefix(qname.getPrefix()); } return element; }
From source file:com.evolveum.midpoint.prism.marshaller.ItemPathHolder.java
public Map<String, String> getNamespaceMap() { Map<String, String> namespaceMap = new HashMap<>(); Iterator<PathHolderSegment> iter = segments.iterator(); while (iter.hasNext()) { PathHolderSegment seg = iter.next(); QName qname = seg.getQName(); if (qname != null) { if (qname.getPrefix() != null && !qname.getPrefix().isEmpty()) { namespaceMap.put(qname.getPrefix(), qname.getNamespaceURI()); }//ww w.j a va 2 s . c o m // this code seems to be currently of no use // else { // // Default namespace // // HACK. See addPureXpath method // namespaceMap.put(DEFAULT_PREFIX, qname.getNamespaceURI()); // } } } return namespaceMap; }