Example usage for javax.xml.namespace QName getLocalPart

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

Introduction

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

Prototype

public String getLocalPart() 

Source Link

Document

Get the local part of this QName.

Usage

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

private XName buildVariableName(QName name) {
    return new XName(name.getNamespaceURI(), name.getLocalPart());
}

From source file:com.evolveum.midpoint.model.impl.validator.ResourceValidatorImpl.java

private void registerName(ResourceValidationContext ctx, Set<QName> existingNames, Set<QName> duplicates,
        ItemPathType ref) {//from  w  w w.  ja va2  s .  c  om
    QName name = itemRefToName(ref);
    if (name != null) {
        if (name.getNamespaceURI() == null) {
            name = new QName(ResourceTypeUtil.getResourceNamespace(ctx.resourceObject), name.getLocalPart()); // TODO is this correct?
        }
        if (!existingNames.add(name)) {
            duplicates.add(name);
        }
    }
}

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

@NotNull
@Override/* ww  w .ja  v  a2 s  .c  om*/
@SuppressWarnings("unchecked")
public <ID extends ItemDefinition> List<ID> findItemDefinitionsByElementName(@NotNull QName elementName,
        @NotNull Class<ID> definitionClass) {
    List<Definition> matching = new ArrayList<>();
    CollectionUtils.addIgnoreNull(matching, itemDefinitionMap.get(elementName));
    if (QNameUtil.hasNamespace(elementName)) {
        CollectionUtils.addIgnoreNull(matching, itemDefinitionMap.get(QNameUtil.unqualify(elementName)));
    } else if (namespace != null) {
        CollectionUtils.addIgnoreNull(matching,
                itemDefinitionMap.get(new QName(namespace, elementName.getLocalPart())));
    }
    return matching.stream().filter(d -> definitionClass.isAssignableFrom(d.getClass())).map(d -> (ID) d)
            .collect(Collectors.toList());
}

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

/**
 * Adds XSD element definition.//from w w  w.  j  a v  a  2  s. co m
 * @param name element QName
 * @param typeName element type QName
 * @param parent element under which the definition will be added
 */
private Element addElementDefinition(QName name, QName typeName, int minOccurs, int maxOccurs, Element parent) {
    Element elementDef = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "element"));
    parent.appendChild(elementDef);

    if (isMyNamespace(name)) {
        setAttribute(elementDef, "name", name.getLocalPart());

        if (typeName.equals(DOMUtil.XSD_ANY)) {
            addSequenceXsdAnyDefinition(elementDef);
        } else {
            setQNameAttribute(elementDef, "type", typeName);
        }
    } else {
        // Need to create "ref" instead of "name"
        setAttribute(elementDef, "ref", name);
        if (typeName != null) {
            // Type cannot be stored directly, XSD does not allow it with "ref"s.
            addAnnotationToDefinition(elementDef, A_TYPE, typeName);
        }
    }

    setMultiplicityAttribute(elementDef, "minOccurs", minOccurs);
    setMultiplicityAttribute(elementDef, "maxOccurs", maxOccurs);

    return elementDef;
}

From source file:com.evolveum.midpoint.prism.lex.json.AbstractJsonLexicalProcessor.java

private String createKeyUri(Entry<QName, XNode> entry, JsonSerializationContext ctx) {
    QName key = entry.getKey();
    if (namespaceMatch(ctx.currentNamespace, key.getNamespaceURI())) {
        return key.getLocalPart();
    } else if (StringUtils.isNotEmpty(ctx.currentNamespace) && !isAttribute(entry.getValue())) {
        return QNameUtil.qNameToUri(key, true); // items with no namespace should be written as such (starting with '#')
    } else {//from   ww  w.  j a v a 2s.co  m
        return QNameUtil.qNameToUri(key, false); // items with no namespace can be written in plain
    }
}

From source file:com.streamsets.pipeline.lib.xml.StreamingXmlParser.java

private String getNameAndTrackNs(QName name) {
    final String uri = name.getNamespaceURI();
    if (!Strings.isNullOrEmpty(uri)) {
        String prefix;//from w w w. java  2s .  c  o  m
        if (!namespaceUriToPrefix.containsKey(uri)) {
            prefix = name.getPrefix();
            if (Strings.isNullOrEmpty(prefix)) {
                //generate a new namespace prefix for it
                prefix = GENERATED_NAMESPACE_PREFIX + generatedNsPrefixCount++;
            } //else the element already came with a prefix, so just use that
            namespaceUriToPrefix.put(uri, prefix);
        } else {
            prefix = namespaceUriToPrefix.get(uri);
        }
        return prefix + ":" + name.getLocalPart();
    } else {
        // element is in no namespace
        return name.getLocalPart();
    }
}

From source file:de.uzk.hki.da.model.ObjectPremisXmlWriter.java

/**
 * Integrate jhove data./*w  ww . j av  a2s  . c om*/
 *
 * @param jhoveFilePath the jhove file path
 * @param tab the tab
 * @throws XMLStreamException the xML stream exception
 * @author Thomas Kleinke
 * @throws FileNotFoundException 
 */
private void integrateJhoveData(String jhoveFilePath, int tab)
        throws XMLStreamException, FileNotFoundException {
    File jhoveFile = new File(jhoveFilePath);
    if (!jhoveFile.exists())
        throw new FileNotFoundException("file does not exist. " + jhoveFile);

    FileInputStream inputStream = null;

    inputStream = new FileInputStream(jhoveFile);

    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLStreamReader streamReader = inputFactory.createXMLStreamReader(inputStream);

    boolean textElement = false;

    while (streamReader.hasNext()) {
        int event = streamReader.next();

        switch (event) {

        case XMLStreamConstants.START_ELEMENT:
            writer.writeDTD("\n");
            indent(tab);
            tab++;

            String prefix = streamReader.getPrefix();

            if (prefix != null && !prefix.equals("")) {
                writer.setPrefix(prefix, streamReader.getNamespaceURI());
                writer.writeStartElement(streamReader.getNamespaceURI(), streamReader.getLocalName());
            } else
                writer.writeStartElement(streamReader.getLocalName());

            for (int i = 0; i < streamReader.getNamespaceCount(); i++)
                writer.writeNamespace(streamReader.getNamespacePrefix(i), streamReader.getNamespaceURI(i));

            for (int i = 0; i < streamReader.getAttributeCount(); i++) {
                QName qname = streamReader.getAttributeName(i);
                String attributeName = qname.getLocalPart();
                String attributePrefix = qname.getPrefix();
                if (attributePrefix != null && !attributePrefix.equals(""))
                    attributeName = attributePrefix + ":" + attributeName;

                writer.writeAttribute(attributeName, streamReader.getAttributeValue(i));
            }

            break;

        case XMLStreamConstants.CHARACTERS:
            if (!streamReader.isWhiteSpace()) {
                writer.writeCharacters(streamReader.getText());
                textElement = true;
            }
            break;

        case XMLStreamConstants.END_ELEMENT:
            tab--;

            if (!textElement) {
                writer.writeDTD("\n");
                indent(tab);
            }

            writer.writeEndElement();
            textElement = false;
            break;

        default:
            break;
        }
    }

    streamReader.close();
    try {
        inputStream.close();
    } catch (IOException e) {
        throw new RuntimeException("Failed to close input stream", e);
    }
}

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");
    }/*  w  ww.  j  a v  a  2s  .  co m*/
    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);
    }
}

From source file:com.evolveum.midpoint.prism.lex.json.AbstractJsonLexicalProcessor.java

private String createElementNameUri(QName elementName, JsonSerializationContext ctx) {
    if (namespaceMatch(ctx.currentNamespace, elementName.getNamespaceURI())) {
        return elementName.getLocalPart();
    } else {//  w  w w .j  ava  2 s. c o m
        return QNameUtil.qNameToUri(elementName, StringUtils.isNotEmpty(ctx.currentNamespace));
    }
}

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

public static void validateNonEmptyQName(QName qname, String shortDescription, boolean allowEmptyNamespace) {
    if (qname == null) {
        throw new IllegalArgumentException("null" + shortDescription);
    }//from  ww  w .j ava 2  s. c  o  m
    // This is hard to enforce. There are situations where unmarshalling
    // object reference types as ObjectReferenceType, not as prism references.
    // (E.g. when dealing with reference variables in mappigns/expressions.)
    // In these cases we need to qualify types after the unmarshalling is complete.
    if (!allowEmptyNamespace && StringUtils.isEmpty(qname.getNamespaceURI())) {
        throw new IllegalArgumentException("Missing namespace" + shortDescription);
    }
    if (StringUtils.isEmpty(qname.getLocalPart())) {
        throw new IllegalArgumentException("Missing local part" + shortDescription);
    }
}