Example usage for javax.xml.stream XMLStreamReader getNamespaceURI

List of usage examples for javax.xml.stream XMLStreamReader getNamespaceURI

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamReader getNamespaceURI.

Prototype

public String getNamespaceURI();

Source Link

Document

If the current event is a START_ELEMENT or END_ELEMENT this method returns the URI of the prefix or the default namespace.

Usage

From source file:com.amalto.core.load.context.BufferStateContextWriter.java

public void writeEndElement(XMLStreamReader reader) throws XMLStreamException {
    ProcessedEndElement endElement = new ProcessedEndElement(reader.getNamespaceURI(), reader.getLocalName(),
            reader.getName().getLocalPart());
    processedElements.add(endElement);//from  w w w. j  a  va  2s .co  m

    // Namespace parsing
    Map<String, String> prefixToNamespace = Utils.parseNamespace(reader);
    Set<Map.Entry<String, String>> entries = prefixToNamespace.entrySet();
    for (Map.Entry<String, String> entry : entries) {
        processedElements.add(new ProcessedEndNamespace(entry.getKey()));
    }
}

From source file:com.microsoft.windowsazure.services.table.client.AtomPubParser.java

/**
 * Reserved for internal use. Reads the properties of an entity from the stream into a map of property names to
 * typed values. Reads the entity data as an AtomPub Entry Resource from the specified {@link XMLStreamReader} into
 * a map of <code>String</code> property names to {@link EntityProperty} data typed values.
 * //from w ww .  j ava 2 s  .c  o  m
 * @param xmlr
 *            The <code>XMLStreamReader</code> to read the data from.
 * @param opContext
 *            An {@link OperationContext} object used to track the execution of the operation.
 * 
 * @return
 *         A <code>java.util.HashMap</code> containing a map of <code>String</code> property names to
 *         {@link EntityProperty} data typed values found in the entity data.
 * @throws XMLStreamException
 *             if an error occurs accessing the stream.
 * @throws ParseException
 *             if an error occurs converting the input to a particular data type.
 */
protected static HashMap<String, EntityProperty> readProperties(final XMLStreamReader xmlr,
        final OperationContext opContext) throws XMLStreamException, ParseException {
    int eventType = xmlr.getEventType();
    xmlr.require(XMLStreamConstants.START_ELEMENT, null, ODataConstants.PROPERTIES);
    final HashMap<String, EntityProperty> properties = new HashMap<String, EntityProperty>();

    while (xmlr.hasNext()) {
        eventType = xmlr.next();
        if (eventType == XMLStreamConstants.CHARACTERS) {
            xmlr.getText();
            continue;
        }

        if (eventType == XMLStreamConstants.START_ELEMENT
                && xmlr.getNamespaceURI().equals(ODataConstants.DATA_SERVICES_NS)) {
            final String key = xmlr.getLocalName();
            String val = Constants.EMPTY_STRING;
            String edmType = null;

            if (xmlr.getAttributeCount() > 0) {
                edmType = xmlr.getAttributeValue(ODataConstants.DATA_SERVICES_METADATA_NS, ODataConstants.TYPE);
            }

            // move to chars
            eventType = xmlr.next();

            if (eventType == XMLStreamConstants.CHARACTERS) {
                val = xmlr.getText();

                // end element
                eventType = xmlr.next();
            }

            xmlr.require(XMLStreamConstants.END_ELEMENT, null, key);

            final EntityProperty newProp = new EntityProperty(val, EdmType.parse(edmType));
            properties.put(key, newProp);
        } else if (eventType == XMLStreamConstants.END_ELEMENT && xmlr.getName().toString()
                .equals(ODataConstants.BRACKETED_DATA_SERVICES_METADATA_NS + ODataConstants.PROPERTIES)) {
            // End read properties
            break;
        }
    }

    xmlr.require(XMLStreamConstants.END_ELEMENT, null, ODataConstants.PROPERTIES);
    return properties;
}

From source file:lux.index.XmlPathMapper.java

private void getEventQName(MutableString buf, XMLStreamReader reader) {
    encodeQName(buf, reader.getLocalName(), reader.getPrefix(), reader.getNamespaceURI());
}

From source file:com.predic8.membrane.core.interceptor.balancer.XMLElementSessionIdExtractor.java

private boolean isSessionIdElement(XMLStreamReader reader) {
    return reader.isStartElement() && localName.equals(reader.getLocalName())
            && (namespace == null || namespace.equals(reader.getNamespaceURI()));
}

From source file:davmail.exchange.dav.ExchangeDavMethod.java

protected void handleMultiValuedProperty(XMLStreamReader reader, MultiStatusResponse multiStatusResponse)
        throws XMLStreamException {
    String tagLocalName = reader.getLocalName();
    Namespace namespace = Namespace.getNamespace(reader.getNamespaceURI());
    ArrayList<String> values = new ArrayList<String>();
    while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, tagLocalName)) {
        reader.next();/*  w w w . j  a  va  2s.  c  o m*/
        if (XMLStreamUtil.isStartTag(reader)) {
            String tagContent = getTagContent(reader);
            if (tagContent != null) {
                values.add(tagContent);
            }
        }
    }
    multiStatusResponse.add(new DefaultDavProperty(tagLocalName, values, namespace));
}

From source file:StAXStreamTreeViewer.java

private void parseRestOfDocument(XMLStreamReader reader, DefaultMutableTreeNode current)
        throws XMLStreamException {

    while (reader.hasNext()) {
        int type = reader.next();
        switch (type) {
        case XMLStreamConstants.START_ELEMENT:

            DefaultMutableTreeNode element = new DefaultMutableTreeNode(reader.getLocalName());
            current.add(element);//  www. j  a  va 2s  .com
            current = element;

            if (reader.getNamespaceURI() != null) {
                String prefix = reader.getPrefix();
                if (prefix == null) {
                    prefix = "[None]";
                }
                DefaultMutableTreeNode namespace = new DefaultMutableTreeNode(
                        "prefix = '" + prefix + "', URI = '" + reader.getNamespaceURI() + "'");
                current.add(namespace);
            }

            if (reader.getAttributeCount() > 0) {
                for (int i = 0; i < reader.getAttributeCount(); i++) {
                    DefaultMutableTreeNode attribute = new DefaultMutableTreeNode(
                            "Attribute (name = '" + reader.getAttributeLocalName(i) + "', value = '"
                                    + reader.getAttributeValue(i) + "')");
                    String attURI = reader.getAttributeNamespace(i);
                    if (attURI != null) {
                        String attPrefix = reader.getAttributePrefix(i);
                        if (attPrefix == null || attPrefix.equals("")) {
                            attPrefix = "[None]";
                        }
                        DefaultMutableTreeNode attNamespace = new DefaultMutableTreeNode(
                                "prefix=" + attPrefix + ",URI=" + attURI);
                        attribute.add(attNamespace);
                    }
                    current.add(attribute);
                }
            }

            break;
        case XMLStreamConstants.END_ELEMENT:
            current = (DefaultMutableTreeNode) current.getParent();
            break;
        case XMLStreamConstants.CHARACTERS:
            if (!reader.isWhiteSpace()) {
                DefaultMutableTreeNode data = new DefaultMutableTreeNode("CD:" + reader.getText());
                current.add(data);
            }
            break;
        case XMLStreamConstants.DTD:
            DefaultMutableTreeNode dtd = new DefaultMutableTreeNode("DTD:" + reader.getText());
            current.add(dtd);
            break;
        case XMLStreamConstants.SPACE:
            break;
        case XMLStreamConstants.COMMENT:
            DefaultMutableTreeNode comment = new DefaultMutableTreeNode(reader.getText());
            current.add(comment);
            break;
        default:
            System.out.println(type);
        }
    }
}

From source file:davmail.exchange.dav.ExchangeDavMethod.java

protected void handleProperty(XMLStreamReader reader, MultiStatusResponse multiStatusResponse)
        throws XMLStreamException {
    while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "prop")) {
        reader.next();//from  ww  w  .jav a  2 s.  c om
        if (XMLStreamUtil.isStartTag(reader)) {
            Namespace namespace = Namespace.getNamespace(reader.getNamespaceURI());
            String tagLocalName = reader.getLocalName();
            if (reader.getAttributeCount() > 0 && "mv.string".equals(reader.getAttributeValue(0))) {
                handleMultiValuedProperty(reader, multiStatusResponse);
            } else {
                String tagContent = getTagContent(reader);
                if (tagContent != null) {
                    multiStatusResponse.add(new DefaultDavProperty(tagLocalName, tagContent, namespace));
                }
            }
        }
    }
}

From source file:de.tuebingen.uni.sfs.germanet.api.WiktionaryLoader.java

/**
 * Loads <code>WiktionaryParaphrases</code> from the specified file into this
 * <code>WiktionaryLoader</code>'s <code>GermaNet</code> object.
 * @param wiktionaryFile the file containing <code>WiktionaryParaphrases</code> data
 * @throws java.io.FileNotFoundException
 * @throws javax.xml.stream.XMLStreamException
 */// w ww  .  ja v a 2  s  . c  o m
protected void loadWiktionary(File wiktionaryFile) throws FileNotFoundException, XMLStreamException {
    wikiDir = wiktionaryFile;
    FilenameFilter filter = new WikiFilter(); //get only wiktionary files
    File[] wikiFiles = wikiDir.listFiles(filter);

    if (wikiFiles == null || wikiFiles.length == 0) {
        throw new FileNotFoundException(
                "Unable to load Wiktionary Paraphrases from \"" + this.wikiDir.getPath() + "\"");
    }

    for (File wikiFile : wikiFiles) {
        logger.debug("Loading " + wikiFile.getName() + "...");
        InputStream in = new FileInputStream(wikiFile);
        XMLInputFactory factory = XMLInputFactory.newInstance();
        XMLStreamReader parser = factory.createXMLStreamReader(in);
        int event;
        String nodeName;

        //Parse entire file, looking for Wiktionary paraphrase start elements
        while (parser.hasNext()) {
            event = parser.next();
            switch (event) {
            case XMLStreamConstants.START_DOCUMENT:
                namespace = parser.getNamespaceURI();
                break;
            case XMLStreamConstants.START_ELEMENT:
                nodeName = parser.getLocalName();
                if (nodeName.equals(GermaNet.XML_WIKTIONARY_PARAPHRASE)) {
                    WiktionaryParaphrase wiki = processWiktionaryParaphrase(parser);
                    germaNet.addWiktionaryParaphrase(wiki);
                }
                break;
            }
        }
        parser.close();
    }

    logger.debug("Done.");

}

From source file:de.tuebingen.uni.sfs.germanet.api.IliLoader.java

/**
 * Loads <code>IliRecords</code> from the specified file into this
 * <code>IliLoader</code>'s <code>GermaNet</code> object.
 * @param iliFile the file containing <code>IliRecords</code> data
 * @throws java.io.FileNotFoundException
 * @throws javax.xml.stream.XMLStreamException
 *//*from  www. ja  va2 s  .  c o m*/
protected void loadILI(File iliFile) throws FileNotFoundException, XMLStreamException {
    InputStream in = new FileInputStream(iliFile);
    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLStreamReader parser = factory.createXMLStreamReader(in);
    int event;
    String nodeName;
    logger.debug("Loading " + iliFile.getName() + "...");

    //Parse entire file, looking for ili record start elements
    while (parser.hasNext()) {
        event = parser.next();
        switch (event) {
        case XMLStreamConstants.START_DOCUMENT:
            namespace = parser.getNamespaceURI();
            break;
        case XMLStreamConstants.START_ELEMENT:
            nodeName = parser.getLocalName();
            if (nodeName.equals(GermaNet.XML_ILI_RECORD)) {
                IliRecord ili = processIliRecord(parser);
                germaNet.addIliRecord(ili);
            }
            break;
        }
    }
    parser.close();
    logger.debug("Done.");
}

From source file:de.tuebingen.uni.sfs.germanet.api.IliLoader.java

/**
 * Loads <code>IliRecords</code> from the specified stream into this
 * <code>IliLoader</code>'s <code>GermaNet</code> object.
 * @param inputStream the stream containing <code>IliRecords</code> data
 * @throws javax.xml.stream.XMLStreamException
 *//*from   ww w .ja va 2 s .c  o m*/
protected void loadILI(InputStream inputStream) throws XMLStreamException {
    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLStreamReader parser = factory.createXMLStreamReader(inputStream);
    int event;
    String nodeName;
    logger.debug("Loading input stream interLingualIndex_DE-EN.xml...");

    //Parse entire file, looking for ili record start elements
    while (parser.hasNext()) {
        event = parser.next();
        switch (event) {
        case XMLStreamConstants.START_DOCUMENT:
            namespace = parser.getNamespaceURI();
            break;
        case XMLStreamConstants.START_ELEMENT:
            nodeName = parser.getLocalName();
            if (nodeName.equals(GermaNet.XML_ILI_RECORD)) {
                IliRecord ili = processIliRecord(parser);
                germaNet.addIliRecord(ili);
            }
            break;
        }
    }
    parser.close();
    logger.debug("Done.");
}