List of usage examples for javax.xml.stream XMLStreamWriter writeStartDocument
public void writeStartDocument(String encoding, String version) 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 {// w w w. j a va 2 s. 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 {/* w ww . j a v a 2 s.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();// w ww .j a va 2 s . co 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 {//from w ww .ja va2 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.xwiki.xar.XarPackage.java
/** * Write the package descriptor to the passed stream as XML. * // ww w. j av a 2 s. c om * @param stream the stream to the resulting XML file * @param encoding the encoding to use to write the descriptor * @throws XarException when failing to parse the descriptor * @throws IOException when failing to read the file */ public void write(OutputStream stream, String encoding) throws XarException, IOException { XMLStreamWriter writer; try { writer = XMLOutputFactory.newInstance().createXMLStreamWriter(stream, encoding); } catch (Exception e) { throw new XarException("Failed to create an instance of XML stream writer", e); } writer = new IndentingXMLStreamWriter(writer); try { writer.writeStartDocument(encoding, "1.0"); write(writer); writer.writeEndDocument(); writer.flush(); } catch (Exception e) { throw new XarException("Failed to write XML", e); } finally { try { writer.close(); } catch (XMLStreamException e) { throw new XarException("Failed to close XML writer", e); } } }
From source file:solidbase.core.DBVersion.java
/** * Dumps the current log in XML format to the given output stream, with the given character set. * * @param out The outputstream to which the xml will be written. * @param charSet The requested character set. *///w w w. jav a 2s .c om protected void logToXML(OutputStream out, Charset charSet) { // This method does not care about staleness boolean spec11 = SPEC11.equals(this.effectiveSpec); try { Connection connection = this.database.getDefaultConnection(); Statement stat = connection.createStatement(); try { ResultSet result = stat.executeQuery("SELECT " + (spec11 ? "TYPE, " : "") + "SOURCE, TARGET, STATEMENT, STAMP, COMMAND, RESULT FROM " + this.logTableName + " ORDER BY STAMP"); XMLOutputFactory xof = XMLOutputFactory.newInstance(); XMLStreamWriter xml = xof.createXMLStreamWriter(new OutputStreamWriter(out, charSet)); xml.writeStartDocument("UTF-8", SPEC10); xml.writeStartElement("log"); while (result.next()) { int i = 1; xml.writeStartElement("record"); if (spec11) xml.writeAttribute("type", result.getString(i++)); xml.writeAttribute("source", StringUtils.defaultString(result.getString(i++))); xml.writeAttribute("target", result.getString(i++)); xml.writeAttribute("statement", String.valueOf(result.getInt(i++))); xml.writeAttribute("stamp", String.valueOf(result.getTimestamp(i++))); String sql = result.getString(i++); if (sql != null) { xml.writeStartElement("command"); xml.writeCharacters(sql); xml.writeEndElement(); } String res = result.getString(i++); if (res != null) { xml.writeStartElement("result"); xml.writeCharacters(res); xml.writeEndElement(); } xml.writeEndElement(); } xml.writeEndElement(); xml.writeEndDocument(); xml.close(); } finally { stat.close(); connection.commit(); } } catch (XMLStreamException e) { throw new SystemException(e); } catch (SQLException e) { throw new SystemException(e); } }