]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Reintroduce encoding feature for Text Renderer that was in the maintenance branch.
authorJeremias Maerki <jeremias@apache.org>
Wed, 9 Nov 2005 21:17:38 +0000 (21:17 +0000)
committerJeremias Maerki <jeremias@apache.org>
Wed, 9 Nov 2005 21:17:38 +0000 (21:17 +0000)
Configuration layout for the text renderer is:
<renderer mime="text/plain">
  <encoding>US-ASCII</encoding>
</renderer>

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@332144 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/render/txt/TXTRenderer.java
src/java/org/apache/fop/render/txt/TXTStream.java

index a06c815eaa018dbe70536a60a6fe5d21e5b0bcc8..85236a8229768770572374a09e8df50d8e85a3e7 100644 (file)
@@ -24,6 +24,8 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.util.List;
 
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.CTM;
@@ -99,12 +101,33 @@ public class TXTRenderer extends AbstractPathOrientedRenderer {
     /** Saves current coordinate transformation. */
     private TXTState currentState = new TXTState();
 
+    private String encoding;
+    
     /**
      * Constructs a newly allocated <code>TXTRenderer</code> object.
      */
     public TXTRenderer() {
     }
 
+    /** @see org.apache.fop.render.AbstractRenderer#getMimeType() */
+    public String getMimeType() {
+        return "text/plain";
+    }
+
+    /** @see org.apache.fop.render.AbstractRenderer */
+    public void configure(Configuration conf) throws ConfigurationException {
+        super.configure(conf);
+        this.encoding = conf.getChild("encoding", true).getValue(null);
+    }
+    
+    /**
+     * Sets the encoding of the target file.
+     * @param encoding the encoding, null to select the default encoding (UTF-8)
+     */
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+
     /**
      * Indicates if point (x, y) lay inside currentPage.
      * 
@@ -271,6 +294,7 @@ public class TXTRenderer extends AbstractPathOrientedRenderer {
         log.info("Rendering areas to TEXT.");
         this.outputStream = os;
         currentStream = new TXTStream(os);
+        currentStream.setEncoding(this.encoding);
         firstPage = true;
     }
 
index f3dc9e194a4aad755f646ad85f7e011c6a1becc9..617acd2a742b11bffff75d61692bf501c8b14d5f 100644 (file)
@@ -26,8 +26,11 @@ import java.io.OutputStream;
  */
 public class TXTStream {
     
+    private static final String DEFAULT_ENCODING = "UTF-8";
+    
     private OutputStream out = null;
     private boolean doOutput = true;
+    private String encoding = DEFAULT_ENCODING;
 
     /**
      * Main constructor.
@@ -47,7 +50,7 @@ public class TXTStream {
         }
 
         try {
-            byte[] buff = str.getBytes("UTF-8");
+            byte[] buff = str.getBytes(encoding);
             out.write(buff);
         } catch (IOException e) {
             throw new RuntimeException(e.toString());
@@ -61,6 +64,16 @@ public class TXTStream {
     public void setDoOutput(boolean doout) {
         doOutput = doout;
     }
-
+    
+    /**
+     * Set the encoding for the text stream.
+     * @param encoding the encoding, if null, "UTF-8" is chosen as default
+     */
+    public void setEncoding(String encoding) {
+        if (encoding != null)
+            this.encoding = encoding;
+        else
+            this.encoding = DEFAULT_ENCODING;
+    }
 }