List of usage examples for javax.xml.stream XMLStreamReader next
public int next() throws XMLStreamException;
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 w w w .jav a2 s .c om*/ 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."); }
From source file:edu.harvard.iq.dvn.core.analysis.NetworkDataServiceBean.java
private void processXML(String fileName, NetworkDataFile ndf) throws XMLStreamException, IOException { File file = new File(fileName); FileReader fileReader = new FileReader(file); javax.xml.stream.XMLInputFactory xmlif = javax.xml.stream.XMLInputFactory.newInstance(); xmlif.setProperty("javax.xml.stream.isCoalescing", java.lang.Boolean.TRUE); XMLStreamReader xmlr = xmlif.createXMLStreamReader(fileReader); for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) { if (event == XMLStreamConstants.START_ELEMENT) { if (xmlr.getLocalName().equals("key")) processKey(xmlr, ndf);//from w w w .j a v a2s .c om else if (xmlr.getLocalName().equals("graph")) processGraph(xmlr, ndf); } else if (event == XMLStreamConstants.END_ELEMENT) { if (xmlr.getLocalName().equals("graphml")) return; } } // If #nodes and #edges is not set, then go thru list to count them }
From source file:babel.content.pages.Page.java
public void unpersist(XMLStreamReader reader) throws XMLStreamException { String elemTag;/*from w w w . j a va2s . c o m*/ 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:edu.harvard.iq.dvn.core.analysis.NetworkDataServiceBean.java
private void processGraph(XMLStreamReader xmlr, NetworkDataFile ndf) throws XMLStreamException { for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) { if (event == XMLStreamConstants.START_ELEMENT) { if (xmlr.getLocalName().equals("node")) { Long caseQuantity = ndf.getVertexDataTable().getCaseQuantity(); if (caseQuantity == null) { caseQuantity = new Long(0); }/* ww w.j a v a 2s . co m*/ caseQuantity++; ndf.getVertexDataTable().setCaseQuantity(caseQuantity); } else if (xmlr.getLocalName().equals("edge")) { Long caseQuantity = ndf.getEdgeDataTable().getCaseQuantity(); if (caseQuantity == null) { caseQuantity = new Long(0); } caseQuantity++; ndf.getEdgeDataTable().setCaseQuantity(caseQuantity); } } else if (event == XMLStreamConstants.END_ELEMENT) { if (xmlr.getLocalName().equals("graph")) { ndf.getEdgeDataTable() .setVarQuantity(new Long(ndf.getEdgeDataTable().getDataVariables().size())); ndf.getVertexDataTable() .setVarQuantity(new Long(ndf.getVertexDataTable().getDataVariables().size())); return; } } } }
From source file:davmail.exchange.dav.ExchangeDavMethod.java
protected void handleResponse(XMLStreamReader reader) throws XMLStreamException { MultiStatusResponse multiStatusResponse = null; String href = null;//from w w w.ja va 2 s. c o m String responseStatus = ""; while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "response")) { reader.next(); if (XMLStreamUtil.isStartTag(reader)) { String tagLocalName = reader.getLocalName(); if ("href".equals(tagLocalName)) { href = reader.getElementText(); } else if ("status".equals(tagLocalName)) { responseStatus = reader.getElementText(); } else if ("propstat".equals(tagLocalName)) { if (multiStatusResponse == null) { multiStatusResponse = new MultiStatusResponse(href, responseStatus); } handlePropstat(reader, multiStatusResponse); } } } if (multiStatusResponse != null) { responses.add(multiStatusResponse); } }
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. * //ww w . j a v 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; }
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 w w w . j a v a 2 s. 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:Main.java
public static void dumpXML(XMLStreamReader parser) throws XMLStreamException { int depth = 0; do {//from w ww . jav a2 s .co m switch (parser.getEventType()) { case XMLStreamConstants.START_ELEMENT: for (int i = 1; i < depth; ++i) { System.out.print(" "); } System.out.print("<"); System.out.print(parser.getLocalName()); for (int i = 0; i < parser.getAttributeCount(); ++i) { System.out.print(" "); System.out.print(parser.getAttributeLocalName(i)); System.out.print("=\""); System.out.print(parser.getAttributeValue(i)); System.out.print("\""); } System.out.println(">"); ++depth; break; case XMLStreamConstants.END_ELEMENT: --depth; for (int i = 1; i < depth; ++i) { System.out.print(" "); } System.out.print("</"); System.out.print(parser.getLocalName()); System.out.println(">"); break; case XMLStreamConstants.CHARACTERS: for (int i = 1; i < depth; ++i) { System.out.print(" "); } System.out.println(parser.getText()); break; } if (depth > 0) parser.next(); } while (depth > 0); }
From source file:edu.indiana.d2i.htrc.portal.HTRCAgentClient.java
private boolean parseJobDeleteResponse(InputStream stream) throws XMLStreamException { XMLStreamReader parser = factory.createXMLStreamReader(stream); while (parser.hasNext()) { int event = parser.next(); if (event == XMLStreamConstants.START_ELEMENT) { if (parser.hasName()) { String localName = parser.getLocalName(); if (localName.equals("success")) return true; else { log.error(parser.getElementText()); return false; }/*from www . j a v a 2s . c o m*/ } } } return false; }
From source file:hudson.plugins.report.jck.parsers.JtregReportParser.java
private String findStatusLine(XMLStreamReader in) throws Exception { while (in.hasNext()) { int event = in.next(); if (event == END_ELEMENT && PROPERTIES.equals(in.getLocalName())) { break; }/* w w w . j ava 2s.c o m*/ if (event == START_ELEMENT && "property".equals(in.getLocalName())) { if ("execStatus".equals(findAttributeValue(in, "name"))) { return findAttributeValue(in, "value"); } } } return ""; }