KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > generator > WriteDomlFile


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 JavaDoc;
26 import java.io.FileOutputStream JavaDoc;
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 JavaDoc;
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  * WriteDomlFile class writes the doml file.
38  * @author Radoslav Dutina
39  * @version 1.0
40  */

41 public class WriteDomlFile {
42
43     private String JavaDoc domlName = null;
44     private Logger logger;
45     /**
46      * Construct object WriteDomlFile with associated parameters.
47      * @param documentDoml is reference object of the Document class.
48      * @param generatorParameters represents the references to InputParameter object.
49      * database.
50      * @throws LoaderException
51      */

52     public WriteDomlFile(Document JavaDoc documentDoml, InputParameters generatorParameters) throws LoaderException {
53                 setLogger();
54                 this.logger.write("full", "WriteDomlFile is started.");
55         domlName = generatorParameters.getTargetType();
56         try {
57             File JavaDoc xmlFile = null;
58             if (generatorParameters.getGeneratorOutput().equalsIgnoreCase("")) {
59                 xmlFile = new File JavaDoc("doml");
60             } else {
61                 xmlFile = new File JavaDoc(generatorParameters.getGeneratorOutput() + "/doml");
62             }
63             if (!xmlFile.exists())
64                 xmlFile.mkdirs();
65
66             FileOutputStream JavaDoc os = new FileOutputStream JavaDoc(xmlFile + "/" + domlName + ".doml");
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(documentDoml);
77         } catch (Exception JavaDoc e) {
78             String JavaDoc msg = "Exception in class WriteDomlFile: Error has occurred when trying to write doml file!";
79                         LoaderException le = new LoaderException(msg, (Throwable JavaDoc) 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     /**
87                * This method will set logger object
88                * @param logger
89                  */

90     private void setLogger() {
91         this.logger = StandardLogger.getCentralLogger();
92     }
93 }
Popular Tags