Java 类org.dom4j.io.SAXWriter 实例源码

项目:vfs-maven-plugin    文件:XmlHandling.java   
/**
 * Opens the metadata file and initializes the internal XML document for the
 * metadata.
 * <p>
 * from org.opencms.importexport.CmsExport
 *
 * @param metadataFile
 *            file to write metadata to
 * @return the node in the XML document where all files are appended to
 * @throws SAXException
 *             if something goes wrong procesing the manifest.xml
 * @throws IOException
 *             if something goes wrong while closing the export file
 */

// code taken from org.opencms.importexport.CmsExport
protected final Element openExportFile(final File metadataFile)
    throws IOException, SAXException {
    CmsXmlSaxWriter saxHandler;

    if (metadataFile.isDirectory()) {
        metadataFile.mkdirs();
    } else {
        final File parentFolder = new File(metadataFile.getPath()
                                                       .replace('/',
                    File.separatorChar)
                                                       .substring(0,
                    metadataFile.getPath().lastIndexOf(File.separator)));
        parentFolder.mkdirs();
    }

    final String encoding = OpenCms.getSystemInfo().getDefaultEncoding();
    // saxHandler = new CmsXmlSaxWriter(new BufferedWriter(new
    // FileWriter(metadataFile)),
    // OpenCms.getSystemInfo().getDefaultEncoding());
    // in contrast to original OpenCms using a StringWriter we need to
    // explicitely set the file encoding here - it's expected to be
    // different from the systems default file encoding
    saxHandler = new CmsXmlSaxWriter(new OutputStreamWriter(
                new BufferedOutputStream(new FileOutputStream(metadataFile)),
                encoding), encoding);
    // new with OpenCms 6.2.3, but not supported by older CmsXmlSaxWriter class:
    //saxHandler.setEscapeXml(true);
    //saxHandler.setEscapeUnknownChars(true);

    // initialize the dom4j writer object as member variable
    this.setSaxWriter(new SAXWriter(saxHandler, saxHandler));

    // the XML document to write the XMl to
    final Document doc = DocumentHelper.createDocument();
    // start the document
    saxHandler.startDocument();

    // the node in the XML document where the file entries are appended to
    final String exportNodeName = this.getExportNodeName();

    // add main export node to XML document
    final Element exportNode = doc.addElement(exportNodeName);
    this.getSaxWriter().writeOpen(exportNode);

    return exportNode;
}
项目:vfs-maven-plugin    文件:XmlHandling.java   
/**
 * Sets the SAX based xml writer to write the XML output to.
 * <p>
 *
 * @param sW
 *            the SAX based xml writer to write the XML output to
 */
private void setSaxWriter(final SAXWriter sW) {
    this.saxWriter = sW;
}
项目:vfs-maven-plugin    文件:XmlHandling.java   
/**
 * Returns the SAX based xml writer to write the XML output to.
 * <p>
 *
 * @return the SAX based xml writer to write the XML output to
 */
protected final SAXWriter getSaxWriter() {
    return this.saxWriter;
}