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:com.evolveum.midpoint.prism.xml.XsdTypeMapper.java

public static QName determineQNameWithNs(QName xsdType) {
    if (StringUtils.isNotBlank(xsdType.getNamespaceURI())) {
        return xsdType;
    }// ww w  . ja v  a 2 s.  c o m
    Set<QName> keys = xsdToJavaTypeMap.keySet();
    for (Iterator<QName> iterator = keys.iterator(); iterator.hasNext();) {
        QName key = iterator.next();
        if (QNameUtil.match(key, xsdType)) {
            return key;
        }
    }
    return null;
}

From source file:com.predic8.membrane.core.util.SOAPUtil.java

public static boolean isFault(XMLInputFactory xmlInputFactory, XOPReconstitutor xopr, Message msg) {
    int state = 0;
    /*//from  w w w  .  ja v a2 s .  c o  m
     * 0: waiting for "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">"
     * 1: waiting for "<soapenv:Body>" (skipping any "<soapenv:Header>")
     * 2: waiting for "<soapenv:Fault>"
     */
    try {
        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();
                if (!Constants.SOAP11_NS.equals(name.getNamespaceURI())
                        && !Constants.SOAP12_NS.equals(name.getNamespaceURI()))
                    return false;

                if ("Header".equals(name.getLocalPart())) {
                    // skip header
                    int stack = 0;
                    while (parser.hasNext()) {
                        event = parser.nextEvent();
                        if (event.isStartElement())
                            stack++;
                        if (event.isEndElement())
                            if (stack == 0)
                                break;
                            else
                                stack--;
                    }
                    continue;
                }

                String expected;
                switch (state) {
                case 0:
                    expected = "Envelope";
                    break;
                case 1:
                    expected = "Body";
                    break;
                case 2:
                    expected = "Fault";
                    break;
                default:
                    return false;
                }
                if (expected.equals(name.getLocalPart())) {
                    if (state == 2)
                        return true;
                    else
                        state++;
                } else
                    return false;
            }
            if (event.isEndElement())
                return false;
        }
    } catch (Exception e) {
        log.warn("Ignoring exception: ", e);
    }
    return false;
}

From source file:com.evolveum.midpoint.util.QNameUtil.java

public static boolean isUnqualified(QName targetTypeQName) {
    return StringUtils.isBlank(targetTypeQName.getNamespaceURI());
}

From source file:com.moss.jaxwslite.ServiceFactory.java

public static <T> T createDefault(String url, QName qname, Class<T> iface) {
    try {//  w w w .  ja  va  2  s  . c  om
        return defaultFactory.create(new URL(url), qname.getNamespaceURI(), iface);
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static boolean isEqual(QName qn1, QName qn2, boolean ignoreCase) {
    if (qn1 == null && qn2 == null) {
        return true;
    }/*w ww .j  a va2  s . c o  m*/

    if (qn1 != null && qn2 != null && isEqual(qn1.getLocalPart(), qn2.getLocalPart(), ignoreCase)
            && isEqual(qn1.getNamespaceURI(), qn2.getNamespaceURI(), ignoreCase)) {
        return true;
    }

    return false;

}

From source file:eu.esdihumboldt.hale.io.wfs.ui.KVPUtil.java

/**
 * Add typename and namespace parameters for a WFS request to the given URI
 * builder.// w  w  w .java 2 s . c  om
 * 
 * @param builder the builder for the WFS request URI
 * @param selected the type names to include
 * @param version the targeted WFS version
 */
public static void addTypeNameParameter(URIBuilder builder, Iterable<QName> selected, WFSVersion version) {
    // namespaces mapped to prefixes
    Map<String, String> namespaces = new HashMap<>();
    // type names with updated prefix
    Set<QName> typeNames = new HashSet<>();

    for (QName type : selected) {
        String prefix;
        if (type.getNamespaceURI() != null && !type.getNamespaceURI().isEmpty()) {
            prefix = namespaces.get(type.getNamespaceURI());
            if (prefix == null) {
                // no mapping yet for namespace
                String candidate = type.getPrefix();
                prefix = addPrefix(candidate, type.getNamespaceURI(), namespaces);
            }
        } else {
            // default namespace
            prefix = XMLConstants.DEFAULT_NS_PREFIX;
        }

        // add updated type
        typeNames.add(new QName(type.getNamespaceURI(), type.getLocalPart(), prefix));
    }

    final String paramNamespaces;
    final String paramTypenames;
    final String prefixNamespaceDelim;
    switch (version) {
    case V1_1_0:
        paramNamespaces = "NAMESPACE";
        paramTypenames = "TYPENAME";
        prefixNamespaceDelim = "=";
        break;
    case V2_0_0:
    case V2_0_2:
        /*
         * XXX below are the values as defined in the WFS 2 specification.
         * There have been problems with some GeoServer instances if used in
         * that manner.
         */
        paramNamespaces = "NAMESPACES";
        paramTypenames = "TYPENAMES";
        prefixNamespaceDelim = ",";
        break;
    default:
        // fall-back to WFS 1.1
        paramNamespaces = "NAMESPACE";
        paramTypenames = "TYPENAME";
        prefixNamespaceDelim = "=";
    }

    // add namespace prefix definitions
    if (!namespaces.isEmpty()) {
        builder.addParameter(paramNamespaces, Joiner.on(',')
                .join(Maps.transformEntries(namespaces, new EntryTransformer<String, String, String>() {

                    @Override
                    public String transformEntry(String namespace, String prefix) {
                        StringBuilder sb = new StringBuilder();
                        sb.append("xmlns(");
                        sb.append(prefix);
                        sb.append(prefixNamespaceDelim);
                        sb.append(namespace);
                        sb.append(")");
                        return sb.toString();
                    }

                }).values()));
    }
    // add type names
    if (!typeNames.isEmpty()) {
        builder.addParameter(paramTypenames,
                Joiner.on(',').join(Iterables.transform(typeNames, new Function<QName, String>() {

                    @Override
                    public String apply(QName typeName) {
                        String prefix = typeName.getPrefix();
                        if (prefix == null || prefix.isEmpty()) {
                            return typeName.getLocalPart();
                        }
                        return prefix + ":" + typeName.getLocalPart();
                    }
                })));
    }
}

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 {//from  w ww  . ja  v  a 2s  .c  om
            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  ww  .  ja v  a 2s  .  co  m
 * @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: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./*from w  w  w .  j  av a  2  s .  c  o  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);
    }
    Element elem = doc.createElementNS(qName.getNamespaceURI(), qName.getLocalPart());
    return elem;
}

From source file:eu.esdihumboldt.hale.io.xslt.XslTransformationUtil.java

/**
 * Create a XPath statement to select instances specified by the given type
 * entity definition.//  w  w w.  j av a 2  s  .c  o m
 * 
 * @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();
}