1 22 23 24 package org.webdocwf.util.loader; 25 26 import java.util.*; 27 import java.io.*; 28 import javax.xml.parsers.DocumentBuilderFactory ; 29 import javax.xml.parsers.DocumentBuilder ; 30 import org.w3c.dom.*; 31 import org.xml.sax.*; 32 import org.webdocwf.util.loader.logging.*; 33 34 39 public class ParseLoggerParam { 40 41 private String logClassName = ""; 42 private String pathToLoggerConf = ""; 43 private String pathToLoaderJob=""; 44 45 50 public ParseLoggerParam(String loaderJob) throws LoaderException { 51 File file = new File(loaderJob); 52 this.pathToLoaderJob=file.getAbsoluteFile().getParent(); 53 Document doc = null; 54 try { 55 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 56 DocumentBuilder db = null; 57 db = dbf.newDocumentBuilder(); 58 doc = db.parse(file); 59 } 60 catch (Exception e) { 61 System.out.println("Sorry, an error occurred: " + e.getMessage()); 62 BufferOctopusClass.getInstance().writeToBuffer("Sorry, an error occurred: " + e.getMessage() 63 + "\n"); 64 LoaderException le = new LoaderException("Exception: ", (Throwable )e); 65 throw le; 66 } 67 68 if (doc != null) { 69 NodeList tagLoaderJob = doc.getElementsByTagName("loaderJob"); 70 if (tagLoaderJob.getLength() != 0) { 71 NamedNodeMap log = tagLoaderJob.item(0).getAttributes(); 72 Node nodeLogClassName = log.getNamedItem("logClassName"); 73 if (nodeLogClassName != null) 74 this.logClassName = nodeLogClassName.getNodeValue(); 75 Node nodeLogPath = log.getNamedItem("pathToLoggerConf"); 76 if (nodeLogPath != null){ 77 this.pathToLoggerConf = nodeLogPath.getNodeValue(); 78 File fileLogger=new File(this.pathToLoggerConf); 79 if(!fileLogger.isAbsolute()){ 80 String fullPathToLoggerConf=this.pathToLoaderJob+System.getProperty("file.separator")+ 81 this.pathToLoggerConf; 82 File loggerFile=new File(fullPathToLoggerConf); 83 try { 84 this.pathToLoggerConf=loggerFile.getCanonicalPath(); 85 } 86 catch (Exception ex) { 87 System.out.println(ex.getMessage()); 88 ex.printStackTrace(); 89 } 90 } 91 } 92 } 93 } 94 } 95 96 100 public String getLogClassName() { 101 return this.logClassName; 102 } 103 104 108 public String getPathToLoggerConf() { 109 return this.pathToLoggerConf; 110 } 111 } | Popular Tags |