You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2004/09/12 18:04:59 UTC

cvs commit: jakarta-commons/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util LoadTextTag.java

dion        2004/09/12 09:04:59

  Modified:    jelly/jelly-tags/util/xdocs changes.xml
               jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util
                        LoadTextTag.java
  Log:
  Jelly-57. support encoding parameter for util:loadText
  
  Revision  Changes    Path
  1.4       +1 -0      jakarta-commons/jelly/jelly-tags/util/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/util/xdocs/changes.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- changes.xml	12 Sep 2004 16:03:01 -0000	1.3
  +++ changes.xml	12 Sep 2004 16:04:59 -0000	1.4
  @@ -25,6 +25,7 @@
     </properties>
     <body>
       <release version="1.1-SNAPSHOT" date="in CVS">
  +      <action dev="dion" type="update" issue="JELLY-57" due-to="Bill Keese">support encoding parameter for util:loadText</action>
       </release>
       <release version="1.0" date="2004-09-10">
         <action dev="dion" type="fix" issue="JELLY-77" due-to="Paul O'Fallon">Update jelly:util replace tag to replace entire strings</action>
  
  
  
  1.7       +19 -17    jakarta-commons/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/LoadTextTag.java
  
  Index: LoadTextTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/LoadTextTag.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- LoadTextTag.java	8 Sep 2004 04:51:54 -0000	1.6
  +++ LoadTextTag.java	12 Sep 2004 16:04:59 -0000	1.7
  @@ -62,30 +62,31 @@
           if (file == null && uri == null) {
               throw new JellyTagException( "This tag must have a 'file' or 'uri' specified" );
           }
  -        Reader reader = null;
  +        
  +        InputStream in = null;
           if (file != null) {
               if (! file.exists()) {
                   throw new JellyTagException( "The file: " + file + " does not exist" );
               }
   
               try {
  -                if ( encoding == null )
  -                    reader = new FileReader(file);
  -                else
  -                    reader = new InputStreamReader(new FileInputStream(file),encoding);
  +                in = new FileInputStream(file);
               } catch (FileNotFoundException e) {
                   throw new JellyTagException("could not find the file",e);
  -            } catch (UnsupportedEncodingException e) {
  -                throw new JellyTagException("Could not use the encoding \"" + encoding + "\".",e);
               }
           }
           else {
  -            InputStream in = context.getResourceAsStream(uri);
  +            in = context.getResourceAsStream(uri);
               if (in == null) {
                   throw new JellyTagException( "Could not find uri: " + uri );
               }
  -            // @todo should we allow an encoding to be specified?
  -            reader = new InputStreamReader(in);
  +        }
  +
  +        Reader reader = null;
  +        try {
  +            reader = new InputStreamReader(in, encoding);
  +        } catch (UnsupportedEncodingException e) {
  +            throw new JellyTagException("unsupported encoding",e);
           }
   
           String text = null;
  @@ -142,18 +143,19 @@
       }
   
       /**
  +     * Sets the encoding to use to read the file
  +     */
  +    public void setEncoding(String encoding) {
  +        this.encoding = encoding;
  +    }
  +
  +    /**
        * Sets the uri to be parsed as text.
        * This can be an absolute URL or a relative or absolute URI
        * from this Jelly script or the root context.
        */
       public void setUri(String uri) {
           this.uri = uri;
  -    }
  -
  -    /** Sets the encoding to be used to read the file, defaults to the platform-encoding.
  -      */
  -    public void setEncoding(String encName) {
  -        this.encoding = encName;
       }
   
       /** Returns the encoding set.
  
  
  

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