commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From commons-...@jakarta.apache.org
Subject [jira] Closed: (JELLY-57) support encoding parameter for util:loadText
Date Sun, 12 Sep 2004 16:07:38 GMT
Message:

   The following issue has been closed.

   Resolver: dion gillard
       Date: Sun, 12 Sep 2004 9:07 AM

In v1.1 of the taglib
---------------------------------------------------------------------
View the issue:
  http://issues.apache.org/jira/browse/JELLY-57

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

     Status: Closed
   Priority: Minor
 Resolution: FIXED

    Project: jelly
 Components: 
             taglib.util
   Fix Fors:
             1.0-beta-5

   Assignee: 
   Reporter: Bill Keese

    Created: Sun, 22 Jun 2003 9:42 PM
    Updated: Sun, 12 Sep 2004 9:07 AM

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://issues.apache.org/jira/secure/Administrators.jspa

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


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


Mime
View raw message