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:iristk.flow.FlowCompiler.java

private Map<String, String> getParameters(Map<QName, String> attributes, List<Object> content, Object parent)
        throws FlowCompilerException {
    Map<String, String> result = new HashMap<String, String>();
    for (QName attr : attributes.keySet()) {
        if (attr.getNamespaceURI() != null && attr.getNamespaceURI().equals("http://www.w3.org/2000/xmlns/"))
            continue;
        String name = attr.getLocalPart();
        String value = formatAttrExpr(attributes.get(attr));
        result.put(name, value);//w  ww . j  av  a 2  s .c  om
    }
    if (content.size() > 0) {
        ListMap<String, String> paramList = new ListMap<>();
        for (Object child : content) {
            if (child instanceof Element) {
                Element elem = (Element) child;
                if (elem.getNamespaceURI().equals("iristk.flow.param")) {
                    String key = elem.getLocalName();
                    List<Object> paramChildren = new ArrayList<Object>();
                    for (int j = 0; j < elem.getChildNodes().getLength(); j++) {
                        paramChildren.add(elem.getChildNodes().item(j));
                    }
                    String text = createExpression(paramChildren, elem);
                    paramList.add(key, text);
                }
            }
        }
        if (paramList.size() == 0) {
            paramList.add("text", createExpression(content, parent));
        }
        for (String key : paramList.keySet()) {
            if (paramList.get(key).size() > 1) {
                result.put(key, "java.util.Arrays.asList(" + listToString(paramList.get(key)) + ")");
            } else {
                result.put(key, paramList.get(key).get(0));
            }
        }
    }
    return result;
}

From source file:com.nortal.jroad.typegen.xmlbeans.XteeSchemaCodePrinter.java

static String prettyQName(QName qname) {
    String result = qname.getLocalPart();
    if (qname.getNamespaceURI() != null)
        result += "(@" + qname.getNamespaceURI() + ")";
    return result;
}

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

private <C extends Containerable> PrismContainerValue<C> parseContainerValueFromMap(@NotNull MapXNode map,
        @NotNull PrismContainerDefinition<C> containerDef, @NotNull ParsingContext pc) throws SchemaException {
    Long id = getContainerId(map);

    ComplexTypeDefinition complexTypeDefinition = containerDef.getComplexTypeDefinition();

    PrismContainerValue<C> cval;/*w  w w .  j av  a 2s.  c  o  m*/
    if (containerDef instanceof PrismObjectDefinition) {
        cval = ((PrismObjectDefinition) containerDef).createValue();
    } else {
        // override container definition, if explicit type is specified
        if (map.getTypeQName() != null) {
            ComplexTypeDefinition specificDef = getSchemaRegistry()
                    .findComplexTypeDefinitionByType(map.getTypeQName());
            if (specificDef != null) {
                complexTypeDefinition = specificDef;
            } else {
                pc.warnOrThrow(LOGGER, "Unknown type " + map.getTypeQName() + " in " + map);
            }
        }
        cval = new PrismContainerValue<>(null, null, null, id, complexTypeDefinition, prismContext);
    }
    for (Entry<QName, XNode> entry : map.entrySet()) {
        QName itemName = entry.getKey();
        if (itemName == null) {
            throw new IllegalArgumentException("Null item name while parsing " + map.debugDump());
        }
        if (QNameUtil.match(itemName, XNode.KEY_CONTAINER_ID)) {
            continue;
        }
        if (containerDef instanceof PrismObjectDefinition
                && (QNameUtil.match(itemName, XNode.KEY_OID) || QNameUtil.match(itemName, XNode.KEY_VERSION))) {
            continue;
        }
        ItemDefinition itemDef = locateItemDefinition(itemName, complexTypeDefinition, entry.getValue());

        if (itemDef == null) {
            if (complexTypeDefinition == null || complexTypeDefinition.isXsdAnyMarker()
                    || complexTypeDefinition.isRuntimeSchema()) {
                PrismSchema itemSchema = getSchemaRegistry().findSchemaByNamespace(itemName.getNamespaceURI());
                if (itemSchema != null) {
                    // If we already have schema for this namespace then a missing element is
                    // an error. We positively know that it is not in the schema.
                    pc.warnOrThrow(LOGGER,
                            "Item " + itemName + " has no definition (schema present, in container "
                                    + containerDef + ")" + "while parsing " + map.debugDump());
                    // we can go along this item (at least show it in repository pages) - MID-3249
                    // TODO make this configurable
                } else {
                    // No definition for item, but the schema is runtime. the definition may come later.
                    // Null is OK here. The item will be parsed as "raw"
                }
            } else { // complex type definition is static
                pc.warnOrThrow(LOGGER, "Item " + itemName + " has no definition (in container value "
                        + complexTypeDefinition + ")" + "while parsing " + map.debugDump());
                continue; // don't even attempt to parse it
            }
        }
        Item<?, ?> item;
        if (entry.getValue() == null) {
            if (itemDef != null) {
                item = itemDef.instantiate(); // TODO or skip the creation altogether?
            } else {
                item = null;
            }
        } else {
            item = parseItemInternal(entry.getValue(), itemName, itemDef, pc);
        }
        // Merge must be here, not just add. Some items (e.g. references) have alternative
        // names and representations and these cannot be processed as one map or list
        if (item != null) {
            cval.merge(item);
        }
    }
    return cval;
}

From source file:com.evolveum.midpoint.prism.schema.SchemaRegistryImpl.java

@Override
public ItemDefinition findItemDefinitionByElementName(QName elementName,
        @Nullable List<String> ignoredNamespaces) {
    if (StringUtils.isEmpty(elementName.getNamespaceURI())) {
        return resolveGlobalItemDefinitionWithoutNamespace(elementName.getLocalPart(), ItemDefinition.class,
                true, ignoredNamespaces);
    }//  www .  j a  v a  2 s  .  c o  m
    PrismSchema schema = findSchemaByNamespace(elementName.getNamespaceURI());
    if (schema == null) {
        return null;
    }
    return schema.findItemDefinitionByElementName(elementName, ItemDefinition.class);
}

From source file:com.evolveum.midpoint.prism.parser.XNodeProcessor.java

public PrismReferenceValue parseReferenceValue(MapXNode xmap, PrismReferenceDefinition referenceDefinition)
        throws SchemaException {
    String oid = xmap.getParsedPrimitiveValue(XNode.KEY_REFERENCE_OID, DOMUtil.XSD_STRING);
    PrismReferenceValue refVal = new PrismReferenceValue(oid);

    QName type = xmap.getParsedPrimitiveValue(XNode.KEY_REFERENCE_TYPE, DOMUtil.XSD_QNAME);
    if (type == null) {
        type = referenceDefinition.getTargetTypeName();
        if (type == null) {
            throw new SchemaException("Target type specified neither in reference nor in the schema");
        }/* w  w  w.jav  a 2 s  .co  m*/
    } else {
        if (StringUtils.isBlank(type.getNamespaceURI())) {
            // resolve type without namespace (only when prismContext is known)
            if (prismContext == null) {
                throw new SchemaException(
                        "Couldn't parse unqualified type name '" + type + "' without prismContext");
            }
            type = prismContext.getSchemaRegistry().resolveUnqualifiedTypeName(type);
        }

        QName defTargetType = referenceDefinition.getTargetTypeName();

        if (defTargetType != null && !QNameUtil.match(defTargetType, type)) {
            //one more check - if the type is not a subtype of the schema type
            Class clazz = qnameToClass(type);
            if (clazz == null) {
                throw new SchemaException("Unknown target type: " + type);
            }
            if (!qnameToClass(defTargetType).isAssignableFrom(clazz)) {
                throw new SchemaException("Target type specified in reference (" + type
                        + ") does not match target type in schema (" + defTargetType + ")");
            }
        }
    }

    PrismObjectDefinition<Objectable> objectDefinition = getSchemaRegistry().findObjectDefinitionByType(type);
    if (objectDefinition == null) {
        throw new SchemaException("No definition for type " + type + " in reference");
    }
    refVal.setTargetType(type);

    QName relationAttribute = xmap.getParsedPrimitiveValue(XNode.KEY_REFERENCE_RELATION, DOMUtil.XSD_QNAME);
    refVal.setRelation(relationAttribute);

    refVal.setDescription(
            (String) xmap.getParsedPrimitiveValue(XNode.KEY_REFERENCE_DESCRIPTION, DOMUtil.XSD_STRING));

    refVal.setFilter(parseFilter(xmap.get(XNode.KEY_REFERENCE_FILTER)));

    XNode xnodeForTargetName = xmap.get(XNode.KEY_REFERENCE_TARGET_NAME);
    if (xnodeForTargetName != null) {
        Class targetNameClass = PolyStringType.class;
        if (xnodeForTargetName instanceof PrimitiveXNode
                && ((PrimitiveXNode) xnodeForTargetName).getValue() instanceof PolyString) {
            targetNameClass = PolyString.class; // targetName in audit report comes as PolyString
        }
        Object o = getBeanConverter().unmarshall(xnodeForTargetName, targetNameClass);
        // working around polystring-related type mess in unmarshaller
        if (o instanceof PolyString) {
            refVal.setTargetName((PolyString) o);
        } else if (o instanceof PolyStringType) {
            refVal.setTargetName((PolyStringType) o);
        } else {
            throw new IllegalStateException("targetName is not a polystring, it's a " + o.getClass().getName());
        }
    }

    XNode xrefObject = xmap.get(XNode.KEY_REFERENCE_OBJECT);
    if (xrefObject != null) {
        if (!(xrefObject instanceof MapXNode)) {
            throw new SchemaException("Cannot parse object from " + xrefObject);
        }
        PrismObject<Objectable> object = parseObject((MapXNode) xrefObject, objectDefinition);
        setReferenceObject(refVal, object);
    }

    return refVal;
}

From source file:com.stratumsoft.xmlgen.SchemaTypeXmlGenerator.java

private Element createDomElemFromSchemaElem(XmlSchemaElement schEl) {
    Element el = null;//from w  ww .ja va  2s.  co m
    if (schEl != null) {
        QName elName = schEl.getQName();

        //get the value from the schema
        XmlSchema sch = getSchemaForElement(elName);

        //get the element form value
        XmlSchemaForm form;

        if (sch == null) {
            //not a global element 
            form = schEl.getForm();
            if (form == XmlSchemaForm.NONE) {
                //get the default elem form value from the schema
                String nsUri = elName.getNamespaceURI();
                sch = getSchemaByTargetNamespace(nsUri);
                if (sch != null) {
                    form = sch.getElementFormDefault();
                } else {
                    form = XmlSchemaForm.UNQUALIFIED;
                }
            }
        } else {
            //global elements must be qualified
            form = XmlSchemaForm.QUALIFIED;
        }

        org.dom4j.QName dom4jQName = createDom4jQName(elName, form);

        el = factory.createElement(dom4jQName);

    }
    return el;
}

From source file:eu.eidas.auth.engine.SamlEngine.java

/**
 * Converts an assertion to an attribute map.
 *
 * @param assertion the assertion/*from  w ww. ja v a 2 s. co m*/
 * @return the attribute map
 * @throws EIDASSAMLEngineException the SAML engine exception
 */
@Nonnull
private ImmutableAttributeMap convertToAttributeMap(@Nonnull Assertion assertion)
        throws EIDASSAMLEngineException {
    LOG.trace("Generate personal attribute list from XMLObject.");

    AttributeStatement attributeStatement = findAttributeStatement(assertion);

    List<Attribute> attributes = attributeStatement.getAttributes();

    ImmutableAttributeMap.Builder mapBuilder = ImmutableAttributeMap.builder();

    // Process the attributes.
    for (final Attribute attribute : attributes) {

        String attributeName = attribute.getName();

        String friendlyName = attribute.getFriendlyName();

        AttributeDefinition<?> attributeDefinition = getAttributeDefinitionNotNull(attributeName);

        AttributeValueMarshaller<?> attributeValueMarshaller = attributeDefinition
                .getAttributeValueMarshaller();

        ImmutableSet.Builder<AttributeValue<?>> setBuilder = new ImmutableSet.Builder<>();

        List<XMLObject> values = attribute.getOrderedChildren();

        QName xmlType = attributeDefinition.getXmlType();

        QName latinScript = new QName(xmlType.getNamespaceURI(), "LatinScript", xmlType.getPrefix());

        // Process the values.
        for (XMLObject xmlObject : values) {

            try {
                if (xmlObject instanceof XSStringImpl) {

                    // Process simple value.
                    setBuilder.add(
                            attributeValueMarshaller.unmarshal(((XSStringImpl) xmlObject).getValue(), false));

                } else if (xmlObject instanceof XSAnyImpl) {

                    XSAnyImpl xsAny = (XSAnyImpl) xmlObject;

                    // TODO: move to STORK Extension Processor
                    if ("http://www.stork.gov.eu/1.0/signedDoc".equals(attributeName)) {

                        setBuilder.add(attributeValueMarshaller.unmarshal(computeSimpleValue(xsAny), false));

                        // TODO: move to STORK Extension Processor
                    } else if ("http://www.stork.gov.eu/1.0/canonicalResidenceAddress".equals(attributeName)) {

                        // Process complex value.
                        setBuilder.add(attributeValueMarshaller.unmarshal(computeComplexValue(xsAny).toString(),
                                false));
                    } else {

                        boolean isNonLatinScriptAlternateVersion = false;
                        String latinScriptAttrValue = xsAny.getUnknownAttributes().get(latinScript);
                        if (StringUtils.isNotBlank(latinScriptAttrValue)
                                && "false".equals(latinScriptAttrValue)) {
                            isNonLatinScriptAlternateVersion = true;
                        }

                        // Process simple value.
                        setBuilder.add(attributeValueMarshaller.unmarshal(xsAny.getTextContent(),
                                isNonLatinScriptAlternateVersion));
                    }

                    // TODO: remove
                } else if (xmlObject instanceof GenericEidasAttributeType) {

                    // Process simple value.
                    setBuilder.add(attributeValueMarshaller
                            .unmarshal(((GenericEidasAttributeType) xmlObject).getValue(), false));

                } else {
                    LOG.info(
                            "BUSINESS EXCEPTION : attribute value is unknown in generatePersonalAttributeList.");
                    throw new EIDASSAMLEngineException(EidasErrorKey.INTERNAL_ERROR.errorCode(),
                            EidasErrorKey.INTERNAL_ERROR.errorCode(),
                            "Attribute value is unknown for \""
                                    + attributeDefinition.getNameUri().toASCIIString() + "\" - value: \""
                                    + xmlObject + "\"");
                }
            } catch (AttributeValueMarshallingException e) {
                LOG.error("BUSINESS EXCEPTION : Illegal Attribute Value: " + e, e);
                throw new EIDASSAMLEngineException(EidasErrorKey.INTERNAL_ERROR.errorCode(),
                        EidasErrorKey.INTERNAL_ERROR.errorCode(), e);
            }
        }

        // Check if friendlyName matches when provided  - TODO Temorary removed due to validator failure
        /*            if (StringUtils.isNotEmpty(friendlyName) &&
            attributeDefinition != null &&
            !friendlyName.equals(attributeDefinition.getFriendlyName())) {
        LOG.error("BUSINESS EXCEPTION : Illegal Attribute friendlyName for " + attributeDefinition.getNameUri().toString() +
                " expected " +  attributeDefinition.getFriendlyName() + " got " + friendlyName);
        throw new EIDASSAMLEngineException(EidasErrorKey.INTERNAL_ERROR.errorCode(),
                EidasErrorKey.INTERNAL_ERROR.errorCode(), "Illegal Attribute friendlyName for " + attributeDefinition.getNameUri().toString() +
                " expected " +  attributeDefinition.getFriendlyName() + " got " + friendlyName);
                    }*/

        mapBuilder.put((AttributeDefinition) attributeDefinition, (ImmutableSet) setBuilder.build());
    }

    return mapBuilder.build();
}

From source file:com.evolveum.midpoint.prism.schema.SchemaRegistryImpl.java

@Nullable
@Override//  w ww  . j av a2 s  . c  o m
public <TD extends TypeDefinition> TD findTypeDefinitionByType(@NotNull QName typeName,
        @NotNull Class<TD> definitionClass) {
    if (QNameUtil.noNamespace(typeName)) {
        return resolveGlobalTypeDefinitionWithoutNamespace(typeName.getLocalPart(), definitionClass);
    }
    PrismSchema schema = findSchemaByNamespace(typeName.getNamespaceURI());
    if (schema == null) {
        return null;
    }
    return schema.findTypeDefinitionByType(typeName, definitionClass);
}

From source file:com.evolveum.midpoint.prism.schema.SchemaRegistryImpl.java

@NotNull
@Override//w w  w . ja v a 2s  .  co m
public <TD extends TypeDefinition> Collection<? extends TD> findTypeDefinitionsByType(@NotNull QName typeName,
        @NotNull Class<TD> definitionClass) {
    if (QNameUtil.noNamespace(typeName)) {
        return resolveGlobalTypeDefinitionsWithoutNamespace(typeName.getLocalPart(), definitionClass);
    }
    PrismSchema schema = findSchemaByNamespace(typeName.getNamespaceURI());
    if (schema == null) {
        return Collections.emptyList();
    }
    return schema.findTypeDefinitionsByType(typeName, definitionClass);
}

From source file:eu.eidas.auth.engine.core.stork.StorkExtensionProcessor.java

/**
 * Converts an assertion to an attribute map.
 *
 * @param assertion the assertion//from  w w w .j a va  2  s  .  co  m
 * @return the attribute map
 * @throws EIDASSAMLEngineException the SAML engine exception
 */
@Nonnull
private ImmutableAttributeMap convertToAttributeMap(@Nonnull Assertion assertion)
        throws EIDASSAMLEngineException {
    LOG.trace("Generate personal attribute list from XMLObject.");

    AttributeStatement attributeStatement = ResponseUtil.findAttributeStatement(assertion);

    List<Attribute> attributes = attributeStatement.getAttributes();

    ImmutableAttributeMap.Builder mapBuilder = ImmutableAttributeMap.builder();

    // Process the attributes.
    for (final Attribute attribute : attributes) {
        String attributeName = attribute.getName();

        AttributeDefinition<?> attributeDefinition = getAttributeDefinitionNotNull(attributeName);

        AttributeValueMarshaller<?> attributeValueMarshaller = attributeDefinition
                .getAttributeValueMarshaller();

        ImmutableSet.Builder<eu.eidas.auth.commons.attribute.AttributeValue<?>> setBuilder = new ImmutableSet.Builder<>();

        List<XMLObject> values = attribute.getOrderedChildren();

        QName xmlType = attributeDefinition.getXmlType();

        QName latinScript = new QName(xmlType.getNamespaceURI(), "LatinScript", xmlType.getPrefix());

        // Process the values.
        for (XMLObject xmlObject : values) {
            try {
                if (xmlObject instanceof XSStringImpl) {
                    // Process simple value.
                    setBuilder.add(
                            attributeValueMarshaller.unmarshal(((XSStringImpl) xmlObject).getValue(), false));
                } else if (xmlObject instanceof XSAnyImpl) {
                    XSAnyImpl xsAny = (XSAnyImpl) xmlObject;

                    // TODO: move to STORK Extension Processor
                    if ("http://www.stork.gov.eu/1.0/signedDoc".equals(attributeName)) {
                        setBuilder.add(attributeValueMarshaller.unmarshal(computeSimpleValue(xsAny), false));

                        // TODO: move to STORK Extension Processor
                    } else if ("http://www.stork.gov.eu/1.0/canonicalResidenceAddress".equals(attributeName)) {
                        // Process complex value.
                        setBuilder.add(attributeValueMarshaller.unmarshal(computeComplexValue(xsAny).toString(),
                                false));
                    } else {
                        boolean isNonLatinScriptAlternateVersion = false;
                        String latinScriptAttrValue = xsAny.getUnknownAttributes().get(latinScript);
                        if (StringUtils.isNotBlank(latinScriptAttrValue)
                                && "false".equals(latinScriptAttrValue)) {
                            isNonLatinScriptAlternateVersion = true;
                        }

                        // Process simple value.
                        setBuilder.add(attributeValueMarshaller.unmarshal(xsAny.getTextContent(),
                                isNonLatinScriptAlternateVersion));
                    }

                    // TODO: remove
                } else if (xmlObject instanceof GenericEidasAttributeType) {
                    // Process simple value.
                    setBuilder.add(attributeValueMarshaller
                            .unmarshal(((GenericEidasAttributeType) xmlObject).getValue(), false));
                } else {
                    LOG.info(
                            "BUSINESS EXCEPTION : attribute value is unknown in generatePersonalAttributeList.");
                    throw new EIDASSAMLEngineException(EidasErrorKey.INTERNAL_ERROR.errorCode(),
                            EidasErrorKey.INTERNAL_ERROR.errorCode(),
                            "Attribute value is unknown for \""
                                    + attributeDefinition.getNameUri().toASCIIString() + "\" - value: \""
                                    + xmlObject + "\"");
                }
            } catch (AttributeValueMarshallingException e) {
                LOG.error("BUSINESS EXCEPTION : Illegal Attribute Value: " + e, e);
                throw new EIDASSAMLEngineException(EidasErrorKey.INTERNAL_ERROR.errorCode(),
                        EidasErrorKey.INTERNAL_ERROR.errorCode(), e);
            }
        }

        mapBuilder.put((AttributeDefinition) attributeDefinition, (ImmutableSet) setBuilder.build());
    }

    return mapBuilder.build();
}