Example usage for javax.xml.stream XMLStreamReader getAttributeValue

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

Introduction

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

Prototype

public String getAttributeValue(int index);

Source Link

Document

Returns the value of the attribute at the index

Usage

From source file:jodtemplate.io.xml.ContentTypesReader.java

private DefaultElement createDefaultElement(final XMLStreamReader xmlStreamReader) {
    final DefaultElement defaultElement = new DefaultElement();
    for (int index = 0; index < xmlStreamReader.getAttributeCount(); ++index) {
        final String attributeName = xmlStreamReader.getAttributeName(index).getLocalPart();
        final String attributeNS = xmlStreamReader.getAttributeName(index).getNamespaceURI();
        if (OOXMLDocument.CONTENT_TYPE_ATTRIBUTE.equals(attributeName) && StringUtils.isBlank(attributeNS)) {
            defaultElement.setContentType(xmlStreamReader.getAttributeValue(index));
        } else if (OOXMLDocument.EXTENSION_ATTRIBUTE.equals(attributeName)
                && StringUtils.isBlank(attributeNS)) {
            defaultElement.setExtension(xmlStreamReader.getAttributeValue(index));
        }//  w  w  w .  j  a  va2s  .  c o  m
    }
    return defaultElement;
}

From source file:net.solarnetwork.util.JavaBeanXmlSerializer.java

private void parseElement(Map<String, Object> result, XMLStreamReader reader) {
    int attrCount = reader.getAttributeCount();
    for (int i = 0; i < attrCount; i++) {
        String name = reader.getAttributeLocalName(i);
        String val = reader.getAttributeValue(i);
        putMapValue(result, name, val);
    }//from   w  w w  . ja v  a2  s .c o m
}

From source file:jodtemplate.io.xml.ContentTypesReader.java

private OverrideElement createOverrideElement(final XMLStreamReader xmlStreamReader) {
    final OverrideElement overrideElement = new OverrideElement();
    for (int index = 0; index < xmlStreamReader.getAttributeCount(); ++index) {
        final String attributeName = xmlStreamReader.getAttributeName(index).getLocalPart();
        final String attributeNS = xmlStreamReader.getAttributeName(index).getNamespaceURI();
        if (OOXMLDocument.CONTENT_TYPE_ATTRIBUTE.equals(attributeName) && StringUtils.isBlank(attributeNS)) {
            overrideElement.setContentType(xmlStreamReader.getAttributeValue(index));
        } else if (OOXMLDocument.PART_NAME_ATTRIBUTE.equals(attributeName)
                && StringUtils.isBlank(attributeNS)) {
            overrideElement.setPartName(xmlStreamReader.getAttributeValue(index));
        }//  w  w w .  j a v  a  2 s  .c  om
    }
    return overrideElement;
}

From source file:hudson.plugins.report.jck.parsers.JtregReportParser.java

private String findAttributeValue(XMLStreamReader in, String name) {
    int count = in.getAttributeCount();
    for (int i = 0; i < count; i++) {
        if (name.equals(in.getAttributeLocalName(i))) {
            return in.getAttributeValue(i);
        }//from ww w  .j ava2 s.  c o m
    }
    return null;
}

From source file:Main.java

/**
 * Borrowed from org.apache.xml.security.test.stax.utils.XmlReaderToWriter
 *///from   w ww .  j  a v a  2  s .c  om
public static void write(XMLStreamReader xmlr, XMLStreamWriter writer) throws XMLStreamException {
    switch (xmlr.getEventType()) {
    case XMLEvent.START_ELEMENT:
        final String localName = xmlr.getLocalName();
        final String namespaceURI = xmlr.getNamespaceURI();
        if (namespaceURI != null && namespaceURI.length() > 0) {
            final String prefix = xmlr.getPrefix();
            if (prefix != null) {
                writer.writeStartElement(prefix, localName, namespaceURI);
            } else {
                writer.writeStartElement(namespaceURI, localName);
            }
        } else {
            writer.writeStartElement(localName);
        }

        for (int i = 0, len = xmlr.getNamespaceCount(); i < len; i++) {
            String prefix = xmlr.getNamespacePrefix(i);
            if (prefix == null) {
                writer.writeDefaultNamespace(xmlr.getNamespaceURI(i));
            } else {
                writer.writeNamespace(prefix, xmlr.getNamespaceURI(i));
            }
        }

        for (int i = 0, len = xmlr.getAttributeCount(); i < len; i++) {
            final String attUri = xmlr.getAttributeNamespace(i);

            if (attUri != null && attUri.length() > 0) {
                final String prefix = xmlr.getAttributePrefix(i);
                if (prefix != null) {
                    writer.writeAttribute(prefix, attUri, xmlr.getAttributeLocalName(i),
                            xmlr.getAttributeValue(i));
                } else {
                    writer.writeAttribute(attUri, xmlr.getAttributeLocalName(i), xmlr.getAttributeValue(i));
                }
            } else {
                writer.writeAttribute(xmlr.getAttributeLocalName(i), xmlr.getAttributeValue(i));
            }

        }
        break;
    case XMLEvent.END_ELEMENT:
        writer.writeEndElement();
        break;
    case XMLEvent.SPACE:
    case XMLEvent.CHARACTERS:
        char[] text = new char[xmlr.getTextLength()];
        xmlr.getTextCharacters(0, text, 0, xmlr.getTextLength());
        writer.writeCharacters(text, 0, text.length);
        break;
    case XMLEvent.PROCESSING_INSTRUCTION:
        writer.writeProcessingInstruction(xmlr.getPITarget(), xmlr.getPIData());
        break;
    case XMLEvent.CDATA:
        writer.writeCData(xmlr.getText());
        break;
    case XMLEvent.COMMENT:
        writer.writeComment(xmlr.getText());
        break;
    case XMLEvent.ENTITY_REFERENCE:
        writer.writeEntityRef(xmlr.getLocalName());
        break;
    case XMLEvent.START_DOCUMENT:
        String encoding = xmlr.getCharacterEncodingScheme();
        String version = xmlr.getVersion();

        if (encoding != null && version != null) {
            writer.writeStartDocument(encoding, version);
        } else if (version != null) {
            writer.writeStartDocument(xmlr.getVersion());
        }
        break;
    case XMLEvent.END_DOCUMENT:
        writer.writeEndDocument();
        break;
    case XMLEvent.DTD:
        writer.writeDTD(xmlr.getText());
        break;
    }
}

From source file:at.lame.hellonzb.parser.NzbParser.java

/**
 * This private method is used to create a new instance of DownloadFileSegment.
 * /*www  .  jav a  2 s .c om*/
 * @param parser The parser object to query (XMLStreamReader)
 * @param file The current DownloadFile object
 * @return The new DownloadFileSegment object
 */
private DownloadFileSegment newDownloadFileSegment(XMLStreamReader parser, DownloadFile file) {
    long bytes = 0;
    int index = 0;

    for (int i = 0; i < parser.getAttributeCount(); i++) {
        String attName = parser.getAttributeLocalName(i).toLowerCase();
        if (attName.equals("bytes"))
            bytes = Long.parseLong(parser.getAttributeValue(i));
        else if (attName.equals("number"))
            index = Integer.parseInt(parser.getAttributeValue(i));
    }

    return new DownloadFileSegment(file, bytes, index, file.getGroups());
}

From source file:at.lame.hellonzb.parser.NzbParser.java

/**
 * This private method is used to create a new instance of DownloadFile.
 * //  w ww . ja  v  a 2  s . co m
 * @param parser The parser object to query (XMLStreamReader)
 * @return The new DownloadFile object
 */
private DownloadFile newDownloadFile(XMLStreamReader parser) {
    String poster = "";
    String date = "";
    String subject = "";

    for (int i = 0; i < parser.getAttributeCount(); i++) {
        String attName = parser.getAttributeLocalName(i).toLowerCase();
        if (attName.equals("poster"))
            poster = parser.getAttributeValue(i);
        else if (attName.equals("date"))
            date = parser.getAttributeValue(i);
        else if (attName.equals("subject"))
            subject = parser.getAttributeValue(i);
    }

    return new DownloadFile(poster, date, subject, HelloNzbToolkit.getLastFilename(name));
}

From source file:ar.com.zauber.commons.spring.test.impl.TamperdataHttpServletRequestFactory.java

/** hace el trabajo sucio 
 * @throws UnsupportedEncodingException */
private HttpServletRequest parse(final XMLStreamReader reader)
        throws XMLStreamException, UnsupportedEncodingException {
    final MockHttpServletRequest ret = new MockHttpServletRequest();
    ret.setMethod("POST");
    String header = null;/* w  ww .  j a  v a 2 s . c o  m*/
    String postHeader = null;
    int event;
    while ((event = reader.next()) != XMLStreamConstants.END_DOCUMENT) {
        if (event == XMLStreamConstants.START_ELEMENT) {
            final String name = reader.getLocalName();
            if (name.equals("tdRequestHeader") || name.equals("tdPostHeader")) {
                header = reader.getAttributeValue(0);
            } else if (name.equals("tdPostElements")) {
                ret.setMethod("POST");
            } else if (name.equals("tdPostElement")) {
                postHeader = reader.getAttributeValue(0);
            }
        } else if (event == XMLStreamConstants.CHARACTERS) {
            String text = reader.getText();
            if (text.length() > 1 && Character.isWhitespace(text.charAt(0))) {
                text = text.substring(1);
            }
            if (text.length() > 1 && Character.isWhitespace(text.charAt(text.length() - 1))) {
                text = text.substring(0, text.length() - 1);
            }

            final String value = URLDecoder.decode(URLDecoder.decode(text, encoding), encoding);
            if (header != null) {
                ret.addHeader(header, value);
            } else if (postHeader != null) {
                ret.addParameter(postHeader, value);
            }
            header = null;
            postHeader = null;
        } else {
            header = null;
            postHeader = null;
        }
    }
    reader.close();
    return ret;
}

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();/*  w  ww.j av  a 2s.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:edu.indiana.d2i.htrc.portal.HTRCAgentClient.java

private JobDetailsBean parseJobSubmit(InputStream stream) throws XMLStreamException {
    JobDetailsBean res = new JobDetailsBean();
    XMLStreamReader parser = factory.createXMLStreamReader(stream);
    while (parser.hasNext()) {
        int event = parser.next();
        if (event == XMLStreamConstants.START_ELEMENT) {
            if (parser.hasName()) {
                // only parse several attributes
                if (parser.getLocalName().equals(JobDetailsBean.STATUS)) {
                    res.setJobStatus(parser.getAttributeValue(0));
                } else if (parser.getLocalName().equals(JobDetailsBean.JOBID)) {
                    res.setJobId(parser.getElementText());
                } else if (parser.getLocalName().equals(JobDetailsBean.JOBNAME)) {
                    res.setJobTitle(parser.getElementText());
                } else if (parser.getLocalName().equals(JobDetailsBean.DATE)) {
                    res.setLastUpdatedDate(parser.getElementText());
                } else if (parser.getLocalName().equals(JobDetailsBean.USER)) {
                    res.setUserName(parser.getElementText());
                }//  w w  w  . jav a2s.  c om
            }
        }
    }
    return res;
}