List of usage examples for javax.xml.stream XMLStreamReader next
public int next() 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(); if (XMLStreamUtil.isStartTag(reader)) { String tagLocalName = reader.getLocalName(); Namespace namespace = Namespace.getNamespace(reader.getNamespaceURI()); multiStatusResponse.add(new DefaultDavProperty(tagLocalName, reader.getElementText(), namespace)); }/*from ww w . j a v a 2 s . c o m*/ } }
From source file:com.microsoft.tfs.core.ws.runtime.types.StaxAnyContentType.java
@Override public void writeAsElement(final XMLStreamWriter writer, final String name) throws XMLStreamException { final Iterator i = getElementIterator(); /*/*from ww w .j a v a2 s .c o m*/ * Use the regular public iterator for reader access. */ for (; i.hasNext();) { final XMLStreamReader reader = (XMLStreamReader) i.next(); /* * Advance one event, beyond the start document, to get the first * element. */ reader.next(); StaxUtils.copyCurrentElement(reader, writer); reader.close(); } if (i instanceof Closable) { ((Closable) i).close(); } }
From source file:com.autonomy.aci.client.services.impl.AbstractStAXProcessorTest.java
@Test(expected = XMLStreamException.class) public void testForwardToNextStartElement() throws XMLStreamException { final XMLStreamReader mockXmlStreamReader = mock(XMLStreamReader.class); when(mockXmlStreamReader.hasNext()).thenReturn(true, true, true, true, false); when(mockXmlStreamReader.next()).thenReturn(XMLEvent.START_DOCUMENT, XMLEvent.START_ELEMENT, XMLEvent.END_ELEMENT, XMLEvent.END_DOCUMENT); try {/*w w w . j a v a 2 s . c o m*/ final AbstractStAXProcessor<?> abstractStAXProcessor = spy(AbstractStAXProcessor.class); abstractStAXProcessor.forwardToNextStartElement(mockXmlStreamReader); // Should work... abstractStAXProcessor.forwardToNextStartElement(mockXmlStreamReader); // Should iterate out and thrown exception... } finally { verify(mockXmlStreamReader, times(5)).hasNext(); verify(mockXmlStreamReader, times(4)).next(); verifyNoMoreInteractions(mockXmlStreamReader); } }
From source file:com.autonomy.aci.client.services.impl.AbstractStAXProcessorTest.java
@Test(expected = XMLStreamException.class) public void testForwardToNextStartOrEndElement() throws XMLStreamException { final XMLStreamReader mockXmlStreamReader = mock(XMLStreamReader.class); when(mockXmlStreamReader.hasNext()).thenReturn(true, true, true, true, false); when(mockXmlStreamReader.next()).thenReturn(XMLEvent.START_DOCUMENT, XMLEvent.START_ELEMENT, XMLEvent.END_ELEMENT, XMLEvent.END_DOCUMENT); try {/*from ww w . ja v a 2s.c o m*/ final AbstractStAXProcessor<?> abstractStAXProcessor = spy(AbstractStAXProcessor.class); abstractStAXProcessor.forwardToNextStartOrEndElement(mockXmlStreamReader); // Should work, start element... abstractStAXProcessor.forwardToNextStartOrEndElement(mockXmlStreamReader); // Should work, end element... abstractStAXProcessor.forwardToNextStartOrEndElement(mockXmlStreamReader); // Should iterate out and thrown exception... } finally { verify(mockXmlStreamReader, times(5)).hasNext(); verify(mockXmlStreamReader, times(4)).next(); verifyNoMoreInteractions(mockXmlStreamReader); } }
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 *//* www . ja v a 2s .co m*/ 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:com.autonomy.aci.client.services.impl.AbstractStAXProcessorTest.java
@Test(expected = XMLStreamException.class) public void testForwardToNamedStartElement() throws XMLStreamException { final XMLStreamReader mockXmlStreamReader = mock(XMLStreamReader.class); when(mockXmlStreamReader.hasNext()).thenReturn(true, true, true, true, true, true, false); when(mockXmlStreamReader.next()).thenReturn(XMLEvent.START_DOCUMENT, XMLEvent.START_ELEMENT, XMLEvent.END_ELEMENT, XMLEvent.START_ELEMENT, XMLEvent.END_ELEMENT, XMLEvent.END_DOCUMENT); when(mockXmlStreamReader.getLocalName()).thenReturn("wibble", "wobble"); try {//from w w w . j a va 2s .co m final AbstractStAXProcessor<?> abstractStAXProcessor = spy(AbstractStAXProcessor.class); abstractStAXProcessor.forwardToNamedStartElement("wibble", mockXmlStreamReader); // Should work abstractStAXProcessor.forwardToNamedStartElement("wibble", mockXmlStreamReader); // Should iterate out and thrown exception... } finally { verify(mockXmlStreamReader, times(7)).hasNext(); verify(mockXmlStreamReader, times(6)).next(); verify(mockXmlStreamReader, times(2)).getLocalName(); verifyNoMoreInteractions(mockXmlStreamReader); } }
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(); 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;/*w w w. jav a 2 s. com*/ } } else if ("prop".equals(tagLocalName) && propstatStatus == HttpStatus.SC_OK) { handleProperty(reader, multiStatusResponse); } } } }
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 */// w w w .j a va 2 s . co 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:davmail.exchange.dav.ExchangePropPatchMethod.java
protected void handleResponse(XMLStreamReader reader) throws XMLStreamException { String href = null;// w ww .j a v a 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)) { MultiStatusResponse multiStatusResponse = new MultiStatusResponse(href, responseStatus); handlePropstat(reader, multiStatusResponse); responses.add(multiStatusResponse); } } } }
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(); } else {/*from w w w . jav a2s . c om*/ 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()); }