You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ca...@apache.org on 2007/08/23 19:07:10 UTC
svn commit: r569073 - in
/logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/xml:
UtilLoggingEntityResolver.java UtilLoggingXMLDecoder.java
Author: carnold
Date: Thu Aug 23 10:06:59 2007
New Revision: 569073
URL: http://svn.apache.org/viewvc?rev=569073&view=rev
Log:
Eliminate need to resolve logger.dtd
Modified:
logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/xml/UtilLoggingEntityResolver.java
logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/xml/UtilLoggingXMLDecoder.java
Modified: logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/xml/UtilLoggingEntityResolver.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/xml/UtilLoggingEntityResolver.java?rev=569073&r1=569072&r2=569073&view=diff
==============================================================================
--- logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/xml/UtilLoggingEntityResolver.java (original)
+++ logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/xml/UtilLoggingEntityResolver.java Thu Aug 23 10:06:59 2007
@@ -17,21 +17,16 @@
package org.apache.log4j.xml;
-import org.apache.log4j.LogManager;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
-import java.io.InputStream;
+import java.io.ByteArrayInputStream;
/**
* An {@link EntityResolver} specifically designed to return
- * <code>java 1.4's logging dtd, logger.dtd</code>
- * which is embedded within the log4j jar file. Based on EntityResolver.
+ * an empty InputSource for logger.dtd.
*
- *
- * @author Paul Austin
- * @author Scott Deboy (sdeboy@apache.org)
*/
public final class UtilLoggingEntityResolver implements EntityResolver {
@@ -47,17 +42,7 @@
public InputSource resolveEntity(final String publicId,
final String systemId) {
if (systemId.endsWith("logger.dtd")) {
- Class clazz = getClass();
- InputStream in =
- clazz.getResourceAsStream("/org/apache/log4j/xml/logger.dtd");
- if (in == null) {
- LogManager.getLogger(UtilLoggingEntityResolver.class).error(
- "Could not find [logger.dtd]. Used [" + clazz.getClassLoader()
- + "] class loader in the search.");
- return null;
- } else {
- return new InputSource(in);
- }
+ return new InputSource(new ByteArrayInputStream(new byte[0]));
} else {
return null;
}
Modified: logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/xml/UtilLoggingXMLDecoder.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/xml/UtilLoggingXMLDecoder.java?rev=569073&r1=569072&r2=569073&view=diff
==============================================================================
--- logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/xml/UtilLoggingXMLDecoder.java (original)
+++ logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/xml/UtilLoggingXMLDecoder.java Thu Aug 23 10:06:59 2007
@@ -63,8 +63,7 @@
* Document prolog.
*/
private static final String BEGIN_PART =
- "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
- + "<!DOCTYPE log SYSTEM \"logger.dtd\"><log>";
+ "<log>";
/**
* Document close.
*/
@@ -163,7 +162,6 @@
InputSource inputSource =
new InputSource(new StringReader(buf.toString()));
- inputSource.setSystemId("dummy://logger.dtd");
document = docBuilder.parse(inputSource);
} catch (Exception e) {
e.printStackTrace();
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org
Re: svn commit: r569073 - in /logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/xml: UtilLoggingEntityResolver.java UtilLoggingXMLDecoder.java
Posted by Curt Arnold <ca...@apache.org>.
This change should eliminate the need to provide logger.dtd with no
degradation of behavior (actually should be a tad faster).
On Aug 23, 2007, at 12:07 PM, carnold@apache.org wrote:
> Author: carnold
> Date: Thu Aug 23 10:06:59 2007
> New Revision: 569073
>
> URL: http://svn.apache.org/viewvc?rev=569073&view=rev
> Log:
> Eliminate need to resolve logger.dtd
>
> Modified:
> logging/log4j/companions/receivers/trunk/src/main/java/org/
> apache/log4j/xml/UtilLoggingEntityResolver.java
> logging/log4j/companions/receivers/trunk/src/main/java/org/
> apache/log4j/xml/UtilLoggingXMLDecoder.java
>
> Modified: logging/log4j/companions/receivers/trunk/src/main/java/
> org/apache/log4j/xml/UtilLoggingEntityResolver.java
> URL: http://svn.apache.org/viewvc/logging/log4j/companions/
> receivers/trunk/src/main/java/org/apache/log4j/xml/
> UtilLoggingEntityResolver.java?
> rev=569073&r1=569072&r2=569073&view=diff
> ======================================================================
> ========
> --- logging/log4j/companions/receivers/trunk/src/main/java/org/
> apache/log4j/xml/UtilLoggingEntityResolver.java (original)
> +++ logging/log4j/companions/receivers/trunk/src/main/java/org/
> apache/log4j/xml/UtilLoggingEntityResolver.java Thu Aug 23 10:06:59
> 2007
Basically any request for logger.dtd will get you an empty
InputSource (just like the file was there but empty). Sun's
logger.dtd does not contain any default attribute values which would
be the only thing a DTD would provide when validation is disabled
(like it is in UtilLoggingXMLDecoder).
>
> Modified: logging/log4j/companions/receivers/trunk/src/main/java/
> org/apache/log4j/xml/UtilLoggingXMLDecoder.java
> URL: http://svn.apache.org/viewvc/logging/log4j/companions/
> receivers/trunk/src/main/java/org/apache/log4j/xml/
> UtilLoggingXMLDecoder.java?rev=569073&r1=569072&r2=569073&view=diff
> ======================================================================
> ========
> --- logging/log4j/companions/receivers/trunk/src/main/java/org/
> apache/log4j/xml/UtilLoggingXMLDecoder.java (original)
> +++ logging/log4j/companions/receivers/trunk/src/main/java/org/
> apache/log4j/xml/UtilLoggingXMLDecoder.java Thu Aug 23 10:06:59 2007
> @@ -63,8 +63,7 @@
> * Document prolog.
> */
> private static final String BEGIN_PART =
> - "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
> - + "<!DOCTYPE log SYSTEM \"logger.dtd\"><log>";
> + "<log>";
The encoding is meaningless when parsing from a String. I really
doubt that anything would encounter the differences between XML 1.0
and 1.1 which are very esoteric. Adding the DOCTYPE only adds
useless overhead since validation is disabled and the DTD provides no
default values. If it were to stay, the URL should be changed to a
absolute URL since the parser is going to be helpless to resolve
logger.dtd relative to a String (and some parsers attempt to resolve
the URL before passing to the entity resolver).
> /**
> * Document close.
> */
> @@ -163,7 +162,6 @@
>
> InputSource inputSource =
> new InputSource(new StringReader(buf.toString()));
> - inputSource.setSystemId("dummy://logger.dtd");
>
Setting the SystemID for the input source was a kludge to resolve the
relative URL for the DTD. Similar code needed to be removed in the
XMLDecoder since some parsers check that the URL scheme is recognized.
> document = docBuilder.parse(inputSource);
> } catch (Exception e) {
> e.printStackTrace();
>
The code still has some remaining issues. The code that checks
whether the source needs to be wrapped in start and end tags have
holes (for example if the closing </log> tag is followed by
whitespace then a stray extra </log> tag will be added). A more
robust way to do would be to parse something like:
<DOCTYPE log [
<!ENTITY body SYSTEM 'http://localhost/body.xml'>
<log>
&body;
</log>
and provide an EntityResolver that substitutes the string for
body.xml. If you actually had a <log> element in your source, then
you would need to post-process the DOM document to move the second
level log element up to the top.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org