Example usage for javax.xml.stream XMLStreamReader getName

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

Introduction

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

Prototype

public QName getName();

Source Link

Document

Returns a QName for the current START_ELEMENT or END_ELEMENT event

Usage

From source file:babel.content.pages.Page.java

public void unpersist(XMLStreamReader reader) throws XMLStreamException {
    String elemTag;/*  ww w  .  java 2s  .c  om*/
    PageVersion ver;

    m_pageURL = reader.getAttributeValue(0);
    m_versions.clear();

    while (true) {
        int event = reader.next();

        if (event == XMLStreamConstants.END_ELEMENT && XML_TAG_PAGE.equals(reader.getName().toString())) {
            break;
        }

        if (event == XMLStreamConstants.START_ELEMENT) {
            elemTag = reader.getName().toString();

            if ("MetaData".equals(elemTag)) {
                m_pageProps.unpersist(reader);
            } else if ("PageVersion".equals(elemTag)) {
                ver = new PageVersion();
                ver.unpersist(reader);

                m_versions.add(ver);
            }
        }
    }
}

From source file:com.predic8.membrane.core.http.xml.Response.java

@Override
protected void parseChildren(XMLStreamReader token, String child) throws Exception {
    if (Headers.ELEMENT_NAME.equals(child)) {
        headers = (Headers) new Headers().parse(token);
    } else if ("status".equals(child)) {
        statusCode = Integer/*from   ww w. jav a2s  .  c  o m*/
                .parseInt(StringUtils.defaultIfBlank(token.getAttributeValue("", "status-code"), "0"));
        statusMessage = "";
        while (token.hasNext()) {
            token.next();
            if (token.isStartElement()) {
                parseChildren(token, token.getName().getLocalPart());
            } else if (token.isCharacters()) {
                statusMessage += token.getText();
            } else if (token.isEndElement()) {
                break;
            }
        }
    }
}

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

public void writeStartElement(XMLStreamReader reader) throws XMLStreamException, SAXException {
    // Namespace parsing
    Map<String, String> prefixToNamespace = Utils.parseNamespace(reader);
    Set<Map.Entry<String, String>> entries = prefixToNamespace.entrySet();
    for (Map.Entry<String, String> entry : entries) {
        contentHandler.startPrefixMapping(entry.getKey(), entry.getValue());
    }//from   w w w.j  a va2  s  . c o  m

    // Attribute parsing
    Attributes attributes = Utils.parseAttributes(reader);

    // Start new XML element
    contentHandler.startElement(getURI(reader), reader.getLocalName(), reader.getName().getLocalPart(),
            attributes);
}

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

public void writeStartElement(XMLStreamReader reader) throws XMLStreamException {
    // Attribute parsing
    Attributes attributes = Utils.parseAttributes(reader);

    // 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 ProcessedStartNamespace(entry.getKey(), entry.getValue()));
    }/*from   www.ja va  2  s. co  m*/

    // New start element
    ProcessedStartElement startElement = new ProcessedStartElement(reader.getNamespaceURI(),
            reader.getLocalName(), reader.getName().getLocalPart(), attributes);
    processedElements.add(startElement);
}

From source file:babel.content.pages.PageVersion.java

public void unpersist(XMLStreamReader reader) throws XMLStreamException {
    String elemTag;/*from   w ww. j a va 2 s .  com*/
    String elemAttrib;

    m_verProps.clear();
    ;
    m_contentMeta.clear();
    m_parseMeta.clear();
    m_outLinks = null;
    m_content = new String();

    while (true) {
        int event = reader.next();

        if (event == XMLStreamConstants.END_ELEMENT
                && XML_TAG_PAGEVERSION.equals(reader.getName().toString())) {
            break;
        }

        if (event == XMLStreamConstants.START_ELEMENT) {
            elemTag = reader.getName().toString();
            elemAttrib = reader.getAttributeValue(0);

            if ("MetaData".equals(elemTag)) {
                if ("VersionProperties".equals(elemAttrib)) {
                    m_verProps.unpersist(reader);
                } else if ("ContentMetadata".equals(elemAttrib)) {
                    m_contentMeta.unpersist(reader);
                } else if ("ParseMetadata".equals(elemAttrib)) {
                    m_parseMeta.unpersist(reader);
                }
            } else if (XML_TAG_CONTENT.equals(elemTag)) {
                //m_content = new String(Base64.decodeBase64(reader.getElementText().getBytes()));
                m_content = reader.getElementText();
            }

            //TODO: Not reading the out links
        }
    }
}

From source file:com.amalto.core.load.xml.Selector.java

public void parse(StateContext context, XMLStreamReader reader) throws XMLStreamException {
    int next = reader.next();

    switch (next) {
    case XMLEvent.START_ELEMENT:
        context.setCurrent(StartElement.INSTANCE);
        break;//www  .  ja v a  2s  . c o m
    case XMLEvent.END_ELEMENT:
        /*
         * Switch to EndPayload only if we're at the level of begin payload.
         * If the document has the following structure:
         *
         * <root>
         *    <root>...</root>
         * </root>
         *
         * We want to end the payload for the top level <root> element, hence the depth == 1 condition.
         */
        if (context.getDepth() == 1
                && context.getPayLoadElementName().equals(reader.getName().getLocalPart())) {
            context.setCurrent(EndPayload.INSTANCE);
        } else {
            context.setCurrent(EndElement.INSTANCE);
        }
        break;
    case XMLEvent.CHARACTERS:
        context.setCurrent(Characters.INSTANCE);
        break;
    case XMLEvent.END_DOCUMENT:
        context.setCurrent(End.INSTANCE);
        break;
    case XMLEvent.COMMENT:
        // Ignore comment storage in MDM
        break;
    default:
        // Nothing to do?
        throw new NotImplementedException("Support for event id #" + next);
    }
}

From source file:jp.co.atware.solr.geta.GETAssocComponent.java

/**
 * GETAssoc?????<code>NamedList</code>???????
 * // w  w w. j a  v a 2s .c  o  m
 * @param inputStream GETAssoc??
 * @return <code>NamedList</code>?
 * @throws FactoryConfigurationError
 * @throws IOException
 */
protected NamedList<Object> convertResult(InputStream inputStream)
        throws FactoryConfigurationError, IOException {
    NamedList<Object> result = new NamedList<Object>();
    LinkedList<NamedList<Object>> stack = new LinkedList<NamedList<Object>>();
    stack.push(result);
    try {
        XMLStreamReader xml = XMLInputFactory.newInstance().createXMLStreamReader(inputStream);
        while (xml.hasNext()) {
            switch (xml.getEventType()) {
            case XMLStreamConstants.START_ELEMENT:
                NamedList<Object> element = new NamedList<Object>();
                stack.peek().add(xml.getName().toString(), element);
                stack.push(element);
                for (int i = 0; i < xml.getAttributeCount(); i++) {
                    String name = xml.getAttributeName(i).toString();
                    String value = xml.getAttributeValue(i);
                    ValueOf valueOf = valueTransMap.get(name);
                    if (valueOf != null) {
                        try {
                            element.add(name, valueOf.toValue(value));
                        } catch (NumberFormatException e) {
                            element.add(name, value);
                        }
                    } else {
                        element.add(name, value);
                    }
                }
                break;
            case XMLStreamConstants.END_ELEMENT:
                stack.pop();
                break;
            default:
                break;
            }
            xml.next();

        }
        xml.close();
    } catch (XMLStreamException e) {
        throw new IOException(e);
    }

    LOG.debug(result.toString());
    return result;
}

From source file:org.maodian.flyingcat.xmpp.codec.InfoQueryCodec.java

@Override
public Object decode(XMLStreamReader xmlsr) {
    try {/*from  w ww.j a  v a  2 s .co  m*/
        String id = xmlsr.getAttributeValue("", "id");
        String type = xmlsr.getAttributeValue("", "type");
        Builder builder = new Builder(id, type);

        String from = xmlsr.getAttributeValue("", "from");
        String to = xmlsr.getAttributeValue("", "to");
        String language = xmlsr.getAttributeValue(XMLConstants.XML_NS_URI, "lang");
        builder.from(from).to(to).language(language);

        switch (type) {
        case InfoQuery.GET:
        case InfoQuery.SET:
            if (xmlsr.nextTag() != XMLStreamConstants.START_ELEMENT) {
                throw new XmppException(StanzaErrorCondition.BAD_REQUEST);
            }
            QName key = xmlsr.getName();
            builder.payload(findDecoder(key, builder.build()).decode(xmlsr));
            break;
        case InfoQuery.RESULT:
            // do nothing
            break;
        case InfoQuery.ERROR:
            throw new IllegalStateException(
                    "Since this is a server, it should not dealing with incoming result and error");
        default:
            break;
        }
        return builder.build();
    } catch (XMLStreamException e) {
        throw new RuntimeException(e);
    }
}

From source file:iTests.framework.utils.WebuiTestUtils.java

/**
 * retrieves the license key from gigaspaces installation license key
 * @throws javax.xml.stream.FactoryConfigurationError
 * @throws javax.xml.stream.XMLStreamException
 * @throws java.io.IOException/*from  w w w . j  av  a2 s.  co m*/
 */
public String getLicenseKey() throws XMLStreamException, FactoryConfigurationError, IOException {

    String licensekey = LICENSE_PATH.replace("lib/required/../../", "");
    InputStream is = new FileInputStream(new File(licensekey));
    XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(is);
    int element;
    while (true) {
        element = parser.next();
        if (element == XMLStreamReader.START_ELEMENT) {
            if (parser.getName().toString().equals("licensekey")) {
                return parser.getElementText();
            }
        }
        if (element == XMLStreamReader.END_DOCUMENT) {
            break;
        }
    }
    return null;

}

From source file:com.microsoft.windowsazure.storage.table.TableParser.java

/**
 * Reserved for internal use. Parses the operation response as a collection of entities. Reads entity data from the
 * specified input stream using the specified class type and optionally projects each entity result with the
 * specified resolver into an {@link ODataPayload} containing a collection of {@link TableResult} objects.
 * /*from w  ww  .j av a 2  s.c om*/
 * @param inStream
 *            The <code>InputStream</code> to read the data to parse from.
 * @param clazzType
 *            The class type <code>T</code> implementing {@link TableEntity} for the entities returned. Set to
 *            <code>null</code> to ignore the returned entities and copy only response properties into the
 *            {@link TableResult} objects.
 * @param resolver
 *            An {@link EntityResolver} instance to project the entities into instances of type <code>R</code>. Set
 *            to <code>null</code> to return the entities as instances of the class type <code>T</code>.
 * @param opContext
 *            An {@link OperationContext} object used to track the execution of the operation.
 * @return
 *         An {@link ODataPayload} containing a collection of {@link TableResult} objects with the parsed operation
 *         response.
 * 
 * @throws XMLStreamException
 *             if an error occurs while accessing the stream.
 * @throws ParseException
 *             if an error occurs while parsing the stream.
 * @throws InstantiationException
 *             if an error occurs while constructing the result.
 * @throws IllegalAccessException
 *             if an error occurs in reflection while parsing the result.
 * @throws StorageException
 *             if a storage service error occurs.
 */
@SuppressWarnings("unchecked")
private static <T extends TableEntity, R> ODataPayload<?> parseAtomQueryResponse(final InputStream inStream,
        final Class<T> clazzType, final EntityResolver<R> resolver, final OperationContext opContext)
        throws XMLStreamException, ParseException, InstantiationException, IllegalAccessException,
        StorageException {
    ODataPayload<T> corePayload = null;
    ODataPayload<R> resolvedPayload = null;
    ODataPayload<?> commonPayload = null;

    if (resolver != null) {
        resolvedPayload = new ODataPayload<R>();
        commonPayload = resolvedPayload;
    } else {
        corePayload = new ODataPayload<T>();
        commonPayload = corePayload;
    }

    final XMLStreamReader xmlr = Utility.createXMLStreamReaderFromStream(inStream);
    int eventType = xmlr.getEventType();
    xmlr.require(XMLStreamConstants.START_DOCUMENT, null, null);
    eventType = xmlr.next();

    xmlr.require(XMLStreamConstants.START_ELEMENT, null, ODataConstants.FEED);
    // skip feed chars
    eventType = xmlr.next();

    while (xmlr.hasNext()) {
        eventType = xmlr.next();

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

        final String name = xmlr.getName().toString();

        if (eventType == XMLStreamConstants.START_ELEMENT) {
            if (name.equals(ODataConstants.BRACKETED_ATOM_NS + ODataConstants.ENTRY)) {
                final TableResult res = parseAtomEntity(xmlr, clazzType, resolver, opContext);
                if (corePayload != null) {
                    corePayload.tableResults.add(res);
                }

                if (resolver != null) {
                    resolvedPayload.results.add((R) res.getResult());
                } else {
                    corePayload.results.add((T) res.getResult());
                }
            }
        } else if (eventType == XMLStreamConstants.END_ELEMENT
                && name.equals(ODataConstants.BRACKETED_ATOM_NS + ODataConstants.FEED)) {
            break;
        }
    }

    xmlr.require(XMLStreamConstants.END_ELEMENT, null, ODataConstants.FEED);
    return commonPayload;
}