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(final String namespaceURI, final String localPart) 

Source Link

Document

QName constructor specifying the Namespace URI and local part.

If the Namespace URI is null, it is set to javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI .

Usage

From source file:edu.internet2.middleware.shibboleth.common.config.attribute.resolver.attributeDefinition.BaseAttributeDefinitionBeanDefinitionParser.java

/** {@inheritDoc} */
protected void doParse(String pluginId, Element pluginConfig, Map<QName, List<Element>> pluginConfigChildren,
        BeanDefinitionBuilder pluginBuilder, ParserContext parserContext) {

    String sourceAttributeId = pluginConfig.getAttributeNS(null, "sourceAttributeID");
    log.debug("Setting source attribute ID for attribute definition {} to: {}", pluginId, sourceAttributeId);
    pluginBuilder.addPropertyValue("sourceAttributeId", sourceAttributeId);

    List<Element> displayNames = pluginConfigChildren
            .get(new QName(AttributeResolverNamespaceHandler.NAMESPACE, "DisplayName"));
    if (displayNames != null) {
        log.debug("Setting {} display names for attribute definition {}", displayNames.size(), pluginId);
        pluginBuilder.addPropertyValue("displayNames", processLocalizedElement(displayNames));
    }//w ww . j a  v  a 2  s. c o  m

    List<Element> displayDescriptions = pluginConfigChildren
            .get(new QName(AttributeResolverNamespaceHandler.NAMESPACE, "DisplayDescription"));
    if (displayDescriptions != null) {
        log.debug("Setting {} display descriptions for attribute definition {}", displayDescriptions.size(),
                pluginId);
        pluginBuilder.addPropertyValue("displayDescriptions", processLocalizedElement(displayDescriptions));
    }

    boolean dependencyOnly = false;
    if (pluginConfig.hasAttributeNS(null, "dependencyOnly")) {
        dependencyOnly = XMLHelper
                .getAttributeValueAsBoolean(pluginConfig.getAttributeNodeNS(null, "dependencyOnly"));
    }
    if (log.isDebugEnabled()) {
        log.debug("Attribute definition {} produces attributes that are only dependencies: {}", pluginId,
                dependencyOnly);
    }
    pluginBuilder.addPropertyValue("dependencyOnly", dependencyOnly);

    pluginBuilder.addPropertyValue("attributeEncoders", SpringConfigurationUtils
            .parseInnerCustomElements(pluginConfigChildren.get(ATTRIBUTE_ENCODER_ELEMENT_NAME), parserContext));
}

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

public static <T> void parseProtectedType(ProtectedDataType<T> protectedType, MapXNode xmap,
        PrismContext prismContext, ParsingContext pc) throws SchemaException {
    RootXNode xEncryptedData = xmap.getEntryAsRoot(ProtectedDataType.F_ENCRYPTED_DATA);
    if (xEncryptedData != null) {
        if (!(xEncryptedData.getSubnode() instanceof MapXNode)) {
            throw new SchemaException("Cannot parse encryptedData from " + xEncryptedData);
        }/* w  w  w . j  a v a 2s  . c o m*/
        EncryptedDataType encryptedDataType = prismContext.parserFor(xEncryptedData).context(pc)
                .parseRealValue(EncryptedDataType.class);
        protectedType.setEncryptedData(encryptedDataType);
    } else {
        // Check for legacy EncryptedData
        RootXNode xLegacyEncryptedData = xmap.getEntryAsRoot(ProtectedDataType.F_XML_ENC_ENCRYPTED_DATA);
        if (xLegacyEncryptedData != null) {
            if (!(xLegacyEncryptedData.getSubnode() instanceof MapXNode)) {
                throw new SchemaException("Cannot parse EncryptedData from " + xEncryptedData);
            }
            RootXNode xConvertedEncryptedData = (RootXNode) xLegacyEncryptedData.cloneTransformKeys(in -> {
                String elementName = StringUtils.uncapitalize(in.getLocalPart());
                if (elementName.equals("type")) {
                    // this is rubbish, we don't need it, we don't want it
                    return null;
                }
                return new QName(null, elementName);
            });

            EncryptedDataType encryptedDataType = prismContext.parserFor(xConvertedEncryptedData).context(pc)
                    .parseRealValue(EncryptedDataType.class);
            protectedType.setEncryptedData(encryptedDataType);

            if (protectedType instanceof ProtectedStringType) {
                transformEncryptedValue(protectedType, prismContext);
            }
        }
    }
    RootXNode xHashedData = xmap.getEntryAsRoot(ProtectedDataType.F_HASHED_DATA);
    if (xHashedData != null) {
        if (!(xHashedData.getSubnode() instanceof MapXNode)) {
            throw new SchemaException("Cannot parse hashedData from " + xHashedData);
        }
        HashedDataType hashedDataType = prismContext.parserFor(xHashedData).context(pc)
                .parseRealValue(HashedDataType.class);
        protectedType.setHashedData(hashedDataType);
    }
    // protected data empty..check for clear value
    if (protectedType.isEmpty()) {
        XNode xClearValue = xmap.get(ProtectedDataType.F_CLEAR_VALUE);
        if (xClearValue == null) {
            //TODO: try to use common namespace (only to be compatible with previous versions)
            //FIXME maybe add some warning, info...
            xClearValue = xmap.get(new QName(ProtectedDataType.F_CLEAR_VALUE.getLocalPart()));
        }
        if (xClearValue == null) {
            return;
        }
        if (!(xClearValue instanceof PrimitiveXNode)) {
            //this is maybe not good..
            throw new SchemaException("Cannot parse clear value from " + xClearValue);
        }
        // TODO: clearValue
        T clearValue = (T) ((PrimitiveXNode) xClearValue).getParsedValue(DOMUtil.XSD_STRING, String.class);
        protectedType.setClearValue(clearValue);
    }

}

From source file:edu.internet2.middleware.shibboleth.common.config.security.AbstractBasicCredentialBeanDefinitionParser.java

/**
 * Parses the secret key from the credential configuration.
 * //ww w  .j a  v a 2  s .  c  o m
 * @param configChildren children of the credential element
 * @param builder credential build
 */
protected void parseSecretKey(Map<QName, List<Element>> configChildren, BeanDefinitionBuilder builder) {
    List<Element> keyElems = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "SecretKey"));
    if (keyElems == null || keyElems.isEmpty()) {
        return;
    }

    log.debug("Parsing credential secret key");
    Element secretKeyElem = keyElems.get(0);
    byte[] encodedKey = getEncodedSecretKey(
            DatatypeHelper.safeTrimOrNullString(secretKeyElem.getTextContent()));
    String keyPassword = DatatypeHelper.safeTrimOrNullString(secretKeyElem.getAttributeNS(null, "password"));
    try {
        SecretKey key = SecurityHelper.decodeSecretKey(encodedKey, keyPassword.toCharArray());
        builder.addPropertyValue("secretKey", key);
    } catch (KeyException e) {
        throw new FatalBeanException("Unable to create credential, unable to parse secret key", e);
    }
}

From source file:org.javelin.sws.ext.bind.internal.model.ClassHierarchyTest.java

@Test
public void handleXmlAccessTypeNONE() throws Exception {
    // f3, f4, p3, p4 - explicitely annotated
    System.out.println("\nC1");
    JAXBContext.newInstance(C1.class).createMarshaller()
            .marshal(new JAXBElement<C1>(new QName("", "r"), C1.class, new C1()), System.out);
    JAXBContext ctx = SweJaxbContextFactory.createContext(new Class[] { C1.class }, null);
    Map<Class<?>, TypedPattern<?>> patterns = (Map<Class<?>, TypedPattern<?>>) ReflectionTestUtils.getField(ctx,
            "patterns");
    ComplexTypePattern<C1> pattern = (ComplexTypePattern<C1>) patterns.get(C1.class);
    Map<QName, PropertyMetadata<C1, ?>> elements = (Map<QName, PropertyMetadata<C1, ?>>) ReflectionTestUtils
            .getField(pattern, "elements");
    assertThat(elements.size(), equalTo(4));
    assertTrue(elements.containsKey(new QName("", "f3")));
    assertTrue(elements.containsKey(new QName("", "f4")));
    assertTrue(elements.containsKey(new QName("", "p3")));
    assertTrue(elements.containsKey(new QName("", "p4")));
}

From source file:argendata.service.impl.AppServiceImpl.java

@Override
public App getApprovedAppByQName(String qName) {
    QName QN = new QName(properties.getNamespace(), qName);
    Semanticapp mySemanticApp = this.semanticAppDao.getById(QN);
    RelationalApp myRelationalApp = this.relationalAppDao.getRelationalApp(qName);

    return new App(mySemanticApp, myRelationalApp);
}

From source file:com._4dconcept.springframework.data.marklogic.core.mapping.BasicMarklogicPersistentProperty.java

@Override
public QName getQName() {
    String namespaceUri = null;//from ww  w .  j  a  v  a  2  s  .  c  o  m
    String localName = null;

    XmlElement xmlElement = this.findAnnotation(XmlElement.class);
    if (xmlElement != null) {
        if (!xmlElement.namespace().equals("##default")) {
            namespaceUri = xmlElement.namespace();
        }

        localName = xmlElement.name().equals("##default") ? getName() : xmlElement.name();
    }

    if (namespaceUri == null && this.getField() != null) {
        XmlSchema xmlSchema = this.getField().getDeclaringClass().getPackage().getAnnotation(XmlSchema.class);
        if (xmlSchema != null) {
            if (xmlSchema.elementFormDefault().equals(XmlNsForm.QUALIFIED)) {
                namespaceUri = xmlSchema.namespace();
            }
        }
    }

    if (namespaceUri == null)
        namespaceUri = "";
    if (localName == null)
        localName = getName();

    return new QName(namespaceUri, localName);
}

From source file:be.agiv.security.handler.WSAddressingHandler.java

private void handleInboundMessage(SOAPMessageContext context) {
    String messageId = (String) context.get(MESSAGE_ID_CONTEXT_ATTRIBUTE);
    LOG.debug("checking RelatesTo message id: " + messageId);
    Object[] headers = context.getHeaders(new QName(WSConstants.WS_ADDR_NAMESPACE, "RelatesTo"),
            this.jaxbContext, false);
    for (Object headerObject : headers) {
        JAXBElement<RelatesToType> element = (JAXBElement<RelatesToType>) headerObject;
        RelatesToType relatesTo = element.getValue();
        if (false == messageId.equals(relatesTo.getValue())) {
            throw new ProtocolException("incorrect a:RelatesTo value");
        }/*from   ww w .  j  av a  2s  .  c o m*/
    }
}

From source file:com.predic8.membrane.core.interceptor.WSDLInterceptor.java

@Override
protected void rewrite(Exchange exc) throws Exception, IOException {

    log.debug("Changing endpoint address in WSDL");

    ByteArrayOutputStream stream = new ByteArrayOutputStream();

    Relocator relocator = new Relocator(new OutputStreamWriter(stream, exc.getResponse().getCharset()),
            getLocationProtocol(), getLocationHost(exc), getLocationPort(exc), pathRewriter);

    if (rewriteEndpoint) {
        relocator.getRelocatingAttributes().put(new QName(WSDL_SOAP11_NS, "address"), "location");
        relocator.getRelocatingAttributes().put(new QName(WSDL_SOAP12_NS, "address"), "location");
        relocator.getRelocatingAttributes().put(new QName(WSDL_HTTP_NS, "address"), "location");
    }// ww  w  .  ja  v a2  s .c o m
    relocator.getRelocatingAttributes().put(new QName(XSD_NS, "import"), "schemaLocation");
    relocator.getRelocatingAttributes().put(new QName(XSD_NS, "include"), "schemaLocation");

    relocator.relocate(
            new InputStreamReader(exc.getResponse().getBodyAsStreamDecoded(), exc.getResponse().getCharset()));

    if (relocator.isWsdlFound()) {
        registerWSDL(exc);
    }
    exc.getResponse().setBodyContent(stream.toByteArray());
}

From source file:be.fedict.trust.xkms2.WSSecurityServerHandler.java

/**
 * {@inheritDoc}/*from   w  w w. j av a  2  s .c om*/
 */
public Set<QName> getHeaders() {

    Set<QName> headers = new HashSet<QName>();
    headers.add(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
            "Security"));
    return headers;
}

From source file:be.fedict.trust.client.WSSecurityClientHandler.java

public Set<QName> getHeaders() {
    Set<QName> headers = new HashSet<QName>();
    headers.add(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
            "Security"));
    return headers;
}