WikipediaImport implements Import<StartElement> { public WikipediaImport(final Path xmlFile, final Path sirixDatabase) throws SirixException { mPageEvents = new ArrayDeque<>(); final XMLInputFactory xmlif = XMLInputFactory.newInstance(); try { mReader = xmlif.createXMLEventReader(new FileInputStream(checkNotNull(xmlFile.toFile()))); } catch (XMLStreamException | FileNotFoundException e) { LOGWRAPPER.error(e.getMessage(), e); } final DatabaseConfiguration config = new DatabaseConfiguration(sirixDatabase); Databases.createXmlDatabase(config); mDatabase = Databases.openXmlDatabase(sirixDatabase); mDatabase.createResource(new ResourceConfiguration.Builder("shredded").build()); mResourceManager = mDatabase.openResourceManager("shredded"); mWtx = mResourceManager.beginNodeTrx(); } WikipediaImport(final Path xmlFile, final Path sirixDatabase); @Override void importData(final DateBy dateRange, final List<StartElement> data); static void main(final String[] args);  }
@Test public void testWikipediaImport() throws Exception { Databases.removeDatabase(PATHS.PATH2.getFile()); final String NSP_URI = ""; final XMLEventFactory eventFactory = XMLEventFactory.newInstance(); final StartElement timestamp = eventFactory.createStartElement( new QName(NSP_URI, "timestamp", XMLConstants.DEFAULT_NS_PREFIX), null, null); final StartElement page = eventFactory.createStartElement( new QName(NSP_URI, "page", XMLConstants.DEFAULT_NS_PREFIX), null, null); final StartElement rev = eventFactory.createStartElement( new QName(NSP_URI, "revision", XMLConstants.DEFAULT_NS_PREFIX), null, null); final StartElement id = eventFactory.createStartElement( new QName(NSP_URI, "id", XMLConstants.DEFAULT_NS_PREFIX), null, null); final StartElement text = eventFactory.createStartElement( new QName(NSP_URI, "text", XMLConstants.DEFAULT_NS_PREFIX), null, null); final List<StartElement> list = new LinkedList<StartElement>(); list.add(timestamp); list.add(page); list.add(rev); list.add(id); list.add(text); new WikipediaImport(WIKIPEDIA, PATHS.PATH2.getFile()).importData(DateBy.HOURS, list); XmlSerializer.main( PATHS.PATH2.getFile().toAbsolutePath().toString(), PATHS.PATH3.getFile().toAbsolutePath().toString()); final StringBuilder actual = XmlTestHelper.readFile(PATHS.PATH3.getFile().toAbsolutePath(), false); final StringBuilder expected = XmlTestHelper.readFile(EXPECTED, false); assertEquals("XML files match", expected.toString(), actual.toString()); }