Uploaded image for project: 'Commons Jelly'
  1. Commons Jelly
  2. JELLY-57

support encoding parameter for util:loadText

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.0-beta-5
    • taglib.util
    • 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)

      { 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; }

      /**

      Attachments

        Activity

          People

            Unassigned Unassigned
            wkeese Bill Keese
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 2h
                2h
                Remaining:
                Remaining Estimate - 2h
                2h
                Logged:
                Time Spent - Not Specified
                Not Specified