1 6 7 package org.contineo.core.config; 8 9 import java.util.ArrayList ; 10 import java.util.Collection ; 11 import java.util.Iterator ; 12 import java.util.List ; 13 14 import org.contineo.core.XMLBean; 15 import org.jdom.Element; 16 20 public class LoggingConfigurator { 21 22 28 private XMLBean xml; 29 30 31 32 public LoggingConfigurator() { 33 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 34 xml = new XMLBean(loader.getResource("logging.xml")); 35 } 36 37 40 public Collection getLoggingFiles() { 41 Collection result = new ArrayList (); 42 List list = xml.getAllChild("appender"); 43 Iterator iter = list.iterator(); 44 while (iter.hasNext()) { 45 Element elem = (Element)iter.next(); 46 List childs = elem.getChildren("param"); 47 Iterator children = childs.iterator(); 48 while (children.hasNext()) { 49 Element child = (Element)children.next(); 50 if (child.getAttributeValue("name").equals("file")) 51 result.add(elem.getAttributeValue("name")); 52 } 53 } 54 return result; 55 } 56 57 60 public Collection getFiles() { 61 Collection result = new ArrayList (); 62 List list = xml.getAllChild("appender"); 63 Iterator iter = list.iterator(); 64 while (iter.hasNext()) { 65 Element elem = (Element)iter.next(); 66 List childs = elem.getChildren("param"); 67 Iterator children = childs.iterator(); 68 while (children.hasNext()) { 69 Element child = (Element)children.next(); 70 if (child.getAttributeValue("name").equals("file")) { 71 String appender = elem.getAttributeValue("name"); 72 String file = getFile(appender); 73 LoggerProperty logger = new LoggerProperty(); 74 logger.setAppender(appender.toLowerCase()); 75 logger.setFile(file); 76 result.add(logger); 77 } 78 } 79 } 80 return result; 81 } 82 83 86 public String getFile(String appender) { 87 String result = ""; 88 Element elem = xml.getChild("appender", "name", appender); 89 List childs = elem.getChildren("param"); 90 Iterator children = childs.iterator(); 91 while (children.hasNext()) { 92 Element child = (Element)children.next(); 93 if (child.getAttributeValue("name").equals("file")) 94 result = child.getAttributeValue("value"); 95 } 96 return result; 97 } 98 99 102 public void setFile(String appender, String file) { 103 Element elem = xml.getChild("appender", "name", appender); 104 List childs = elem.getChildren("param"); 105 Iterator children = childs.iterator(); 106 while (children.hasNext()) { 107 Element child = (Element)children.next(); 108 if (child.getAttributeValue("name").equals("file")) 109 child.setAttribute("value", file); 110 } 111 } 112 113 public boolean write() { 114 return xml.writeXMLDoc(); 115 } 116 } 117 | Popular Tags |