
Author: ceki Date: Fri Oct 13 17:17:45 2006 New Revision: 673 Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java Log: Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java ============================================================================== --- (empty file) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java Fri Oct 13 17:17:45 2006 @@ -0,0 +1,102 @@ +package ch.qos.logback.core.joran; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.List; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.xml.sax.InputSource; + +import ch.qos.logback.core.joran.spi.JoranException; +import ch.qos.logback.core.joran.spi.SaxEvent; +import ch.qos.logback.core.joran.spi.SaxEventRecorder; +import ch.qos.logback.core.spi.ContextAwareBase; + +public class GenericConfigurator extends ContextAwareBase { + + final public void doConfigure(URL url) throws JoranException { + try { + InputStream in = url.openStream(); + doConfigure(in); + in.close(); + } catch (IOException ioe) { + String errMsg = "Could not open URL [" + url + "]."; + addError(errMsg, ioe); + throw new JoranException(errMsg, ioe); + } + } + + final public void doConfigure(String filename) throws JoranException { + doConfigure(new File(filename)); + } + + final public void doConfigure(File file) throws JoranException { + FileInputStream fis = null; + try { + fis = new FileInputStream(file); + doConfigure(fis); + } catch (IOException ioe) { + String errMsg = "Could not open [" + file.getName() + "]."; + addError(errMsg, ioe); + throw new JoranException(errMsg, ioe); + } finally { + if (fis != null) { + try { + fis.close(); + } catch (java.io.IOException ioe) { + String errMsg = "Could not close [" + file.getName() + "]."; + addError(errMsg, ioe); + throw new JoranException(errMsg,ioe); + } + } + } + } + + final public void doConfigure(InputStream inputStream) throws JoranException { + doConfigure(new InputSource(inputStream)); + } + + List<SaxEvent> recordEvents(InputSource inputSource) throws JoranException { + SAXParser saxParser = null; + SaxEventRecorder saxEventRecorder = new SaxEventRecorder(); + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setValidating(false); + spf.setNamespaceAware(true); + saxParser = spf.newSAXParser(); + } catch (Exception pce) { + String errMsg = "Parser configuration error occured"; + addError(errMsg, pce); + throw new JoranException(errMsg, pce); + } + + try { + saxParser.parse(inputSource, saxEventRecorder); + return saxEventRecorder.saxEventList; + + } catch (IOException ie) { + String errMsg = "I/O error occurred while parsing xml file"; + addError(errMsg, ie); + throw new JoranException(errMsg, ie); + } catch (Exception ex) { + String errMsg = "Problem parsing XML document. See previously reported errors. Abandoning all further processing."; + addError(errMsg, ex); + throw new JoranException(errMsg, ex); + } + + } + + final public void doConfigure(final InputSource inputSource) + throws JoranException { + + List<SaxEvent> saxEventList; + saxEventList = recordEvents(inputSource); + + } + +} Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java Fri Oct 13 17:17:45 2006 @@ -59,8 +59,7 @@ */ abstract public class JoranConfiguratorBase extends ContextAwareBase { Interpreter joranInterpreter; - boolean listAppnderAttached = false; - + final public void doConfigure(URL url) { try {