Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
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)
- 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 {
{ throw new JellyTagException( "Could not find uri: " + uri ); }
+ in = context.getResourceAsStream(uri);
if (in == null) - // @todo should we allow an encoding to be specified?
- reader = new InputStreamReader(in);
} +
{ + reader = new InputStreamReader(in, encoding); + }
+ Reader reader = null;
+ trycatch (UnsupportedEncodingException e)
{ + throw new JellyTagException("unsupported encoding",e); + }+
String text = null;
try {
@@ -177,6 +183,13 @@
*/
public void setFile(File file)
+
+ /**
+ * Sets the encoding to use to read the file
+ */
+ public void setEncoding(String encoding)
/**