Example usage for javax.xml XMLConstants NULL_NS_URI

List of usage examples for javax.xml XMLConstants NULL_NS_URI

Introduction

In this page you can find the example usage for javax.xml XMLConstants NULL_NS_URI.

Prototype

String NULL_NS_URI

To view the source code for javax.xml XMLConstants NULL_NS_URI.

Click Source Link

Document

Namespace URI to use to represent that there is no Namespace.

Usage

From source file:eu.esdihumboldt.hale.common.instance.orient.internal.ONamespaceMap.java

/**
 * Determine the original namespace of the given qualified name with a
 * namespace previously mapped with {@link #map(QName)} and return the
 * original name.//from   ww w  .j  a v a 2s  . c  om
 * 
 * @param mapped the adapted qualified name
 * @return the original qualified name
 */
public static QName unmap(QName mapped) {
    if (XMLConstants.NULL_NS_URI.equals(mapped.getNamespaceURI())) {
        return mapped;
    }

    return new QName(IDS.getObject(mapped.getNamespaceURI()), mapped.getLocalPart());
}

From source file:MainClass.java

public String getNamespaceURI(String prefix) {
    if (prefix == null)
        throw new IllegalArgumentException("prefix cannot be null");
    if (urisByPrefix.containsKey(prefix))
        return (String) urisByPrefix.get(prefix);
    else/*from www.j a  va  2  s.  c  o m*/
        return XMLConstants.NULL_NS_URI;
}

From source file:eu.esdihumboldt.hale.common.instance.orient.internal.ONamespaceMap.java

/**
 * Decode a name based on the runtime namespace map.
 * //from   www.  j av a 2  s.co  m
 * @param name the encoded name
 * @return the decoded qualified name
 * @throws DecoderException of decoding the local part of the name fails
 */
public static QName decode(String name) throws DecoderException {
    int pos = name.indexOf('_'); // find first underscore
    String local;
    String ns = XMLConstants.NULL_NS_URI;
    if (pos < 0) {
        local = ONameUtil.decodeName(name);
    } else {
        ns = IDS.getObject(name.substring(0, pos));
        local = ONameUtil.decodeName(name.substring(pos + 1));
    }
    return new QName(ns, local);
}

From source file:Main.java

/**
 * End element on <code>contentHandler</code> with given <code>prefix</code>
 * and <code>localName</code>.
 * /*  ww  w. j  a va 2  s  .c o m*/
 * @param contentHandler
 *          to start element on.
 * @param prefix
 *          of element
 * @param localName
 *          of element
 * @throws SAXException
 *           if {@link ContentHandler#endElement(String, String, String)}
 *           throws {@link SAXException}.
 * @since 8.1
 */
static public void endElement(final ContentHandler contentHandler, final String prefix, final String localName)
        throws SAXException {
    contentHandler.endElement(XMLConstants.NULL_NS_URI, localName, prefix + ":" + localName);
}

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

@Override
protected void replayNonNullString(String value, XMLEventWriter eventWriter, MarshallingContext context)
        throws XMLStreamException {
    if (!XMLConstants.NULL_NS_URI.equals(this.attributeName.getNamespaceURI())) {
        // we MUST create second namespace declaration if the current one has default ("") prefix, otherwise the attribute will have absent
        // namespace!
        // see: http://www.w3.org/TR/xml-names11/#defaulting - "The namespace name for an unprefixed attribute name always has no value."
        String prefix = this.safeRegisterNamespace(context, eventWriter, this.attributeName);
        if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
            Namespace namespace = this.safePrepareNamespace(
                    context, eventWriter, new QName(this.attributeName.getNamespaceURI(),
                            this.attributeName.getLocalPart(), context.newPrefix()),
                    NamespaceRegistration.IF_DEFAULT_PREFIX);
            prefix = namespace.getPrefix();
        }/* w w  w.  j a va 2  s  . co m*/
        eventWriter.add(XML_EVENTS_FACTORY.createAttribute(prefix, this.attributeName.getNamespaceURI(),
                this.attributeName.getLocalPart(), value));
    } else {
        // attribute is unqalified and has no namespace
        eventWriter.add(XML_EVENTS_FACTORY.createAttribute(this.attributeName.getLocalPart(), value));
    }
}

From source file:com.elsevier.xml.NamespaceContextMappings.java

/**
 * Provide namespace prefix to namespace uri resolution capability. All of
 * the namespace prefixed declared in XPath Expressions should be mapped to
 * the correct URI (in the XML) otherwise the evaluation will not be
 * correct./*from w  ww. j ava  2  s.  c  om*/
 * 
 * @param prefix Namespace prefix
 *            
 * @return Namespace uri
 */
public String getNamespaceURI(String prefix) {

    if (prefix == null)
        throw new NullPointerException("Null prefix");
    String uri = prefixNamespaceMap.get(prefix);
    if (uri == null) {
        return XMLConstants.NULL_NS_URI;
    } else {
        return uri;
    }

}

From source file:net.bpelunit.test.unit.TestSOAPEncoder.java

@Test
public void testEncodeRPCLiteResponseUnwrapped() throws Exception {
    Element literal = TestUtil.readLiteralData(PATH_TO_FILES + "rpclit1.xmlfrag");
    SOAPOperationCallIdentifier operation = TestUtil.getCall(PATH_TO_FILES, PARTNER_WSDL, PARTNER_OPERATION,
            SOAPOperationDirectionIdentifier.OUTPUT);
    ISOAPEncoder encoder = new RPCLiteralEncoder();
    SOAPMessage message = encoder.construct(operation, literal, BPELUnitConstants.SOAP_FAULT_CODE_CLIENT,
            BPELUnitConstants.SOAP_FAULT_DESCRIPTION);

    final Node firstChild = message.getSOAPBody().getFirstChild();
    assertEquals(XMLConstants.NULL_NS_URI, firstChild.getNamespaceURI());
    assertEquals(operation.getName() + "Response", firstChild.getLocalName());
}

From source file:fr.acxio.tools.agia.alfresco.AlfrescoCategoryConverter.java

/**
 * Encode a path according to ISO 9075.</br> Each part of the path is
 * encoded by itself, the path separators are preserved.</br> A part of a
 * path is a {@link fr.acxio.tools.agia.alfresco.domain.QName QName},
 * therefore it can use the short or the long representation.
 * /*  w  w  w.  j  a  v  a  2  s.c  om*/
 * @param sPath
 *            a path to encode
 * @return the encoded path
 */
private String encodePath(String sPath) {
    String aResult = sPath;
    if ((sPath != null) && (sPath.length() > 0)) {
        StringBuilder aBuilder = new StringBuilder();
        Matcher aMatcher = PATH_SPLIT_PATTERN.matcher(sPath);
        QName aQName;
        String aGroup2;
        while (aMatcher.find()) {
            if (aMatcher.group(1) != null) {
                aBuilder.append(aMatcher.group(1));
            }
            aGroup2 = aMatcher.group(2);
            if ((aGroup2 != null) && (aGroup2.length() > 0)) {
                try {
                    aQName = new QName(aGroup2, namespaceContext);
                    if (aQName.getPrefix().equals(XMLConstants.DEFAULT_NS_PREFIX)
                            && aQName.getNamespaceURI().equals(XMLConstants.NULL_NS_URI)) {
                        aBuilder.append(aGroup2); // Not a qname so just
                                                  // pass it
                    } else {
                        aBuilder.append(aQName.getPrefix()).append(":")
                                .append(ISO9075.encode(aQName.getLocalName()));
                    }
                } catch (IllegalArgumentException e) {
                    aBuilder.append(aGroup2);
                }
            }
        }
        aResult = aBuilder.toString();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("The path '" + sPath + "' is encoded as '" + aResult + "'");
        }
    }
    return aResult;
}

From source file:InlineSchemaValidator.java

public String getNamespaceURI(String prefix) {
    if (prefix == null) {
        throw new IllegalArgumentException("Prefix cannot be null.");
    } else if (XMLConstants.XML_NS_PREFIX.equals(prefix)) {
        return XMLConstants.XML_NS_URI;
    } else if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) {
        return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
    } else if (fPrefixToURIMappings != null) {
        String uri = (String) fPrefixToURIMappings.get(prefix);
        if (uri != null) {
            return uri;
        }/*from w  ww  .  j  a va 2s . c om*/
    }
    return XMLConstants.NULL_NS_URI;
}

From source file:org.javelin.sws.ext.bind.internal.metadata.PropertyCallback.java

/**
 * @param field/*ww  w.jav  a  2 s  .com*/
 * @param class1
 */
private <P> void doWithPropertySafe(PropertyMetadata<T, P> metadata)
        throws IllegalArgumentException, IllegalAccessException {

    AnnotatedElement[] accessors = metadata.getAccessors();

    if (this.findJaxbAnnotation(accessors, XmlTransient.class) != null)
        return;

    XmlSchemaType xmlSchemaType = this.findJaxbAnnotation(accessors, XmlSchemaType.class);
    // a pattern for property's class - force creating
    TypedPattern<P> pattern = null;
    if (xmlSchemaType != null) {
        // the schema type determines the pattern - if it is not present in the registry, it will be present after determining it on the basis of Java class
        // of the property
        QName typeName = new QName(xmlSchemaType.namespace(), xmlSchemaType.name());
        pattern = this.patternRegistry.findPatternByType(typeName, metadata.getPropertyClass());
        if (log.isTraceEnabled() && pattern != null)
            log.trace("-- @XmlSchemaType points to {}", pattern.toString());
    }

    if (pattern == null)
        pattern = this.patternRegistry.determineAndCacheXmlPattern(metadata.getPropertyClass());

    // is it value or list?
    XmlValue xmlValue = this.findJaxbAnnotation(accessors, XmlValue.class);
    XmlList xmlList = this.findJaxbAnnotation(accessors, XmlList.class);
    if (xmlValue != null || xmlList != null) {
        // the field's class must be a simpleType, i.e., a type convertible to String, which is either:
        //  - a type registered in org.javelin.sws.ext.bind.internal.BuiltInMappings.initialize()
        //  - a type which has only one property annotated with @XmlValue
        // a type with one @XmlValue property + non-zero @XmlAttribute properties is complex type with simple content, not a simple type
        if (!(pattern.isSimpleType() && pattern instanceof SimpleContentPattern))
            throw new RuntimeException("TODO: should be simpleType");

        if (log.isTraceEnabled())
            log.trace("-- @XmlValue property \"{}\" of type {} mapped to {}", metadata.getPropertyName(),
                    pattern.getJavaType().getName(), pattern.toString());

        metadata.setPattern(pattern);
        if (this.valueMetadata != null)
            throw new RuntimeException("TODO: Only one @XmlValue allowed!");

        this.valueMetadata = metadata;
        return;
    }

    // is it an attribute?
    XmlAttribute xmlAttribute = this.findJaxbAnnotation(accessors, XmlAttribute.class);
    if (xmlAttribute != null) {
        String namespace = XMLConstants.NULL_NS_URI;
        if (this.attributeFormDefault == XmlNsForm.QUALIFIED) {
            // the attribute MUST have namespace
            namespace = "##default".equals(xmlAttribute.namespace()) ? this.typeName.getNamespaceURI()
                    : xmlAttribute.namespace();
        } else {
            // the attribute MAY have namespace
            // TODO: handle org.javelin.sws.ext.bind.annotations.XmlAttribute
            if (!"##default".equals(xmlAttribute.namespace()))
                namespace = xmlAttribute.namespace();
        }
        String name = "##default".equals(xmlAttribute.name()) ? metadata.getPropertyName()
                : xmlAttribute.name();

        if (!(pattern.isSimpleType() && pattern instanceof SimpleContentPattern))
            throw new RuntimeException("TODO: should be simpleType");

        QName attributeQName = new QName(namespace, name);

        if (log.isTraceEnabled())
            log.trace("-- @XmlAttribute property \"{}\" of type {} mapped to {} attribute {}",
                    metadata.getPropertyName(), pattern.getJavaType().getName(), attributeQName,
                    pattern.toString());

        metadata.setPattern(
                AttributePattern.newAttributePattern(attributeQName, (SimpleContentPattern<P>) pattern));
        this.childAttributeMetadata.add(metadata);
        return;
    }

    // is it an element?
    XmlElement xmlElement = this.findJaxbAnnotation(accessors, XmlElement.class);

    // field is also an element when told so using XmlAccessorType
    boolean isElement = false;

    if (accessors[0] instanceof Field) {
        if (this.accessType == XmlAccessType.FIELD)
            isElement = true;
        else if (this.accessType == XmlAccessType.PUBLIC_MEMBER
                && Modifier.isPublic(((Field) accessors[0]).getModifiers()))
            isElement = true;
    } else if (accessors[0] instanceof Method) {
        if (this.accessType == XmlAccessType.PROPERTY)
            isElement = true;
        else if (this.accessType == XmlAccessType.PUBLIC_MEMBER
                && Modifier.isPublic(((Method) accessors[0]).getModifiers())) {
            // TODO: what if getter is private and setter is public?
            isElement = true;
        }
    }

    if (xmlElement != null || isElement) {
        String namespace = XMLConstants.NULL_NS_URI;
        if (this.elementFormDefault == XmlNsForm.QUALIFIED) {
            // the element MUST have namespace
            namespace = xmlElement == null || "##default".equals(xmlElement.namespace())
                    ? this.typeName.getNamespaceURI()
                    : xmlElement.namespace();
        } else {
            // the element MAY have namespace
            if (xmlElement != null && !"##default".equals(xmlElement.namespace()))
                namespace = xmlElement.namespace();
        }
        String name = xmlElement == null || "##default".equals(xmlElement.name()) ? metadata.getPropertyName()
                : xmlElement.name();
        QName elementQName = new QName(namespace, name);

        if (log.isTraceEnabled())
            log.trace("-- @XmlElement property \"{}\" of type {} mapped to {} element with {}",
                    metadata.getPropertyName(), pattern.getJavaType().getName(), elementQName,
                    pattern.toString());

        ElementPattern<?> elementPattern = ElementPattern.newElementPattern(elementQName, pattern);
        XmlElementWrapper xmlElementWrapper = this.findJaxbAnnotation(accessors, XmlElementWrapper.class);
        if (xmlElementWrapper != null) {
            if (!"##default".equals(xmlElementWrapper.namespace()))
                namespace = xmlElementWrapper.namespace();
            name = !"##default".equals(xmlElementWrapper.name()) ? xmlElementWrapper.name()
                    : metadata.getPropertyName();

            // XmlElementWrapper creates (in XSD Category) a new complex, anonymous, nested (inside element declaration) type
            // DESIGNFLAW: XmlElementWrapper works, but not as clean as it should
            PropertyMetadata<T, ?> md = PropertyMetadata.newPropertyMetadata(this.clazz,
                    metadata.getCollectionClass(), "", PropertyKind.PASSTHROUGH);
            md.setPattern(elementPattern);
            ComplexTypePattern<T> newAnonymousType = ComplexTypePattern.newContentModelPattern(null, this.clazz,
                    md);
            // TODO: Handle @XmlElementWrapper for collection properties
            // TODO: JAXB2 doesn't allow this, but maybe it's a good idea to be able to wrap non-collection properties also?
            // TODO: maybe it's a good idea to create @XmlElementWrappers class (aggregating multime @XmlElementWrapper annotations?)
            elementPattern = ElementPattern.newElementPattern(new QName(namespace, name), newAnonymousType);
            metadata.setWrappedCollection(true);
        }

        metadata.setPattern(elementPattern);
        this.childElementMetadata.add(metadata);
        return;
    }
}