List of usage examples for javax.xml.namespace QName getLocalPart
public String getLocalPart()
Get the local part of this QName
.
From source file:com.evolveum.midpoint.schema.util.ValueDisplayUtil.java
public static String toStringValue(PrismPropertyValue propertyValue) { Object value = propertyValue.getValue(); if (value == null) { return null; } else if (value instanceof String) { return (String) value; } else if (value instanceof PolyString) { return ((PolyString) value).getOrig(); } else if (value instanceof ProtectedStringType) { return "(protected string)"; // todo i18n } else if (value instanceof Boolean || value instanceof Integer || value instanceof Long) { return value.toString(); } else if (value instanceof XMLGregorianCalendar) { return ((XMLGregorianCalendar) value).toGregorianCalendar().getTime().toLocaleString(); // todo fix } else if (value instanceof Date) { return ((Date) value).toLocaleString(); // todo fix } else if (value instanceof LoginEventType) { LoginEventType loginEventType = (LoginEventType) value; if (loginEventType.getTimestamp() != null) { return loginEventType.getTimestamp().toGregorianCalendar().getTime().toLocaleString(); // todo fix } else {/* w ww.j av a 2 s. c o m*/ return ""; } } else if (value instanceof ApprovalSchemaType) { ApprovalSchemaType approvalSchemaType = (ApprovalSchemaType) value; return approvalSchemaType.getName() + (approvalSchemaType.getDescription() != null ? (": " + approvalSchemaType.getDescription()) : "") + " (...)"; } else if (value instanceof ConstructionType) { ConstructionType ct = (ConstructionType) value; Object resource = (ct.getResource() != null ? ct.getResource().getName() : (ct.getResourceRef() != null ? ct.getResourceRef().getOid() : null)); return "resource object" + (resource != null ? " on " + resource : "") + (ct.getDescription() != null ? ": " + ct.getDescription() : ""); } else if (value instanceof Enum) { return value.toString(); } else if (value instanceof ResourceAttributeDefinitionType) { ResourceAttributeDefinitionType radt = (ResourceAttributeDefinitionType) value; ItemPathType ref = radt.getRef(); String path; if (ref != null) { path = ref.getItemPath().toString(); } else { path = "(null)"; } StringBuilder sb = new StringBuilder(); MappingType mappingType = radt.getOutbound(); if (mappingType != null) { if (mappingType.getExpression() == null) { sb.append("Empty mapping for ").append(path); } else { sb.append(path).append(" = "); boolean first = true; for (JAXBElement<?> evaluator : mappingType.getExpression().getExpressionEvaluator()) { if (first) { first = false; } else { sb.append(", "); } if (QNameUtil.match(SchemaConstants.C_VALUE, evaluator.getName()) && evaluator.getValue() instanceof RawType) { RawType raw = (RawType) evaluator.getValue(); try { XNode xnode = raw.serializeToXNode(); if (xnode instanceof PrimitiveXNode) { sb.append(((PrimitiveXNode) xnode).getStringValue()); } else { sb.append("(a complex value)"); } } catch (SchemaException e) { sb.append("(an invalid value)"); } } else { sb.append("(a complex expression)"); } } } if (mappingType.getStrength() != null) { sb.append(" (").append(mappingType.getStrength().value()).append(")"); } } else { sb.append("Empty mapping for ").append(path); } return sb.toString(); } else if (value instanceof QName) { QName qname = (QName) value; if (StringUtils.isNotEmpty(qname.getNamespaceURI())) { return qname.getLocalPart() + " (in " + qname.getNamespaceURI() + ")"; } else { return qname.getLocalPart(); } } else { return "(a value of type " + value.getClass().getName() + ")"; // todo i18n } }
From source file:Main.java
/** * The method returns attribute node by the given qname. * /*from w w w . j ava 2 s. com*/ * @param el owner element. * @param attributeName QName of the attribute node to be searched. * @return attribute node by the given qname. */ static public Attr getAttribute(Element el, QName attributeName) { if (el == null) throw new IllegalArgumentException("Element can not be NULL"); if (attributeName == null) throw new IllegalArgumentException("Attribute name can not be NULL"); String nsURI = attributeName.getNamespaceURI(); String localPart = attributeName.getLocalPart(); if (localPart == null) throw new IllegalArgumentException("Local part of the attribute name can not be NULL"); Attr a = el.getAttributeNodeNS(nsURI, localPart); if (a == null) // try to get with null namespace a = el.getAttributeNodeNS(null, localPart); return a; }
From source file:XMLUtils.java
public static Element createElementNS(Document root, QName name) { return createElementNS(root, name.getNamespaceURI(), name.getLocalPart()); }
From source file:com.liferay.wsrp.proxy.TypeConvertorUtil.java
private static void _convert(int sourceVersion, String sourcePackage, Object sourceClass, Object sourceChild, String sourceChildName, Object destination) throws Exception { Class<?> sourceChildClass = sourceChild.getClass(); if (sourceChildClass == NavigationalContext.class) { sourceChildName = "navigationalState"; NavigationalContext navigationalContext = (NavigationalContext) sourceChild; sourceChild = navigationalContext.getOpaqueValue(); } else if (sourceChildClass == SessionParams.class) { sourceChildName = "sessionID"; SessionParams sessionParams = (SessionParams) sourceChild; sourceChild = sessionParams.getSessionID(); }//from w w w . j a v a 2 s .c o m if (sourceChild == null) { return; } sourceChildClass = sourceChild.getClass(); Object destinationChild = null; if (sourceChildClass.isArray()) { destinationChild = convert(sourceChild, sourceVersion); } else { destinationChild = sourceChild; sourceChildClass = sourceChild.getClass(); if (sourceChildClass.getName().contains(sourcePackage)) { destinationChild = convert(sourceChild, sourceVersion); } } String destinationChildName = sourceChildName; if (sourceChildName.equals("itemBinary")) { destinationChildName = "markupBinary"; } else if (sourceChildName.equals("itemString")) { destinationChildName = "markupString"; } else if (sourceChildName.equals("markupBinary")) { destinationChildName = "itemBinary"; } else if (sourceChildName.equals("markupString")) { destinationChildName = "itemString"; } else if (sourceChildName.equals("name") && (sourceClass == Property.class)) { QName qName = (QName) destinationChild; destinationChild = qName.getLocalPart(); } else if (sourceChildName.equals("name") && (sourceClass == PropertyDescription.class)) { String name = (String) destinationChild; destinationChild = new QName("namespace", name, "prefix"); } else if (sourceChildName.equals("navigationalState") && (sourceClass == MarkupParams.class)) { String navigationalState = (String) sourceChild; NavigationalContext navigationalContext = new NavigationalContext(); navigationalContext.setOpaqueValue(navigationalState); destinationChild = navigationalContext; destinationChildName = "navigationalContext"; } else if (sourceChildName.equals("requiresRewriting")) { destinationChildName = "requiresUrlRewriting"; } else if (sourceChildName.equals("requiresUrlRewriting")) { destinationChildName = "requiresRewriting"; } else if (sourceChildName.equals("sessionID") && (sourceClass == RuntimeContext.class)) { String sessionID = (String) sourceChild; SessionParams sessionParams = new SessionParams(); sessionParams.setSessionID(sessionID); destinationChild = sessionParams; destinationChildName = "sessionParams"; } try { PropertyUtils.setProperty(destination, destinationChildName, destinationChild); } catch (NoSuchMethodException nsme) { if (_log.isWarnEnabled()) { _log.warn(nsme, nsme); } } }
From source file:com.predic8.membrane.core.util.SOAPUtil.java
public static boolean isSOAP(XMLInputFactory xmlInputFactory, XOPReconstitutor xopr, Message msg) { try {/* www .ja va 2 s.com*/ XMLEventReader parser; synchronized (xmlInputFactory) { parser = xmlInputFactory.createXMLEventReader(xopr.reconstituteIfNecessary(msg)); } while (parser.hasNext()) { XMLEvent event = parser.nextEvent(); if (event.isStartElement()) { QName name = ((StartElement) event).getName(); return (Constants.SOAP11_NS.equals(name.getNamespaceURI()) || Constants.SOAP12_NS.equals(name.getNamespaceURI())) && "Envelope".equals(name.getLocalPart()); } } } catch (Exception e) { log.warn("Ignoring exception: ", e); } return false; }
From source file:XMLUtils.java
public static Element createElementNS(Node node, QName name) { return createElementNS(node.getOwnerDocument(), name.getNamespaceURI(), name.getLocalPart()); }
From source file:eu.esdihumboldt.hale.io.xslt.XslTransformationUtil.java
/** * Create a XPath statement to select instances specified by the given type * entity definition.//from w ww. jav a 2s . com * * @param ted the type entity definition * @param context the context for the XPath expression, e.g. the empty * string for the document root or <code>/</code> for anywhere in * the document * @param namespaces the namespace context * @return the XPath expression or <code>null</code> if there are no * elements that match the type */ public static String selectInstances(TypeEntityDefinition ted, String context, NamespaceContext namespaces) { TypeDefinition type = ted.getDefinition(); // get the XML elements associated to the type XmlElements elements = type.getConstraint(XmlElements.class); if (elements.getElements().isEmpty()) { /* * XXX dirty hack * * In CityGML 1.0 no element for AppearanceType is defined, only a * property that is not detected in this way. The source route * element is not known here, so we also cannot do a search based on * the type. Thus for now we handle it as a special case. */ QName typeName = ted.getDefinition().getName(); if ("http://www.opengis.net/citygml/appearance/1.0".equals(typeName.getNamespaceURI()) && "AppearanceType".equals(typeName.getLocalPart())) { // create a dummy XML element elements = new XmlElements(); elements.addElement( new XmlElement(new QName("http://www.opengis.net/citygml/appearance/1.0", "Appearance"), ted.getDefinition(), null)); } else // XXX dirty hack end return null; } // XXX which elements should be used? // for now use all elements StringBuilder select = new StringBuilder(); boolean first = true; for (XmlElement element : elements.getElements()) { if (first) { first = false; } else { select.append(" | "); } select.append(context); select.append('/'); String ns = element.getName().getNamespaceURI(); if (ns != null && !ns.isEmpty()) { String prefix = namespaces.getPrefix(ns); if (prefix != null && !prefix.isEmpty()) { select.append(prefix); select.append(':'); } } select.append(element.getName().getLocalPart()); } // filter if (ted.getFilter() != null) { String filterxpath = FilterToXPath.toXPath(ted.getDefinition(), namespaces, ted.getFilter()); if (filterxpath != null && !filterxpath.isEmpty()) { select.insert(0, '('); select.append(")["); select.append(StringEscapeUtils.escapeXml(filterxpath)); select.append(']'); } } return select.toString(); }
From source file:Main.java
/** * Creates a new Element having the specified qualified name. The element * must be {@link Document#adoptNode(Node) adopted} when inserted into * another Document./* w ww. j ava 2 s .co m*/ * * @param qName * A QName object. * @return An Element node (with a Document owner but no parent). */ public static Element createElement(QName qName) { Document doc = null; try { doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } StringBuilder nodeName = new StringBuilder(); if (qName.getPrefix().isEmpty()) { nodeName.append(qName.getLocalPart()); } else { nodeName.append(qName.getPrefix()).append(':').append(qName.getLocalPart()); } Element elem = doc.createElementNS(qName.getNamespaceURI(), nodeName.toString()); return elem; }
From source file:net.di2e.ecdr.search.transform.atom.response.security.SecurityMarkingParser.java
public static SecurityDataImpl getFeedSecurityMarkings(Feed feed) { List<QName> attributes = feed.getAttributes(); if (attributes != null) { HashMap<String, List<String>> securityProps = new HashMap<String, List<String>>(); String feedNamespace = null; for (QName qName : attributes) { String namespace = qName.getNamespaceURI(); if (NAMESPACES.contains(namespace)) { String value = feed.getAttributeValue(qName); if (StringUtils.isNotBlank(value)) { securityProps.put(qName.getLocalPart(), getValues(value)); if (feedNamespace == null) { feedNamespace = namespace; }/* w w w .j av a2 s . co m*/ } } } if (!securityProps.isEmpty()) { return new SecurityDataImpl(securityProps, feedNamespace); } } return null; }
From source file:net.di2e.ecdr.search.transform.atom.response.security.SecurityMarkingParser.java
public static Metacard addSecurityToMetacard(Metacard metacard, Entry entry) { HashMap<String, List<String>> securityProps = new HashMap<String, List<String>>(); CDRMetacard metacardImpl = new CDRMetacard(metacard); List<QName> attributes = entry.getAttributes(); if (attributes != null) { String metacardSecurityNamespace = null; for (QName qName : attributes) { String namespace = qName.getNamespaceURI(); if (NAMESPACES.contains(namespace)) { String value = entry.getAttributeValue(qName); if (StringUtils.isNotBlank(value)) { securityProps.put(qName.getLocalPart(), getValues(value)); if (metacardSecurityNamespace == null) { metacardSecurityNamespace = namespace; }//from w w w . j ava 2 s . c o m } } } if (!securityProps.isEmpty()) { metacardImpl.setSecurity(securityProps); metacardImpl.setAttribute(SecurityConstants.SECURITY_NAMESPACE, metacardSecurityNamespace); } } return metacardImpl; }