Example usage for javax.xml.stream XMLStreamReader getLocalName

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

Introduction

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

Prototype

public String getLocalName();

Source Link

Document

Returns the (local) name of the current event.

Usage

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: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.config.AbstractXmlElement.java

/**
 * Needed to resolve interceptor IDs into interceptor beans
 *//*from   www  .j  av  a  2 s .co  m*/

public XMLElement parse(XMLStreamReader token) throws Exception {
    move2RootElementIfNeeded(token);
    log.debug("<" + token.getLocalName() + ">");
    parseAttributes(token);
    while (token.hasNext()) {
        token.next();
        if (token.isStartElement()) {
            parseChildren(token, token.getName().getLocalPart());
        } else if (token.isCharacters()) {
            parseCharacters(token);
        } else if (token.isEndElement()) {
            log.debug("</" + token.getLocalName() + ">");
            break;
        }
    }
    doAfterParsing();
    return this;
}

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   ww  w  .j  a  v  a 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:edu.utah.further.core.xml.stax.XmlStreamElementPrinter.java

@Override
public void visitEntityReference(final XMLStreamReader xmlReader) {
    final String str = xmlReader.getLocalName() + "=";
    os.print(str);//from  w  w w .  j a v  a  2 s .  c om
    if (xmlReader.hasText()) {
        os.print("[" + xmlReader.getText() + "]");
    }
}

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.
 * //w  w  w. java2 s.  co 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:de.huxhorn.sulky.plist.impl.PropertyListReader.java

private Object readValue(XMLStreamReader reader) throws XMLStreamException {
    int type = reader.getEventType();
    if (XMLStreamConstants.START_ELEMENT == type && TRUE_NODE.equals(reader.getLocalName())) {
        reader.nextTag();/* ww w.j a  va 2  s  .  c o m*/
        reader.require(XMLStreamConstants.END_ELEMENT, null, TRUE_NODE);
        reader.nextTag();
        return Boolean.TRUE;
    }
    if (XMLStreamConstants.START_ELEMENT == type && FALSE_NODE.equals(reader.getLocalName())) {
        reader.nextTag();
        reader.require(XMLStreamConstants.END_ELEMENT, null, FALSE_NODE);
        reader.nextTag();
        return Boolean.FALSE;
    }
    if (XMLStreamConstants.START_ELEMENT == type && REAL_NODE.equals(reader.getLocalName())) {
        String text = StaxUtilities.readSimpleTextNodeIfAvailable(reader, null, REAL_NODE);

        return Double.parseDouble(text);
    }
    if (XMLStreamConstants.START_ELEMENT == type && INTEGER_NODE.equals(reader.getLocalName())) {
        String text = StaxUtilities.readSimpleTextNodeIfAvailable(reader, null, INTEGER_NODE);

        return Long.parseLong(text);
    }
    if (XMLStreamConstants.START_ELEMENT == type && STRING_NODE.equals(reader.getLocalName())) {
        return StaxUtilities.readSimpleTextNodeIfAvailable(reader, null, STRING_NODE);
    }
    if (XMLStreamConstants.START_ELEMENT == type && DATA_NODE.equals(reader.getLocalName())) {
        return readData(reader);
    }
    if (XMLStreamConstants.START_ELEMENT == type && DATE_NODE.equals(reader.getLocalName())) {
        return readDate(reader);
    }
    if (XMLStreamConstants.START_ELEMENT == type && ARRAY_NODE.equals(reader.getLocalName())) {
        return readArray(reader);
    }
    if (XMLStreamConstants.START_ELEMENT == type && DICT_NODE.equals(reader.getLocalName())) {
        return readDict(reader);
    }
    throw new RuntimeException("Unexpected XML-Node: " + reader.getLocalName());
}

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

protected String getTagContent(XMLStreamReader reader) throws XMLStreamException {
    String value = null;//from  w ww.  ja v a 2s . c  o m
    String tagLocalName = reader.getLocalName();
    while (reader.hasNext() && !((reader.getEventType() == XMLStreamConstants.END_ELEMENT)
            && tagLocalName.equals(reader.getLocalName()))) {
        reader.next();
        if (reader.getEventType() == XMLStreamConstants.CHARACTERS) {
            value = reader.getText();
        }
    }
    // empty tag
    if (!reader.hasNext()) {
        throw new XMLStreamException("End element for " + tagLocalName + " not found");
    }
    return value;
}

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();//from  w  w w. ja 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);//from w w w  .  j ava  2s .c  om
            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);
        }
    }
}