Example usage for javax.xml.namespace QName QName

List of usage examples for javax.xml.namespace QName QName

Introduction

In this page you can find the example usage for javax.xml.namespace QName QName.

Prototype

public QName(String localPart) 

Source Link

Document

QName constructor specifying the local part.

If the local part is null an IllegalArgumentException is thrown.

Usage

From source file:fr.openwide.talendalfresco.rest.client.ClientImportCommand.java

protected void handleResponseContentEvent(XMLEvent event) {
    String[] resultLog;/*w w w .  j a  va  2s .  c  om*/
    boolean isSuccessLog;
    switch (event.getEventType()) {
    case XMLEvent.START_ELEMENT:
        StartElement startElement = event.asStartElement();
        String elementName = startElement.getName().getLocalPart();
        if (RestConstants.RES_IMPORT_SUCCESS.equals(elementName)) {
            isSuccessLog = true;
        } else if (RestConstants.RES_IMPORT_ERROR.equals(elementName)) {
            isSuccessLog = false;
        } else {
            break;
        }

        Attribute noderefAttr = startElement.getAttributeByName(new QName(RestConstants.RES_IMPORT_NODEREF));
        String noderef = (noderefAttr == null) ? null : noderefAttr.getValue();
        Attribute doctypeAttr = startElement.getAttributeByName(new QName(RestConstants.RES_IMPORT_DOCTYPE));
        String doctype = (doctypeAttr == null) ? null : doctypeAttr.getValue();
        resultLog = new String[] { elementName, // error or success
                startElement.getAttributeByName(new QName(RestConstants.RES_IMPORT_NAMEPATH)).getValue(),
                startElement.getAttributeByName(new QName(RestConstants.RES_IMPORT_MESSAGE)).getValue(),
                startElement.getAttributeByName(new QName(RestConstants.RES_IMPORT_DATE)).getValue(), noderef,
                doctype };
        resultLogs.add(resultLog);
        if (isSuccessLog) {
            successLogs.add(resultLog);
        } else { // errorLog
            errorLogs.add(resultLog);
        }
        break;
    }
}

From source file:org.apache.axis2.transport.nhttp.HttpCoreNIOSSLSender.java

protected SSLContext getSSLContext(TransportOutDescription transportOut) throws AxisFault {

    KeyManager[] keymanagers = null;
    TrustManager[] trustManagers = null;

    Parameter keyParam = transportOut.getParameter("keystore");
    Parameter trustParam = transportOut.getParameter("truststore");

    if (keyParam != null) {
        OMElement ksEle = keyParam.getParameterElement().getFirstElement();
        String location = ksEle.getFirstChildWithName(new QName("Location")).getText();
        String type = ksEle.getFirstChildWithName(new QName("Type")).getText();
        String storePassword = ksEle.getFirstChildWithName(new QName("Password")).getText();
        String keyPassword = ksEle.getFirstChildWithName(new QName("KeyPassword")).getText();

        try {/*from  www. j  av a  2 s . com*/
            KeyStore keyStore = KeyStore.getInstance(type);
            URL url = getClass().getClassLoader().getResource(location);
            log.debug("Loading Key Store from URL : " + url);

            keyStore.load(url.openStream(), storePassword.toCharArray());
            KeyManagerFactory kmfactory = KeyManagerFactory
                    .getInstance(KeyManagerFactory.getDefaultAlgorithm());
            kmfactory.init(keyStore, keyPassword.toCharArray());
            keymanagers = kmfactory.getKeyManagers();

        } catch (GeneralSecurityException gse) {
            log.error("Error loading Key store : " + location, gse);
            throw new AxisFault("Error loading Key store : " + location, gse);
        } catch (IOException ioe) {
            log.error("Error opening Key store : " + location, ioe);
            throw new AxisFault("Error opening Key store : " + location, ioe);
        }
    }

    if (trustParam != null) {
        OMElement tsEle = trustParam.getParameterElement().getFirstElement();
        String location = tsEle.getFirstChildWithName(new QName("Location")).getText();
        String type = tsEle.getFirstChildWithName(new QName("Type")).getText();
        String storePassword = tsEle.getFirstChildWithName(new QName("Password")).getText();

        try {
            KeyStore trustStore = KeyStore.getInstance(type);
            URL url = getClass().getClassLoader().getResource(location);
            log.debug("Loading Trust Key Store from URL : " + url);

            trustStore.load(url.openStream(), storePassword.toCharArray());
            TrustManagerFactory trustManagerfactory = TrustManagerFactory
                    .getInstance(TrustManagerFactory.getDefaultAlgorithm());
            trustManagerfactory.init(trustStore);
            trustManagers = trustManagerfactory.getTrustManagers();

        } catch (GeneralSecurityException gse) {
            log.error("Error loading Key store : " + location, gse);
            throw new AxisFault("Error loading Key store : " + location, gse);
        } catch (IOException ioe) {
            log.error("Error opening Key store : " + location, ioe);
            throw new AxisFault("Error opening Key store : " + location, ioe);
        }
    }

    try {
        SSLContext sslcontext = SSLContext.getInstance("TLS");
        sslcontext.init(keymanagers, trustManagers, null);
        return sslcontext;

    } catch (GeneralSecurityException gse) {
        log.error("Unable to create SSL context with the given configuration", gse);
        throw new AxisFault("Unable to create SSL context with the given configuration", gse);
    }
}

From source file:com.microfocus.application.automation.tools.octane.tests.TestResultIterator.java

@Override
public boolean hasNext() {
    try {//w w  w.  j av a2  s . c o m
        while (items.isEmpty() && !closed) {
            if (reader.hasNext()) {
                XMLEvent event = reader.nextEvent();
                if (event instanceof StartElement) {
                    Attribute attribute;
                    StartElement element = (StartElement) event;
                    String localName = element.getName().getLocalPart();
                    if ("test_run".equals(localName)) {
                        String moduleName = element.getAttributeByName(new QName("module")).getValue();
                        String packageName = element.getAttributeByName(new QName("package")).getValue();
                        String className = element.getAttributeByName(new QName("class")).getValue();
                        String testName = element.getAttributeByName(new QName("name")).getValue();
                        long duration = Long
                                .valueOf(element.getAttributeByName(new QName("duration")).getValue());
                        TestResultStatus status = TestResultStatus
                                .fromPrettyName(element.getAttributeByName(new QName("status")).getValue());
                        long started = Long
                                .valueOf(element.getAttributeByName(new QName("started")).getValue());
                        items.add(new JUnitTestResult(moduleName, packageName, className, testName, status,
                                duration, started, null, null));
                    } else if ("build".equals(localName)) {
                        attribute = element.getAttributeByName(new QName("server_id"));
                        if (attribute != null) {
                            serverId = attribute.getValue();
                        }
                        attribute = element.getAttributeByName(new QName("job_id"));
                        if (attribute != null) {
                            jobId = attribute.getValue();
                        }
                        attribute = element.getAttributeByName(new QName("build_id"));
                        if (attribute != null) {
                            buildId = attribute.getValue();
                        }
                        attribute = element.getAttributeByName(new QName("sub_type"));
                        if (attribute != null) {
                            this.subType = attribute.getValue();
                        }
                    }
                }
            } else {
                closed = true;
                IOUtils.closeQuietly(input);
                reader.close();
            }
        }
        return !items.isEmpty();
    } catch (XMLStreamException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.konakart.bl.modules.ordertotal.thomson.HeaderSecrityHandler.java

public boolean handleMessage(SOAPMessageContext smc) {
    Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

    if (outboundProperty.booleanValue()) {
        SOAPMessage message = smc.getMessage();

        if (log.isInfoEnabled()) {
            log.info("Adding Credentials : " + getUName() + "/" + getPWord());
        }/* w ww .jav  a2  s  . c o m*/

        try {
            SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
            envelope.setPrefix("soapenv");
            envelope.getBody().setPrefix("soapenv");

            SOAPHeader header = envelope.addHeader();
            SOAPElement security = header.addChildElement("Security", "wsse",
                    "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");

            SOAPElement usernameToken = security.addChildElement("UsernameToken", "wsse");
            usernameToken.addAttribute(new QName("wsu:Id"), "UsernameToken-1");
            usernameToken.setAttribute("wsu:Id", "UsernameToken-1");

            usernameToken.addAttribute(new QName("xmlns:wsu"),
                    "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");

            SOAPElement username = usernameToken.addChildElement("Username", "wsse");
            username.addTextNode(getUName());

            SOAPElement password = usernameToken.addChildElement("Password", "wsse");
            password.setAttribute("Type",
                    "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
            password.addTextNode(getPWord());

            SOAPElement encodingType = usernameToken.addChildElement("Nonce", "wsse");
            encodingType.setAttribute("EncodingType",
                    "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
            encodingType.addTextNode("Encoding");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return outboundProperty;
}

From source file:org.apache.servicemix.jms.JmsConsumerEndpointTest.java

protected void setUp() throws Exception {
    super.setUp();

    ReceiverComponent rec = new ReceiverComponent();
    rec.setService(new QName("receiver"));
    rec.setEndpoint("endpoint");
    container.activateComponent(rec, "receiver");
    receiver = rec;//from  w  w w.j a  v  a  2s. c  o m

    EchoComponent echo = new EchoComponent();
    echo.setService(new QName("echo"));
    echo.setEndpoint("endpoint");
    container.activateComponent(echo, "echo");

    // initialize the black list
    blackList = new LinkedList<String>();
    blackList.add(MSG_PROPERTY_BLACKLISTED);
}

From source file:com.evolveum.midpoint.wf.impl.util.SingleItemSerializationSafeContainerImpl.java

@Override
public void setValue(T value) {
    this.actualValue = value;

    checkPrismContext();//from   w  ww.  j  a v  a 2  s.  c  o m
    if (value != null && prismContext.canSerialize(value)) {
        try {
            this.valueForStorageWhenEncoded = prismContext.serializeAnyData(value, new QName("value"),
                    PrismContext.LANG_XML);
        } catch (SchemaException e) {
            throw new SystemException(
                    "Couldn't serialize value of type " + value.getClass() + ": " + e.getMessage(), e);
        }
        this.valueForStorageWhenNotEncoded = null;
        encodingScheme = EncodingScheme.PRISM;
    } else if (value == null || value instanceof Serializable) {
        this.valueForStorageWhenNotEncoded = value;
        this.valueForStorageWhenEncoded = null;
        encodingScheme = EncodingScheme.NONE;
        if (value instanceof Itemable) {
            throw new IllegalStateException(
                    "Itemable value is used as not-encoded serializable item; value = " + value);
        }
    } else {
        throw new IllegalStateException("Attempt to put non-serializable item " + value.getClass() + " into "
                + this.getClass().getSimpleName());
    }
}

From source file:com.evolveum.midpoint.wf.impl.util.SerializationSafeContainer.java

public void setValue(T value) {
    this.actualValue = value;

    checkPrismContext();//from  w w w  .j ava 2  s  .  co m
    if (value != null && prismContext.canSerialize(value)) {
        try {
            this.valueForStorageWhenEncoded = prismContext.serializeAnyData(value, new QName("value"),
                    PrismContext.LANG_XML);
        } catch (SchemaException e) {
            throw new SystemException(
                    "Couldn't serialize value of type " + value.getClass() + ": " + e.getMessage(), e);
        }
        this.valueForStorageWhenNotEncoded = null;
        encodingScheme = EncodingScheme.PRISM;
    } else if (value == null || value instanceof Serializable) {
        this.valueForStorageWhenNotEncoded = value;
        this.valueForStorageWhenEncoded = null;
        encodingScheme = EncodingScheme.NONE;
        if (value instanceof Itemable) {
            throw new IllegalStateException(
                    "Itemable value is used as not-encoded serializable item; value = " + value);
        }
    } else {
        throw new IllegalStateException("Attempt to put non-serializable item " + value.getClass() + " into "
                + this.getClass().getSimpleName());
    }
}

From source file:com.marklogic.client.test.KeyValueSearchTest.java

@Test(expected = FailedRequestException.class)
public void testKVSearchBadNamespacePrefix() throws IOException {
    QueryManager queryMgr = Common.client.newQueryManager();
    KeyValueQueryDefinition qdef = queryMgr.newKeyValueDefinition(null);

    qdef.put(queryMgr.newElementLocator(new QName("badprefix:leaf")), "leaf3");
    @SuppressWarnings("unused")
    SearchHandle results = queryMgr.search(qdef, new SearchHandle());
    fail("Test should have thrown a Failed Request with bad prefix");
}

From source file:de.tudarmstadt.ukp.integration.alignment.xml.AlignmentXmlWriter.java

public void writeAlignments(Alignments alignments) throws IOException {
    try {//w  ww  .j a v  a  2  s. c  o m
        marshaller.marshal(new JAXBElement<Alignments>(new QName("alignments"), Alignments.class, alignments),
                xmlEventWriter);
    } catch (JAXBException e) {
        throw new IOException(e);
    }

}

From source file:com.vangent.hieos.services.xds.bridge.support.XDSBridgeConfigXmlParser.java

/**
 * Method description/*from  w ww  . jav  a 2 s. c om*/
 *
 *
 *
 * @param name
 * @param parserConfigElem
 *
 * @return
 */
private ContentParserConfig parseContentConfig(String name, OMElement parserConfigElem) {

    // pull template or use default
    String templateFilename = parserConfigElem.getAttributeValue(new QName("template"));
    if (StringUtils.isBlank(templateFilename)) {
        templateFilename = this.defaultTemplate;
    }

    OMElement namespacesElem = parserConfigElem.getFirstChildWithName(new QName("Namespaces"));
    Map<String, String> namespaces = null;

    if (namespacesElem != null) {

        // pull namespaces
        namespaces = parseNameValuePairs(namespacesElem, "Namespace", "prefix", "uri", false);
    }

    OMElement dynamicElem = parserConfigElem.getFirstChildWithName(new QName("DocumentContentVariables"));
    Map<String, String> expressions = null;

    if (dynamicElem != null) {

        // pull expressions
        expressions = parseNameValuePairs(dynamicElem, "Variable", "name", "expression", true);
    }

    OMElement staticElem = parserConfigElem.getFirstChildWithName(new QName("StaticContentVariables"));
    Map<String, Map<String, String>> staticValues = null;

    if (staticElem != null) {

        // pull static groups
        staticValues = parseStaticGroups(staticElem);

        // pull static values
        Map<String, String> staticVariables = parseNameValuePairs(staticElem, "Variable", "name", "value",
                true);

        for (Map.Entry<String, String> entry : staticVariables.entrySet()) {

            Map<String, String> value = new HashMap<String, String>();

            value.put(entry.getKey(), entry.getValue());
            staticValues.put(entry.getKey(), value);
        }
    }

    OMElement contentConversionsElem = parserConfigElem.getFirstChildWithName(new QName("ContentConversions"));
    Map<String, String> contentConversions = null;

    if (contentConversionsElem != null) {

        // pull expressions
        contentConversions = parseNameValuePairs(contentConversionsElem, "Variable", "name", "converter", true);
    }

    return new ContentParserConfig(name, namespaces, expressions, staticValues, contentConversions,
            templateFilename);
}