Example usage for javax.xml XMLConstants XML_NS_URI

List of usage examples for javax.xml XMLConstants XML_NS_URI

Introduction

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

Prototype

String XML_NS_URI

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

Click Source Link

Document

The official XML Namespace name URI.

Usage

From source file:org.apache.olingo.commons.core.data.AtomSerializer.java

private void entry(final XMLStreamWriter writer, final Entry entry) throws XMLStreamException {
    if (entry.getBaseURI() != null) {
        writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE,
                entry.getBaseURI().toASCIIString());
    }/* w  w w . j  av a 2s.  com*/

    if (StringUtils.isNotBlank(entry.getId())) {
        writer.writeStartElement(Constants.ATOM_ELEM_ID);
        writer.writeCharacters(entry.getId());
        writer.writeEndElement();
    }

    writer.writeStartElement(Constants.ATOM_ELEM_CATEGORY);
    writer.writeAttribute(Constants.ATOM_ATTR_SCHEME,
            version.getNamespaceMap().get(ODataServiceVersion.NS_SCHEME));
    writer.writeAttribute(Constants.ATOM_ATTR_TERM, entry.getType());
    writer.writeEndElement();

    if (entry instanceof AbstractAtomObject) {
        common(writer, (AbstractAtomObject) entry);
    }

    links(writer, entry.getAssociationLinks());
    links(writer, entry.getNavigationLinks());
    links(writer, entry.getMediaEditLinks());

    writer.writeStartElement(Constants.ATOM_ELEM_CONTENT);
    if (entry.isMediaEntry()) {
        if (StringUtils.isNotBlank(entry.getMediaContentType())) {
            writer.writeAttribute(Constants.ATTR_TYPE, entry.getMediaContentType());
        }
        if (StringUtils.isNotBlank(entry.getMediaContentSource())) {
            writer.writeAttribute(Constants.ATOM_ATTR_SRC, entry.getMediaContentSource());
        }
        writer.writeEndElement();

        writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
                Constants.PROPERTIES);
        properties(writer, entry.getProperties());
    } else {
        writer.writeAttribute(Constants.ATTR_TYPE, ContentType.APPLICATION_XML);
        writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
                Constants.PROPERTIES);
        properties(writer, entry.getProperties());
        writer.writeEndElement();
    }
    writer.writeEndElement();
}

From source file:org.apache.olingo.commons.core.data.AtomSerializer.java

private void feed(final XMLStreamWriter writer, final Feed feed) throws XMLStreamException {
    if (feed.getBaseURI() != null) {
        writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE,
                feed.getBaseURI().toASCIIString());
    }/*from www.ja  v  a2 s .c o m*/

    if (feed.getCount() != null) {
        writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
                Constants.ATOM_ELEM_COUNT);
        writer.writeCharacters(Integer.toString(feed.getCount()));
        writer.writeEndElement();
    }

    if (StringUtils.isNotBlank(feed.getId())) {
        writer.writeStartElement(Constants.ATOM_ELEM_ID);
        writer.writeCharacters(feed.getId());
        writer.writeEndElement();
    }

    if (feed instanceof AbstractAtomObject) {
        common(writer, (AbstractAtomObject) feed);
    }

    for (Entry entry : feed.getEntries()) {
        writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
        entry(writer, entry);
        writer.writeEndElement();
    }

    if (feed.getNext() != null) {
        final LinkImpl next = new LinkImpl();
        next.setRel(Constants.NEXT_LINK_REL);
        next.setHref(feed.getNext().toASCIIString());

        links(writer, Collections.<Link>singletonList(next));
    }
}

From source file:org.apache.olingo.commons.core.serialization.AbstractAtomDealer.java

protected void namespaces(final XMLStreamWriter writer) throws XMLStreamException {
    writer.writeNamespace(StringUtils.EMPTY, Constants.NS_ATOM);
    writer.writeNamespace(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI);
    writer.writeNamespace(Constants.PREFIX_METADATA,
            version.getNamespace(ODataServiceVersion.NamespaceKey.METADATA));
    writer.writeNamespace(Constants.PREFIX_DATASERVICES,
            version.getNamespace(ODataServiceVersion.NamespaceKey.DATASERVICES));
    writer.writeNamespace(Constants.PREFIX_GML, Constants.NS_GML);
    writer.writeNamespace(Constants.PREFIX_GEORSS, Constants.NS_GEORSS);
}

From source file:org.apache.olingo.commons.core.serialization.AtomSerializer.java

private void entity(final XMLStreamWriter writer, final Entity entity)
        throws XMLStreamException, EdmPrimitiveTypeException {
    if (entity.getBaseURI() != null) {
        writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE,
                entity.getBaseURI().toASCIIString());
    }/*  w  w  w  . jav  a 2  s .  co  m*/

    if (serverMode && StringUtils.isNotBlank(entity.getETag())) {
        writer.writeAttribute(namespaceMetadata, Constants.ATOM_ATTR_ETAG, entity.getETag());
    }

    if (entity.getId() != null) {
        writer.writeStartElement(Constants.ATOM_ELEM_ID);
        writer.writeCharacters(entity.getId().toASCIIString());
        writer.writeEndElement();
    }

    writer.writeStartElement(Constants.ATOM_ELEM_CATEGORY);
    writer.writeAttribute(Constants.ATOM_ATTR_SCHEME,
            version.getNamespace(ODataServiceVersion.NamespaceKey.SCHEME));
    if (StringUtils.isNotBlank(entity.getType())) {
        writer.writeAttribute(Constants.ATOM_ATTR_TERM,
                new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external(version));
    }
    writer.writeEndElement();

    if (entity instanceof AbstractODataObject) {
        common(writer, (AbstractODataObject) entity);
    }

    if (serverMode) {
        if (entity.getEditLink() != null) {
            links(writer, Collections.singletonList(entity.getEditLink()));
        }

        if (entity.getSelfLink() != null) {
            links(writer, Collections.singletonList(entity.getSelfLink()));
        }
    }

    links(writer, entity.getAssociationLinks());
    links(writer, entity.getNavigationLinks());
    links(writer, entity.getMediaEditLinks());

    if (serverMode) {
        for (ODataOperation operation : entity.getOperations()) {
            writer.writeStartElement(namespaceMetadata, Constants.ATOM_ELEM_ACTION);
            writer.writeAttribute(Constants.ATTR_METADATA, operation.getMetadataAnchor());
            writer.writeAttribute(Constants.ATTR_TITLE, operation.getTitle());
            writer.writeAttribute(Constants.ATTR_TARGET, operation.getTarget().toASCIIString());
            writer.writeEndElement();
        }
    }

    writer.writeStartElement(Constants.ATOM_ELEM_CONTENT);
    if (entity.isMediaEntity()) {
        if (StringUtils.isNotBlank(entity.getMediaContentType())) {
            writer.writeAttribute(Constants.ATTR_TYPE, entity.getMediaContentType());
        }
        if (entity.getMediaContentSource() != null) {
            writer.writeAttribute(Constants.ATOM_ATTR_SRC, entity.getMediaContentSource().toASCIIString());
        }
        writer.writeEndElement();

        writer.writeStartElement(namespaceMetadata, Constants.PROPERTIES);
        properties(writer, entity.getProperties());
    } else {
        writer.writeAttribute(Constants.ATTR_TYPE, ContentType.APPLICATION_XML.toContentTypeString());
        writer.writeStartElement(namespaceMetadata, Constants.PROPERTIES);
        properties(writer, entity.getProperties());
        writer.writeEndElement();
    }
    writer.writeEndElement();

    for (Annotation annotation : entity.getAnnotations()) {
        annotation(writer, annotation, null);
    }
}

From source file:org.apache.olingo.commons.core.serialization.AtomSerializer.java

private void entitySet(final XMLStreamWriter writer, final EntitySet entitySet)
        throws XMLStreamException, EdmPrimitiveTypeException {
    if (entitySet.getBaseURI() != null) {
        writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE,
                entitySet.getBaseURI().toASCIIString());
    }//from  ww  w .j a va2 s .  c om

    if (entitySet.getCount() != null) {
        writer.writeStartElement(namespaceMetadata, Constants.ATOM_ELEM_COUNT);
        writer.writeCharacters(Integer.toString(entitySet.getCount()));
        writer.writeEndElement();
    }

    if (entitySet.getId() != null) {
        writer.writeStartElement(Constants.ATOM_ELEM_ID);
        writer.writeCharacters(entitySet.getId().toASCIIString());
        writer.writeEndElement();
    }

    if (entitySet instanceof AbstractODataObject) {
        common(writer, (AbstractODataObject) entitySet);
    }

    for (Entity entity : entitySet.getEntities()) {
        if (entity.getType() == null && entity.getProperties().isEmpty()) {
            entityRef(writer, entity);
            writer.writeEndElement();
        } else {
            writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
            entity(writer, entity);
            writer.writeEndElement();
        }
    }

    if (serverMode) {
        if (entitySet.getNext() != null) {
            final LinkImpl next = new LinkImpl();
            next.setRel(Constants.NEXT_LINK_REL);
            next.setHref(entitySet.getNext().toASCIIString());

            links(writer, Collections.<Link>singletonList(next));
        }
        if (entitySet.getDeltaLink() != null) {
            final LinkImpl next = new LinkImpl();
            next.setRel(ODataServiceVersion.V40.getNamespace(NamespaceKey.DELTA_LINK_REL));
            next.setHref(entitySet.getDeltaLink().toASCIIString());

            links(writer, Collections.<Link>singletonList(next));
        }
    }
}

From source file:org.betaconceptframework.astroboa.configuration.W3CRelatedSchemaEntityResolver.java

/**
 * Resolves Entities with the following properties
 * //from w w w  .j  av  a2  s.c om
 * publicId = http://www.w3.org/XML/1998/namespace
 * systemId = http://www.w3.org/2001/03/xml.xsd
 * 
 * publicId = datatypes
 * systemId = http://www.w3.org/2001/03/datatypes.dtd
 * 
 * publicId = -//W3C//DTD XMLSCHEMA 200102//EN
 * systemId = http://www.w3.org/2001/03/XMLSchema.dtd
 * 
 * If above schemata are not reachable (probably due to a lack of Internet access),
 * they are loaded from the package
 * 
 * @return
 * @throws IOException 
 */
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {

    if (StringUtils.equals(systemId, CmsConstants.XML_SCHEMA_LOCATION)) {
        return locateEntity(CmsConstants.XML_SCHEMA_LOCATION, XMLConstants.XML_NS_URI);
    }

    if (StringUtils.equals(systemId, CmsConstants.XML_SCHEMA_DTD_LOCATION)) {
        return locateEntity(CmsConstants.XML_SCHEMA_DTD_LOCATION, "-//W3C//DTD XMLSCHEMA 200102//EN");
    }

    if (StringUtils.equals(systemId, CmsConstants.XML_DATATYPES_DTD_LOCATION)) {
        return locateEntity(CmsConstants.XML_DATATYPES_DTD_LOCATION, "datatypes");
    }

    return null;
}

From source file:org.betaconceptframework.astroboa.engine.definition.RepositoryEntityResolver.java

@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {

    if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(systemId) || XMLConstants.XML_NS_URI.equals(systemId)
            || CmsConstants.XML_SCHEMA_LOCATION.equals(systemId)
            || CmsConstants.XML_SCHEMA_DTD_LOCATION.equals(systemId)) {
        return entityResolverForBuiltInSchemas.resolveXmlSchemaRelatedToW3C(publicId, systemId);
    }//  w  w  w.  jav  a 2 s .c  o  m

    byte[] schema = getSchema(systemId);

    if (schema == null) {
        return null;
    }

    InputSource is = new InputSource(new ByteArrayInputStream(schema));

    is.setSystemId(systemId);
    is.setPublicId(publicId);

    return is;

}

From source file:org.betaconceptframework.astroboa.engine.jcr.io.contenthandler.ImportContentHandler.java

private void importAttributes(Attributes atts) throws SAXException {

    if (atts != null && atts.getLength() > 0) {
        for (int i = 0; i < atts.getLength(); i++) {
            //Ignore attributes with specific namespaces
            String uri = atts.getURI(i);

            if (StringUtils.equals(uri, XMLConstants.XMLNS_ATTRIBUTE_NS_URI)
                    || StringUtils.equals(uri, XMLConstants.XML_NS_URI)
                    || StringUtils.equals(uri, XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI)
                    || StringUtils.equals(uri, XMLConstants.W3C_XML_SCHEMA_NS_URI)
                    || StringUtils.equals(uri, XMLConstants.W3C_XPATH_DATATYPE_NS_URI)) {
                continue;
            }// www .  j  av  a 2 s  .com

            addAttributeToImportedEntity(atts.getLocalName(i), atts.getValue(i));
        }
    }

}

From source file:org.dhatim.delivery.dom.DOMBuilder.java

public void startElement(StartElementEvent startEvent) throws SAXException {
    Element newElement = null;//from  www . j  a v a  2 s.  c  o m
    int attsCount = startEvent.atts.getLength();
    Node currentNode = (Node) nodeStack.peek();

    try {
        if (startEvent.uri != null && startEvent.qName != null && !startEvent.qName.equals("")) {
            newElement = ownerDocument.createElementNS(startEvent.uri.intern(), startEvent.qName);
        } else {
            newElement = ownerDocument.createElement(startEvent.localName.intern());
        }

        currentNode.appendChild(newElement);
        if (!emptyElements.contains(startEvent.qName != null ? startEvent.qName : startEvent.localName)) {
            nodeStack.push(newElement);
        }
    } catch (DOMException e) {
        logger.error("DOMException creating start element: namespaceURI=" + startEvent.uri + ", localName="
                + startEvent.localName, e);
        throw e;
    }

    for (int i = 0; i < attsCount; i++) {
        String attNamespace = startEvent.atts.getURI(i);
        String attQName = startEvent.atts.getQName(i);
        String attLocalName = startEvent.atts.getLocalName(i);
        String attValue = startEvent.atts.getValue(i);
        try {
            if (attNamespace != null && attQName != null) {
                attNamespace = attNamespace.intern();
                if (attNamespace.equals(XMLConstants.NULL_NS_URI)) {
                    if (attQName.startsWith(XMLConstants.XMLNS_ATTRIBUTE)) {
                        attNamespace = XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
                    } else if (attQName.startsWith("xml:")) {
                        attNamespace = XMLConstants.XML_NS_URI;
                    }
                }
                newElement.setAttributeNS(attNamespace, attQName, attValue);
            } else {
                newElement.setAttribute(attLocalName.intern(), attValue);
            }
        } catch (DOMException e) {
            logger.error("DOMException setting element attribute " + attLocalName + "=" + attValue
                    + "[namespaceURI=" + startEvent.uri + ", localName=" + startEvent.localName + "].", e);
            throw e;
        }
    }
}

From source file:org.iish.visualmets.services.TocDaoImp.java

private XPathExpression getXPathExpression(String xquery) throws XPathExpressionException {
    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();

    // http://www.ibm.com/developerworks/library/x-javaxpathapi.html
    NamespaceContext ns = new NamespaceContext() {

        @Override/* w w  w  .  j ava 2 s .  c o  m*/
        public String getPrefix(String namespaceURI) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Iterator getPrefixes(String namespaceURI) {
            throw new UnsupportedOperationException();
        }

        @Override
        public String getNamespaceURI(String prefix) {
            final String metsNs = "http://www.loc.gov/METS/";
            if (prefix == null)
                throw new NullPointerException(metsNs);

            if (prefix.equalsIgnoreCase("mets"))
                return metsNs;

            if (prefix.equalsIgnoreCase("xml"))
                return XMLConstants.XML_NS_URI;

            return XMLConstants.NULL_NS_URI;
        }
    };

    //        if ( !namespaceName.equals("") ) {
    xpath.setNamespaceContext(ns);
    //        }
    XPathExpression expr = xpath.compile(xquery);

    return expr;
}