List of usage examples for javax.xml.stream XMLStreamReader hasNext
public boolean hasNext() throws XMLStreamException;
From source file:davmail.exchange.dav.ExchangePropPatchMethod.java
protected void handleProperty(XMLStreamReader reader, MultiStatusResponse multiStatusResponse) throws XMLStreamException { while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "prop")) { reader.next();/*from ww w. ja va 2 s. com*/ if (XMLStreamUtil.isStartTag(reader)) { String tagLocalName = reader.getLocalName(); Namespace namespace = Namespace.getNamespace(reader.getNamespaceURI()); multiStatusResponse.add(new DefaultDavProperty(tagLocalName, reader.getElementText(), namespace)); } } }
From source file:davmail.exchange.dav.ExchangeDavMethod.java
protected String getTagContent(XMLStreamReader reader) throws XMLStreamException { String value = null;//from w w w.j av a2 s. com 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:com.autonomy.aci.client.services.impl.AbstractStAXProcessor.java
/** * Forwards through the stream looking for the an element with <tt>elementName</tt> * @param elementName The name of the element to find. * @param xmlStreamReader The stream to forward through * @throws XMLStreamException If there was an error using the stream, or if no element with <tt>elementName</tt> * could be found *///from w ww. java 2 s .co m protected void forwardToNamedStartElement(final String elementName, final XMLStreamReader xmlStreamReader) throws XMLStreamException { while (xmlStreamReader.hasNext()) { final int eventType = xmlStreamReader.next(); if ((eventType == XMLEvent.START_ELEMENT) && (elementName.equals(xmlStreamReader.getLocalName()))) { return; } } throw new XMLStreamException("Unable to find a start element for, " + elementName); }
From source file:davmail.exchange.dav.ExchangeDavMethod.java
protected void handlePropstat(XMLStreamReader reader, MultiStatusResponse multiStatusResponse) throws XMLStreamException { int propstatStatus = 0; while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "propstat")) { reader.next();/* www . j a v a 2 s . co m*/ if (XMLStreamUtil.isStartTag(reader)) { String tagLocalName = reader.getLocalName(); if ("status".equals(tagLocalName)) { if ("HTTP/1.1 200 OK".equals(reader.getElementText())) { propstatStatus = HttpStatus.SC_OK; } else { propstatStatus = 0; } } else if ("prop".equals(tagLocalName) && propstatStatus == HttpStatus.SC_OK) { handleProperty(reader, multiStatusResponse); } } } }
From source file:davmail.exchange.dav.ExchangePropPatchMethod.java
protected void handleResponse(XMLStreamReader reader) throws XMLStreamException { String href = null;/*w w w . j ava2 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)) { MultiStatusResponse multiStatusResponse = new MultiStatusResponse(href, responseStatus); handlePropstat(reader, multiStatusResponse); responses.add(multiStatusResponse); } } } }
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 w w .j a 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:com.hp.mqm.clt.XmlProcessorTest.java
private void assertXml(List<TestResult> expectedTestResults, Set<XmlElement> expectedElements, File xmlFile) throws FileNotFoundException, XMLStreamException { FileInputStream fis = new FileInputStream(xmlFile); XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlInputFactory.setProperty("javax.xml.stream.isCoalescing", true); XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(fis); boolean isFirstEvent = true; while (xmlStreamReader.hasNext()) { if (!isFirstEvent) { xmlStreamReader.next();/*from ww w . j a va 2 s. c o m*/ } else { isFirstEvent = false; } if (xmlStreamReader.getEventType() == XMLStreamReader.START_ELEMENT) { String localName = xmlStreamReader.getLocalName(); if ("taxonomy".equals(localName)) { assertElement(localName, false, xmlStreamReader, expectedElements); } else if ("test_field".equals(localName)) { assertElement(localName, false, xmlStreamReader, expectedElements); } else if ("product_area_ref".equals(localName)) { assertElement(localName, true, xmlStreamReader, expectedElements); } else if ("backlog_item_ref".equals(localName)) { assertElement(localName, true, xmlStreamReader, expectedElements); } else if ("release_ref".equals(localName)) { assertElement(localName, true, xmlStreamReader, expectedElements); } else if ("test_run".equals(localName)) { assertXmlTest(xmlStreamReader, expectedTestResults); } } } xmlStreamReader.close(); IOUtils.closeQuietly(fis); Assert.assertTrue(expectedElements.isEmpty()); Assert.assertTrue(expectedTestResults.isEmpty()); }
From source file:de.tuebingen.uni.sfs.germanet.api.WiktionaryLoader.java
/** * Loads <code>WiktionaryParaphrases</code> from the given streams into this * <code>WiktionaryLoader</code>'s <code>GermaNet</code> object. * @param inputStreams the list of streams containing <code>WiktionaryParaphrases</code> data * @param xmlNames the names of the streams * @throws javax.xml.stream.XMLStreamException *///from ww w.jav a 2 s . c o m protected void loadWiktionary(List<InputStream> inputStreams, List<String> xmlNames) throws XMLStreamException { for (int i = 0; i < inputStreams.size(); i++) { if (xmlNames.get(i).startsWith("wiktionary")) { logger.debug("Loading input stream " + xmlNames.get(i) + "..."); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader parser = factory.createXMLStreamReader(inputStreams.get(i)); 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 w w w .ja v a2 s .c om 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:davmail.exchange.dav.ExchangeDavMethod.java
protected void handleResponse(XMLStreamReader reader) throws XMLStreamException { MultiStatusResponse multiStatusResponse = null; String href = null;//from w w w . j a va 2s . 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); } }