List of usage examples for javax.xml.stream XMLStreamWriter writeEndDocument
public void writeEndDocument() throws XMLStreamException;
From source file:org.tolven.assembler.facesconfig.FacesConfigAssembler.java
protected String getXSLT(PluginDescriptor pluginDescriptor) throws XMLStreamException { StringWriter xslt = new StringWriter(); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter xmlStreamWriter = null; boolean added = false; try {/*from ww w . ja v a 2s. c o m*/ xmlStreamWriter = factory.createXMLStreamWriter(xslt); xmlStreamWriter.writeStartDocument("UTF-8", "1.0"); xmlStreamWriter.writeCharacters("\n"); xmlStreamWriter.writeStartElement("xsl:stylesheet"); xmlStreamWriter.writeAttribute("version", "2.0"); xmlStreamWriter.writeNamespace("xsl", "http://www.w3.org/1999/XSL/Transform"); xmlStreamWriter.writeNamespace("tp", "http://java.sun.com/xml/ns/javaee"); xmlStreamWriter.writeAttribute("exclude-result-prefixes", "tp"); xmlStreamWriter.writeCharacters("\n"); xmlStreamWriter.writeStartElement("xsl:output"); xmlStreamWriter.writeAttribute("method", "xml"); xmlStreamWriter.writeAttribute("indent", "yes"); xmlStreamWriter.writeAttribute("encoding", "UTF-8"); xmlStreamWriter.writeAttribute("omit-xml-declaration", "no"); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); addMainTemplate(xmlStreamWriter); addRootTemplate(xmlStreamWriter); added = added | addApplicationChildren(pluginDescriptor, xmlStreamWriter); added = added | addGlobalValidatorTemplates(pluginDescriptor, xmlStreamWriter); added = added | addGlobalConverterTemplates(pluginDescriptor, xmlStreamWriter); added = added | addLifeCycleTemplates(pluginDescriptor, xmlStreamWriter); added = added | addNavigationRuleTemplates(pluginDescriptor, xmlStreamWriter); added = added | addManagedBeanTemplates(pluginDescriptor, xmlStreamWriter); xmlStreamWriter.writeEndDocument(); } finally { if (xmlStreamWriter != null) { xmlStreamWriter.close(); } } if (added) { return xslt.toString(); } else { return null; } }
From source file:org.tolven.assembler.tomcatserver.TomcatServerXMLAssembler.java
protected String getXSLT(ExtensionPoint connectorExtensionPoint) throws XMLStreamException, IOException { StringWriter xslt = new StringWriter(); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter xmlStreamWriter = null; try {//from w ww.ja v a2s . c o m xmlStreamWriter = factory.createXMLStreamWriter(xslt); xmlStreamWriter.writeStartDocument("UTF-8", "1.0"); xmlStreamWriter.writeCharacters("\n"); xmlStreamWriter.writeStartElement("xsl:stylesheet"); xmlStreamWriter.writeAttribute("version", "2.0"); xmlStreamWriter.writeNamespace("xsl", "http://www.w3.org/1999/XSL/Transform"); xmlStreamWriter.writeCharacters("\n"); xmlStreamWriter.writeStartElement("xsl:output"); xmlStreamWriter.writeAttribute("method", "xml"); xmlStreamWriter.writeAttribute("indent", "yes"); xmlStreamWriter.writeAttribute("encoding", "UTF-8"); xmlStreamWriter.writeAttribute("omit-xml-declaration", "no"); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); addMainTemplate(xmlStreamWriter); addServiceTemplate(connectorExtensionPoint, xmlStreamWriter); xmlStreamWriter.writeEndDocument(); xmlStreamWriter.writeEndDocument(); } finally { if (xmlStreamWriter != null) { xmlStreamWriter.close(); } } return xslt.toString(); }
From source file:org.tolven.assembler.war.WARAssembler.java
protected void addTagInfo(Extension taglibExn, File myWARPluginDir) throws IOException, XMLStreamException { File metaInfTagDir = new File(myWARPluginDir.getPath() + "/META-INF/tags"); metaInfTagDir.mkdirs();/*from www.j ava2 s .c o m*/ StringWriter tagLibWriter = new StringWriter(); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = null; try { writer = factory.createXMLStreamWriter(tagLibWriter); writer.writeStartDocument("UTF-8", "1.0"); writer.writeCharacters("\n"); writer.writeDTD( "<!DOCTYPE facelet-taglib PUBLIC \"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN\" \"http://java.sun.com/dtd/facelet-taglib_1_0.dtd\">"); writer.writeCharacters("\n"); writer.writeStartElement("facelet-taglib"); writer.writeCharacters("\n"); String namespace = taglibExn.getParameter("namespace").valueAsString(); writer.writeStartElement("namespace"); writer.writeCharacters(namespace); writer.writeEndElement(); writer.writeCharacters("\n"); PluginDescriptor taglibPD = taglibExn.getDeclaringPluginDescriptor(); addTagSource(taglibPD, metaInfTagDir, writer); addTagValidator(taglibPD, writer); addTagConverter(taglibPD, writer); writer.writeEndElement(); writer.writeCharacters("\n"); writer.writeEndDocument(); } finally { if (writer != null) { writer.close(); } } String tagFilename = taglibExn.getParameter("tag-filename").valueAsString(); File metaInfTagFile = new File(metaInfTagDir, tagFilename); logger.debug("Write tagLib string to " + metaInfTagFile.getPath()); FileUtils.writeStringToFile(metaInfTagFile, tagLibWriter.toString()); }
From source file:org.tolven.assembler.webxml.WebXMLAssembler.java
protected String getXSLT(PluginDescriptor pd) throws XMLStreamException { StringWriter xslt = new StringWriter(); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter xmlStreamWriter = null; try {// w ww . j a v a 2 s .co m xmlStreamWriter = factory.createXMLStreamWriter(xslt); xmlStreamWriter.writeStartDocument("UTF-8", "1.0"); xmlStreamWriter.writeCharacters("\n"); xmlStreamWriter.writeStartElement("xsl:stylesheet"); xmlStreamWriter.writeAttribute("version", "2.0"); xmlStreamWriter.writeNamespace("xsl", "http://www.w3.org/1999/XSL/Transform"); xmlStreamWriter.writeNamespace("tp", "http://java.sun.com/xml/ns/javaee"); xmlStreamWriter.writeAttribute("exclude-result-prefixes", "tp"); xmlStreamWriter.writeCharacters("\n"); xmlStreamWriter.writeStartElement("xsl:output"); xmlStreamWriter.writeAttribute("method", "xml"); xmlStreamWriter.writeAttribute("indent", "yes"); xmlStreamWriter.writeAttribute("encoding", "UTF-8"); xmlStreamWriter.writeAttribute("omit-xml-declaration", "no"); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); addMainTemplate(xmlStreamWriter); addRootTemplate(xmlStreamWriter); addContextParameterTemplate(xmlStreamWriter); addContextParameterCallTemplates(pd, xmlStreamWriter); addFilterTemplates(pd, xmlStreamWriter); addListenerTemplates(pd, xmlStreamWriter); addServletTemplates(pd, xmlStreamWriter); addEJBLocalRefTemplates(pd, xmlStreamWriter); addSessionConfigTemplates(pd, xmlStreamWriter); addWelcomeFileListTemplates(pd, xmlStreamWriter); addWebSecurityConstraintTemplates(pd, xmlStreamWriter); addLoginConfigTemplates(pd, xmlStreamWriter); addSecurityRoleTemplates(pd, xmlStreamWriter); addEnvEntryTemplates(pd, xmlStreamWriter); addErrorPageTemplates(pd, xmlStreamWriter); xmlStreamWriter.writeEndDocument(); } finally { if (xmlStreamWriter != null) { xmlStreamWriter.close(); } } return xslt.toString(); }
From source file:org.unitedinternet.cosmo.dav.impl.StandardDavResponse.java
public void sendDavError(CosmoDavException e) throws IOException { setStatus(e.getErrorCode());// w w w . java 2 s . c o m if (!e.hasContent()) { return; } XMLStreamWriter writer = null; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); writer.writeStartDocument(); e.writeTo(writer); writer.writeEndDocument(); setContentType("text/xml; charset=UTF-8"); byte[] bytes = out.toByteArray(); setContentLength(bytes.length); getOutputStream().write(bytes); } catch (Exception e2) { LOG.error("Error writing XML", e2); LOG.error("Original exception", e); setStatus(500); } finally { if (writer != null) { try { writer.close(); } catch (XMLStreamException e2) { LOG.warn("Unable to close XML writer", e2); } } } }
From source file:org.vanbest.xmltv.Horizon.java
/** * @param args/* w ww .j a v a2 s . c om*/ */ 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();/*w w w. j a v a2s .c o m*/ 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/*from w w w . j a v a2s .com*/ * @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//from w ww . j av a 2s .com */ 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//w w w. j a v a2 s .co m */ 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); } }