List of usage examples for javax.xml.stream XMLStreamReader next
public int next() throws XMLStreamException;
From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.ddi.DDIFileReader.java
private void processDimensns(XMLStreamReader xmlr, SDIOMetadata smd) throws XMLStreamException { for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) { if (event == XMLStreamConstants.START_ELEMENT) { if (xmlr.getLocalName().equals("caseQnty")) { try { setCaseQnty(new Integer(parseText(xmlr))); } catch (NumberFormatException ex) { throw new XMLStreamException( "Invalid case quantity value in codeBook/fileDscr/fileTxt/dimensns: " + parseText(xmlr)); }//from w w w . j a v a2 s . c o m } else if (xmlr.getLocalName().equals("varQnty")) { try { setVarQnty(new Integer(parseText(xmlr))); } catch (NumberFormatException ex) { throw new XMLStreamException( "Invalid variable quantity value in codeBook/fileDscr/fileTxt/dimensns: " + parseText(xmlr)); } } else if (xmlr.getLocalName().equals("recPrCas")) { throw new XMLStreamException( "recPrCas (Records per Case) not supported for this type of data ingest, yet"); } else { throw new XMLStreamException( "Unsupported DDI Element: codeBook/fileDscr/fileTxt/dimensns/" + xmlr.getLocalName()); } } else if (event == XMLStreamConstants.END_ELEMENT) {// </codeBook> if (xmlr.getLocalName().equals("dimensns")) { return; } else { throw new XMLStreamException( "Mismatched DDI Formatting: </dimensns> expected, found " + xmlr.getLocalName()); } } } }
From source file:davmail.exchange.ews.EWSMethod.java
private void handleItems(XMLStreamReader reader) throws XMLStreamException { while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, responseCollectionName)) { reader.next(); if (XMLStreamUtil.isStartTag(reader)) { responseItems.add(handleItem(reader)); }/*ww w .ja v a 2 s. c om*/ } }
From source file:net.landora.animeinfo.mylistreader.ListReader.java
public boolean download(InputStream input) throws Throwable { TarInputStream is = null;//from w w w . j av a 2 s .c o m try { is = new TarInputStream(new GZIPInputStream(input)); TarEntry entry; while ((entry = is.getNextEntry()) != null) { if (!entry.getName().equalsIgnoreCase("mylist.xml")) { continue; } XMLStreamReader reader = XMLInputFactory.newFactory().createXMLStreamReader(is); reader.nextTag(); reader.require(XMLStreamReader.START_ELEMENT, null, "my_anime_list"); values = new HashMap<String, String>(); StringBuilder value = new StringBuilder(); while (reader.nextTag() != XMLStreamReader.END_ELEMENT) { reader.require(XMLStreamReader.START_ELEMENT, null, null); String tableName = reader.getLocalName(); values.clear(); while (reader.nextTag() != XMLStreamReader.END_ELEMENT) { String valueName = reader.getLocalName(); value.setLength(0); while (reader.next() != XMLStreamReader.END_ELEMENT) { switch (reader.getEventType()) { case XMLStreamReader.CDATA: case XMLStreamReader.CHARACTERS: case XMLStreamReader.SPACE: value.append(reader.getText()); } } reader.require(XMLStreamReader.END_ELEMENT, null, valueName); values.put(valueName, value.toString()); } reader.require(XMLStreamReader.END_ELEMENT, null, tableName); handleTable(tableName); } reader.require(XMLStreamReader.END_ELEMENT, null, "my_anime_list"); saveLast(); } return true; } finally { if (is != null) { IOUtils.closeQuietly(is); } else if (input != null) { IOUtils.closeQuietly(input); } } }
From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.ddi.DDIFileReader.java
private void processDataDscr(XMLStreamReader xmlr, SDIOMetadata smd) throws XMLStreamException { int variableCounter = 0; for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) { if (event == XMLStreamConstants.START_ELEMENT) { if (xmlr.getLocalName().equals("var")) { processVar(xmlr, smd, variableCounter); variableCounter++;/*from www . j a v a2 s . com*/ } else { throw new XMLStreamException( "Unsupported element in the DDI: codeBook/dataDscr/" + xmlr.getLocalName()); } } else if (event == XMLStreamConstants.END_ELEMENT) { if (xmlr.getLocalName().equals("dataDscr")) { dbgLog.info("processed dataDscr section"); return; } else { throw new XMLStreamException( "Mismatched DDI Formatting: </dataDscr> expected, found " + xmlr.getLocalName()); } } } }
From source file:davmail.exchange.ews.EWSMethod.java
protected void handleEmailAddresses(XMLStreamReader reader, Item item) throws XMLStreamException { while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "EmailAddresses"))) { reader.next(); if (XMLStreamUtil.isStartTag(reader)) { String tagLocalName = reader.getLocalName(); if ("Entry".equals(tagLocalName)) { item.put(reader.getAttributeValue(null, "Key"), XMLStreamUtil.getElementText(reader)); }/* w ww.j a v a 2s . c om*/ } } }
From source file:davmail.exchange.ews.EWSMethod.java
protected void handleModifiedOccurrences(XMLStreamReader reader, Item item) throws XMLStreamException { while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "ModifiedOccurrences"))) { reader.next(); if (XMLStreamUtil.isStartTag(reader)) { String tagLocalName = reader.getLocalName(); if ("Occurrence".equals(tagLocalName)) { handleOccurrence(reader, item); }//from w w w .j ava 2 s . co m } } }
From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.ddi.DDIFileReader.java
private void processInvalrng(XMLStreamReader xmlr, SDIOMetadata smd, String variableName) throws XMLStreamException { for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) { if (event == XMLStreamConstants.START_ELEMENT) { if (xmlr.getLocalName().equals("item")) { // Ranges -- not supported? (TODO) //VariableRange range = new VariableRange(); //dv.getInvalidRanges().add(range); //range.setDataVariable(dv); //range.setBeginValue( xmlr.getAttributeValue(null, "VALUE") ); //range.setBeginValueType(varService.findVariableRangeTypeByName( variableRangeTypeList, DB_VAR_RANGE_TYPE_POINT ) ); String invalidValue = xmlr.getAttributeValue(null, "VALUE"); // STORE (?) // TODO: // Figure out what to do with these. // Aren't the same values specified as "MISSING" in the // categories? What's the difference? -- otherwise this // is kind of redundant. //} else if (xmlr.getLocalName().equals("range")) { // ... } } else { throw new XMLStreamException( "Unsupported DDI Element: codeBook/dataDscr/var/invalrng/" + xmlr.getLocalName()); }//from www . j av a2 s. c o m } else if (event == XMLStreamConstants.END_ELEMENT) { if (xmlr.getLocalName().equals("invalrng")) { return; } else if (xmlr.getLocalName().equals("item")) { // continue; } else { throw new XMLStreamException( "Mismatched DDI Formatting: </invalrng> expected, found " + xmlr.getLocalName()); } } } }
From source file:net.landora.anidb.mylist.ListReader.java
public boolean download(InputStream input) throws Throwable { TarInputStream is = null;// w w w.j a v a 2 s .c o m try { is = new TarInputStream(new GZIPInputStream(input)); TarEntry entry; while ((entry = is.getNextEntry()) != null) { if (!entry.getName().equalsIgnoreCase("mylist.xml")) { continue; } XMLStreamReader reader = XMLInputFactory.newFactory().createXMLStreamReader(is); reader.nextTag(); reader.require(XMLStreamReader.START_ELEMENT, null, "my_anime_list"); values = new HashMap<>(); StringBuilder value = new StringBuilder(); while (reader.nextTag() != XMLStreamReader.END_ELEMENT) { reader.require(XMLStreamReader.START_ELEMENT, null, null); String tableName = reader.getLocalName(); values.clear(); while (reader.nextTag() != XMLStreamReader.END_ELEMENT) { String valueName = reader.getLocalName(); value.setLength(0); while (reader.next() != XMLStreamReader.END_ELEMENT) { switch (reader.getEventType()) { case XMLStreamReader.CDATA: case XMLStreamReader.CHARACTERS: case XMLStreamReader.SPACE: value.append(reader.getText()); } } reader.require(XMLStreamReader.END_ELEMENT, null, valueName); values.put(valueName, value.toString()); } reader.require(XMLStreamReader.END_ELEMENT, null, tableName); handleTable(tableName); } reader.require(XMLStreamReader.END_ELEMENT, null, "my_anime_list"); saveLast(); } return true; } finally { if (is != null) { IOUtils.closeQuietly(is); } else if (input != null) { IOUtils.closeQuietly(input); } } }
From source file:davmail.exchange.ews.EWSMethod.java
protected void handleAttendees(XMLStreamReader reader, Item item, String attendeeType) throws XMLStreamException { while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, attendeeType))) { reader.next(); if (XMLStreamUtil.isStartTag(reader)) { String tagLocalName = reader.getLocalName(); if ("Attendee".equals(tagLocalName)) { handleAttendee(reader, item, attendeeType); }// w ww . j a v a 2 s . c om } } }
From source file:de.tuebingen.uni.sfs.germanet.api.IliLoader.java
/** * Returns the <code>IliRecord</code> for which the start tag was just encountered. * @param parser the <code>parser</code> being used on the current file * @return a <code>IliRecord</code> representing the data parsed * @throws javax.xml.stream.XMLStreamException *//*from w w w. j a v a2s . c o m*/ private IliRecord processIliRecord(XMLStreamReader parser) throws XMLStreamException { int lexUnitId; String ewnRelation; String pwnWord; String pwn20Id; String pwn30Id; String pwn20paraphrase = ""; String source; IliRecord curIli; List<String> englishSynonyms = new ArrayList<String>(); boolean done = false; int event; String nodeName; lexUnitId = Integer.valueOf(parser.getAttributeValue(namespace, GermaNet.XML_LEX_UNIT_ID).substring(1)); ewnRelation = parser.getAttributeValue(namespace, GermaNet.XML_EWN_RELATION); pwnWord = parser.getAttributeValue(namespace, GermaNet.XML_PWN_WORD); pwn20Id = parser.getAttributeValue(namespace, GermaNet.XML_PWN20_ID); pwn30Id = parser.getAttributeValue(namespace, GermaNet.XML_PWN30_ID); pwn20paraphrase = parser.getAttributeValue(namespace, GermaNet.XML_PWN20_PARAPHRASE); source = parser.getAttributeValue(namespace, GermaNet.XML_SOURCE); // process this lexUnit while (parser.hasNext() && !done) { event = parser.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: nodeName = parser.getLocalName(); if (nodeName.equals(GermaNet.XML_PWN20_SYNONYM)) { englishSynonyms.add(processEnglishSynonyms(parser)); } case XMLStreamConstants.END_ELEMENT: nodeName = parser.getLocalName(); // quit when we reach the end lexUnit tag if (nodeName.equals(GermaNet.XML_ILI_RECORD)) { done = true; } break; } } curIli = new IliRecord(lexUnitId, EwnRel.valueOf(ewnRelation), pwnWord, pwn20Id, pwn30Id, pwn20paraphrase, source); for (String synonym : englishSynonyms) { curIli.addEnglishSynonym(synonym); } return curIli; }