List of usage examples for javax.xml.stream XMLStreamReader isStartElement
public boolean isStartElement();
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();//from ww w. j av a 2 s . c o m for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) { // <entry> xmlReader.nextTag(); 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();//w w w .j a va2s. c o m for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) { String elementName = xmlReader.getLocalName(); if (elementName.equals("object")) { readObject(xmlReader); } 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 . j a v a 2 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.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 v a 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 . j ava 2 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); }/* www . ja va 2 s . 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. * //from www . j a v a 2s . co m * @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); }
From source file:rjc.jplanner.model.Plan.java
/******************************************* loadXML *******************************************/ public void loadXML(XMLStreamReader xsr, String filename, String fileloc) throws XMLStreamException { // as id of plan-calendar read before the calendars, need temporary store int calendarId = -1; // load plan from XML stream while (xsr.hasNext()) { // if reached end of plan data, exit loop if (xsr.isEndElement() && xsr.getLocalName().equals(XmlLabels.XML_PLAN_DATA)) break; // if start element read data if (xsr.isStartElement()) switch (xsr.getLocalName()) { case XmlLabels.XML_JPLANNER: loadXmlJPlanner(xsr);//www .j ava 2 s. c o m break; case XmlLabels.XML_PLAN_DATA: calendarId = loadXmlPlan(xsr); break; case XmlLabels.XML_DAY_DATA: daytypes.loadXML(xsr); break; case XmlLabels.XML_CAL_DATA: calendars.loadXML(xsr); break; case XmlLabels.XML_RES_DATA: resources.loadXML(xsr); break; case XmlLabels.XML_TASK_DATA: tasks.loadXML(xsr); break; default: JPlanner.trace("Unhandled start element '" + xsr.getLocalName() + "'"); break; } xsr.next(); } // if calendar-id still negative, default to first calendar if (calendarId < 0) m_calendar = calendar(0); else m_calendar = calendar(calendarId); m_filename = filename; m_fileLocation = fileloc; }