List of usage examples for org.dom4j.io SAXWriter SAXWriter
public SAXWriter(ContentHandler contentHandler, LexicalHandler lexicalHandler)
From source file:com.christophermrossi.jpt.HTMLFragment.java
License:Open Source License
public void toXhtml(ContentHandler contentHandler, LexicalHandler lexicalHandler) throws PageTemplateException, SAXException { if (dom == null) { parseFragment();/*from w w w.j av a2s . c o m*/ } SAXWriter writer = new SAXWriter(contentHandler, lexicalHandler); for (Iterator i = dom.nodeIterator(); i.hasNext();) { Node node = (Node) i.next(); writer.write(node); } }
From source file:com.webslingerz.jpt.HTMLFragment.java
License:Open Source License
public void toXhtml(ContentHandler contentHandler, LexicalHandler lexicalHandler) throws PageTemplateException, SAXException { if (dom == null) { parseFragment();// w w w . j a va2 s .c o m } SAXWriter writer = new SAXWriter(contentHandler, lexicalHandler); for (Iterator<Node> i = dom.nodeIterator(); i.hasNext();) { Node node = i.next(); writer.write(node); } }
From source file:org.apache.commons.jelly.tags.xml.CopyOfTag.java
License:Apache License
public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException { Object xpathContext = getXPathContext(); if (select == null) { throw new MissingAttributeException("select"); }// w ww .ja v a2 s.c o m SAXWriter saxWriter; if (lexical) { saxWriter = new SAXWriter(output, output); } else { saxWriter = new SAXWriter(output); } Object obj; try { obj = select.evaluate(xpathContext); } catch (JaxenException e) { throw new JellyTagException("Failed to evaluate XPath expression", e); } try { if (obj instanceof List) { List nodes = (List) obj; for (Iterator iter = nodes.iterator(); iter.hasNext();) { Object object = iter.next(); if (object instanceof Node) { saxWriter.write((Node) object); } else if (object != null) { saxWriter.write(object.toString()); } } } else if (obj instanceof Node) { saxWriter.write((Node) obj); } else { saxWriter.write(obj.toString()); } } catch (SAXException e) { throw new JellyTagException("Failed to write XML output.", e); } }
From source file:org.apache.commons.jelly.tags.xml.CopyTag.java
License:Apache License
public void doTag(XMLOutput output) throws JellyTagException { Object xpathContext = getXPathContext(); Object node = xpathContext;//w ww .j a va 2s .co m try { if (select != null) { node = select.selectSingleNode(xpathContext); } if (node instanceof Element) { Element element = (Element) node; SAXWriter saxWriter; if (lexical) { saxWriter = new SAXWriter(output, output); } else { saxWriter = new SAXWriter(output); } saxWriter.writeOpen(element); invokeBody(output); saxWriter.writeClose(element); } else { invokeBody(output); } } catch (SAXException e) { throw new JellyTagException(e); } catch (JaxenException e) { throw new JellyTagException(e); } }
From source file:org.opencms.importexport.CmsExportHelper.java
License:Open Source License
/** * Creates a new export helper.<p> * //from w w w .ja va 2 s. c o m * @param exportPath the export path * @param exportAsFiles indicates if the resources should be exported as individual files or in one big ZIP file * @param validateXml indicates of the manifest.xml should be validated * * @throws SAXException in case of issues creating the manifest.xml * @throws IOException in case of file access issues */ public CmsExportHelper(String exportPath, boolean exportAsFiles, boolean validateXml) throws SAXException, IOException { m_exportPath = exportPath; m_isExportAsFiles = exportAsFiles; removeOldExport(exportPath); Writer writer; if (m_isExportAsFiles) { m_exportPath = m_exportPath + "/"; // write to file system directly String fileName = getRfsFileName(CmsImportExportManager.EXPORT_MANIFEST); File rfsFile = new File(fileName); rfsFile.getParentFile().mkdirs(); rfsFile.createNewFile(); writer = new FileWriter(rfsFile); } else { // create the export ZIP stream m_exportZipStream = new ZipOutputStream(new FileOutputStream(m_exportPath)); // delegate writing to a String writer writer = new StringWriter(SUB_LENGTH); } // generate the SAX XML writer CmsXmlSaxWriter saxHandler = new CmsXmlSaxWriter(writer, OpenCms.getSystemInfo().getDefaultEncoding()); saxHandler.setEscapeXml(true); saxHandler.setEscapeUnknownChars(true); // start the document saxHandler.startDocument(); // set the doctype if needed if (validateXml) { saxHandler.startDTD(CmsImportExportManager.N_EXPORT, null, CmsConfigurationManager.DEFAULT_DTD_PREFIX + CmsImportVersion7.DTD_FILENAME); saxHandler.endDTD(); } // initialize the dom4j writer object m_saxWriter = new SAXWriter(saxHandler, saxHandler); }