List of usage examples for javax.xml.stream XMLStreamWriter flush
public void flush() throws XMLStreamException;
From source file:com.norconex.collector.http.filter.impl.SegmentCountURLFilter.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {/*from w w w . j av a 2s. c o m*/ XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("filter"); writer.writeAttribute("class", getClass().getCanonicalName()); super.saveToXML(writer); writer.writeAttribute("count", Integer.toString(count)); writer.writeAttribute("duplicate", Boolean.toString(duplicate)); writer.writeAttribute("separator", separator); writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:com.norconex.collector.http.sitemap.impl.StandardSitemapResolverFactory.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {//from ww w . ja v a 2 s .c o m XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("sitemapResolverFactory"); writer.writeAttribute("class", getClass().getCanonicalName()); writer.writeAttribute("lenient", Boolean.toString(lenient)); if (sitemapLocations != null) { for (String location : sitemapLocations) { writer.writeStartElement("location"); writer.writeCharacters(location); writer.writeEndElement(); } } writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:gdv.xport.util.HtmlFormatter.java
private static void writeDetailsTo(final XMLStreamWriter xmlStreamWriter, final Teildatensatz teildatensatz, final int zeile) throws XMLStreamException { xmlStreamWriter.writeStartElement("h4"); xmlStreamWriter/*from w w w. j a v a 2s . c o m*/ .writeCharacters("Zeile " + zeile + ": Teildatensatz " + teildatensatz.getNummer().getInhalt()); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); xmlStreamWriter.writeStartElement("table"); xmlStreamWriter.writeStartElement("thead"); xmlStreamWriter.writeStartElement("tr"); writeTagTo(xmlStreamWriter, "th", "Nr"); writeTagTo(xmlStreamWriter, "th", "Byte"); writeTagTo(xmlStreamWriter, "th", "Bezeichner"); writeTagTo(xmlStreamWriter, "th", "Datentyp"); writeTagTo(xmlStreamWriter, "th", "Inhalt"); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); xmlStreamWriter.writeStartElement("tbody"); int nr = 1; for (Iterator<Feld> iterator = teildatensatz.getFelder().iterator(); iterator.hasNext();) { Feld feld = iterator.next(); writeDetailsTo(xmlStreamWriter, feld, zeile, nr); nr++; } xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); xmlStreamWriter.flush(); }
From source file:com.norconex.committer.idol.IdolCommitter.java
/** * Commits the addition operations.//w w w . j a va 2 s . c om * @param addOperations additions */ public void dreAddData(List<IAddOperation> addOperations) { if (addOperations.isEmpty()) { return; } if (LOG.isInfoEnabled()) { LOG.info("Sending " + addOperations.size() + " documents for addition to " + createURL()); } StringBuilder b = new StringBuilder(); b.append(createURL()); if (isCFS()) { b.append("action=ingest&adds="); StringWriter xml = new StringWriter(); XMLOutputFactory factory = XMLOutputFactory.newInstance(); try { XMLStreamWriter writer = factory.createXMLStreamWriter(xml); writer.writeStartElement("adds"); buildCfsXmlBatchContent(writer, addOperations); writer.writeEndElement(); writer.flush(); writer.close(); b.append(URLEncoder.encode(xml.toString(), CharEncoding.UTF_8)); } catch (Exception e) { throw new CommitterException("Cannot create XML.", e); } postToIDOL(b.toString(), StringUtils.EMPTY); } else { b.append("DREADDDATA?"); QueryString qs = new QueryString(); for (String key : dreAddDataParams.keySet()) { qs.addString(key, dreAddDataParams.get(key)); } String addURL = qs.applyOnURL(b.toString()); String idxBatch = buildIdxBatchContent(addOperations); postToIDOL(addURL, idxBatch); } if (LOG.isInfoEnabled()) { LOG.debug("Done sending additions to " + createURL()); } }
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 . j a v a2 s .c o m 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:com.norconex.collector.http.fetch.impl.DefaultDocumentFetcher.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {/*from w w w . j av a 2s . c om*/ XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("httpDocumentFetcher"); writer.writeAttribute("class", getClass().getCanonicalName()); writer.writeStartElement("validStatusCodes"); if (validStatusCodes != null) { writer.writeCharacters(StringUtils.join(validStatusCodes)); } writer.writeEndElement(); writer.writeStartElement("headersPrefix"); if (headersPrefix != null) { writer.writeCharacters(headersPrefix); } writer.writeEndElement(); writer.writeEndElement(); writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:com.rockhoppertech.music.midi.js.xml.ModeFactoryXMLHelper.java
public static void write(List<Scale> modeList, String fileName) { XMLOutputFactory xof = XMLOutputFactory.newInstance(); XMLStreamWriter xtw = null; // <mode> // <name>Peruvian tritonic 2</name> // <interval>3</interval> // <interval>4</interval> // <interval>5</interval> // </mode> String ns = "http://rockhoppertech.com/modes-1.0"; // StringWriter sw = new StringWriter(); try {//from www . j av a 2 s. com xtw = xof.createXMLStreamWriter(new FileWriter(fileName)); // xtw = xof.createXMLStreamWriter(sw); xtw.writeComment("all elements here are explicitly in the mode namespace"); xtw.writeStartDocument("utf-8", "1.0"); xtw.setPrefix("modes", ns); xtw.writeStartElement(ns, "modes"); xtw.writeNamespace("modes", ns); for (Scale scale : modeList) { // xtw.writeStartElement(ns, "mode"); xtw.writeStartElement("mode"); // xtw.writeStartElement(ns, "name"); xtw.writeStartElement("name"); xtw.writeCharacters(scale.getName()); xtw.writeEndElement(); // xtw.writeStartElement(ns, "intervals"); // xtw.writeStartElement(ns, "interval"); xtw.writeStartElement("intervals"); int[] intervals = scale.getIntervals(); for (int i = 0; i < intervals.length; i++) { xtw.writeStartElement("interval"); xtw.writeCharacters("" + intervals[i]); xtw.writeEndElement(); } xtw.writeEndElement(); // intervals xtw.writeEndElement(); // mode } xtw.writeEndElement(); // modes xtw.writeEndDocument(); xtw.flush(); xtw.close(); // System.err.println(sw.toString()); } catch (XMLStreamException | IOException e) { logger.error(e.getLocalizedMessage(), e); e.printStackTrace(); } }
From source file:com.norconex.collector.http.sitemap.impl.DefaultSitemapResolver.java
@Override public void saveToXML(Writer out) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try {//from www . j a v a2s . c o m XMLStreamWriter writer = factory.createXMLStreamWriter(out); writer.writeStartElement("sitemap"); writer.writeAttribute("class", getClass().getCanonicalName()); writer.writeAttribute("lenient", Boolean.toString(lenient)); if (sitemapLocations != null) { for (String location : sitemapLocations) { writer.writeStartElement("location"); writer.writeCharacters(location); writer.writeEndElement(); } } writer.writeEndElement(); writer.flush(); writer.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } }
From source file:de.qucosa.webapi.v1.RelationResource.java
@RequestMapping(value = "/relation/urn/{URN}", method = RequestMethod.GET) public ResponseEntity<String> describeRelationships(@PathVariable String URN) throws XMLStreamException, IOException, FedoraClientException { String pid = fedoraRepository.getPIDByIdentifier(URN); List<Tuple<String>> constituentPredecessorPids = fedoraRepository.getPredecessorPIDs(pid, FedoraRepository.RELATION_CONSTITUENT); List<Tuple<String>> derivativePredecessorPIDs = fedoraRepository.getPredecessorPIDs(pid, FedoraRepository.RELATION_DERIVATIVE); List<Tuple<String>> constituentSuccessorPids = fedoraRepository.getSuccessorPIDs(pid, FedoraRepository.RELATION_CONSTITUENT); List<Tuple<String>> derivativeSuccessorPids = fedoraRepository.getSuccessorPIDs(pid, FedoraRepository.RELATION_DERIVATIVE); XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory(); StringWriter sw = new StringWriter(); XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(sw); w.writeStartDocument("UTF-8", "1.0"); w.writeStartElement("Opus"); w.writeStartElement("Opus_Document"); w.writeStartElement("DocumentId"); w.writeCharacters(stripPrefix(pid)); w.writeEndElement();//from ww w . j a v a 2s . co m w.writeStartElement("Relations"); writeRelationElement(constituentPredecessorPids, w, "PredecessorRelation", "journal"); writeRelationElement(derivativePredecessorPIDs, w, "PredecessorRelation", "predecessor"); writeRelationElement(constituentSuccessorPids, w, "SuccessorRelation", "issue"); writeRelationElement(derivativeSuccessorPids, w, "SuccessorRelation", "predecessor"); w.writeEndElement(); w.writeEndElement(); w.writeEndElement(); w.writeEndDocument(); w.flush(); return new ResponseEntity<>(sw.toString(), HttpStatus.OK); }
From source file:com.smartbear.jenkins.plugins.testcomplete.TcLogParser.java
public TcLogInfo parse(BuildListener listener) { try {/*from w ww. j a v a2 s. c o m*/ ZipFile logArchive = new ZipFile(log); Node descriptionTopLevelNode = NodeUtils.getRootDocumentNodeFromArchive(logArchive, DESCRIPTION_ENTRY_NAME); if (descriptionTopLevelNode == null) { throw new ParsingException("Unable to obtain description top-level node."); } long startTime = Utils .safeConvertDate(NodeUtils.getTextProperty(descriptionTopLevelNode, START_TIME_PROPERTY_NAME)); long stopTime = Utils .safeConvertDate(NodeUtils.getTextProperty(descriptionTopLevelNode, STOP_TIME_PROPERTY_NAME)); int testCount = 0; try { testCount = Integer .parseInt(NodeUtils.getTextProperty(descriptionTopLevelNode, TEST_COUNT_PROPERTY_NAME)); } catch (NumberFormatException e) { // Do nothing } int warningCount = 0; try { warningCount = Integer .parseInt(NodeUtils.getTextProperty(descriptionTopLevelNode, WARNING_COUNT_PROPERTY_NAME)); } catch (NumberFormatException e) { // Do nothing } int errorCount = 0; try { errorCount = Integer .parseInt(NodeUtils.getTextProperty(descriptionTopLevelNode, ERROR_COUNT_PROPERTY_NAME)); } catch (NumberFormatException e) { // Do nothing } TcLogInfo logInfo = new TcLogInfo(startTime, stopTime, testCount, errorCount, warningCount); String xml = null; if (generateJUnitReports) { XMLStreamWriter xmlStreamWriter = null; try { StringWriter stringWriter = new StringWriter(); xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(stringWriter); convertToXML(logArchive, logInfo, xmlStreamWriter); xmlStreamWriter.flush(); xmlStreamWriter.close(); xmlStreamWriter = null; xml = stringWriter.toString(); } catch (Exception e) { TcLog.error(listener, Messages.TcTestBuilder_ExceptionOccurred(), e.toString()); } finally { if (xmlStreamWriter != null) { xmlStreamWriter.close(); } } } logInfo.setXML(xml); return logInfo; } catch (Exception e) { TcLog.error(listener, Messages.TcTestBuilder_ExceptionOccurred(), e.toString()); return null; } }