morgand     2003/01/26 01:01:28

  Modified:    
jelly/jelly-tags/velocity/src/java/org/apache/commons/jelly/tags/velocity
                        MergeTag.java VelocityTagSupport.java
  Log:
  converted velocity taglib from Exception to JellyTagException
  
  Revision  Changes    Path
  1.2       +36 -12    
jakarta-commons-sandbox/jelly/jelly-tags/velocity/src/java/org/apache/commons/jelly/tags/velocity/MergeTag.java
  
  Index: MergeTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/velocity/src/java/org/apache/commons/jelly/tags/velocity/MergeTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MergeTag.java     7 Jan 2003 03:33:31 -0000       1.1
  +++ MergeTag.java     26 Jan 2003 09:01:28 -0000      1.2
  @@ -56,10 +56,15 @@
    * ====================================================================
    */
   
  -import org.apache.commons.jelly.JellyException;
  +import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.XMLOutput;
   
  +import org.apache.velocity.exception.MethodInvocationException;
  +import org.apache.velocity.exception.ParseErrorException;
  +import org.apache.velocity.exception.ResourceNotFoundException;
  +
   import java.io.FileOutputStream;
  +import java.io.IOException;
   import java.io.OutputStreamWriter;
   import java.io.StringWriter;
   import java.io.Writer;
  @@ -86,21 +91,26 @@
   
       // -- Tag interface -----------------------------------------------------
   
  -    public void doTag( final XMLOutput output ) throws Exception 
  +    public void doTag( final XMLOutput output ) throws JellyTagException 
       {
           if ( basedir == null || template == null )
           {
  -            throw new JellyException( 
  +            throw new JellyTagException( 
                       "This tag must define 'basedir' and 'template'" );
           }
   
           if ( name != null )
           {
  -            Writer writer = new OutputStreamWriter( 
  -                    new FileOutputStream( name ), 
  -                    outputEncoding == null ? ENCODING : outputEncoding );
  -            mergeTemplate( writer );
  -            writer.close();
  +            try {
  +                Writer writer = new OutputStreamWriter( 
  +                        new FileOutputStream( name ), 
  +                        outputEncoding == null ? ENCODING : outputEncoding );
  +                mergeTemplate( writer );
  +                writer.close();
  +            } 
  +            catch (IOException e) {
  +                throw new JellyTagException(e);
  +            } 
           }
           else if ( var != null )
           {
  @@ -110,7 +120,7 @@
           }
           else 
           {
  -            throw new JellyException( 
  +            throw new JellyTagException( 
                       "This tag must define either 'name' or 'var'" );
           }
       }
  @@ -207,16 +217,30 @@
        * @param writer The output writer used to write the merged results.
        * @throws Exception If an exception occurs during the merge.
        */
  -    private void mergeTemplate( Writer writer ) throws Exception 
  +    private void mergeTemplate( Writer writer ) throws JellyTagException
       {
           JellyContextAdapter adapter = new JellyContextAdapter( getContext() );
           adapter.setReadOnly( readOnly );
   
  -        getVelocityEngine( basedir ).mergeTemplate( 
  +        try {
  +            getVelocityEngine( basedir ).mergeTemplate( 
                   template,
                   inputEncoding == null ? ENCODING : inputEncoding, 
                   adapter,
                   writer );
  +        } 
  +        catch (ResourceNotFoundException e) {
  +            throw new JellyTagException(e);
  +        }
  +        catch (ParseErrorException e) {
  +            throw new JellyTagException(e);
  +        }
  +        catch (MethodInvocationException e) {
  +            throw new JellyTagException(e);
  +        } 
  +        catch (Exception e) {
  +            throw new JellyTagException(e);
  +        }
       }
   }
       
  
  
  
  1.2       +10 -3     
jakarta-commons-sandbox/jelly/jelly-tags/velocity/src/java/org/apache/commons/jelly/tags/velocity/VelocityTagSupport.java
  
  Index: VelocityTagSupport.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/velocity/src/java/org/apache/commons/jelly/tags/velocity/VelocityTagSupport.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- VelocityTagSupport.java   7 Jan 2003 03:33:31 -0000       1.1
  +++ VelocityTagSupport.java   26 Jan 2003 09:01:28 -0000      1.2
  @@ -56,6 +56,7 @@
    * ====================================================================
    */
   
  +import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.TagSupport;
   import org.apache.velocity.app.VelocityEngine;
   
  @@ -82,7 +83,7 @@
        * @return A VelocityEngine with a file resource loader configured
        * for the specified base directory.
        */
  -    public VelocityEngine getVelocityEngine( String basedir ) throws Exception
  +    public VelocityEngine getVelocityEngine( String basedir ) throws 
JellyTagException
       {
           VelocityEngine ve = ( VelocityEngine ) getContext().getVariable( 
                   keyName( basedir ) );
  @@ -92,7 +93,13 @@
               ve = new VelocityEngine();
               ve.setProperty( VelocityEngine.RUNTIME_LOG_LOGSYSTEM, this );
               ve.setProperty( VelocityEngine.FILE_RESOURCE_LOADER_PATH, basedir );
  -            ve.init();
  +            
  +            try {
  +                ve.init();
  +            }
  +            catch (Exception e) {
  +                throw new JellyTagException(e);
  +            }
   
               getContext().setVariable( keyName( basedir ), ve );
           }
  
  
  

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

Reply via email to