cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject cvs commit: xml-cocoon2/src/org/apache/cocoon/xml XMLizable.java
Date Sat, 08 Sep 2001 04:39:04 GMT
vgritsenko    01/09/07 21:39:04

  Modified:    src/org/apache/cocoon/components/language/markup/xsp Tag:
                        cocoon_20_branch XSPObjectHelper.java
               src/org/apache/cocoon/components/source Tag:
                        cocoon_20_branch SitemapSource.java URLSource.java
               src/org/apache/cocoon/generation Tag: cocoon_20_branch
                        FileGenerator.java
               src/org/apache/cocoon/xml Tag: cocoon_20_branch
                        XMLizable.java
  Log:
  exception handling in XMLizable and sources
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.1.1.2.4 +9 -3      xml-cocoon2/src/org/apache/cocoon/components/language/markup/xsp/XSPObjectHelper.java
  
  Index: XSPObjectHelper.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/language/markup/xsp/XSPObjectHelper.java,v
  retrieving revision 1.1.1.1.2.3
  retrieving revision 1.1.1.1.2.4
  diff -u -r1.1.1.1.2.3 -r1.1.1.1.2.4
  --- XSPObjectHelper.java	2001/09/05 22:18:11	1.1.1.1.2.3
  +++ XSPObjectHelper.java	2001/09/08 04:39:03	1.1.1.1.2.4
  @@ -10,6 +10,8 @@
   import org.apache.cocoon.xml.XMLFragment;
   import org.apache.cocoon.xml.XMLizable;
   import org.apache.cocoon.xml.dom.DOMStreamer;
  +import org.apache.cocoon.ProcessingException;
  +
   import org.w3c.dom.Node;
   import org.xml.sax.ContentHandler;
   import org.xml.sax.SAXException;
  @@ -24,7 +26,7 @@
    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
    * @author <a href="sylvain.wallez@anyware-tech.com">Sylvain Wallez</a>
    *         (Cocoon1 <code>xspExpr()</code> methods port)
  - * @version CVS $Revision: 1.1.1.1.2.3 $ $Date: 2001/09/05 22:18:11 $
  + * @version CVS $Revision: 1.1.1.1.2.4 $ $Date: 2001/09/08 04:39:03 $
    */
   public class XSPObjectHelper {
     /**
  @@ -281,7 +283,11 @@
     {
       if (v != null)
       {
  -      v.toSAX(contentHandler);
  +      try{
  +        v.toSAX(contentHandler);
  +      }catch(ProcessingException e){
  +        throw new SAXException(e);
  +      }
       }
     }
   
  @@ -352,7 +358,7 @@
       }
   
       // Check handled object types in case they were not typed in the XSP
  -    
  +
       // XMLizable
       if (v instanceof XMLizable)
       {
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.19  +29 -15    xml-cocoon2/src/org/apache/cocoon/components/source/SitemapSource.java
  
  Index: SitemapSource.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/source/SitemapSource.java,v
  retrieving revision 1.1.2.18
  retrieving revision 1.1.2.19
  diff -u -r1.1.2.18 -r1.1.2.19
  --- SitemapSource.java	2001/09/06 14:04:30	1.1.2.18
  +++ SitemapSource.java	2001/09/08 04:39:03	1.1.2.19
  @@ -3,7 +3,7 @@
    * ------------------------------------------------------------------------- *
    * This software is published under the terms of the Apache Software License *
    * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                               s                          *
  + * the LICENSE file.                                                         *
    *****************************************************************************/
   
   package org.apache.cocoon.components.source;
  @@ -48,7 +48,7 @@
    * Description of a source which is defined by a pipeline.
    *
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.1.2.18 $ $Date: 2001/09/06 14:04:30 $
  + * @version CVS $Revision: 1.1.2.19 $ $Date: 2001/09/08 04:39:03 $
    */
   
   public final class SitemapSource
  @@ -86,7 +86,7 @@
       private Source redirectSource;
   
       /** The <code>SAXException</code> if unable to get resource */
  -    private SAXException exception;
  +    private ProcessingException exception;
   
       /** Do I need a refresh ? */
       private boolean needsRefresh;
  @@ -110,7 +110,7 @@
           }
   
           // does the uri point to this sitemap or to the root sitemap?
  -        if (uri.startsWith("//") == true) {
  +        if (uri.startsWith("//")) {
               uri = uri.substring(2);
               Processor processor = null;
               try {
  @@ -120,7 +120,7 @@
               }
               this.prefix = ""; // start at the root
               this.processor = processor;
  -        } else if (uri.startsWith("/") == true) {
  +        } else if (uri.startsWith("/")) {
               this.prefix = null;
               uri = uri.substring(1);
               this.processor = sitemap;
  @@ -155,7 +155,9 @@
        * is not possible to determine the date.
        */
       public long getLastModified() {
  -        if (this.needsRefresh == true) this.refresh();
  +        if (this.needsRefresh) {
  +            this.refresh();
  +        }
           return this.lastModificationDate;
       }
   
  @@ -172,11 +174,13 @@
        */
       public InputStream getInputStream()
       throws ProcessingException, IOException {
  +        if (this.needsRefresh) {
  +            this.refresh();
  +        }
           // VG: Why exception is not thrown in constructor?
           if (this.exception != null) {
  -            throw new ProcessingException(this.exception);
  +            throw this.exception;
           }
  -        if (this.needsRefresh == true) this.refresh();
           SitemapComponentSelector serializerSelector = null;
           Serializer serializer = null;
           try {
  @@ -191,6 +195,8 @@
               return new ByteArrayInputStream(os.toByteArray());
           } catch (ComponentException cme) {
               throw new ProcessingException("could not lookup pipeline components", cme);
  +        } catch (ProcessingException e) {
  +            throw e;
           } catch (Exception e) {
               throw new ProcessingException("Exception during processing of " + this.systemId,
e);
           } finally {
  @@ -248,10 +254,13 @@
                       this.redirectSource = this.environment.resolve(redirectURL);
                       this.lastModificationDate = this.redirectSource.getLastModified();
                   }
  +        } catch (ProcessingException e) {
  +            reset();
  +            this.exception = e;
           } catch (Exception e) {
               reset();
  -            this.exception = new SAXException("Could not get sitemap source "
  -                                              + this.systemId, e);
  +            this.exception = new ProcessingException("Could not get sitemap source "
  +                                                     + this.systemId, e);
           }
           this.needsRefresh = false;
       }
  @@ -270,11 +279,13 @@
        * Stream content to the content handler
        */
       public void toSAX(ContentHandler contentHandler)
  -    throws SAXException {
  +    throws SAXException, ProcessingException {
  +        if (this.needsRefresh) {
  +            this.refresh();
  +        }
           if (this.exception != null) {
               throw this.exception;
           }
  -        if (this.needsRefresh == true) this.refresh();
           try {
               XMLConsumer consumer;
               if (contentHandler instanceof XMLConsumer) {
  @@ -291,10 +302,13 @@
                   eventPipeline.process(this.environment);
               }
           } catch (ComponentException cme) {
  -            throw new SAXException("could not lookup pipeline components", cme);
  +            throw new ProcessingException("Could not lookup pipeline components", cme);
  +        } catch (ProcessingException e) {
  +            // Preserve original exception
  +            throw e;
           } catch (Exception e) {
  -            throw new SAXException("Exception during processing of "
  -                                   + this.systemId, e);
  +            throw new ProcessingException("Exception during processing of "
  +                                          + this.systemId, e);
           } finally {
               reset();
           }
  
  
  
  1.1.2.12  +45 -26    xml-cocoon2/src/org/apache/cocoon/components/source/URLSource.java
  
  Index: URLSource.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/source/URLSource.java,v
  retrieving revision 1.1.2.11
  retrieving revision 1.1.2.12
  diff -u -r1.1.2.11 -r1.1.2.12
  --- URLSource.java	2001/09/06 14:04:30	1.1.2.11
  +++ URLSource.java	2001/09/08 04:39:03	1.1.2.12
  @@ -11,6 +11,7 @@
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.cocoon.ProcessingException;
  +import org.apache.cocoon.ResourceNotFoundException;
   import org.apache.cocoon.components.parser.Parser;
   import org.apache.cocoon.environment.ModifiableSource;
   import org.apache.cocoon.xml.XMLConsumer;
  @@ -22,6 +23,7 @@
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.IOException;
  +import java.io.FileNotFoundException;
   import java.io.InputStream;
   import java.lang.reflect.Method;
   import java.net.URL;
  @@ -31,7 +33,7 @@
    * Description of a source which is described by an URL.
    *
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.1.2.11 $ $Date: 2001/09/06 14:04:30 $
  + * @version CVS $Revision: 1.1.2.12 $ $Date: 2001/09/08 04:39:03 $
    */
   
   public final class URLSource implements ModifiableSource {
  @@ -125,27 +127,36 @@
   
       /**
        * Return an <code>InputStream</code> object to read from the source.
  +     *
  +     * @throws ResourceNotFoundException if file not found or 
  +     *         HTTP location does not exist.
  +     * @throws IOException if I/O error occured.
        */
       public InputStream getInputStream()
  -    throws IOException {
  +    throws IOException, ProcessingException {
           this.getInfos();
  -        InputStream input = null;
  -        if (this.isFile == true) {
  -            input = new FileInputStream(this.systemId.substring(FILE.length()));
  -        } else {
  -            if (this.connection == null) {
  -                this.connection = this.url.openConnection();
  -                /* The following requires a jdk 1.3 */
  -                String userInfo = this.getUserInfo();
  -                if (this.url.getProtocol().startsWith("http") == true && userInfo
!= null) {
  -                    this.connection.setRequestProperty("Authorization","Basic "+encodeBASE64(userInfo));
  +        try{
  +            InputStream input = null;
  +            if (this.isFile == true) {
  +                input = new FileInputStream(this.systemId.substring(FILE.length()));
  +            } else {
  +                if (this.connection == null) {
  +                    this.connection = this.url.openConnection();
  +                    /* The following requires a jdk 1.3 */
  +                    String userInfo = this.getUserInfo();
  +                    if (this.url.getProtocol().startsWith("http") == true && userInfo
!= null) {
  +                        this.connection.setRequestProperty("Authorization","Basic "+encodeBASE64(userInfo));
  +                    }
                   }
  -            }
   
  -            input = this.connection.getInputStream();
  -            this.connection = null; // make sure a new connection is created next time
  +                input = this.connection.getInputStream();
  +                this.connection = null; // make sure a new connection is created next time
  +            }
  +            return input;
  +        }catch(FileNotFoundException e){
  +            throw new ResourceNotFoundException("Resource not found "
  +                                                + this.systemId);
           }
  -        return input;
       }
   
       private static boolean checkedURLClass = false;
  @@ -203,9 +214,13 @@
   
       /**
        * Return a new <code>InputSource</code> object
  +     *
  +     * @throws ResourceNotFoundException if file not found or 
  +     *         HTTP location does not exist.
  +     * @throws IOException if I/O error occured.
        */
       public InputSource getInputSource()
  -    throws IOException {
  +    throws IOException, ProcessingException {
           InputSource newObject = new InputSource(this.getInputStream());
           newObject.setSystemId(this.systemId);
           return newObject;
  @@ -292,11 +307,12 @@
            return new String ( out );
        }
   
  -     /**
  -      * Stream content to a content handler or to an XMLConsumer
  +    /**
  +     * Stream content to a content handler or to an XMLConsumer
        */
       public void toSAX(ContentHandler handler)
  -        throws SAXException {
  +        throws SAXException, ProcessingException
  +    {
           Parser parser = null;
           try {
               parser = (Parser)this.manager.lookup(Parser.ROLE);
  @@ -310,15 +326,18 @@
                   }
               }
               parser.parse(this.getInputSource());
  +        } catch (ProcessingException e){
  +            // Preserve original exception
  +            throw e;
           } catch (Exception e){
  -            throw new SAXException("Exception in URLSource.stream()", e);
  +            throw new ProcessingException("Exception during processing of "
  +                                          + this.systemId, e);
           } finally {
               if (parser != null) this.manager.release(parser);
           }
  -     }
  +    }
   
  -  public void recycle()
  -  {
  -  }
  +    public void recycle()
  +    {
  +    }
   }
  -
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.9.2.14  +6 -4      xml-cocoon2/src/org/apache/cocoon/generation/FileGenerator.java
  
  Index: FileGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/generation/FileGenerator.java,v
  retrieving revision 1.9.2.13
  retrieving revision 1.9.2.14
  diff -u -r1.9.2.13 -r1.9.2.14
  --- FileGenerator.java	2001/09/06 11:08:08	1.9.2.13
  +++ FileGenerator.java	2001/09/08 04:39:04	1.9.2.14
  @@ -35,7 +35,7 @@
    * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.9.2.13 $ $Date: 2001/09/06 11:08:08 $
  + * @version CVS $Revision: 1.9.2.14 $ $Date: 2001/09/08 04:39:04 $
    */
   public class FileGenerator extends ComposerGenerator
   implements Cacheable, Recyclable {
  @@ -101,17 +101,19 @@
        * Generate XML data.
        */
       public void generate()
  -    throws IOException, SAXException {
  +    throws IOException, SAXException, ProcessingException {
           try {
               getLogger().debug("processing file " + super.source);
               getLogger().debug("file resolved to " + this.inputSource.getSystemId());
   
               this.inputSource.toSAX(super.xmlConsumer);
  +        } catch (ProcessingException e) {
  +            throw e;
           } catch (Exception e) {
               getLogger().error("Could not read resource "
                                 + this.inputSource.getSystemId(), e);
  -            throw new SAXException("Could not read resource "
  -                                   + this.inputSource.getSystemId(), e);
  +            throw new ProcessingException("Could not read resource "
  +                                          + this.inputSource.getSystemId(), e);
           }
       }
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +5 -3      xml-cocoon2/src/org/apache/cocoon/xml/XMLizable.java
  
  Index: XMLizable.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/xml/XMLizable.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- XMLizable.java	2001/09/05 22:18:16	1.1.2.1
  +++ XMLizable.java	2001/09/08 04:39:04	1.1.2.2
  @@ -7,6 +7,8 @@
    *****************************************************************************/
   package org.apache.cocoon.xml;
   
  +import org.apache.cocoon.ProcessingException;
  +
   import org.xml.sax.ContentHandler;
   import org.xml.sax.SAXException;
   
  @@ -15,7 +17,7 @@
    * of their current state as SAX events.
    *
    * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
  - * @version CVS $Revision: 1.1.2.1 $ $Date: 2001/09/05 22:18:16 $
  + * @version CVS $Revision: 1.1.2.2 $ $Date: 2001/09/08 04:39:04 $
    */
   
   public interface XMLizable {
  @@ -25,6 +27,6 @@
        * that <code>handler</code> can actually be a {@link XMLConsumer} that
accepts such
        * events.
        */
  -    void toSAX(ContentHandler handler) throws SAXException;
  -    
  +    void toSAX(ContentHandler handler) throws SAXException, ProcessingException;
  +
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message