commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From patri...@apache.org
Subject cvs commit: jakarta-commons/digester/src/java/org/apache/commons/digester Digester.java
Date Tue, 20 Aug 2002 00:58:55 GMT
patrickl    2002/08/19 17:58:55

  Modified:    digester/src/java/org/apache/commons/digester Digester.java
  Log:
  This patch makes the SAX's EntityResolver instance configurable and available via the set/get
method. Also, private schema variables are now protected, instead of private, to allow child
of this class to use it. Now Tomcat-5 will use the setEntityResolver to implement XML schema
support locally.
  Submitted by:	Jean-Francois Arcand (jeanfrancois.arcand@sun.com)
  
  Revision  Changes    Path
  1.65      +47 -20    jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java
  
  Index: Digester.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java,v
  retrieving revision 1.64
  retrieving revision 1.65
  diff -u -r1.64 -r1.65
  --- Digester.java	15 Aug 2002 16:42:08 -0000	1.64
  +++ Digester.java	20 Aug 2002 00:58:55 -0000	1.65
  @@ -92,6 +92,7 @@
   import org.xml.sax.helpers.DefaultHandler;
   import org.xml.sax.InputSource;
   import org.xml.sax.Locator;
  +import org.xml.sax.EntityResolver;
   import org.xml.sax.SAXException;
   import org.xml.sax.SAXNotRecognizedException;
   import org.xml.sax.SAXNotSupportedException;
  @@ -205,6 +206,11 @@
   
   
       /**
  +     * The EntityResolver used by the SAX parser. By default it use this class
  +     */
  +    protected EntityResolver entityResolver;
  +    
  +    /**
        * The URLs of entityValidator that have been registered, keyed by the public
        * identifier that corresponds.
        */
  @@ -233,7 +239,7 @@
       /**
        * The JAXP 1.2 property to set up the schemaLanguage used.
        */
  -    private String JAXP_SCHEMA_LANGUAGE =
  +    protected String JAXP_SCHEMA_LANGUAGE =
           "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
   
       
  @@ -311,13 +317,13 @@
        * The XML schema language to use for validating an XML instance. By
        * default this value is set to <code>W3C_XML_SCHEMA</code>
        */
  -    private String schemaLanguage = W3C_XML_SCHEMA;
  +    protected String schemaLanguage = W3C_XML_SCHEMA;
       
           
       /**
        * The XML schema to use for validating an XML instance.
        */
  -    private String schemaLocation = null;
  +    protected String schemaLocation = null;
       
       
       /**
  @@ -349,14 +355,14 @@
       /**
        * The Log to which all SAX event related logging calls will be made.
        */
  -    private Log saxLog =
  +    protected Log saxLog =
           LogFactory.getLog("org.apache.commons.digester.Digester.sax");
       
           
       /**
        * The schema language supported. By default, we use this one.
        */
  -    private static final String W3C_XML_SCHEMA =
  +    protected static final String W3C_XML_SCHEMA =
           "http://www.w3.org/2001/XMLSchema";
       
   
  @@ -895,7 +901,12 @@
           reader.setDTDHandler(this);           
           reader.setContentHandler(this);        
           
  -        reader.setEntityResolver(this);
  +        if (entityResolver == null){
  +            reader.setEntityResolver(this);
  +        } else {
  +            reader.setEntityResolver(entityResolver);           
  +        }
  +        
           reader.setErrorHandler(this);
           return reader;
       }
  @@ -1189,7 +1200,7 @@
        * @param qName The qualified name (with prefix), or the empty
        *   string if qualified names are not available.\
        * @param list The attributes attached to the element. If there are
  -     *   no attributes, it shall be an empty Attributes object.
  +     *   no attributes, it shall be an empty Attributes object. 
        * @exception SAXException if a parsing error is to be reported
        */
       public void startElement(String namespaceURI, String localName,
  @@ -1319,6 +1330,24 @@
   
       // ----------------------------------------------- EntityResolver Methods
   
  +    /**
  +     * Set the <code>EntityResolver</code> used by SAX when resolving
  +     * public id and system id.
  +     * This must be called before the first call to <code>parse()</code>.
  +     * @param entityResolver a class that implement the <code>EntityResolver</code>
interface.
  +     */
  +    public void setEntityResolver(EntityResolver entityResolver){
  +        this.entityResolver = entityResolver;
  +    }
  +    
  +    
  +    /**
  +     * Return the Entity Resolver used by the SAX parser.
  +     * @return Return the Entity Resolver used by the SAX parser.
  +     */
  +    public EntityResolver getEntityResolver(){
  +        return entityResolver;
  +    }
   
       /**
        * Resolve the requested external entity.
  @@ -1337,6 +1366,7 @@
           if (saxLog.isDebugEnabled()) {
               saxLog.debug("resolveEntity('" + publicId + "', '" + systemId + "')");
           }
  +        
           if (publicId != null)
               this.publicId = publicId;
                                          
  @@ -1351,23 +1381,20 @@
               entityURL = (String)entityValidator.get(systemId);
           } 
   
  -        if (entityURL == null){
  +        if (entityURL == null){ 
              return (null); 
           }
           
           // Return an input source to our alternative URL
           if (debug) {
               log.debug(" Resolving to alternate DTD '" + entityURL + "'");
  -        }
  +        }  
           
           try {
  -            URL url = new URL(entityURL);
  -            InputStream stream = url.openStream();
  -            return (new InputSource(stream));
  +            return (new InputSource(entityURL));
           } catch (Exception e) {
               throw createSAXException(e);
           }
  - 
       }
   
   
  @@ -1423,11 +1450,11 @@
        * @exception SAXException if a parsing exception occurs
        */
       public void warning(SAXParseException exception) throws SAXException {
  -
  -        log.error("Parse Warning at line " + exception.getLineNumber() +
  +         if (errorHandler != null) {
  +            log.warn("Parse Warning Error at line " + exception.getLineNumber() +
                   " column " + exception.getColumnNumber() + ": " +
                   exception.getMessage(), exception);
  -        if (errorHandler != null) {
  +            
               errorHandler.warning(exception);
           }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message