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:org.dhatim.flatfile.FlatFileReader.java

public void parse(InputSource inputSource) throws IOException, SAXException {
    if (contentHandler == null) {
        throw new IllegalStateException("'contentHandler' not set.  Cannot parse Record stream.");
    }//from w  w  w  .j  a va2s  . c  o m
    if (execContext == null) {
        throw new IllegalStateException("'execContext' not set.  Cannot parse Record stream.");
    }

    try {
        Reader recordReader;

        // Create the record parser....
        RecordParser recordParser = parserFactory.newRecordParser();
        recordParser.setRecordParserFactory(parserFactory);
        recordParser.setDataSource(inputSource);

        try {
            recordParser.initialize();

            // Start the document and add the root "record-set" element...
            contentHandler.startDocument();
            contentHandler.startElement(XMLConstants.NULL_NS_URI, rootElementName, StringUtils.EMPTY,
                    EMPTY_ATTRIBS);

            // Output each of the CVS line entries...
            int lineNumber = 0;

            Record record = recordParser.nextRecord();
            while (record != null) {
                lineNumber++; // First line is line "1"

                if (record != null) {
                    List<Field> recordFields = record.getFields();

                    if (indent) {
                        contentHandler.characters(INDENT_LF, 0, 1);
                        contentHandler.characters(INDENTCHARS, 0, 1);
                    }

                    AttributesImpl attrs = new AttributesImpl();
                    attrs.addAttribute(XMLConstants.NULL_NS_URI, RECORD_NUMBER_ATTR, RECORD_NUMBER_ATTR,
                            "xs:int", Integer.toString(lineNumber));

                    RecordMetaData recordMetaData = record.getRecordMetaData();
                    if (recordFields.size() < recordMetaData.getUnignoredFieldCount()) {
                        attrs.addAttribute(XMLConstants.NULL_NS_URI, RECORD_TRUNCATED_ATTR,
                                RECORD_TRUNCATED_ATTR, "xs:boolean", Boolean.TRUE.toString());
                    }

                    contentHandler.startElement(XMLConstants.NULL_NS_URI, record.getName(), StringUtils.EMPTY,
                            attrs);
                    for (Field recordField : recordFields) {
                        String fieldName = recordField.getName();

                        if (indent) {
                            contentHandler.characters(INDENT_LF, 0, 1);
                            contentHandler.characters(INDENTCHARS, 0, 2);
                        }

                        contentHandler.startElement(XMLConstants.NULL_NS_URI, fieldName, StringUtils.EMPTY,
                                EMPTY_ATTRIBS);

                        String value = recordField.getValue();
                        contentHandler.characters(value.toCharArray(), 0, value.length());
                        contentHandler.endElement(XMLConstants.NULL_NS_URI, fieldName, StringUtils.EMPTY);
                    }

                    if (indent) {
                        contentHandler.characters(INDENT_LF, 0, 1);
                        contentHandler.characters(INDENTCHARS, 0, 1);
                    }

                    contentHandler.endElement(XMLConstants.NULL_NS_URI, record.getName(), StringUtils.EMPTY);
                }

                record = recordParser.nextRecord();
            }

            if (indent) {
                contentHandler.characters(INDENT_LF, 0, 1);
            }

            // Close out the "csv-set" root element and end the document..
            contentHandler.endElement(XMLConstants.NULL_NS_URI, rootElementName, StringUtils.EMPTY);
            contentHandler.endDocument();
        } finally {
            recordParser.uninitialize();
        }
    } finally {
        // These properties need to be reset for every execution (e.g. when reader is pooled).
        contentHandler = null;
        execContext = null;
    }
}

From source file:org.dhatim.json.JSONReader.java

private void startElement(String name, int indent) throws SAXException {
    indent(indent);/*from   w ww .ja  va  2s.c o  m*/
    contentHandler.startElement(XMLConstants.NULL_NS_URI, name, "", EMPTY_ATTRIBS);
}

From source file:org.dhatim.json.JSONReader.java

private void endElement(String name) throws SAXException {
    contentHandler.endElement(XMLConstants.NULL_NS_URI, name, "");
}

From source file:org.dhatim.xml.DomUtils.java

/**
 * Rename element.//from   ww  w  .ja  v a2  s  .c o  m
 * @param element The element to be renamed.
 * @param replacementElement The tag name of the replacement element.  Can be a prefix qualified
  * name if the namespace is not the null namepsace ({@link javax.xml.XMLConstants#NULL_NS_URI}).
  * @param namespace The element namespace.
 * @param keepChildContent <code>true</code> if the target element's child content
 * is to be copied to the replacement element, false if not. Default <code>true</code>.
 * @param keepAttributes <code>true</code> if the target element's attributes
 * are to be copied to the replacement element, false if not. Default <code>true</code>.
 * @return The renamed element.
 */
public static Element renameElementNS(Element element, String replacementElement, String namespace,
        boolean keepChildContent, boolean keepAttributes) {
    AssertArgument.isNotNull(element, "element");
    AssertArgument.isNotNull(replacementElement, "replacementElement");

    Element replacement;
    if (namespace != null && !XMLConstants.NULL_NS_URI.equals(namespace)) {
        replacement = element.getOwnerDocument().createElementNS(namespace, replacementElement);
    } else {
        replacement = element.getOwnerDocument().createElement(replacementElement);
    }

    if (keepChildContent) {
        DomUtils.copyChildNodes(element, replacement);
    }
    if (keepAttributes) {
        NamedNodeMap attributes = element.getAttributes();
        int attributeCount = attributes.getLength();

        for (int i = 0; i < attributeCount; i++) {
            Attr attribute = (Attr) attributes.item(i);
            replacement.setAttribute(attribute.getName(), attribute.getValue());
        }
    }
    DomUtils.replaceNode(replacement, element);

    return replacement;
}

From source file:org.dhatim.yaml.handler.YamlToSaxHandler.java

private void startElement(String name, String anchorName, boolean addAnchorAttribute) throws SAXException {
    AttributesImpl attributes;/* w  ww. j  av a  2 s .c  om*/
    if (anchorName == null) {
        attributes = EMPTY_ATTRIBS;
    } else {
        attributes = new AttributesImpl();

        String attributeName = addAnchorAttribute ? anchorAttributeName : aliasAttributeName;
        String attributeType = addAnchorAttribute ? ATTRIBUTE_ID : ATTRIBUTE_IDREF;
        if (addAnchorAttribute) {

        }
        attributes.addAttribute(XMLConstants.NULL_NS_URI, attributeName, attributeName, attributeType,
                anchorName);
    }
    contentHandler.startElement(XMLConstants.NULL_NS_URI, name, StringUtils.EMPTY, attributes);
}

From source file:org.dhatim.yaml.handler.YamlToSaxHandler.java

private void endElement(String name) throws SAXException {
    contentHandler.endElement(XMLConstants.NULL_NS_URI, name, StringUtils.EMPTY);
}

From source file:org.docx4j.jaxb.NamespacePrefixMappings.java

protected static String getNamespaceURIStatic(String prefix) {

    // Pre-defined prefixes
    if (prefix.equals("w"))
        return Namespaces.NS_WORD12;
    if (prefix.equals("r"))
        return Namespaces.RELATIONSHIPS_OFFICEDOC;
    if (prefix.equals("pkg"))
        return Namespaces.PKG_XML;

    if (prefix.equals("p"))
        return "http://schemas.openxmlformats.org/presentationml/2006/main";

    if (prefix.equals("prop"))
        return "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties";

    if (prefix.equals("properties"))
        return "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties";

    if (prefix.equals("cp"))
        return "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";

    if (prefix.equals("vt"))
        return "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes";

    if (prefix.equals("rel"))
        return "http://schemas.openxmlformats.org/package/2006/relationships";

    // DrawingML//w w  w  .j  a v a  2s  . co  m
    if (prefix.equals("wp"))
        return "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing";

    if (prefix.equals("c"))
        return "http://schemas.openxmlformats.org/drawingml/2006/chart";

    if (prefix.equals("a"))
        return "http://schemas.openxmlformats.org/drawingml/2006/main";

    if (prefix.equals("pic"))
        return "http://schemas.openxmlformats.org/drawingml/2006/picture";

    if (prefix.equals("dgm"))
        return "http://schemas.openxmlformats.org/drawingml/2006/diagram";

    if (prefix.equals("dsp"))
        return "http://schemas.microsoft.com/office/drawing/2008/diagram";

    if (prefix.equals("o"))
        return "urn:schemas-microsoft-com:office:office";

    if (prefix.equals("v"))
        return "urn:schemas-microsoft-com:vml";

    if (prefix.equals("WX"))
        return "http://schemas.microsoft.com/office/word/2003/auxHint";

    if (prefix.equals("wne"))
        return "http://schemas.microsoft.com/office/word/2006/wordml";

    if (prefix.equals("w14"))
        return "http://schemas.microsoft.com/office/word/2010/wordml";

    if (prefix.equals("w15"))
        return "http://schemas.microsoft.com/office/word/2012/wordml";

    if (prefix.equals("aml"))
        return "http://schemas.microsoft.com/aml/2001/core";

    if (prefix.equals("w10"))
        return "urn:schemas-microsoft-com:office:word";

    if (prefix.equals("m"))
        return "http://schemas.openxmlformats.org/officeDocument/2006/math";

    if (prefix.equals("xsi"))
        return "http://www.w3.org/2001/XMLSchema-instance";

    if (prefix.equals("dc"))
        return "http://purl.org/dc/elements/1.1/";

    if (prefix.equals("dcterms"))
        return "http://purl.org/dc/terms/";

    if (prefix.equals("xml"))
        return "http://www.w3.org/XML/1998/namespace";

    if (prefix.equals("ds"))
        return "http://schemas.openxmlformats.org/officeDocument/2006/customXml";

    if (prefix.equals("mc"))
        return "http://schemas.openxmlformats.org/markup-compatibility/2006";

    if (prefix.equals("xdr"))
        return "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing";

    // OpenDoPE
    if (prefix.equals("odx"))
        return "http://opendope.org/xpaths";
    if (prefix.equals("odc"))
        return "http://opendope.org/conditions";
    if (prefix.equals("odi"))
        return "http://opendope.org/components";
    if (prefix.equals("odq"))
        return "http://opendope.org/questions";
    if (prefix.equals("oda"))
        return "http://opendope.org/answers";
    if (prefix.equals("odgm"))
        return "http://opendope.org/SmartArt/DataHierarchy";

    if (prefix.equals("xf"))
        return Namespaces.XFORMS;
    else if (prefix.equals("xe"))
        return Namespaces.XML_EVENTS;
    else if (prefix.equals("xs"))
        return Namespaces.XML_SCHEMA;

    // Registered prefixes
    String result = namespaces.get(prefix);
    if (result == null) {
        return XMLConstants.NULL_NS_URI;
    } else {
        return result;
    }

}

From source file:org.expath.tools.model.exist.EXistSequence.java

private void setOutputKey(Properties props, String name, QName value) throws ToolsException {
    if (value != null) {
        if (value.getNamespaceURI() != null && !value.getNamespaceURI().equals(XMLConstants.NULL_NS_URI)) {
            throw new ToolsException(
                    "A QName with a non-null namespace not supported as a serialization param: {"
                            + value.getNamespaceURI() + "}" + value.getLocalPart());
        }/*from  w  w  w  .j a va2 s  .c  o  m*/
        props.setProperty(name, value.getLocalPart());
    }
}

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

From source file:org.kalypsodeegree.xml.XMLTools.java

/**
 * Parses the submitted {@link String} as a {@link QName}.<br/>
 * The string must be of form <code>prefix:localPart</code>.
 * The reuturned qname alsways has namespace {@link XMLConstants#NULL_NS_URI}.
 *///from w w  w . j av a2  s .  c o m
public static QName parsePrefixedQName(String prefixed) {
    String[] tmp = StringUtils.split(prefixed, ":", 2); //$NON-NLS-1$
    if (tmp.length == 2)
        return new QName(XMLConstants.NULL_NS_URI, tmp[1], tmp[0]);
    else
        return new QName(prefixed);
}