Enclosed is a real cvs patch file, if that is preferred.

-Mark

-----Original Message-----
From: Mark Womack 
Sent: Tuesday, August 14, 2001 10:56 AM
To: 'LOG4J Users Mailing List'
Subject: [PATCH] DOMConfigurator.java


Enclosed is a modified version of DOMConfigurator.java, based on the current
CVS version 1.27.  This modified version supports java.io.Reader objects in
the method doConfigure(), instead of only InputStream.
org.xml.sax.InputSource supports a constructor which takes a Reader object,
so the change is very simple:

- modified the existing doConfigure(InputStream, Hierarchy) method to
doConfigure(InputSource, Hierarchy) and made it protected instead of public.
- created a new public version of doConfigure(InputStream,Hierarchy) which
calls doConfigure(InputSource, Hierarchy).
- created a new public method, doConfigure(Reader, Hierarchy), which calls
doConfigure(InputSource, Hierarchy).

That's it.  I needed this modification because I have a case where the xml
configuration data is coming from a string, not a file.  So I need to use
the java.io.StringReader class to wrap the existing string.

I would appreciate it if someone on the ant-dev mailing list could evaluate
and submit this change for inclusion in the next version of log4j.

If you have any questions or concerns, please contact me.

Thanks,
-Mark



Index: DOMConfigurator.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-log4j/src/java/org/apache/log4j/xml/DOMConfigurator.java,v
retrieving revision 1.27
diff -u -r1.27 DOMConfigurator.java
--- DOMConfigurator.java        2001/08/06 20:21:01     1.27
+++ DOMConfigurator.java        2001/08/14 18:12:03
@@ -33,6 +33,7 @@
 import org.xml.sax.InputSource;
 import java.io.FileInputStream;
 import java.io.InputStream;
+import java.io.Reader;
 import java.io.IOException;
 import java.net.URL;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -594,6 +595,28 @@
   public
   void doConfigure(InputStream inputStream, Hierarchy hierarchy) 
                                           throws FactoryConfigurationError {
+    doConfigure(new InputSource(inputStream), hierarchy);
+  }
+
+  /**
+     Configure log4j by reading in a log4j.dtd compliant XML
+     configuration file.
+
+  */
+  public
+  void doConfigure(Reader reader, Hierarchy hierarchy) 
+                                          throws FactoryConfigurationError {
+    doConfigure(new InputSource(reader), hierarchy);
+  }
+
+  /**
+     Configure log4j by reading in a log4j.dtd compliant XML
+     configuration file.
+
+  */
+  protected
+  void doConfigure(InputSource inputSource, Hierarchy hierarchy) 
+                                          throws FactoryConfigurationError {
     DocumentBuilderFactory dbf = null;
     try { 
       LogLog.debug("System property is :"+
@@ -616,7 +639,6 @@
       DocumentBuilder docBuilder = dbf.newDocumentBuilder();
       //docBuilder.setErrorHandler(new ReportParserError());
 
-      InputSource inputSource = new InputSource(inputStream);
       Class clazz = this.getClass();
       URL dtdURL = clazz.getResource("/org/apache/log4j/xml/log4j.dtd");
       if(dtdURL == null) {
@@ -631,7 +653,7 @@
       parse(doc.getDocumentElement(), hierarchy);
     } catch (Exception e) {
       // I know this is miserable...
-      LogLog.error("Could not parse input stream ["+inputStream+"].", e);
+      LogLog.error("Could not parse input source ["+inputSource+"].", e);
     }
   }
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to