View Javadoc
1 2 /* 3 LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus. 4 5 6 Copyright (C) 2003 Together 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Lesser General Public 10 License as published by the Free Software Foundation; either 11 version 2.1 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Lesser General Public License for more details. 17 18 You should have received a copy of the GNU Lesser General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 */ 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 /*** 37 * 38 * WriteXmlFile writes the xml file (ImportDefinition.xml), and creates generatorOutput 39 * directory if they don't exists. 40 * @author Radoslav Dutina 41 * @version 1.0 42 */ 43 public class WriteXmlFile { 44 private Logger logger; 45 /*** 46 * Construct object WriteXmlFile with associated parameters. 47 * @param document is the org.w3c.dom.Document object, which is created in CreateIncludeFile class. 48 * @param generatorParameters represents the references to InputParameter object. 49 * @throws LoaderException 50 */ 51 52 public WriteXmlFile(Document document, InputParameters generatorParameters) throws LoaderException { 53 setLogger(); 54 this.logger.write("full", "WriteXmlFile is started."); 55 try { 56 IncludeTagAttributes includeTagAttributes = new IncludeTagAttributes(); 57 File xmlFile = null; 58 if (generatorParameters.getGeneratorOutput().equalsIgnoreCase("")) { 59 xmlFile = new File("xml"); 60 } else { 61 xmlFile = new File(generatorParameters.getGeneratorOutput() + "/xml"); 62 } 63 if (!xmlFile.exists()) 64 xmlFile.mkdirs(); 65 66 FileOutputStream os = new FileOutputStream(xmlFile + includeTagAttributes.getHref().substring(includeTagAttributes.getHref().lastIndexOf("/"))); 67 OutputFormat of = new OutputFormat(); //xerces apache.xml.serializer 68 of.setIndenting(true); 69 of.setIndent(4); 70 of.setMethod(Method.XML); 71 of.setPreserveSpace(false); 72 of.setLineWidth(0); 73 of.setOmitXMLDeclaration(true); 74 XMLSerializer out = new XMLSerializer(os, of); 75 //IOException 76 out.serialize(document); 77 78 } catch (Exception e) { 79 String msg = "Exception in class WriteXmlFile: Error has occurred when trying to write xml file!"; 80 LoaderException le = new LoaderException(msg, (Throwable) e); 81 this.logger.write("full","Exception:"+ msg + "\n" + le.getStackTraceAsString()); 82 throw le; 83 } 84 this.logger.write("full", "WriteXmlFile is finished."); 85 } 86 /*** 87 * This method will set logger object 88 * @param logger 89 */ 90 private void setLogger() { 91 this.logger = StandardLogger.getCentralLogger(); 92 } 93 }

This page was automatically generated by Maven