You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2009/03/09 09:12:46 UTC
svn commit: r751613 -
/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSet.java
Author: jeremias
Date: Mon Mar 9 08:12:45 2009
New Revision: 751613
URL: http://svn.apache.org/viewvc?rev=751613&view=rev
Log:
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.
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSet.java
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSet.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSet.java?rev=751613&r1=751612&r2=751613&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSet.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSet.java Mon Mar 9 08:12:45 2009
@@ -27,6 +27,7 @@
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 @@
}
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 @@
* @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 @@
* @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());
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org