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;
/** 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.
*
log.info("Rendering areas to TEXT.");
this.outputStream = os;
currentStream = new TXTStream(os);
+ currentStream.setEncoding(this.encoding);
firstPage = true;
}
*/
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.
}
try {
- byte[] buff = str.getBytes("UTF-8");
+ byte[] buff = str.getBytes(encoding);
out.write(buff);
} catch (IOException e) {
throw new RuntimeException(e.toString());
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;
+ }
}