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.util.DOMUtil.java

private static void setQNameAttribute(Element element, Attr attr, QName attributeQnameValue,
        Element definitionElement) {
    String attributeStringValue;//from  w w  w.  java2 s.co  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 Element getOrCreateAsFirstElement(Element parentElement, QName elementQName) {
    Element element = getChildElement(parentElement, elementQName);
    if (element != null) {
        return element;
    }/*from  w  ww.j a  va 2s  . co  m*/
    Document doc = parentElement.getOwnerDocument();
    element = doc.createElementNS(elementQName.getNamespaceURI(), elementQName.getLocalPart());
    parentElement.insertBefore(element, getFirstChildElement(parentElement));
    return element;
}

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

public static Element createElement(Document document, QName qname) {
    Element element;//from w w  w. jav  a2 s  . co  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.centeractive.ws.builder.soap.XmlUtils.java

public static Document createDocument(QName element) {
    ensureDocumentBuilder();//  ww w.j  a  v  a  2s . c o m

    Document document = documentBuilder.newDocument();
    document.appendChild(document.createElementNS(element.getNamespaceURI(), element.getLocalPart()));
    return document;
}

From source file:com.evolveum.midpoint.web.component.wizard.resource.component.schemahandling.ResourceAttributeEditor.java

private String prepareReferenceDisplayValue(ItemPathType object) {
    if (object == null || object.getItemPath() == null) {
        return "";
    }/*from   w w  w  . j  a  v  a2s . c o  m*/

    ItemPath path = object.getItemPath();
    if (path.getSegments().size() != 1) {
        return path.toString();
    }

    QName name = ItemPathUtil.getOnlySegmentQName(path);

    StringBuilder sb = new StringBuilder();
    String prefix = SchemaConstants.NS_ICF_SCHEMA.equals(name.getNamespaceURI()) ? "icfs" : "ri";
    sb.append(prefix);
    sb.append(": ");
    sb.append(name.getLocalPart());

    return sb.toString();
}

From source file:com.evolveum.midpoint.prism.marshaller.ItemPathHolder.java

public Element toElement(QName elementQName, Document document) {
    return toElement(elementQName.getNamespaceURI(), elementQName.getLocalPart(), document);
}

From source file:org.apache.synapse.mediators.transform.PayloadFactoryMediator.java

private boolean checkAndReplaceEnvelope(OMElement resultElement, MessageContext synCtx) {
    OMElement firstChild = resultElement.getFirstElement();
    QName resultQName = firstChild.getQName();
    if (resultQName.getLocalPart().equals("Envelope")
            && (resultQName.getNamespaceURI().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)
                    || resultQName.getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI))) {
        SOAPEnvelope soapEnvelope = AXIOMUtils.getSOAPEnvFromOM(resultElement.getFirstElement());
        if (soapEnvelope != null) {
            try {
                soapEnvelope.buildWithAttachments();
                synCtx.setEnvelope(soapEnvelope);
            } catch (AxisFault axisFault) {
                handleException("Unable to attach SOAPEnvelope", axisFault, synCtx);
            }/*from   ww  w  .ja v a2  s.c  o  m*/
        }
    } else {
        return false;
    }
    return true;
}

From source file:eu.planets_project.tb.gui.backing.admin.wsclient.util.ComponentBuilder.java

/**
 * Populates a ServiceInfo instance from the specified Service definiition
 *
 * @param   component      The component to populate
 * @param   service        The Service to populate from
 *
 * @return The populated component is returned representing the Service parameter
 *//*w w w.java2 s.c  o  m*/
private ServiceInfo populateComponent(ServiceInfo component, Service service) {
    // Get the qualified service name information
    QName qName = service.getQName();

    // Get the service's namespace URI
    String namespace = qName.getNamespaceURI();

    // Use the local part of the qualified name for the component's name
    String name = qName.getLocalPart();

    // Set the name
    component.setName(name);
    // Get the defined ports for this service
    Map ports = service.getPorts();

    // Use the Ports to create OperationInfos for all request/response messages defined
    Iterator portIter = ports.values().iterator();

    while (portIter.hasNext()) {
        // Get the next defined port
        Port port = (Port) portIter.next();

        // Get the Port's Binding
        Binding binding = port.getBinding();

        // Now we will create operations from the Binding information
        List<?> operations = buildOperations(binding);

        // Process objects built from the binding information
        Iterator<?> operIter = operations.iterator();

        while (operIter.hasNext()) {
            OperationInfo operation = (OperationInfo) operIter.next();

            // Set the namespace URI for the operation.
            operation.setNamespaceURI(namespace);

            // Find the SOAP target URL
            ExtensibilityElement addrElem = findExtensibilityElement(port.getExtensibilityElements(),
                    "address");

            if (addrElem != null && addrElem instanceof SOAPAddress) {
                // Set the SOAP target URL
                SOAPAddress soapAddr = (SOAPAddress) addrElem;
                operation.setTargetURL(soapAddr.getLocationURI());
            }

            // Add the operation info to the component
            component.addOperation(operation);
        }
    }

    return component;
}

From source file:com.evolveum.midpoint.prism.PrismContainerDefinition.java

public PrismContainerDefinition createContainerDefinition(QName name, QName typeName, int minOccurs,
        int maxOccurs) {
    PrismSchema typeSchema = prismContext.getSchemaRegistry().findSchemaByNamespace(typeName.getNamespaceURI());
    if (typeSchema == null) {
        throw new IllegalArgumentException(
                "Schema for namespace " + typeName.getNamespaceURI() + " is not known in the prism context");
    }//from w w w. j a v  a2  s .  c  o  m
    ComplexTypeDefinition typeDefinition = typeSchema.findComplexTypeDefinition(typeName);
    if (typeDefinition == null) {
        throw new IllegalArgumentException("Type " + typeName + " is not known in the schema");
    }
    return createContainerDefinition(name, typeDefinition, minOccurs, maxOccurs);
}

From source file:com.evolveum.midpoint.prism.crypto.ProtectorImpl.java

private boolean compareHashed(ProtectedStringType hashedPs, char[] clearChars)
        throws SchemaException, EncryptionException {
    HashedDataType hashedDataType = hashedPs.getHashedDataType();
    DigestMethodType digestMethodType = hashedDataType.getDigestMethod();
    if (digestMethodType == null) {
        throw new SchemaException("No digest type");
    }/*from  ww  w.ja  v  a  2s  . c om*/
    String algorithmUri = digestMethodType.getAlgorithm();
    QName algorithmQName = QNameUtil.uriToQName(algorithmUri);
    String algorithmNamespace = algorithmQName.getNamespaceURI();
    if (algorithmNamespace == null) {
        throw new SchemaException("No algorithm namespace");
    }

    switch (algorithmNamespace) {
    case PrismConstants.NS_CRYPTO_ALGORITHM_PBKD:
        return compareHashedPbkd(hashedDataType, algorithmQName.getLocalPart(), clearChars);
    default:
        throw new SchemaException("Unkown namespace " + algorithmNamespace);
    }
}