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.parser.DomSerializer.java

/**
 * Create XML element with the correct namespace prefix and namespace definition.
 * @param qname element QName/*from w w  w  .  j a  va2s  .  c o m*/
 * @return created DOM element
 */
private Element createElement(QName qname, Element parentElement) {
    String namespaceURI = qname.getNamespaceURI();
    if (!StringUtils.isBlank(namespaceURI)) {
        qname = setQNamePrefix(qname);
    }
    if (parentElement != null) {
        return DOMUtil.createElement(doc, qname, parentElement, parentElement);
    } else {
        // This is needed otherwise the root element itself could not be created
        // Caller of this method is responsible for setting the topElement
        return DOMUtil.createElement(doc, qname);
    }
}

From source file:de.ingrid.iplug.csw.dsc.cswclient.impl.SoapRequest.java

/**
 * @see OpenGIS Catalogue Services Specification 2.0.2 - ISO Metadata
 *      Application Profile 8.2.2.2//w ww  .  j a v  a2 s. c om
 */
@Override
public Document doGetRecordById(String serverURL, CSWQuery query) throws Exception {

    // create the request
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace cswNs = fac.createOMNamespace(query.getSchema().getQName().getNamespaceURI(),
            query.getSchema().getQName().getPrefix());

    // create method
    OMElement method = fac.createOMElement(Operation.GET_RECORD_BY_ID.toString(), cswNs);

    // add the default parameters
    method.addAttribute("service", CSWConstants.SERVICE_TYPE, null);

    // add the query specific parameters
    method.addAttribute("version", query.getVersion(), null);
    method.addAttribute("outputFormat", query.getOutputFormat().toString(), null);

    QName outputSchemaQN = query.getOutputSchema().getQName();
    method.declareNamespace(outputSchemaQN.getNamespaceURI(), outputSchemaQN.getPrefix());
    if (outputSchemaQN.getLocalPart().length() > 0)
        method.addAttribute("outputSchema", outputSchemaQN.getPrefix() + ":" + outputSchemaQN.getLocalPart(),
                null);
    else
        method.addAttribute("outputSchema", outputSchemaQN.getNamespaceURI(), null);

    // create Id
    OMElement idNode = fac.createOMElement("Id", cswNs);
    idNode.setText(query.getId());
    method.addChild(idNode);

    // create ElementSetName element typename
    OMElement elementSetName = fac.createOMElement("ElementSetName", cswNs);
    elementSetName.setText(query.getElementSetName().toString());
    method.addChild(elementSetName);

    // send the request
    try {
        return sendRequest(serverURL, method);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.autentia.xml.namespace.QNameBuilder.java

private QName discoverQNameAndCachesIt(Class<?> classType, String classTypeNameSuffix, String prefixSuffix,
        QNamesCache cache) {//from   w  w w  . j  a  va2s .  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.prism.lex.dom.DomLexicalWriter.java

private QName setQNamePrefixExplicitIfNeeded(QName name) {
    if (name != null && StringUtils.isNotBlank(name.getNamespaceURI())
            && StringUtils.isBlank(name.getPrefix())) {
        return setQNamePrefixExplicit(name);
    } else {//from   w ww .  j  ava  2s.  c  om
        return name;
    }
}

From source file:de.ingrid.iplug.csw.dsc.cswclient.impl.SoapRequest.java

/**
 * @see OpenGIS Catalogue Services Specification 2.0.2 - ISO Metadata
 *      Application Profile 8.2.2.1//www  .j av  a  2 s  .  co m
 */
@Override
public Document doGetRecords(String serverURL, CSWQuery query) throws Exception {

    // create the request
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace cswNs = fac.createOMNamespace(query.getSchema().getQName().getNamespaceURI(),
            query.getSchema().getQName().getPrefix());

    // create method
    OMElement method = fac.createOMElement(Operation.GET_RECORDS.toString(), cswNs);
    method.declareNamespace(Namespace.ISO.getQName().getNamespaceURI(), Namespace.ISO.getQName().getPrefix());
    method.declareNamespace(Namespace.GML.getQName().getNamespaceURI(), Namespace.GML.getQName().getPrefix());

    // add the default parameters
    method.addAttribute("service", CSWConstants.SERVICE_TYPE, null);

    // add the query specific parameters
    method.addAttribute("version", query.getVersion(), null);
    method.addAttribute("outputFormat", query.getOutputFormat().toString(), null);
    method.addAttribute("resultType", query.getResultType().toString(), null);
    method.addAttribute("startPosition", Integer.toString(query.getStartPosition()), null);
    method.addAttribute("maxRecords", Integer.toString(query.getMaxRecords()), null);

    QName outputSchemaQN = query.getOutputSchema().getQName();
    method.declareNamespace(outputSchemaQN.getNamespaceURI(), outputSchemaQN.getPrefix());
    if (outputSchemaQN.getLocalPart().length() > 0)
        method.addAttribute("outputSchema", outputSchemaQN.getPrefix() + ":" + outputSchemaQN.getLocalPart(),
                null);
    else
        method.addAttribute("outputSchema", outputSchemaQN.getNamespaceURI(), null);

    // create Query element typename
    OMElement queryElem = fac.createOMElement("Query", cswNs);
    // add typeNames attribute
    List<String> typeNames = new ArrayList<String>();
    for (TypeName typeName : query.getTypeNames()) {
        QName typeNameQN = typeName.getQName();
        method.declareNamespace(typeNameQN.getNamespaceURI(), typeNameQN.getPrefix());
        typeNames.add(typeNameQN.getPrefix() + ":" + typeNameQN.getLocalPart());
    }
    String typeNamesValue = StringUtils.join(typeNames.toArray(), ",");
    queryElem.addAttribute("typeNames", typeNamesValue, null);

    // create ElementSetName element typename
    OMElement elementSetName = fac.createOMElement("ElementSetName", cswNs);
    elementSetName.setText(query.getElementSetName().toString());
    queryElem.addChild(elementSetName);

    // add the Filter
    if (query.getConstraint() != null) {
        // create Constraint
        // make sure the constraint element is only created when
        // we have a filter.
        OMElement constraint = fac.createOMElement("Constraint", cswNs);
        constraint.addAttribute("version", query.getConstraintLanguageVersion(), null);
        queryElem.addChild(constraint);
        OMElement filter = XMLUtils.toOM(query.getConstraint().getDocumentElement());
        constraint.addChild(filter);
    }

    method.addChild(queryElem);

    // send the request
    try {
        return sendRequest(serverURL, method);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

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  2  s . com*/
        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.util.DOMUtil.java

public static Element createElement(Document document, QName qname, Element parentElement,
        Element definitionElement) {
    lookupOrCreateNamespaceDeclaration(parentElement, qname.getNamespaceURI(), qname.getPrefix(),
            definitionElement, true);/* ww w .j a v a2  s . co m*/
    return createElement(document, qname);
}

From source file:com.evolveum.midpoint.prism.lex.dom.DomLexicalWriter.java

/**
 * Create XML element with the correct namespace prefix and namespace definition.
 * @param qname element QName//from   w ww. ja v  a  2s  . c  o m
 * @return created DOM element
 */
@NotNull
private Element createElement(QName qname, Element parentElement) {
    String namespaceURI = qname.getNamespaceURI();
    if (!StringUtils.isBlank(namespaceURI)) {
        qname = setQNamePrefix(qname);
    }
    if (parentElement != null) {
        return DOMUtil.createElement(doc, qname, parentElement, parentElement);
    } else {
        // This is needed otherwise the root element itself could not be created
        // Caller of this method is responsible for setting the topElement
        return DOMUtil.createElement(doc, qname);
    }
}

From source file:eu.delving.sip.xml.SourceConverter.java

private void handleAttribute(Path path, Attribute attr) {
    Path extended = path.child(Tag.attribute(attr.getName()));
    if (extended.equals(uniqueElementPath)) {
        unique = attr.getValue();/* w  ww  . j  av a 2  s  .c  om*/
    } else if (path.equals(recordRootPath)) {
        QName a = attr.getName();
        QName attrName = new QName(a.getNamespaceURI(), "_" + a.getLocalPart(), a.getPrefix());
        eventBuffer.add(eventFactory.createStartElement(attrName, null, null));
        eventBuffer.add(eventFactory.createCharacters(attr.getValue()));
        eventBuffer.add(eventFactory.createEndElement(attrName, null));
        eventBuffer.add(eventFactory.createCharacters("\n"));
    }
}

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);// w w  w  .  j  a v a 2 s .  c om
    setQNameAttribute(element, attr, attributeValue, element);
}