commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From morg...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util AvailableTag.java FileTag.java LoadTextTag.java PropertiesTag.java ReplaceTag.java SleepTag.java TokenizeTag.java
Date Sat, 25 Jan 2003 19:31:48 GMT
morgand     2003/01/25 11:31:48

  Modified:    jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util
                        AvailableTag.java FileTag.java LoadTextTag.java
                        PropertiesTag.java ReplaceTag.java SleepTag.java
                        TokenizeTag.java
  Log:
  converted util taglib from Exception to JellyTagException
  
  Revision  Changes    Path
  1.2       +9 -5      jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/AvailableTag.java
  
  Index: AvailableTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/AvailableTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AvailableTag.java	6 Jan 2003 16:15:46 -0000	1.1
  +++ AvailableTag.java	25 Jan 2003 19:31:48 -0000	1.2
  @@ -61,8 +61,10 @@
   import java.io.File;
   import java.io.IOException;
   import java.io.InputStream;
  +import java.net.MalformedURLException;
   import java.net.URL;
   
  +import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
   
  @@ -84,22 +86,24 @@
   
       // Tag interface
       //------------------------------------------------------------------------- 
  -    public void doTag(final XMLOutput output) throws Exception {
  +    public void doTag(final XMLOutput output) throws JellyTagException {
       	boolean available = false;
       	
       	if (file != null) {
       		available = file.exists();
       	}
       	else if (uri != null) {
  -    		URL url = context.getResource(uri);
  -    		String fileName = url.getFile();
               try {
  +                URL url = context.getResource(uri);
  +    		    String fileName = url.getFile();
                   InputStream is = url.openStream();
                   available = (is != null);
                   is.close();
  +            } catch (MalformedURLException e) {
  +                throw new JellyTagException(e);
               } catch (IOException ioe) {
                   available = false;
  -            }
  +            } 
       	}
       	
       	if (available) {
  
  
  
  1.3       +3 -2      jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/FileTag.java
  
  Index: FileTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/FileTag.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FileTag.java	19 Jan 2003 15:14:26 -0000	1.2
  +++ FileTag.java	25 Jan 2003 19:31:48 -0000	1.3
  @@ -60,6 +60,7 @@
   
   import java.io.File;
   
  +import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.MissingAttributeException;
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
  @@ -80,7 +81,7 @@
   
       // Tag interface
       //------------------------------------------------------------------------- 
  -    public void doTag(final XMLOutput output) throws Exception {
  +    public void doTag(final XMLOutput output) throws MissingAttributeException, JellyTagException
{
           boolean available = false;
   
           if (name == null) {
  
  
  
  1.2       +29 -13    jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/LoadTextTag.java
  
  Index: LoadTextTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/LoadTextTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LoadTextTag.java	6 Jan 2003 16:15:46 -0000	1.1
  +++ LoadTextTag.java	25 Jan 2003 19:31:48 -0000	1.2
  @@ -63,12 +63,14 @@
   
   import java.io.BufferedReader;
   import java.io.File;
  +import java.io.FileNotFoundException;
   import java.io.FileReader;
   import java.io.InputStream;
   import java.io.InputStreamReader;
  +import java.io.IOException;
   import java.io.Reader;
   
  -import org.apache.commons.jelly.JellyException;
  +import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.MissingAttributeException;
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
  @@ -96,29 +98,43 @@
   
       // Tag interface
       //------------------------------------------------------------------------- 
  -    public void doTag(XMLOutput output) throws Exception {
  +    public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException
{
           if (var == null) {
               throw new MissingAttributeException("var");
           }
           if (file == null && uri == null) {
  -            throw new JellyException( "This tag must have a 'file' or 'uri' specified"
);
  +            throw new JellyTagException( "This tag must have a 'file' or 'uri' specified"
);
           }
           Reader reader = null;
           if (file != null) {
               if (! file.exists()) {
  -                throw new JellyException( "The file: " + file + " does not exist" );
  +                throw new JellyTagException( "The file: " + file + " does not exist" );
  +            }
  +            
  +            try {
  +                reader = new FileReader(file);
  +            } catch (FileNotFoundException e) {
  +                throw new JellyTagException("could not find the file",e);
               }
  -            reader = new FileReader(file);
           }   
           else {
               InputStream in = context.getResourceAsStream(uri);
               if (in == null) {
  -                throw new JellyException( "Could not find uri: " + uri );
  +                throw new JellyTagException( "Could not find uri: " + uri );
               }
               // @todo should we allow an encoding to be specified?
               reader = new InputStreamReader(in);
           }
  -        String text = loadText(reader);
  +        
  +        String text = null;
  +        
  +        try {
  +            text = loadText(reader);
  +        } 
  +        catch (IOException e) {
  +            throw new JellyTagException(e);
  +        }
  +        
           context.setVariable(var, text);
       }
   
  @@ -179,7 +195,7 @@
       /**
        * Loads all the text from the given Reader
        */
  -    protected String loadText(Reader reader) throws Exception {
  +    protected String loadText(Reader reader) throws IOException {
           StringBuffer buffer = new StringBuffer();
           
           // @todo its probably more efficient to use a fixed char[] buffer instead
  
  
  
  1.2       +21 -8     jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/PropertiesTag.java
  
  Index: PropertiesTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/PropertiesTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PropertiesTag.java	6 Jan 2003 16:15:46 -0000	1.1
  +++ PropertiesTag.java	25 Jan 2003 19:31:48 -0000	1.2
  @@ -60,11 +60,13 @@
   
   import java.io.File;
   import java.io.FileInputStream;
  +import java.io.FileNotFoundException;
   import java.io.InputStream;
  +import java.io.IOException;
   import java.util.Enumeration;
   import java.util.Properties;
   
  -import org.apache.commons.jelly.JellyException;
  +import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
   
  @@ -85,26 +87,37 @@
   
       // Tag interface
       //------------------------------------------------------------------------- 
  -    public void doTag(final XMLOutput output) throws Exception {
  +    public void doTag(final XMLOutput output) throws JellyTagException {
           if (file == null && uri == null) {
  -            throw new JellyException("This tag must define a 'file' or 'uri' attribute");
  +            throw new JellyTagException("This tag must define a 'file' or 'uri' attribute");
           }
           InputStream is = null;
           if (file != null) {
               File f = new File(file);
               if (!f.exists()) {
  -                throw new JellyException("file: " + file + " does not exist!");
  +                throw new JellyTagException("file: " + file + " does not exist!");
  +            }
  +            
  +            try {
  +                is = new FileInputStream(f);
  +            } catch (FileNotFoundException e) {
  +                throw new JellyTagException(e);
               }
  -            is = new FileInputStream(f);
           }
           else {
               is = context.getResourceAsStream(uri);
               if (is == null) {
  -                throw new JellyException( "Could not find: " + uri );
  +                throw new JellyTagException( "Could not find: " + uri );
               }
           }
           Properties props = new Properties();
  -        props.load(is);
  +        
  +        try {
  +            props.load(is);
  +        } catch (IOException e) {
  +            throw new JellyTagException("properties tag could not load from file",e);
  +        }
  +        
           if (var != null) {
               context.setVariable(var, props);
           }
  
  
  
  1.2       +9 -3      jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/ReplaceTag.java
  
  Index: ReplaceTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/ReplaceTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ReplaceTag.java	6 Jan 2003 16:15:46 -0000	1.1
  +++ ReplaceTag.java	25 Jan 2003 19:31:48 -0000	1.2
  @@ -58,13 +58,15 @@
   
   package org.apache.commons.jelly.tags.util;
   
  -import org.apache.commons.jelly.expression.Expression;
  +import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.MissingAttributeException;
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
  +import org.apache.commons.jelly.expression.Expression;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  +import org.xml.sax.SAXException;
   
   /**
    * A tag that replaces occurrences of strings in its body (or value)
  @@ -90,7 +92,7 @@
       
       // Tag interface
       //------------------------------------------------------------------------- 
  -    public void doTag(XMLOutput output) throws Exception {
  +    public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException
{
           // check required properties
           if (oldChar == null) {
               throw new MissingAttributeException("oldChar must be provided");
  @@ -114,7 +116,11 @@
               if ( var != null ) {
                   context.setVariable(var, stringAnswer);
               } else {
  -                output.write(stringAnswer);
  +                try {
  +                    output.write(stringAnswer);
  +                } catch (SAXException e) {
  +                    throw new JellyTagException(e);
  +                }
               }
           }
       }
  
  
  
  1.2       +8 -3      jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/SleepTag.java
  
  Index: SleepTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/SleepTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SleepTag.java	6 Jan 2003 16:15:46 -0000	1.1
  +++ SleepTag.java	25 Jan 2003 19:31:48 -0000	1.2
  @@ -58,6 +58,7 @@
   
   package org.apache.commons.jelly.tags.util;
   
  +import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
   /**
  @@ -74,9 +75,13 @@
   
       // Tag interface
       //------------------------------------------------------------------------- 
  -    public void doTag(final XMLOutput output) throws Exception {
  +    public void doTag(final XMLOutput output) throws JellyTagException {
           if (millis > 0) {
  -            Thread.sleep(millis);
  +            try {
  +                Thread.sleep(millis);
  +            } catch (InterruptedException e) {
  +                throw new JellyTagException(e);
  +            }
           }
       }
   
  
  
  
  1.2       +2 -2      jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/TokenizeTag.java
  
  Index: TokenizeTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/TokenizeTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TokenizeTag.java	6 Jan 2003 16:15:46 -0000	1.1
  +++ TokenizeTag.java	25 Jan 2003 19:31:48 -0000	1.2
  @@ -62,6 +62,7 @@
   import java.util.List;
   import java.util.StringTokenizer;
   
  +import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.MissingAttributeException;
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
  @@ -79,8 +80,7 @@
       // Tag interface
       //------------------------------------------------------------------------- 
       
  -    public void doTag(final XMLOutput output) throws Exception
  -    {
  +    public void doTag(final XMLOutput output) throws MissingAttributeException, JellyTagException
{
           if ( this.var == null )
           {
               throw new MissingAttributeException( "var" );
  
  
  

--
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