List of usage examples for javax.xml.stream XMLStreamWriter flush
public void flush() throws XMLStreamException;
From source file:org.slc.sli.modeling.xmi.comp.XmiMappingWriter.java
public static final void writeMappingDocument(final XmiComparison document, final OutputStream outstream) { final XMLOutputFactory xof = XMLOutputFactory.newInstance(); try {/*from www.j a v a 2 s . co m*/ final XMLStreamWriter xsw = new IndentingXMLStreamWriter(xof.createXMLStreamWriter(outstream, "UTF-8")); xsw.writeStartDocument("UTF-8", "1.0"); try { writeMappingDocument(document, xsw); } finally { xsw.writeEndDocument(); } xsw.flush(); xsw.close(); } catch (final XMLStreamException e) { throw new XmiCompRuntimeException(e); } }
From source file:org.slc.sli.modeling.xmi.writer.XmiWriter.java
public static final void writeDocument(final Model model, final ModelIndex mapper, final OutputStream outstream) { final XMLOutputFactory xof = XMLOutputFactory.newInstance(); try {/* ww w . j av a 2 s . com*/ final XMLStreamWriter xsw = new IndentingXMLStreamWriter(xof.createXMLStreamWriter(outstream, "UTF-8")); xsw.writeStartDocument("UTF-8", "1.0"); try { XmiWriter.writeXMI(model, mapper, xsw); } finally { xsw.writeEndDocument(); } xsw.flush(); } catch (final XMLStreamException e) { throw new XmiRuntimeException(e); } }
From source file:org.staxcel.internal.SpreadSheetImpl.java
protected void flushDynamicTemplateWriter(TokenEnumerableTemplateWriter templateWriter, XMLOutputFactory xmlOutFactory) throws IOException { String token = templateWriter.getToken(); while (token != null) { XMLStreamWriter xmlWriter = null; try {// w w w .j a va2 s.c om if (token.equals("worksheets.count")) { templateWriter.getOutputWriter().write(String.valueOf(this.worksheetList.size())); } else if (token.equals("worksheets.vector")) { xmlWriter = xmlOutFactory.createXMLStreamWriter(appXmlTemplateWriter.getOutputWriter()); xmlWriter.writeStartElement("vt:vector"); xmlWriter.writeAttribute("size", String.valueOf(this.worksheetList.size())); xmlWriter.writeAttribute("baseType", "lpstr"); for (int index = 0; index < this.worksheetList.size(); ++index) { xmlWriter.writeStartElement("vt:lpstr"); xmlWriter.writeCharacters(this.worksheetList.get(index).getName()); xmlWriter.writeEndElement(); } xmlWriter.writeEndElement(); } else if (token.equals("worksheet.relationships")) { xmlWriter = xmlOutFactory.createXMLStreamWriter(templateWriter.getOutputWriter()); for (int index = 0; index < worksheetList.size(); ++index) { WorksheetImpl worksheet = worksheetList.get(index); xmlWriter.writeStartElement("Relationship"); xmlWriter.writeAttribute("Id", "rId" + worksheet.getResourceId()); xmlWriter.writeAttribute("Type", OpenXMLNamespace.NS_OPENXML_OFFICE_DOC_2006_REL_WORKSHEET); xmlWriter.writeAttribute("Target", "worksheets/sheet" + worksheet.getWorksheetNumber() + ".xml"); xmlWriter.writeEndElement(); } } else if (token.equals("workbook.sheets")) { xmlWriter = xmlOutFactory.createXMLStreamWriter(templateWriter.getOutputWriter()); for (int index = 0; index < worksheetList.size(); ++index) { WorksheetImpl worksheet = worksheetList.get(index); xmlWriter.writeStartElement("sheet"); xmlWriter.writeAttribute("name", "Sheet" + worksheet.getWorksheetNumber()); xmlWriter.writeAttribute("sheetId", String.valueOf(worksheet.getWorksheetNumber())); xmlWriter.writeAttribute("r:id", "rId" + worksheet.getResourceId()); xmlWriter.writeEndElement(); } } else { // unknown. Invoke a protected method which can be // overridden by derived classes // to add new template variables and interpret them // accordingly. expandToken(token, templateWriter); } } catch (XMLStreamException ex) { throw new StaxcelException("Error when replacing " + token + " from template file", ex); } finally { if (xmlWriter != null) { try { xmlWriter.flush(); xmlWriter.close(); } catch (XMLStreamException ex2) { logger.error("Error when closing xmlstream", ex2); } } } token = templateWriter.nextElement(); } templateWriter.getOutputWriter().flush(); templateWriter.getOutputWriter().close(); }
From source file:org.vanbest.xmltv.Horizon.java
/** * @param args// w ww.j a va 2 s . c o m */ public static void main(String[] args) { Config config = Config.getDefaultConfig(); Horizon horizon = new Horizon(config); horizon.clearCache(); try { List<Channel> channels = horizon.getChannels(); System.out.println("Channels: " + channels); XMLStreamWriter writer = XMLOutputFactory.newInstance() .createXMLStreamWriter(new FileWriter("horizon.xml")); writer.writeStartDocument(); writer.writeCharacters("\n"); writer.writeDTD("<!DOCTYPE tv SYSTEM \"xmltv.dtd\">"); writer.writeCharacters("\n"); writer.writeStartElement("tv"); // List<Channel> my_channels = channels; List<Channel> my_channels = channels.subList(0, 5); for (Channel c : my_channels) { c.serialize(writer, true); } writer.flush(); for (int day = 0; day < 5; day++) { List<Programme> programmes = horizon.getProgrammes(my_channels, day); for (Programme p : programmes) { p.serialize(writer); } } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); if (!config.quiet) { EPGSource.Stats stats = horizon.getStats(); System.out.println("Number of programmes from cache: " + stats.cacheHits); System.out.println("Number of programmes fetched: " + stats.cacheMisses); System.out.println("Number of fetch errors: " + stats.fetchErrors); } horizon.close(); } catch (Exception e) { logger.error("Error in horizon testing", e); } }
From source file:org.vanbest.xmltv.Main.java
public void fetchData() throws FactoryConfigurationError, Exception { if (!config.quiet) { showHeader();/*from w w w . j a v a 2 s.com*/ logger.info("Fetching programme data for " + this.days + " days starting from day " + this.offset); int enabledCount = 0; for (Channel c : config.channels) { if (c.enabled) enabledCount++; } logger.info("... from " + enabledCount + " channels"); logger.info("... using cache at " + config.cacheDbHandle); } if (clearCache) { ProgrammeCache cache = new ProgrammeCache(config); cache.clear(); cache.close(); } Map<String, EPGSource> guides = new HashMap<String, EPGSource>(); EPGSourceFactory factory = EPGSourceFactory.newInstance(); // EPGSource gids = new TvGids(config); // if (clearCache) gids.clearCache(); XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputWriter); writer.writeStartDocument(); writer.writeCharacters("\n"); writer.writeDTD("<!DOCTYPE tv SYSTEM \"xmltv.dtd\">"); writer.writeCharacters("\n"); writer.writeStartElement("tv"); writer.writeAttribute("generator-info-url", "http://github.com/janpascal/tv_grab_nl_java"); writer.writeAttribute("source-info-url", "http://tvgids.nl/"); writer.writeAttribute("source-info-name", "TvGids.nl"); writer.writeAttribute("generator-info-name", "tv_grab_nl_java release " + config.project_version + ", built " + config.build_time); writer.writeCharacters(System.getProperty("line.separator")); for (Channel c : config.channels) if (c.enabled) c.serialize(writer, config.fetchLogos); for (int day = offset; day < offset + days; day++) { if (!config.quiet) System.out.print("Fetching information for day " + day); for (Channel c : config.channels) { if (!c.enabled) continue; if (!config.quiet) System.out.print("."); if (!guides.containsKey(c.source)) { guides.put(c.source, factory.createEPGSource(c.source, config)); } List<Programme> programmes = guides.get(c.source).getProgrammes(c, day); for (Programme p : programmes) p.serialize(writer); writer.flush(); } if (!config.quiet) System.out.println(); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); writer.close(); for (String source : guides.keySet()) { guides.get(source).close(); } if (!config.quiet) { EPGSource.Stats stats = new EPGSource.Stats(); for (String source : guides.keySet()) { EPGSource.Stats part = guides.get(source).getStats(); stats.cacheHits += part.cacheHits; stats.cacheMisses += part.cacheMisses; stats.fetchErrors += part.fetchErrors; } logger.info("Number of programmes from cache: " + stats.cacheHits); logger.info("Number of programmes fetched: " + stats.cacheMisses); logger.warn("Number of fetch errors: " + stats.fetchErrors); } }
From source file:org.vanbest.xmltv.RTL.java
/** * @param args// w w w .j a va2 s .c o m * @throws FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException { debug = true; Logger.getRootLogger().setLevel(Level.TRACE); Config config = Config.getDefaultConfig(); config.niceMilliseconds = 50; RTL rtl = new RTL(config); if (debug) { rtl.cache.clear(); logger.info("Writing CSV to rtl.csv"); rtl.debugWriter = new PrintWriter(new BufferedOutputStream(new FileOutputStream("rtl.csv"))); rtl.debugWriter.print("\"zender\",\"starttime\",\"title\",\"quark1\",\"quark2\","); /* for (int k = 0; k < rtl.xmlKeys.length; k++) { rtl.debugWriter.print(rtl.xmlKeys[k]); rtl.debugWriter.print(","); } */ rtl.debugWriter.println(); } try { List<Channel> channels = rtl.getChannels(); logger.info("Channels: " + channels); XMLStreamWriter writer = XMLOutputFactory.newInstance() .createXMLStreamWriter(new FileWriter("rtl.xml")); writer.writeStartDocument(); writer.writeCharacters("\n"); writer.writeDTD("<!DOCTYPE tv SYSTEM \"xmltv.dtd\">"); writer.writeCharacters("\n"); writer.writeStartElement("tv"); for (Channel c : channels) { c.serialize(writer, true); } writer.flush(); // List<Programme> programmes = // rtl.getProgrammes(channels.subList(6, 9), 0); for (int day = 0; day < 10; day++) { List<Programme> programmes = rtl.getProgrammes(channels, day); for (Programme p : programmes) { p.serialize(writer); } } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); if (!config.quiet) { EPGSource.Stats stats = rtl.getStats(); logger.info("Number of programmes from cache: " + stats.cacheHits); logger.info("Number of programmes fetched: " + stats.cacheMisses); logger.info("Number of fetch errors: " + stats.fetchErrors); } if (debug) { rtl.debugWriter.flush(); rtl.debugWriter.close(); } rtl.close(); } catch (Exception e) { // TODO Auto-generated catch block logger.debug("Exception in RTL.main()", e); } }
From source file:org.vanbest.xmltv.TvGids.java
/** * @param args/*ww w . j ava 2 s .co m*/ */ public static void main(String[] args) { Config config = Config.getDefaultConfig(); TvGids gids = new TvGids(config); try { List<Channel> channels = gids.getChannels(); System.out.println("Channels: " + channels); XMLStreamWriter writer = XMLOutputFactory.newInstance() .createXMLStreamWriter(new FileWriter("tvgids.xml")); writer.writeStartDocument(); writer.writeCharacters("\n"); writer.writeDTD("<!DOCTYPE tv SYSTEM \"xmltv.dtd\">"); writer.writeCharacters("\n"); writer.writeStartElement("tv"); // List<Channel> my_channels = channels; List<Channel> my_channels = channels.subList(0, 15); for (Channel c : my_channels) { c.serialize(writer, true); } writer.flush(); List<Programme> programmes = gids.getProgrammes(my_channels, 2); for (Programme p : programmes) { p.serialize(writer); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); if (!config.quiet) { EPGSource.Stats stats = gids.getStats(); System.out.println("Number of programmes from cache: " + stats.cacheHits); System.out.println("Number of programmes fetched: " + stats.cacheMisses); System.out.println("Number of fetch errors: " + stats.fetchErrors); } gids.close(); } catch (Exception e) { logger.error("Error in tvgids testing", e); } }
From source file:org.vanbest.xmltv.ZiggoGids.java
/** * @param args/*from ww w. jav a 2 s. c om*/ */ public static void main(String[] args) { Config config = Config.getDefaultConfig(); logger.setLevel(Level.TRACE); ZiggoGids gids = new ZiggoGids(config); try { List<Channel> channels = gids.getChannels(); System.out.println("Channels: " + channels); XMLStreamWriter writer = XMLOutputFactory.newInstance() .createXMLStreamWriter(new FileWriter("ziggogids.xml")); writer.writeStartDocument(); writer.writeCharacters("\n"); writer.writeDTD("<!DOCTYPE tv SYSTEM \"xmltv.dtd\">"); writer.writeCharacters("\n"); writer.writeStartElement("tv"); //List<Channel> my_channels = channels; //List<Channel> my_channels = channels.subList(0, 15); List<Channel> my_channels = channels.subList(0, 4); for (Channel c : my_channels) { c.serialize(writer, true); } writer.flush(); List<Programme> programmes = gids.getProgrammes(my_channels, 2); for (Programme p : programmes) { p.serialize(writer); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); if (!config.quiet) { EPGSource.Stats stats = gids.getStats(); System.out.println("Number of programmes from cache: " + stats.cacheHits); System.out.println("Number of programmes fetched: " + stats.cacheMisses); System.out.println("Number of fetch errors: " + stats.fetchErrors); } gids.close(); } catch (Exception e) { logger.error("Error in ziggogids testing", e); } }
From source file:org.webguitoolkit.ui.util.export.XMLTableExport.java
public void writeTo(Table table, OutputStream out) { TableExportOptions exportOptions = table.getExportOptions(); boolean showOnlyDisplayed = exportOptions.isShowOnlyDisplayedColumns(); try {//from w ww .ja va 2 s . c o m XMLStreamWriter sw = XMLOutputFactory.newInstance().createXMLStreamWriter(out); logger.debug("export table " + ((Table) table).getTitle() + " to xml"); sw.writeStartElement("export"); List<ITableColumn> columns = getTableColumns(showOnlyDisplayed, table); List<?> tabledata = table.getDefaultModel().getFilteredList(); int rownr = 1; for (Iterator<?> it = tabledata.iterator(); it.hasNext();) { sw.writeStartElement("row"); sw.writeAttribute("rownumber", String.valueOf(rownr)); DataBag dbag = (DataBag) it.next(); for (ITableColumn column : columns) { Object obj = dbag.get(column.getProperty()); if (obj != null) { writeObjectTag(sw, column, obj); } } sw.writeEndElement(); rownr++; } sw.writeEndElement(); sw.flush(); sw.close(); } catch (XMLStreamException e) { throw new RuntimeException(e); } catch (FactoryConfigurationError e) { throw new RuntimeException(e); } }
From source file:org.wso2.appserver.integration.tests.wsdl2java.HelloServiceCodeGenTestCase.java
public static void editBuildXmlFile(String buildXMLPath) throws Exception { InputStream in = new FileInputStream(new File(buildXMLPath)); OMElement root = OMXMLBuilderFactory.createOMBuilder(in).getDocumentElement(); FileOutputStream fileOutputStream = null; XMLStreamWriter writer = null; try {/*from w w w. ja v a2s .c om*/ OMElement node; //iterate through Configuration properties Iterator configurationPropertiesIterator = root.getChildElements(); boolean status = false; while (configurationPropertiesIterator.hasNext()) { node = (OMElement) configurationPropertiesIterator.next(); Iterator attribute = node.getAllAttributes(); while (attribute.hasNext()) { OMAttribute attr = (OMAttribute) attribute.next(); if (attr.getAttributeValue().equals("${env.AXIS2_HOME}")) { System.out.println("Found"); attr.setAttributeValue(axis2Home); status = true; break; } } if (status) { //break if the property is modified break; } } fileOutputStream = new FileOutputStream( new File(codeGenPath + File.separator + "generated-sources" + File.separator + "build.xml")); writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream); root.serialize(writer); Thread.sleep(2000); root.build(); } catch (Exception e) { log.error("Unable to edit build.xml" + e.getMessage()); throw new Exception("Unable to edit build.xml" + e.getMessage()); } finally { assert fileOutputStream != null; fileOutputStream.close(); assert writer != null; writer.flush(); } }