List of usage examples for javax.xml.stream XMLOutputFactory newInstance
public static XMLOutputFactory newInstance() throws FactoryConfigurationError
From source file:com.norconex.collector.http.fetch.impl.GenericMetadataFetcher.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {//from w ww . j av a2 s . com XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("httpHeadersFetcher"); writer.writeAttribute("class", getClass().getCanonicalName()); writer.writeStartElement("validStatusCodes"); writer.writeCharacters(StringUtils.join(validStatusCodes, ",")); writer.writeEndElement(); writer.writeStartElement("headersPrefix"); writer.writeCharacters(headersPrefix); writer.writeEndElement(); writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:com.flexive.shared.media.FxMetadata.java
private static synchronized XMLOutputFactory getXmlOutputFactory() { if (xmlOutputFactory == null) { // cache the factory since profiling showed that this is a rather expensive call xmlOutputFactory = XMLOutputFactory.newInstance(); }/*from w w w. ja v a 2 s . co m*/ return xmlOutputFactory; }
From source file:com.concursive.connect.web.modules.api.services.BackupService.java
public boolean process(TransactionItem transactionItem, Connection db) throws Exception { LOG.debug("Backup requested..."); // TODO: Fix cyclical/endless backups; need to keep an array of ids already archived // TODO: Fix if lookup value is -1, then a lookup is not needed DataRecordFactory factory = DataRecordFactory.INSTANCE; // Override the default response packet so that the returned data records // can be replayed using the RestoreService; stream the output PacketContext packetContext = transactionItem.getPacketContext(); packetContext.setReturnType(PacketContext.RETURN_DATARECORDS); // Start with the original record(s) being backed up LOG.debug("Performing buildList query"); Object object = transactionItem.getObject(); if (object instanceof java.util.AbstractList || object instanceof java.util.AbstractMap) { Object result = TransactionItem.doExecute(transactionItem.getObject(), db, TransactionItem.SELECT, packetContext, "buildList"); // TODO: check result } else {/*from ww w . ja v a 2 s . c om*/ Object newObject = ObjectUtils.constructObject(object.getClass(), db, ObjectUtils.getParamAsInt(object, factory.retrieveUniqueField(transactionItem.getName() + "List"))); transactionItem.setObject(newObject); } // Start backup recursion... // Consider lower-memory options to stream records without holding in memory // option 1: use pagedList to get x record(s) at a time // option 2: consider queue for limiting backup requests and asynchronous backups XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); OutputStream outputStream = null; if (packetContext.getOutputStream() == null) { outputStream = packetContext.getResponse().getOutputStream(); } else { outputStream = packetContext.getOutputStream(); } XMLStreamWriter writer = outputFactory.createXMLStreamWriter(outputStream, "utf-8"); writer.writeStartDocument(); writer.writeCharacters(System.getProperty("line.separator")); writer.writeStartElement("concursive"); writer.writeCharacters(System.getProperty("line.separator")); ArrayList<String> addedRecords = new ArrayList<String>(); addRecords(writer, transactionItem.getObject(), transactionItem, packetContext, db, addedRecords); writer.writeEndElement(); writer.writeCharacters(System.getProperty("line.separator")); writer.flush(); writer.close(); return true; }
From source file:mediathek.controller.IoXmlSchreiben.java
private void xmlSchreibenStart() throws IOException, XMLStreamException { Log.systemMeldung("Start Schreiben nach: " + xmlFilePath.toAbsolutePath()); final OutputStream outputStream = Files.newOutputStream(xmlFilePath); if (xmlFilePath.endsWith(GuiKonstanten.FORMAT_BZ2)) { bZip2CompressorOutputStream = new BZip2CompressorOutputStream(outputStream, 2); out = new OutputStreamWriter(bZip2CompressorOutputStream, Konstanten.KODIERUNG_UTF); } else if (xmlFilePath.endsWith(GuiKonstanten.FORMAT_ZIP)) { zipOutputStream = new ZipOutputStream(outputStream); ZipEntry entry = new ZipEntry(Konstanten.PROGRAMMNAME); zipOutputStream.putNextEntry(entry); out = new OutputStreamWriter(zipOutputStream, Konstanten.KODIERUNG_UTF); } else {/*ww w. java2s. c o m*/ out = new OutputStreamWriter(outputStream, Konstanten.KODIERUNG_UTF); } XMLOutputFactory outFactory = XMLOutputFactory.newInstance(); writer = outFactory.createXMLStreamWriter(out); writer.writeStartDocument(Konstanten.KODIERUNG_UTF, "1.0"); writer.writeCharacters("\n");//neue Zeile writer.writeStartElement(Konstanten.XML_START); writer.writeCharacters("\n");//neue Zeile }
From source file:co.turnus.trace.io.XmlTraceStreamWriter.java
public void open() { try {/*from w w w. j a va 2s.c om*/ XMLOutputFactory factory = XMLOutputFactory.newInstance(); writer = factory.createXMLStreamWriter(stream); if (!compressedXml) { writer = new IndentingXMLStreamWriter(writer); } writeStartDocument(); } catch (XMLStreamException e) { throw new TurnusRuntimeException("Error opening the trace stream writer", e.getCause()); } }
From source file:de.codesourcery.eve.skills.dao.impl.FileShoppingListDAO.java
protected void writeToFile() { XMLStreamWriter writer = null; try {//from w ww. j a va2 s . c o m if (!dataFile.exists()) { final File parent = dataFile.getParentFile(); if (parent != null && !parent.exists()) { if (!parent.mkdirs()) { log.error("writeToFile(): Failed to create parent directory " + parent.getAbsolutePath()); } else { log.info("writeToFile(): Created parent directory " + parent.getAbsolutePath()); } } } final XMLOutputFactory factory = XMLOutputFactory.newInstance(); log.info("writeToFile(): Writing to " + dataFile.getAbsolutePath()); final FileOutputStream outStream = new FileOutputStream(dataFile); writer = factory.createXMLStreamWriter(outStream, OUTPUT_ENCODING); writer.writeStartDocument(OUTPUT_ENCODING, "1.0"); writer.writeStartElement("shoppinglists"); // <shoppinglists> synchronized (this.entries) { for (ShoppingList list : this.entries) { writer.writeStartElement("shoppinglist"); writer.writeAttribute("title", list.getTitle()); if (!StringUtils.isBlank(list.getDescription())) { writer.writeStartElement("description"); writer.writeCharacters(list.getDescription()); writer.writeEndElement(); // </description> } writer.writeStartElement("entries"); for (ShoppingListEntry entry : list.getEntries()) { writer.writeStartElement("entry"); writer.writeAttribute("itemId", Long.toString(entry.getType().getId())); writer.writeAttribute("totalQuantity", Long.toString(entry.getQuantity())); writer.writeAttribute("purchasedQuantity", Long.toString(entry.getPurchasedQuantity())); writer.writeEndElement(); // </entry> } writer.writeEndElement(); // </entries> writer.writeEndElement(); // </shoppinglist> } } writer.writeEndElement(); // </shoppinglists> writer.writeEndDocument(); writer.flush(); writer.close(); } catch (FileNotFoundException e) { log.error("writeToFile(): Caught ", e); throw new RuntimeException("Unable to save shopping list to " + dataFile, e); } catch (XMLStreamException e) { log.error("writeToFile(): Caught ", e); throw new RuntimeException("Unable to save shopping list to " + dataFile, e); } finally { if (writer != null) { try { writer.close(); } catch (XMLStreamException e) { log.error("writeToFile(): Caught ", e); } } } }
From source file:XMLWriteTest.java
/** * Saves the drawing in SVG format, using StAX *//*from w ww . j av a 2s . c o m*/ public void saveStAX() throws FileNotFoundException, XMLStreamException { if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) return; File f = chooser.getSelectedFile(); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = factory.createXMLStreamWriter(new FileOutputStream(f)); comp.writeDocument(writer); writer.close(); }
From source file:com.norconex.committer.core.impl.FileSystemCommitter.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {//from ww w.java2s .c om XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("committer"); writer.writeAttribute("class", getClass().getCanonicalName()); writer.writeStartElement("directory"); writer.writeCharacters(directory); writer.writeEndElement(); writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:com.norconex.jef4.log.FileLogManager.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {/* w ww .j a v a 2 s . com*/ XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("logManager"); writer.writeAttribute("class", getClass().getCanonicalName()); writer.writeStartElement("logDir"); writer.writeCharacters(new File(logdir).getAbsolutePath()); writer.writeEndElement(); writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:com.tamingtext.tagrecommender.ExtractStackOverflowData.java
public void extract() { XMLInputFactory xif = XMLInputFactory.newInstance(); XMLStreamReader reader = null; InputStream is = null;/*from w w w . ja v a 2s . c om*/ XMLOutputFactory xof = XMLOutputFactory.newInstance(); XMLStreamWriter writer = null; OutputStream os = null; try { log.info("Reading data from " + inputFile); is = new FileInputStream(inputFile); reader = xif.createXMLStreamReader(is); os = new FileOutputStream(trainingOutputFile); writer = xof.createXMLStreamWriter(os); int trainingDataCount = extractXMLData(reader, writer, trainingDataSize); os.close(); os = new FileOutputStream(testOutputFile); writer = xof.createXMLStreamWriter(os); int testDataCount = extractXMLData(reader, writer, testDataSize); os.close(); log.info("Extracted " + trainingDataCount + " rows of training data"); log.info("Extracted " + testDataCount + " rows of test data"); } catch (XMLStreamException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }