List of usage examples for javax.xml.stream XMLStreamReader getLocalName
public String getLocalName();
From source file:com.microsoft.tfs.core.memento.XMLMemento.java
/** * Reads the current element from the given reader and returns the * {@link XMLMemento} read from its data. The {@link XMLStreamReader} must * be positioned at {@link XMLStreamConstants#START_ELEMENT}. * * @param reader/* w ww . java2s.c o m*/ * the reader (must not be <code>null</code>) * @return the {@link XMLMemento} read from the stream * @throws XMLStreamException * if an error occurred reading from the reader */ private synchronized void readFromElement(final XMLStreamReader reader) throws XMLStreamException { Check.notNull(reader, "reader"); //$NON-NLS-1$ /* * Read all the attributes from the current element. */ final int attributeCount = reader.getAttributeCount(); for (int i = 0; i < attributeCount; i++) { putString(reader.getAttributeLocalName(i), reader.getAttributeValue(i)); } /* * Process child nodes (which may be text or child Mementos). */ String localName; int event; do { event = reader.next(); if (event == XMLStreamConstants.START_ELEMENT) { localName = reader.getLocalName(); final XMLMemento child = (XMLMemento) createChild(localName); child.readFromElement(reader); } else if (event == XMLStreamConstants.CHARACTERS) { putTextData(reader.getText()); } } while (event != XMLStreamConstants.END_ELEMENT); }
From source file:davmail.exchange.ews.EWSMethod.java
protected Item handleItem(XMLStreamReader reader) throws XMLStreamException { Item responseItem = new Item(); responseItem.type = reader.getLocalName(); while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, responseItem.type)) { reader.next();/*from w w w.jav a 2s .co m*/ if (XMLStreamUtil.isStartTag(reader)) { String tagLocalName = reader.getLocalName(); String value = null; if ("ExtendedProperty".equals(tagLocalName)) { addExtendedPropertyValue(reader, responseItem); } else if (tagLocalName.endsWith("MimeContent")) { handleMimeContent(reader, responseItem); } else if ("Attachments".equals(tagLocalName)) { responseItem.attachments = handleAttachments(reader); } else if ("EmailAddresses".equals(tagLocalName)) { handleEmailAddresses(reader, responseItem); } else if ("RequiredAttendees".equals(tagLocalName) || "OptionalAttendees".equals(tagLocalName)) { handleAttendees(reader, responseItem, tagLocalName); } else if ("ModifiedOccurrences".equals(tagLocalName)) { handleModifiedOccurrences(reader, responseItem); } else { if (tagLocalName.endsWith("Id")) { value = getAttributeValue(reader, "Id"); // get change key responseItem.put("ChangeKey", getAttributeValue(reader, "ChangeKey")); } if (value == null) { value = getTagContent(reader); } if (value != null) { responseItem.put(tagLocalName, value); } } } } return responseItem; }
From source file:davmail.exchange.ews.EWSMethod.java
protected String handleTag(XMLStreamReader reader, String localName) throws XMLStreamException { String result = null;//from w w w. j av a 2 s. c om int event = reader.getEventType(); if (event == XMLStreamConstants.START_ELEMENT && localName.equals(reader.getLocalName())) { while (reader.hasNext() && !((event == XMLStreamConstants.END_ELEMENT && localName.equals(reader.getLocalName())))) { event = reader.next(); if (event == XMLStreamConstants.CHARACTERS) { result = reader.getText(); } } } return result; }
From source file:net.bulletin.pdi.xero.step.support.XMLChunkerImpl.java
private String pullNextXmlChunkFromTopElementOnStack(XMLChunkerState data) throws KettleException { Stack<String> elementStack = data.getElementStack(); XMLStreamReader xmlStreamReader = data.getXmlStreamReader(); int elementStackDepthOnEntry = elementStack.size(); StringWriter stringWriter = new StringWriter(); try {//from w ww . j a v a 2 s .c o m XMLStreamWriter xmlStreamWriter = data.getXmlOutputFactory().createXMLStreamWriter(stringWriter); xmlStreamWriter.writeStartDocument(CharEncoding.UTF_8, "1.0"); // put the current element on because presumably it's the open element for the one // that is being looked for. XmlReaderToWriter.write(xmlStreamReader, xmlStreamWriter); while (xmlStreamReader.hasNext() & elementStack.size() >= elementStackDepthOnEntry) { switch (xmlStreamReader.next()) { case XMLStreamConstants.END_DOCUMENT: break; // handled below explicitly. case XMLStreamConstants.END_ELEMENT: elementStack.pop(); XmlReaderToWriter.write(xmlStreamReader, xmlStreamWriter); break; case XMLStreamConstants.START_ELEMENT: elementStack.push(xmlStreamReader.getLocalName()); XmlReaderToWriter.write(xmlStreamReader, xmlStreamWriter); break; default: XmlReaderToWriter.write(xmlStreamReader, xmlStreamWriter); break; } } xmlStreamWriter.writeEndDocument(); xmlStreamWriter.close(); } catch (Exception e) { throw new KettleException("unable to process a chunk of the xero xml stream", e); } return stringWriter.toString(); }
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();/* w w w.java 2 s. co m*/ if (XMLStreamUtil.isStartTag(reader)) { String tagLocalName = reader.getLocalName(); if ("Entry".equals(tagLocalName)) { item.put(reader.getAttributeValue(null, "Key"), XMLStreamUtil.getElementText(reader)); } } } }
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();/* w w w .ja v a2 s . c om*/ if (XMLStreamUtil.isStartTag(reader)) { String tagLocalName = reader.getLocalName(); if ("Occurrence".equals(tagLocalName)) { handleOccurrence(reader, item); } } } }
From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.ddi.DDIFileReader.java
private void processCodeBook(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("fileDscr")) { processFileDscr(xmlr, smd); } else if (xmlr.getLocalName().equals("dataDscr")) { processDataDscr(xmlr, smd); } else { throw new XMLStreamException("Unsupported DDI Element:" + xmlr.getLocalName()); }/*from w w w. j a v a2s .c o m*/ } else if (event == XMLStreamConstants.END_ELEMENT) { if (xmlr.getLocalName().equals("codeBook")) { dbgLog.info("processed codeBook section;"); return; } else { throw new XMLStreamException( "Mismatched DDI Formatting: </codeBook> expected, found " + xmlr.getLocalName()); } } } }
From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.ddi.DDIFileReader.java
private void processFileTxt(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("dimensns")) { processDimensns(xmlr, smd); } else if (xmlr.getLocalName().equals("fileType")) { // ignore. } else { throw new XMLStreamException( "Unsupported DDI Element: codeBook/fileDscr/fileTxt/" + xmlr.getLocalName()); }/*from w ww . j av a 2s .c om*/ } else if (event == XMLStreamConstants.END_ELEMENT) { if (xmlr.getLocalName().equals("fileTxt")) { return; } else if (xmlr.getLocalName().equals("fileType")) { // continue; } else { throw new XMLStreamException( "Mismatched DDI Formatting: </fileTxt> expected, found " + xmlr.getLocalName()); } } } }
From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.ddi.DDIFileReader.java
private void processFileDscr(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("fileTxt")) { processFileTxt(xmlr, smd); } else if (xmlr.getLocalName().equals("notes")) { // ignore, at least for now. // (the only notes in our fileDscr sections are those with // the UNFs and original file information, i.e., things we // supply during ingest -- so there's no reason for us to // be interested in what's in them; we may, however want to // treat is as an error when any notes are encountered // during TAB+DDI ingest. -- TBD) } else { throw new XMLStreamException( "Unsupported DDI Element: codeBook/fileDscr/" + xmlr.getLocalName()); }// w ww. j a v a 2 s.c om } else if (event == XMLStreamConstants.END_ELEMENT) {// </codeBook> if (xmlr.getLocalName().equals("fileDscr")) { return; } else if (xmlr.getLocalName().equals("notes")) { // continue; } else { throw new XMLStreamException( "Mismatched DDI Formatting: </fileDscr> expected, found " + xmlr.getLocalName()); } } } }
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 ava 2 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()); } } } }