You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ji...@codehaus.org on 2003/08/04 02:57:37 UTC

[jira] Updated: (JELLY-57) support encoding parameter for util:loadText

The following issue has been updated:

    Updater: Bill Keese (mailto:billk@tech.beacon-it.co.jp)
       Date: Sun, 3 Aug 2003 7:56 PM
    Comment:
Patch file for LoadTextTag.java

    Changes:
             Attachment changed to LoadTextTag.patchFile.txt
    ---------------------------------------------------------------------
For a full history of the issue, see:

  http://jira.codehaus.org/secure/ViewIssue.jspa?key=JELLY-57&page=history

---------------------------------------------------------------------
View the issue:

  http://jira.codehaus.org/secure/ViewIssue.jspa?key=JELLY-57


Here is an overview of the issue:
---------------------------------------------------------------------
        Key: JELLY-57
    Summary: support encoding parameter for util:loadText
       Type: Improvement

     Status: Unassigned
   Priority: Minor

 Time Spent: Unknown
  Remaining: 2 hours

    Project: jelly

   Assignee: 
   Reporter: Bill Keese

    Created: Sun, 22 Jun 2003 9:42 PM
    Updated: Sun, 3 Aug 2003 7:56 PM

Description:
This patch lets you  specify the encoding of files you read in with
LoadTextTag.java.

Index: LoadTextTag.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/LoadTextTag.java,v
retrieving revision 1.2
diff -u -r1.2 LoadTextTag.java
--- LoadTextTag.java 25 Jan 2003 19:31:48 -0000 1.2
+++ LoadTextTag.java 20 Jun 2003 04:06:02 -0000
@@ -64,7 +64,8 @@
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
+import java.io.UnsupportedEncodingException;
+import java.io.FileInputStream;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.IOException;
@@ -92,6 +93,7 @@
     private String var;
     private File file;
     private String uri;
+    private String encoding="utf-8";
 
     public LoadTextTag() {
     }
@@ -105,27 +107,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 {
-                reader = new FileReader(file);
+                in = new FileInputStream(file);
             } catch (FileNotFoundException e) {
                 throw new JellyTagException("could not find the file",e);
             }
-        }   
-        else {
-            InputStream in = context.getResourceAsStream(uri);
+        } else {
+            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;
         
         try {
@@ -177,6 +183,13 @@
      */
     public void setFile(File file) {
         this.file = file;
+    }
+
+    /**
+     * Sets the encoding to use to read the file
+     */
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
     }
 
     /**



---------------------------------------------------------------------
JIRA INFORMATION:
This message is automatically generated by JIRA.

If you think it was sent incorrectly contact one of the administrators:
   http://jira.codehaus.org/secure/Administrators.jspa

If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira