📄 writexmlfile.java
字号:
/*
LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
Copyright (C) 2003 Together
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.webdocwf.util.loader.generator;
import java.io.File;
import java.io.FileOutputStream;
import org.apache.xml.serialize.Method;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import org.w3c.dom.Document;
import org.webdocwf.util.loader.LoaderException;
import org.webdocwf.util.loader.logging.Logger;
import org.webdocwf.util.loader.logging.StandardLogger;
/**
*
* WriteXmlFile writes the xml file (ImportDefinition.xml), and creates generatorOutput
* directory if they don't exists.
* @author Radoslav Dutina
* @version 1.0
*/
public class WriteXmlFile {
private Logger logger;
/**
* Construct object WriteXmlFile with associated parameters.
* @param document is the org.w3c.dom.Document object, which is created in CreateIncludeFile class.
* @param generatorParameters represents the references to InputParameter object.
* @throws LoaderException
*/
public WriteXmlFile(Document document, InputParameters generatorParameters) throws LoaderException {
setLogger();
this.logger.write("full", "WriteXmlFile is started.");
try {
IncludeTagAttributes includeTagAttributes = new IncludeTagAttributes();
File xmlFile = null;
if (generatorParameters.getGeneratorOutput().equalsIgnoreCase("")) {
xmlFile = new File("xml");
} else {
xmlFile = new File(generatorParameters.getGeneratorOutput() + "/xml");
}
if (!xmlFile.exists())
xmlFile.mkdirs();
FileOutputStream os = new FileOutputStream(xmlFile + includeTagAttributes.getHref().substring(includeTagAttributes.getHref().lastIndexOf("/")));
OutputFormat of = new OutputFormat(); //xerces apache.xml.serializer
of.setIndenting(true);
of.setIndent(4);
of.setMethod(Method.XML);
of.setPreserveSpace(false);
of.setLineWidth(0);
of.setOmitXMLDeclaration(true);
XMLSerializer out = new XMLSerializer(os, of);
//IOException
out.serialize(document);
} catch (Exception e) {
String msg = "Exception in class WriteXmlFile: Error has occurred when trying to write xml file!";
LoaderException le = new LoaderException(msg, (Throwable) e);
this.logger.write("full","Exception:"+ msg + "\n" + le.getStackTraceAsString());
throw le;
}
this.logger.write("full", "WriteXmlFile is finished.");
}
/**
* This method will set logger object
* @param logger
*/
private void setLogger() {
this.logger = StandardLogger.getCentralLogger();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -