List of usage examples for javax.xml.stream XMLStreamReader nextTag
public int nextTag() throws XMLStreamException;
From source file:org.xwiki.filter.xar.internal.input.DocumentLocaleReader.java
private void readDocument(XMLStreamReader xmlReader, Object filter, XARInputFilter proxyFilter) throws XMLStreamException, FilterException { this.currentSourceType = SourceType.DOCUMENT; // Initialize with a few defaults (thing that don't exist in old XAR format) this.currentDocumentRevisionParameters.put(XWikiWikiDocumentFilter.PARAMETER_SYNTAX, Syntax.XWIKI_1_0); this.currentDocumentRevisionParameters.put(XWikiWikiDocumentFilter.PARAMETER_HIDDEN, false); // Reference/*from w w w .j a va2 s.c o m*/ String referenceString = xmlReader.getAttributeValue(null, XARDocumentModel.ATTRIBUTE_DOCUMENT_REFERENCE); if (StringUtils.isNotEmpty(referenceString)) { this.currentDocumentReference = this.relativeResolver.resolve(referenceString, EntityType.DOCUMENT); this.currentSpaceReference = this.currentDocumentReference.getParent(); // Send needed wiki spaces event if possible switchWikiSpace(proxyFilter, false); } // Locale String localeString = xmlReader.getAttributeValue(null, XARDocumentModel.ATTRIBUTE_DOCUMENT_LOCALE); if (localeString != null) { this.currentDocumentLocale = toLocale(localeString); this.localeFromLegacy = false; } for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) { String elementName = xmlReader.getLocalName(); if (elementName.equals(XARAttachmentModel.ELEMENT_ATTACHMENT)) { readAttachment(xmlReader, filter, proxyFilter); } else if (elementName.equals(XARObjectModel.ELEMENT_OBJECT)) { readObject(xmlReader, filter, proxyFilter); } else if (elementName.equals(XARClassModel.ELEMENT_CLASS)) { readClass(xmlReader, filter, proxyFilter); } else { String value = xmlReader.getElementText(); if (XarDocumentModel.ELEMENT_SPACE.equals(elementName)) { this.currentLegacySpace = value; if (this.currentDocumentReference == null) { // Its an old thing if (this.currentLegacyDocument == null) { this.currentSpaceReference = new EntityReference(value, EntityType.SPACE); } else { this.currentDocumentReference = new LocalDocumentReference(this.currentLegacySpace, this.currentLegacyDocument); this.currentSpaceReference = this.currentDocumentReference.getParent(); } // Send needed wiki spaces event if possible switchWikiSpace(proxyFilter, false); } } else if (XarDocumentModel.ELEMENT_NAME.equals(elementName)) { this.currentLegacyDocument = value; if (this.currentDocumentReference == null) { // Its an old thing if (this.currentLegacySpace != null) { this.currentDocumentReference = new LocalDocumentReference(this.currentLegacySpace, this.currentLegacyDocument); this.currentSpaceReference = this.currentDocumentReference.getParent(); } } } else if (XarDocumentModel.ELEMENT_LOCALE.equals(elementName)) { if (this.localeFromLegacy) { this.currentDocumentLocale = toLocale(value); } } else if (XarDocumentModel.ELEMENT_REVISION.equals(elementName)) { this.currentDocumentRevision = value; } else { EventParameter parameter = XARDocumentModel.DOCUMENT_PARAMETERS.get(elementName); if (parameter != null) { Object wsValue = convert(parameter.type, value); if (wsValue != null) { this.currentDocumentParameters.put(parameter.name, wsValue); } } else { parameter = XARDocumentModel.DOCUMENTLOCALE_PARAMETERS.get(elementName); if (parameter != null) { Object wsValue = convert(parameter.type, value); if (wsValue != null) { this.currentDocumentLocaleParameters.put(parameter.name, wsValue); } } else { parameter = XARDocumentModel.DOCUMENTREVISION_PARAMETERS.get(elementName); if (parameter != null) { Object objectValue; if (parameter.type == EntityReference.class) { objectValue = this.relativeResolver.resolve(value, EntityType.DOCUMENT); } else { objectValue = convert(parameter.type, value); } if (objectValue != null) { this.currentDocumentRevisionParameters.put(parameter.name, objectValue); } } else { // Unknown property // TODO: log something ? } } } } } } sendBeginWikiDocumentRevision(proxyFilter, true); sendWikiAttachments(proxyFilter); sendWikiClass(proxyFilter); sendWikiObjects(proxyFilter); sendEndWikiDocument(proxyFilter); }
From source file:org.xwiki.store.filesystem.internal.migration.R910100XWIKI14871DataMigration.java
private void migrateMetadatas(Session session) throws IOException, XMLStreamException, FactoryConfigurationError, ParserConfigurationException, SAXException { this.logger.info("Migrating filesystem attachment metadatas storded in [{}]", this.fstools.getStorageLocationFile()); File pathByIdStore = this.fstools.getGlobalFile("DELETED_ATTACHMENT_ID_MAPPINGS.xml"); if (pathByIdStore.exists()) { try (FileInputStream stream = new FileInputStream(pathByIdStore)) { XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(stream); // <deletedattachmentids> xmlReader.nextTag(); for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) { // <entry> xmlReader.nextTag();//w w w . j av a 2 s . com String value1 = xmlReader.getElementText(); xmlReader.nextTag(); String value2 = xmlReader.getElementText(); long id; String path; if (xmlReader.getLocalName().equals("path")) { id = Long.valueOf(value1); path = value2; } else { id = Long.valueOf(value2); path = value1; } // </entry> xmlReader.nextTag(); File directory = new File(path); if (!directory.exists()) { this.logger.warn("[{}] does not exist", directory); continue; } if (!directory.isDirectory()) { this.logger.warn("[{}] is not a directory", directory); continue; } storeDeletedAttachment(directory, id, session); } } } }
From source file:org.xwiki.wikistream.confluence.xml.internal.ConfluenceXMLPackage.java
private void createTree() throws XMLStreamException, FactoryConfigurationError, NumberFormatException, IOException, ConfigurationException, WikiStreamException { 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 w w w. ja va2s. c om*/ } else { StAXUtils.skipElement(xmlReader); } } }
From source file:org.xwiki.wikistream.confluence.xml.internal.ConfluenceXMLPackage.java
private int readObjectProperties(XMLStreamReader xmlReader, PropertiesConfiguration properties) throws XMLStreamException, WikiStreamException, ConfigurationException, IOException { int id = -1;/*from w w w . ja va2 s. com*/ 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.wikistream.confluence.xml.internal.ConfluenceXMLPackage.java
private Integer readIdProperty(XMLStreamReader xmlReader) throws WikiStreamException, XMLStreamException { xmlReader.nextTag(); if (!xmlReader.getLocalName().equals("id")) { throw new WikiStreamException( String.format("Was expecting id element but found [%s]", xmlReader.getLocalName())); }/*from w ww .j a va2 s . c o m*/ Integer value = Integer.valueOf(xmlReader.getElementText()); xmlReader.nextTag(); return value; }
From source file:org.xwiki.wikistream.confluence.xml.internal.ConfluenceXMLPackage.java
private List<Object> readListProperty(XMLStreamReader xmlReader) throws XMLStreamException, WikiStreamException { List<Object> list = new ArrayList<Object>(); for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) { list.add(readProperty(xmlReader)); }/*www .ja va 2s . c om*/ return list; }
From source file:org.xwiki.wikistream.confluence.xml.internal.ConfluenceXMLPackage.java
private Set<Object> readSetProperty(XMLStreamReader xmlReader) throws XMLStreamException, WikiStreamException { Set<Object> set = new LinkedHashSet<Object>(); for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) { set.add(readProperty(xmlReader)); }//from ww w .ja va2 s . c om return set; }
From source file:org.xwiki.wikistream.xar.internal.input.AttachmentReader.java
public WikiAttachment read(XMLStreamReader xmlReader) throws XMLStreamException, WikiStreamException { WikiAttachment wikiAttachment = new WikiAttachment(); for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) { String elementName = xmlReader.getLocalName(); String value = xmlReader.getElementText(); EventParameter parameter = XARAttachmentModel.ATTACHMENT_PARAMETERS.get(elementName); if (parameter != null) { Object wsValue = convert(parameter.type, value); if (wsValue != null) { wikiAttachment.parameters.put(parameter.name, wsValue); }// w ww . j a v a 2s . c o m } else { if (XARAttachmentModel.ELEMENT_NAME.equals(elementName)) { wikiAttachment.name = value; } else if (XARAttachmentModel.ELEMENT_CONTENT.equals(elementName)) { wikiAttachment.content = Base64.decodeBase64(value.getBytes()); } } } return wikiAttachment; }
From source file:org.xwiki.xar.internal.XarUtils.java
/** * Extract {@link LocalDocumentReference} from a XAR document XML stream. * //w w w . jav a 2 s . c om * @param documentStream the stream to parse * @return the reference extracted from the stream * @throws XarException when failing to parse the document stream * @since 5.4M1 */ public static LocalDocumentReference getReference(InputStream documentStream) throws XarException { XMLStreamReader xmlReader; try { xmlReader = XML_INPUT_FACTORY.createXMLStreamReader(documentStream); } catch (XMLStreamException e) { throw new XarException("Failed to create a XML read", e); } EntityReference reference = null; Locale locale = null; String legacySpace = null; String legacyPage = null; try { // <xwikidoc> xmlReader.nextTag(); xmlReader.require(XMLStreamReader.START_ELEMENT, null, XarDocumentModel.ELEMENT_DOCUMENT); // Reference String referenceString = xmlReader.getAttributeValue(null, XarDocumentModel.ATTRIBUTE_DOCUMENT_REFERENCE); if (referenceString != null) { reference = RESOLVER.resolve(referenceString, EntityType.DOCUMENT); } // Locale String localeString = xmlReader.getAttributeValue(null, XarDocumentModel.ATTRIBUTE_DOCUMENT_LOCALE); if (localeString != null) { if (localeString.isEmpty()) { locale = Locale.ROOT; } else { locale = LocaleUtils.toLocale(localeString); } } // Legacy fallback if (reference == null || locale == null) { for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) { String elementName = xmlReader.getLocalName(); if (XarDocumentModel.ELEMENT_NAME.equals(elementName)) { if (reference == null) { legacyPage = xmlReader.getElementText(); if (legacySpace != null && locale != null) { break; } } else if (locale != null) { break; } } else if (XarDocumentModel.ELEMENT_SPACE.equals(elementName)) { if (reference == null) { legacySpace = xmlReader.getElementText(); if (legacyPage != null && locale != null) { break; } } else if (locale != null) { break; } } else if (XarDocumentModel.ELEMENT_LOCALE.equals(elementName)) { if (locale == null) { String value = xmlReader.getElementText(); if (value.length() == 0) { locale = Locale.ROOT; } else { locale = LocaleUtils.toLocale(value); } } if (reference != null || (legacySpace != null && legacyPage != null)) { break; } } else { StAXUtils.skipElement(xmlReader); } } } } catch (XMLStreamException e) { throw new XarException("Failed to parse document", e); } finally { try { xmlReader.close(); } catch (XMLStreamException e) { throw new XarException("Failed to close XML reader", e); } } if (reference == null) { if (legacySpace == null) { throw new XarException("Missing space element"); } if (legacyPage == null) { throw new XarException("Missing page element"); } reference = new LocalDocumentReference(legacySpace, legacyPage); } if (locale == null) { throw new XarException("Missing locale element"); } return new LocalDocumentReference(reference, locale); }