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:microsoft.exchange.webservices.data.core.EwsXmlReader.java
/** * Determines whether current element is a end element. * * @param xmlNamespace the xml namespace * @param localName the local name// w w w . jav a 2s. com * @return boolean */ public boolean isEndElement(XmlNamespace xmlNamespace, String localName) { boolean isEndElement = false; /* * if(localName.equals("Body")) { return true; } else */ if (this.presentEvent.isEndElement()) { EndElement endElement = this.presentEvent.asEndElement(); QName qName = endElement.getName(); isEndElement = qName.getLocalPart().equals(localName) && (qName.getPrefix().equals(EwsUtilities.getNamespacePrefix(xmlNamespace)) || qName.getNamespaceURI().equals(EwsUtilities.getNamespaceUri(xmlNamespace))); } return isEndElement; }
From source file:com.evolveum.midpoint.prism.marshaller.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 a2 s.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 (ObjectReferencePathSegment.QNAME.equals(qname)) { sb.append(ObjectReferencePathSegment.SYMBOL); } else if (ParentPathSegment.QNAME.equals(qname)) { sb.append(ParentPathSegment.SYMBOL); } else if (IdentifierPathSegment.QNAME.equals(qname)) { sb.append(IdentifierPathSegment.SYMBOL); } else 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.ettrema.httpclient.Host.java
/** * TODO: should optimise so it only generates once per set of fields * //from ww w . j a v a 2 s. c o m * @param fields * @return */ private String buildPropFindXml(List<QName> fields) { try { if (fields == null) { fields = defaultFields; } Element elPropfind = new Element("propfind", RespUtils.NS_DAV); Document doc = new Document(elPropfind); Element elProp = new Element("prop", RespUtils.NS_DAV); elPropfind.addContent(elProp); for (QName qn : fields) { Element elName = new Element(qn.getLocalPart(), qn.getPrefix(), qn.getNamespaceURI()); elProp.addContent(elName); } XMLOutputter outputter = new XMLOutputter(); ByteArrayOutputStream out = new ByteArrayOutputStream(); outputter.output(doc, out); return out.toString("UTF-8"); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:eu.eidas.auth.engine.SamlEngine.java
/** * Converts an assertion to an attribute map. * * @param assertion the assertion/*from w ww .j ava 2 s . c o m*/ * @return the attribute map * @throws EIDASSAMLEngineException the SAML engine exception */ @Nonnull private ImmutableAttributeMap convertToAttributeMap(@Nonnull Assertion assertion) throws EIDASSAMLEngineException { LOG.trace("Generate personal attribute list from XMLObject."); AttributeStatement attributeStatement = findAttributeStatement(assertion); List<Attribute> attributes = attributeStatement.getAttributes(); ImmutableAttributeMap.Builder mapBuilder = ImmutableAttributeMap.builder(); // Process the attributes. for (final Attribute attribute : attributes) { String attributeName = attribute.getName(); String friendlyName = attribute.getFriendlyName(); AttributeDefinition<?> attributeDefinition = getAttributeDefinitionNotNull(attributeName); AttributeValueMarshaller<?> attributeValueMarshaller = attributeDefinition .getAttributeValueMarshaller(); ImmutableSet.Builder<AttributeValue<?>> setBuilder = new ImmutableSet.Builder<>(); List<XMLObject> values = attribute.getOrderedChildren(); QName xmlType = attributeDefinition.getXmlType(); QName latinScript = new QName(xmlType.getNamespaceURI(), "LatinScript", xmlType.getPrefix()); // Process the values. for (XMLObject xmlObject : values) { try { if (xmlObject instanceof XSStringImpl) { // Process simple value. setBuilder.add( attributeValueMarshaller.unmarshal(((XSStringImpl) xmlObject).getValue(), false)); } else if (xmlObject instanceof XSAnyImpl) { XSAnyImpl xsAny = (XSAnyImpl) xmlObject; // TODO: move to STORK Extension Processor if ("http://www.stork.gov.eu/1.0/signedDoc".equals(attributeName)) { setBuilder.add(attributeValueMarshaller.unmarshal(computeSimpleValue(xsAny), false)); // TODO: move to STORK Extension Processor } else if ("http://www.stork.gov.eu/1.0/canonicalResidenceAddress".equals(attributeName)) { // Process complex value. setBuilder.add(attributeValueMarshaller.unmarshal(computeComplexValue(xsAny).toString(), false)); } else { boolean isNonLatinScriptAlternateVersion = false; String latinScriptAttrValue = xsAny.getUnknownAttributes().get(latinScript); if (StringUtils.isNotBlank(latinScriptAttrValue) && "false".equals(latinScriptAttrValue)) { isNonLatinScriptAlternateVersion = true; } // Process simple value. setBuilder.add(attributeValueMarshaller.unmarshal(xsAny.getTextContent(), isNonLatinScriptAlternateVersion)); } // TODO: remove } else if (xmlObject instanceof GenericEidasAttributeType) { // Process simple value. setBuilder.add(attributeValueMarshaller .unmarshal(((GenericEidasAttributeType) xmlObject).getValue(), false)); } else { LOG.info( "BUSINESS EXCEPTION : attribute value is unknown in generatePersonalAttributeList."); throw new EIDASSAMLEngineException(EidasErrorKey.INTERNAL_ERROR.errorCode(), EidasErrorKey.INTERNAL_ERROR.errorCode(), "Attribute value is unknown for \"" + attributeDefinition.getNameUri().toASCIIString() + "\" - value: \"" + xmlObject + "\""); } } catch (AttributeValueMarshallingException e) { LOG.error("BUSINESS EXCEPTION : Illegal Attribute Value: " + e, e); throw new EIDASSAMLEngineException(EidasErrorKey.INTERNAL_ERROR.errorCode(), EidasErrorKey.INTERNAL_ERROR.errorCode(), e); } } // Check if friendlyName matches when provided - TODO Temorary removed due to validator failure /* if (StringUtils.isNotEmpty(friendlyName) && attributeDefinition != null && !friendlyName.equals(attributeDefinition.getFriendlyName())) { LOG.error("BUSINESS EXCEPTION : Illegal Attribute friendlyName for " + attributeDefinition.getNameUri().toString() + " expected " + attributeDefinition.getFriendlyName() + " got " + friendlyName); throw new EIDASSAMLEngineException(EidasErrorKey.INTERNAL_ERROR.errorCode(), EidasErrorKey.INTERNAL_ERROR.errorCode(), "Illegal Attribute friendlyName for " + attributeDefinition.getNameUri().toString() + " expected " + attributeDefinition.getFriendlyName() + " got " + friendlyName); }*/ mapBuilder.put((AttributeDefinition) attributeDefinition, (ImmutableSet) setBuilder.build()); } return mapBuilder.build(); }
From source file:eu.eidas.auth.engine.core.stork.StorkExtensionProcessor.java
/** * Converts an assertion to an attribute map. * * @param assertion the assertion/*from w w w.ja v a2 s. c o m*/ * @return the attribute map * @throws EIDASSAMLEngineException the SAML engine exception */ @Nonnull private ImmutableAttributeMap convertToAttributeMap(@Nonnull Assertion assertion) throws EIDASSAMLEngineException { LOG.trace("Generate personal attribute list from XMLObject."); AttributeStatement attributeStatement = ResponseUtil.findAttributeStatement(assertion); List<Attribute> attributes = attributeStatement.getAttributes(); ImmutableAttributeMap.Builder mapBuilder = ImmutableAttributeMap.builder(); // Process the attributes. for (final Attribute attribute : attributes) { String attributeName = attribute.getName(); AttributeDefinition<?> attributeDefinition = getAttributeDefinitionNotNull(attributeName); AttributeValueMarshaller<?> attributeValueMarshaller = attributeDefinition .getAttributeValueMarshaller(); ImmutableSet.Builder<eu.eidas.auth.commons.attribute.AttributeValue<?>> setBuilder = new ImmutableSet.Builder<>(); List<XMLObject> values = attribute.getOrderedChildren(); QName xmlType = attributeDefinition.getXmlType(); QName latinScript = new QName(xmlType.getNamespaceURI(), "LatinScript", xmlType.getPrefix()); // Process the values. for (XMLObject xmlObject : values) { try { if (xmlObject instanceof XSStringImpl) { // Process simple value. setBuilder.add( attributeValueMarshaller.unmarshal(((XSStringImpl) xmlObject).getValue(), false)); } else if (xmlObject instanceof XSAnyImpl) { XSAnyImpl xsAny = (XSAnyImpl) xmlObject; // TODO: move to STORK Extension Processor if ("http://www.stork.gov.eu/1.0/signedDoc".equals(attributeName)) { setBuilder.add(attributeValueMarshaller.unmarshal(computeSimpleValue(xsAny), false)); // TODO: move to STORK Extension Processor } else if ("http://www.stork.gov.eu/1.0/canonicalResidenceAddress".equals(attributeName)) { // Process complex value. setBuilder.add(attributeValueMarshaller.unmarshal(computeComplexValue(xsAny).toString(), false)); } else { boolean isNonLatinScriptAlternateVersion = false; String latinScriptAttrValue = xsAny.getUnknownAttributes().get(latinScript); if (StringUtils.isNotBlank(latinScriptAttrValue) && "false".equals(latinScriptAttrValue)) { isNonLatinScriptAlternateVersion = true; } // Process simple value. setBuilder.add(attributeValueMarshaller.unmarshal(xsAny.getTextContent(), isNonLatinScriptAlternateVersion)); } // TODO: remove } else if (xmlObject instanceof GenericEidasAttributeType) { // Process simple value. setBuilder.add(attributeValueMarshaller .unmarshal(((GenericEidasAttributeType) xmlObject).getValue(), false)); } else { LOG.info( "BUSINESS EXCEPTION : attribute value is unknown in generatePersonalAttributeList."); throw new EIDASSAMLEngineException(EidasErrorKey.INTERNAL_ERROR.errorCode(), EidasErrorKey.INTERNAL_ERROR.errorCode(), "Attribute value is unknown for \"" + attributeDefinition.getNameUri().toASCIIString() + "\" - value: \"" + xmlObject + "\""); } } catch (AttributeValueMarshallingException e) { LOG.error("BUSINESS EXCEPTION : Illegal Attribute Value: " + e, e); throw new EIDASSAMLEngineException(EidasErrorKey.INTERNAL_ERROR.errorCode(), EidasErrorKey.INTERNAL_ERROR.errorCode(), e); } } mapBuilder.put((AttributeDefinition) attributeDefinition, (ImmutableSet) setBuilder.build()); } return mapBuilder.build(); }
From source file:nl.knaw.huygens.tei.xpath.XPathUtil.java
public static Map<String, String> getNamespaceInfo(String xml) { Map<String, String> namespaces = Maps.newIdentityHashMap(); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); try {//from ww w . j ava2 s.c o m XMLStreamReader xreader = inputFactory.createXMLStreamReader(IOUtils.toInputStream(xml, "UTF-8")); while (xreader.hasNext()) { if (xreader.next() == XMLStreamConstants.START_ELEMENT) { QName qName = xreader.getName(); if (qName != null) { addNamespace(namespaces, qName.getPrefix(), qName.getNamespaceURI()); for (int i = 0; i < xreader.getAttributeCount(); i++) { addNamespace(namespaces, xreader.getAttributePrefix(i), xreader.getAttributeNamespace(i)); } } } } } catch (XMLStreamException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return namespaces; }
From source file:nl.nn.adapterframework.soap.Wsdl.java
protected void message(XMLStreamWriter w, String root, Collection<QName> parts) throws XMLStreamException, IOException { if (!parts.isEmpty()) { w.writeStartElement(WSDL_NAMESPACE, "message"); w.writeAttribute("name", "Message_" + root); {/*from w w w. j a v a 2 s . c o m*/ for (QName part : parts) { w.writeEmptyElement(WSDL_NAMESPACE, "part"); w.writeAttribute("name", "Part_" + part.getLocalPart()); String type = part.getPrefix() + ":" + part.getLocalPart(); w.writeAttribute("element", type); } } w.writeEndElement(); } }
From source file:org.apache.abdera.util.AbstractStreamWriter.java
public StreamWriter writeAttribute(QName qname, String value) { if (value == null) return this; return writeAttribute(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix(), value); }
From source file:org.apache.abdera.util.AbstractStreamWriter.java
public StreamWriter startElement(QName qname) { return startElement(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix()); }
From source file:org.apache.abdera.util.AbstractStreamWriter.java
public StreamWriter writeAttribute(QName qname, Date value) { return writeAttribute(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix(), value); }