aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2005-11-09 21:17:38 +0000
committerJeremias Maerki <jeremias@apache.org>2005-11-09 21:17:38 +0000
commit9373d427c43ec6be2fa35f199f26292fa9f05f5a (patch)
tree6bcda8b3d23584a6be82b3cd4c5f60b11e550b5e /src
parent8a793a51f6ed47a62633b8ebbf63833d06da72d4 (diff)
downloadxmlgraphics-fop-9373d427c43ec6be2fa35f199f26292fa9f05f5a.tar.gz
xmlgraphics-fop-9373d427c43ec6be2fa35f199f26292fa9f05f5a.zip
Reintroduce encoding feature for Text Renderer that was in the maintenance branch.
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
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/fop/render/txt/TXTRenderer.java24
-rw-r--r--src/java/org/apache/fop/render/txt/TXTStream.java17
2 files changed, 39 insertions, 2 deletions
diff --git a/src/java/org/apache/fop/render/txt/TXTRenderer.java b/src/java/org/apache/fop/render/txt/TXTRenderer.java
index a06c815ea..85236a822 100644
--- a/src/java/org/apache/fop/render/txt/TXTRenderer.java
+++ b/src/java/org/apache/fop/render/txt/TXTRenderer.java
@@ -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;
}
diff --git a/src/java/org/apache/fop/render/txt/TXTStream.java b/src/java/org/apache/fop/render/txt/TXTStream.java
index f3dc9e194..617acd2a7 100644
--- a/src/java/org/apache/fop/render/txt/TXTStream.java
+++ b/src/java/org/apache/fop/render/txt/TXTStream.java
@@ -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;
+ }
}