List of usage examples for javax.xml.stream XMLStreamReader getLocalName
public String getLocalName();
From source file:wiki.link.LinkImporter.java
public boolean readXML(String filename) { //System.exit(1); //MAKE BLOODY SURE YOU HAVE SOME HOURS. DbConnector dbc = new DbConnector("localhost"); dbc.jdbcTemplate.update("TRUNCATE links;"); try {//from w w w. ja v a2s . co m XMLInputFactory xif = XMLInputFactory.newInstance(); XMLStreamReader xsr = xif.createXMLStreamReader(new FileInputStream(filename)); long n = 0; List<Doc> toSave = new ArrayList<>(); while (xsr.hasNext()) { xsr.next(); if (xsr.getEventType() == XMLStreamReader.START_ELEMENT) { if (xsr.getLocalName().equals("page")) { long id = -1; String title = null; String text = null; while (xsr.hasNext()) { xsr.next(); if (xsr.getEventType() == XMLStreamReader.START_ELEMENT) { if (xsr.getLocalName().equals("id") && id == -1) { id = Long.parseLong(xsr.getElementText()); } if (xsr.getLocalName().equals("title")) { title = xsr.getElementText(); } if (xsr.getLocalName().equals("text")) { text = xsr.getElementText(); } } else if (xsr.getEventType() == XMLStreamReader.END_ELEMENT && xsr.getLocalName().equals("page")) { break; } } if (id != -1 && title != null && text != null) { Doc wd = new Doc(id, title, text); toSave.add(wd); n++; if (n % 1000 == 0) { insertLinks(toSave, dbc); // WikiDoc.insertAll(toSave, dbc); System.out.println(n); toSave.clear(); } } } } } } catch (IOException | XMLStreamException e) { e.printStackTrace(); } return true; }
From source file:de.huxhorn.sulky.plist.impl.PropertyListReader.java
private List<?> readArray(XMLStreamReader reader) throws XMLStreamException { reader.require(XMLStreamConstants.START_ELEMENT, null, ARRAY_NODE); reader.nextTag();//from www . j ava2 s.c o m List<Object> array = new ArrayList<Object>(); for (;;) { int type = reader.getEventType(); if (XMLStreamConstants.END_ELEMENT == type && ARRAY_NODE.equals(reader.getLocalName())) { reader.nextTag(); break; } array.add(readValue(reader)); } return array; }
From source file:com.amalto.core.load.context.StateContextSAXWriter.java
public void writeEndElement(XMLStreamReader reader) throws XMLStreamException, SAXException { Map<String, String> prefixToNamespace = Utils.parseNamespace(reader); Set<Map.Entry<String, String>> entries = prefixToNamespace.entrySet(); for (Map.Entry<String, String> entry : entries) { contentHandler.endPrefixMapping(entry.getKey()); }/*from w w w . j a va 2s. c om*/ contentHandler.endElement(getURI(reader), reader.getLocalName(), reader.getName().getLocalPart()); }
From source file:de.huxhorn.sulky.plist.impl.PropertyListReader.java
private Map<String, ?> readDict(XMLStreamReader reader) throws XMLStreamException { reader.require(XMLStreamConstants.START_ELEMENT, null, DICT_NODE); reader.nextTag();/*from w ww. j a va 2 s .com*/ Map<String, Object> map = new HashMap<String, Object>(); for (;;) { int type = reader.getEventType(); if (XMLStreamConstants.END_ELEMENT == type && DICT_NODE.equals(reader.getLocalName())) { reader.nextTag(); break; } String key = StaxUtilities.readSimpleTextNodeIfAvailable(reader, null, KEY_NODE); if (key != null) { map.put(key, readValue(reader)); } } return map; }
From source file:com.flexive.chemistry.webdav.TextDocumentResource.java
protected void processXmlProperties(InputStream in) { final XMLInputFactory factory = XMLInputFactory.newInstance(); try {/*from w ww. j ava2 s . c o m*/ final XMLStreamReader parser = factory.createXMLStreamReader(in); for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) { switch (event) { case XMLStreamConstants.START_ELEMENT: if ("property".equals(parser.getLocalName())) { processProperty(parser); } else if ("name".equals(parser.getLocalName())) { processName(parser); } } } } catch (XMLStreamException e) { throw new RuntimeException("Failed to replace content: " + e.getMessage(), e); } }
From source file:com.sazneo.export.file.FileProcessor.java
/** * Process the XML file//ww w. j a v a 2 s .c o m */ public void process() { try { Reader reader = new FileReader(exportFile); XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); XMLStreamReader xmlStreamReader = xmlFactory.createXMLStreamReader(reader); boolean fileTag = false; String fileName = null; Integer fileSize = null; while (xmlStreamReader.hasNext()) { xmlStreamReader.next(); if (xmlStreamReader.getEventType() == XMLStreamReader.START_ELEMENT) { if ("file".equals(xmlStreamReader.getLocalName())) { fileTag = true; fileName = MessageFormat.format("{0}_{1}", xmlStreamReader.getAttributeValue(null, "id"), xmlStreamReader.getAttributeValue(null, "filename")); fileSize = Integer.parseInt(xmlStreamReader.getAttributeValue(null, "size")); logger.debug(MessageFormat.format("XML contains file with name: {0} and size {1} bytes", fileName, fileSize)); } } if (fileTag) { if (xmlStreamReader.getEventType() == XMLStreamReader.CHARACTERS) { exportFile(xmlStreamReader.getText(), fileName, fileSize); } if (xmlStreamReader.getEventType() == XMLStreamReader.END_ELEMENT) { fileSize = null; fileName = null; fileTag = false; } } } } catch (FileNotFoundException e) { logger.error(MessageFormat.format("Could not find export file:-\n{0}", e)); } catch (XMLStreamException e) { logger.error(MessageFormat.format("Could not parse xml export file:-\n{0}", e)); } }
From source file:com.pocketsoap.salesforce.soap.ChatterClient.java
private RuntimeException handleSoapFault(XMLStreamReader rdr) throws XMLStreamException { String fc = null, fs = null;// ww w .jav a 2 s . com while (rdr.next() != XMLStreamReader.END_DOCUMENT) { if (rdr.getEventType() == XMLStreamReader.START_ELEMENT) { String ln = rdr.getLocalName(); if (ln.equals("faultcode")) fc = rdr.getElementText(); else if (ln.equals("faultstring")) fs = rdr.getElementText(); } } return new SoapFaultException(fc, fs); }
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 ww w .j a v a 2 s. c o 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.ExchangePropPatchMethod.java
protected void handleProperty(XMLStreamReader reader, MultiStatusResponse multiStatusResponse) throws XMLStreamException { while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "prop")) { reader.next();/*from w w w .j a v a 2 s. c o m*/ 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 void handlePropstat(XMLStreamReader reader, MultiStatusResponse multiStatusResponse) throws XMLStreamException { int propstatStatus = 0; while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "propstat")) { reader.next();/*from ww w . j a v a 2 s . c o 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); } } } }