001: /*
002: LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
003:
004:
005: Copyright (C) 2003 Together
006:
007: This library is free software; you can redistribute it and/or
008: modify it under the terms of the GNU Lesser General Public
009: License as published by the Free Software Foundation; either
010: version 2.1 of the License, or (at your option) any later version.
011:
012: This library is distributed in the hope that it will be useful,
013: but WITHOUT ANY WARRANTY; without even the implied warranty of
014: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: Lesser General Public License for more details.
016:
017: You should have received a copy of the GNU Lesser General Public
018: License along with this library; if not, write to the Free Software
019: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021:
022: package org.webdocwf.util.loader.generator;
023:
024: import java.io.File;
025: import java.io.FileOutputStream;
026:
027: import org.apache.xml.serialize.Method;
028: import org.apache.xml.serialize.OutputFormat;
029: import org.apache.xml.serialize.XMLSerializer;
030: import org.w3c.dom.Document;
031: import org.webdocwf.util.loader.LoaderException;
032: import org.webdocwf.util.loader.logging.Logger;
033: import org.webdocwf.util.loader.logging.StandardLogger;
034:
035: /**
036: * WriteDomlFile class writes the doml file.
037: * @author Radoslav Dutina
038: * @version 1.0
039: */
040: public class WriteDomlFile {
041:
042: private String domlName = null;
043: private Logger logger;
044:
045: /**
046: * Construct object WriteDomlFile with associated parameters.
047: * @param documentDoml is reference object of the Document class.
048: * @param generatorParameters represents the references to InputParameter object.
049: * database.
050: * @throws LoaderException
051: */
052: public WriteDomlFile(Document documentDoml,
053: InputParameters generatorParameters) throws LoaderException {
054: setLogger();
055: this .logger.write("full", "WriteDomlFile is started.");
056: domlName = generatorParameters.getTargetType();
057: try {
058: File xmlFile = null;
059: if (generatorParameters.getGeneratorOutput()
060: .equalsIgnoreCase("")) {
061: xmlFile = new File("doml");
062: } else {
063: xmlFile = new File(generatorParameters
064: .getGeneratorOutput()
065: + "/doml");
066: }
067: if (!xmlFile.exists())
068: xmlFile.mkdirs();
069:
070: FileOutputStream os = new FileOutputStream(xmlFile + "/"
071: + domlName + ".doml");
072: OutputFormat of = new OutputFormat(); //xerces apache.xml.serializer
073: of.setIndenting(true);
074: of.setIndent(4);
075: of.setMethod(Method.XML);
076: of.setPreserveSpace(false);
077: of.setLineWidth(0);
078: //of.setOmitXMLDeclaration(true);
079: XMLSerializer out = new XMLSerializer(os, of);
080: //IOException
081: out.serialize(documentDoml);
082: } catch (Exception e) {
083: String msg = "Exception in class WriteDomlFile: Error has occurred when trying to write doml file!";
084: LoaderException le = new LoaderException(msg, (Throwable) e);
085: this .logger.write("full", "Exception:" + msg + "\n"
086: + le.getStackTraceAsString());
087: throw le;
088: }
089: this .logger.write("full", "WriteDomlFile is finished.");
090:
091: }
092:
093: /**
094: * This method will set logger object
095: * @param logger
096: */
097: private void setLogger() {
098: this.logger = StandardLogger.getCentralLogger();
099: }
100: }
|