List of usage examples for javax.xml.stream XMLStreamReader isCharacters
public boolean isCharacters();
From source file:org.unitedinternet.cosmo.util.DomReader.java
private static Node readNode(Document d, XMLStreamReader reader) throws XMLStreamException { Node root = null;/* w w w.jav a 2 s .c o m*/ Node current = null; while (reader.hasNext()) { reader.next(); if (reader.isEndElement()) { //log.debug("Finished reading " + current.getNodeName()); if (current.getParentNode() == null) { break; } //log.debug("Setting current to " + //current.getParentNode().getNodeName()); current = current.getParentNode(); } if (reader.isStartElement()) { Element e = readElement(d, reader); if (root == null) { //log.debug("Setting root to " + e.getNodeName()); root = e; } if (current != null) { //log.debug("Appending child " + e.getNodeName() + " to " + //current.getNodeName()); current.appendChild(e); } //log.debug("Setting current to " + e.getNodeName()); current = e; continue; } if (reader.isCharacters()) { CharacterData cd = d.createTextNode(reader.getText()); if (root == null) { return cd; } if (current == null) { return cd; } //log.debug("Appending text '" + cd.getData() + "' to " + //current.getNodeName()); current.appendChild(cd); continue; } } return root; }
From source file:org.xwiki.filter.xar.internal.input.AttachmentReader.java
@Override public WikiAttachment read(XMLStreamReader xmlReader, XARInputProperties properties) throws XMLStreamException, FilterException { WikiAttachment wikiAttachment = new WikiAttachment(); for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) { String elementName = xmlReader.getLocalName(); EventParameter parameter = XARAttachmentModel.ATTACHMENT_PARAMETERS.get(elementName); if (parameter != null) { Object wsValue = convert(parameter.type, xmlReader.getElementText()); if (wsValue != null) { wikiAttachment.parameters.put(parameter.name, wsValue); }//from w ww .jav a2 s .c o m } else { if (XARAttachmentModel.ELEMENT_NAME.equals(elementName)) { wikiAttachment.name = xmlReader.getElementText(); } else if (XARAttachmentModel.ELEMENT_CONTENT_SIZE.equals(elementName)) { wikiAttachment.size = Long.valueOf(xmlReader.getElementText()); } else if (XARAttachmentModel.ELEMENT_CONTENT.equals(elementName)) { // We copy the attachment content to use it later. We can't directly send it as a stream because XAR // specification does not force any order for the attachment properties and we need to be sure we // have everything when sending the event. // Allocate a temporary file in case the attachment content is big File temporaryFile; try { temporaryFile = File.createTempFile("xar/attachments/attachment", ".bin"); temporaryFile.deleteOnExit(); } catch (IOException e) { throw new FilterException(e); } // Create a deferred file based content (if the content is bigger than 10000 bytes it will end up in // a file) wikiAttachment.content = new DeferredFileOutputStream(100000, temporaryFile); // Copy the content to byte array or file depending on its size for (xmlReader.next(); xmlReader.isCharacters(); xmlReader.next()) { try { wikiAttachment.content.write(xmlReader.getText().getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { throw new FilterException(e); } } } } } return wikiAttachment; }