1 2 22 23 package org.webdocwf.util.loader.generator; 24 25 import java.io.File ; 26 import java.io.FileOutputStream ; 27 28 import org.apache.xml.serialize.Method; 29 import org.apache.xml.serialize.OutputFormat; 30 import org.apache.xml.serialize.XMLSerializer; 31 import org.w3c.dom.Document ; 32 import org.webdocwf.util.loader.LoaderException; 33 import org.webdocwf.util.loader.logging.Logger; 34 import org.webdocwf.util.loader.logging.StandardLogger; 35 36 41 public class WriteDomlFile { 42 43 private String domlName = null; 44 private Logger logger; 45 52 public WriteDomlFile(Document documentDoml, InputParameters generatorParameters) throws LoaderException { 53 setLogger(); 54 this.logger.write("full", "WriteDomlFile is started."); 55 domlName = generatorParameters.getTargetType(); 56 try { 57 File xmlFile = null; 58 if (generatorParameters.getGeneratorOutput().equalsIgnoreCase("")) { 59 xmlFile = new File ("doml"); 60 } else { 61 xmlFile = new File (generatorParameters.getGeneratorOutput() + "/doml"); 62 } 63 if (!xmlFile.exists()) 64 xmlFile.mkdirs(); 65 66 FileOutputStream os = new FileOutputStream (xmlFile + "/" + domlName + ".doml"); 67 OutputFormat of = new OutputFormat(); of.setIndenting(true); 69 of.setIndent(4); 70 of.setMethod(Method.XML); 71 of.setPreserveSpace(false); 72 of.setLineWidth(0); 73 XMLSerializer out = new XMLSerializer(os, of); 75 out.serialize(documentDoml); 77 } catch (Exception e) { 78 String msg = "Exception in class WriteDomlFile: Error has occurred when trying to write doml file!"; 79 LoaderException le = new LoaderException(msg, (Throwable ) e); 80 this.logger.write("full","Exception:"+ msg + "\n" + le.getStackTraceAsString()); 81 throw le; 82 } 83 this.logger.write("full", "WriteDomlFile is finished."); 84 85 } 86 90 private void setLogger() { 91 this.logger = StandardLogger.getCentralLogger(); 92 } 93 } | Popular Tags |