001: /*
002: Loader - tool for transfering data from one JDBC source to another and
003: doing transformations during copy.
004: Copyright (C) 2002-2003 Together
005: This library is free software; you can redistribute it and/or
006: modify it under the terms of the GNU Lesser General Public
007: License as published by the Free Software Foundation; either
008: version 2.1 of the License, or (at your option) any later version.
009: This library is distributed in the hope that it will be useful,
010: but WITHOUT ANY WARRANTY; without even the implied warranty of
011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: Lesser General Public License for more details.
013: You should have received a copy of the GNU Lesser General Public
014: License along with this library; if not, write to the Free Software
015: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
016: Loader.java
017: Date: 03.03.2003.
018: @version 2.1 alpha
019: @author:
020: Radoslav Dutina rale@prozone.co.yu
021: */
022:
023: package org.webdocwf.util.loader;
024:
025: import java.util.*;
026: import java.io.*;
027: import javax.xml.parsers.DocumentBuilderFactory;
028: import javax.xml.parsers.DocumentBuilder;
029: import org.w3c.dom.*;
030: import org.xml.sax.*;
031: import org.webdocwf.util.loader.logging.*;
032:
033: /**
034: * ParseLoggerParam class is use to check needed parameters for Logger object
035: * @author Radoslav Dutina
036: * @version 1.0
037: */
038: public class ParseLoggerParam {
039:
040: private String logClassName = "";
041: private String pathToLoggerConf = "";
042: private String pathToLoaderJob = "";
043:
044: /**
045: * This is the constructor of ParseLoggerParam class
046: * @param loaderJob defines the string path to loaderJob xml file
047: * @throws LoaderException
048: */
049: public ParseLoggerParam(String loaderJob) throws LoaderException {
050: File file = new File(loaderJob);
051: this .pathToLoaderJob = file.getAbsoluteFile().getParent();
052: Document doc = null;
053: try {
054: DocumentBuilderFactory dbf = DocumentBuilderFactory
055: .newInstance();
056: DocumentBuilder db = null;
057: db = dbf.newDocumentBuilder();
058: doc = db.parse(file);
059: } catch (Exception e) {
060: System.out.println("Sorry, an error occurred: "
061: + e.getMessage());
062: BufferOctopusClass.getInstance().writeToBuffer(
063: "Sorry, an error occurred: " + e.getMessage()
064: + "\n");
065: LoaderException le = new LoaderException("Exception: ",
066: (Throwable) e);
067: throw le;
068: }
069:
070: if (doc != null) {
071: NodeList tagLoaderJob = doc
072: .getElementsByTagName("loaderJob");
073: if (tagLoaderJob.getLength() != 0) {
074: NamedNodeMap log = tagLoaderJob.item(0).getAttributes();
075: Node nodeLogClassName = log
076: .getNamedItem("logClassName");
077: if (nodeLogClassName != null)
078: this .logClassName = nodeLogClassName.getNodeValue();
079: Node nodeLogPath = log.getNamedItem("pathToLoggerConf");
080: if (nodeLogPath != null) {
081: this .pathToLoggerConf = nodeLogPath.getNodeValue();
082: File fileLogger = new File(this .pathToLoggerConf);
083: if (!fileLogger.isAbsolute()) {
084: String fullPathToLoggerConf = this .pathToLoaderJob
085: + System.getProperty("file.separator")
086: + this .pathToLoggerConf;
087: File loggerFile = new File(fullPathToLoggerConf);
088: try {
089: this .pathToLoggerConf = loggerFile
090: .getCanonicalPath();
091: } catch (Exception ex) {
092: System.out.println(ex.getMessage());
093: ex.printStackTrace();
094: }
095: }
096: }
097: }
098: }
099: }
100:
101: /**
102: * This method is use to retrive value of logClassName parameter
103: * @return value of logClassName parameter
104: */
105: public String getLogClassName() {
106: return this .logClassName;
107: }
108:
109: /**
110: * This method is use to retrive value of pathToLoggerCong parameter
111: * @return value of pathToLoggerCong parameter
112: */
113: public String getPathToLoggerConf() {
114: return this.pathToLoggerConf;
115: }
116: }
|