List of usage examples for javax.xml.stream XMLStreamReader nextTag
public int nextTag() throws XMLStreamException;
From source file:org.xwiki.contrib.confluence.filter.internal.ConfluenceXMLPackage.java
private Long readObjectReference(XMLStreamReader xmlReader) throws FilterException, XMLStreamException { xmlReader.nextTag(); if (!xmlReader.getLocalName().equals("id")) { throw new FilterException( String.format("Was expecting id element but found [%s]", xmlReader.getLocalName())); }//from w ww . j a v a 2 s. c o m Long id = Long.valueOf(xmlReader.getElementText()); xmlReader.nextTag(); return id; }
From source file:org.xwiki.contrib.confluence.filter.internal.ConfluenceXMLPackage.java
private List<Object> readListProperty(XMLStreamReader xmlReader) throws XMLStreamException, FilterException { List<Object> list = new ArrayList<>(); for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) { list.add(readProperty(xmlReader)); }/*from ww w . j ava2 s .c o m*/ return list; }
From source file:org.xwiki.contrib.confluence.filter.internal.ConfluenceXMLPackage.java
private Set<Object> readSetProperty(XMLStreamReader xmlReader) throws XMLStreamException, FilterException { Set<Object> set = new LinkedHashSet<>(); for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) { set.add(readProperty(xmlReader)); }/*ww w. j ava 2s .co m*/ return set; }
From source file:org.xwiki.filter.confluence.xml.internal.ConfluenceXMLPackage.java
private void createTree() throws XMLStreamException, FactoryConfigurationError, NumberFormatException, IOException, ConfigurationException, FilterException { this.tree = new File(this.directory, "tree"); this.tree.mkdir(); InputStream stream = new FileInputStream(getEntities()); XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(stream); xmlReader.nextTag(); for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) { String elementName = xmlReader.getLocalName(); if (elementName.equals("object")) { readObject(xmlReader);//from ww w. jav a 2 s.c om } else { StAXUtils.skipElement(xmlReader); } } }
From source file:org.xwiki.filter.confluence.xml.internal.ConfluenceXMLPackage.java
private int readObjectProperties(XMLStreamReader xmlReader, PropertiesConfiguration properties) throws XMLStreamException, FilterException, ConfigurationException, IOException { int id = -1;/*from w ww .java2 s.co m*/ for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) { String elementName = xmlReader.getLocalName(); if (elementName.equals("id")) { id = Integer.valueOf(xmlReader.getElementText()); properties.setProperty("id", id); } else if (elementName.equals("property")) { String propertyName = xmlReader.getAttributeValue(null, "name"); properties.setProperty(propertyName, readProperty(xmlReader)); } else if (elementName.equals("collection")) { String propertyName = xmlReader.getAttributeValue(null, "name"); properties.setProperty(propertyName, readProperty(xmlReader)); } else { StAXUtils.skipElement(xmlReader); } } return id; }
From source file:org.xwiki.filter.confluence.xml.internal.ConfluenceXMLPackage.java
private Integer readIdProperty(XMLStreamReader xmlReader) throws FilterException, XMLStreamException { xmlReader.nextTag(); if (!xmlReader.getLocalName().equals("id")) { throw new FilterException( String.format("Was expecting id element but found [%s]", xmlReader.getLocalName())); }//from ww w . jav a2 s . c o m Integer value = Integer.valueOf(xmlReader.getElementText()); xmlReader.nextTag(); return value; }
From source file:org.xwiki.filter.confluence.xml.internal.ConfluenceXMLPackage.java
private List<Object> readListProperty(XMLStreamReader xmlReader) throws XMLStreamException, FilterException { List<Object> list = new ArrayList<Object>(); for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) { list.add(readProperty(xmlReader)); }/*from ww w . j av a 2s . c om*/ return list; }
From source file:org.xwiki.filter.confluence.xml.internal.ConfluenceXMLPackage.java
private Set<Object> readSetProperty(XMLStreamReader xmlReader) throws XMLStreamException, FilterException { Set<Object> set = new LinkedHashSet<Object>(); for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) { set.add(readProperty(xmlReader)); }/* w w w . j a va 2 s . co m*/ return set; }
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 www . j a va 2s .com } 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; }
From source file:org.xwiki.filter.xar.internal.input.DocumentLocaleReader.java
public void read(XMLStreamReader xmlReader, Object filter, XARInputFilter proxyFilter) throws XMLStreamException, FilterException { resetDocument();/* w w w. j a v a2s .c o m*/ // <xwikidoc> xmlReader.nextTag(); this.currentSourceType = this.properties.getSourceType(); if (this.currentSourceType != null && this.currentSourceType != SourceType.DOCUMENT) { switch (this.currentSourceType) { case ATTACHMENT: readAttachment(xmlReader, filter, proxyFilter); break; case CLASS: readClass(xmlReader, filter, proxyFilter); break; case CLASSPROPERTY: readClassProperty(xmlReader, filter, proxyFilter); break; case OBJECT: readObject(xmlReader, filter, proxyFilter); break; case OBJECTPROPERTY: readObjectProperty(xmlReader, filter, proxyFilter); break; default: break; } } else { xmlReader.require(XMLStreamReader.START_ELEMENT, null, XarDocumentModel.ELEMENT_DOCUMENT); readDocument(xmlReader, filter, proxyFilter); } }