ceki        2004/12/15 07:14:28

  Modified:    src/java/org/apache/log4j/joran/util JoranDocument.java
  Log:
  Compensate for JDK differences in the DefaultHandler.resolveEntity signature.
  
  Revision  Changes    Path
  1.4       +31 -2     
logging-log4j/src/java/org/apache/log4j/joran/util/JoranDocument.java
  
  Index: JoranDocument.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/joran/util/JoranDocument.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JoranDocument.java        10 Dec 2004 22:20:20 -0000      1.3
  +++ JoranDocument.java        15 Dec 2004 15:14:28 -0000      1.4
  @@ -109,7 +109,7 @@
         event.replay(handler, replayLocation);
       }
     }
  -
  +  
     public InputSource resolveEntity(
       final String publicId, final String systemId) throws SAXException {
       //
  @@ -123,7 +123,36 @@
          logger.warn("See {}#log4j_dtd for more details.", 
Constants.CODES_HREF);
         return new InputSource(new ByteArrayInputStream(new byte[0]));
       }
  -    return super.resolveEntity(publicId, systemId);
  +    
  +    // If the systemId is not for us to handle, we delegate to our super
  +    // class, at leasts that's the basic idea. However, the code below
  +    // needs to be more complicated.
  +    
  +    // Due to inexplicable voodoo, the original resolveEntity method in 
  +    // org.xml.sax.helpers.DefaultHandler declares throwing an IOException, 
  +    // whereas the org.xml.sax.helpers.DefaultHandler class included in
  +    // JDK 1.4 masks this exception. In JDK 1.5, the IOException has been
  +    // put back...
  +     
  +    // In order to compile under JDK 1.4, we are forced to mask the 
IOException
  +    // as well. Since its signatures varies, we cannot call our super class' 
  +    // resolveEntity method. We are forced to implement the default behavior 
  +    // ourselves, which in this case, is just returning null.
  +    try {
  +      return super.resolveEntity(publicId, systemId);
  +    } catch(Exception e) {
  +      if(e instanceof SAXException) {
  +        throw (SAXException) e;
  +      } else if(e instanceof java.io.IOException) {
  +        // fall back to the default "implementation"
  +        Logger logger = LogManager.getLogger(this.getClass().getName());
  +        logger.error("Default entity resolver threw an IOException", e);
  +        return null;
  +      } else {
  +        // This point should can never be reached.
  +        return null;
  +      }
  +    }
     }
   
     public void setDocumentLocator(Locator location) {
  
  
  

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

Reply via email to