aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2009-03-09 08:12:45 +0000
committerJeremias Maerki <jeremias@apache.org>2009-03-09 08:12:45 +0000
commitefcd8b9100f7dcc85d7a8d8f3d0fe7f919192e99 (patch)
tree8c06fff19d532d7e7ef16416be252848ebd35fc8 /src/java/org/apache/fop
parentafec2bca7df4f7db810a041674755a3663bdd163 (diff)
downloadxmlgraphics-fop-efcd8b9100f7dcc85d7a8d8f3d0fe7f919192e99.tar.gz
xmlgraphics-fop-efcd8b9100f7dcc85d7a8d8f3d0fe7f919192e99.zip
Restored compatibility with Java VMs that don't support nio Charsets for codepages such as Cp500 (EBCDIC). The simplifications for the fallback case may look wrong but the code basically represents the state before revision 746664 which introduced this problem.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@751613 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop')
-rw-r--r--src/java/org/apache/fop/afp/fonts/CharacterSet.java44
1 files changed, 34 insertions, 10 deletions
diff --git a/src/java/org/apache/fop/afp/fonts/CharacterSet.java b/src/java/org/apache/fop/afp/fonts/CharacterSet.java
index 52bebca56..f0b671932 100644
--- a/src/java/org/apache/fop/afp/fonts/CharacterSet.java
+++ b/src/java/org/apache/fop/afp/fonts/CharacterSet.java
@@ -27,6 +27,7 @@ import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;
+import java.nio.charset.UnsupportedCharsetException;
import java.util.Map;
import org.apache.commons.logging.Log;
@@ -114,8 +115,14 @@ public class CharacterSet {
}
this.codePage = codePage;
this.encoding = encoding;
- this.encoder = Charset.forName(encoding).newEncoder();
- this.encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
+ try {
+ this.encoder = Charset.forName(encoding).newEncoder();
+ this.encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
+ } catch (UnsupportedCharsetException uce) {
+ //No nio-capable encoder available
+ //This may happen with "Cp500" on Sun Java 1.4.2
+ this.encoder = null;
+ }
this.path = path;
this.characterSetOrientations = new java.util.HashMap(4);
@@ -321,7 +328,12 @@ public class CharacterSet {
* @return true if the character is in the character set
*/
public boolean hasChar(char c) {
- return encoder.canEncode(c);
+ if (encoder != null) {
+ return encoder.canEncode(c);
+ } else {
+ //Sun Java 1.4.2 compatibility
+ return true;
+ }
}
/**
@@ -331,14 +343,26 @@ public class CharacterSet {
* @throws CharacterCodingException if the encoding operation fails
*/
public byte[] encodeChars(CharSequence chars) throws CharacterCodingException {
- ByteBuffer bb = encoder.encode(CharBuffer.wrap(chars));
- if (bb.hasArray()) {
- return bb.array();
+ if (encoder != null) {
+ ByteBuffer bb = encoder.encode(CharBuffer.wrap(chars));
+ if (bb.hasArray()) {
+ return bb.array();
+ } else {
+ bb.rewind();
+ byte[] bytes = new byte[bb.remaining()];
+ bb.get(bytes);
+ return bytes;
+ }
} else {
- bb.rewind();
- byte[] bytes = new byte[bb.remaining()];
- bb.get(bytes);
- return bytes;
+ //Sun Java 1.4.2 compatibility
+ byte[] bytes;
+ try {
+ bytes = chars.toString().getBytes(this.encoding);
+ return bytes;
+ } catch (UnsupportedEncodingException uee) {
+ throw new UnsupportedOperationException(
+ "Unsupported encoding: " + uee.getMessage());
+ }
}
}