]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Fixed NPE when options or encoding are null.
authorOleg Tkachenko <olegt@apache.org>
Sun, 22 Dec 2002 21:40:07 +0000 (21:40 +0000)
committerOleg Tkachenko <olegt@apache.org>
Sun, 22 Dec 2002 21:40:07 +0000 (21:40 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_20_2-maintain@195788 13f79535-47bb-0310-9956-ffa450edef68

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

index 12fb17d6beaf50b51cbf1984bbec52e7acadff98..73ec02935d94fec9ebd1a990156cad43e4eb9bfa 100755 (executable)
@@ -46,6 +46,7 @@ public class TXTRenderer extends PrintRenderer {
      */
     TXTStream currentStream;
     public static final String encodingOptionName = "txt.encoding";
+    private static final String DEFAULT_ENCODING = "UTF-8";
 
     private int pageHeight = 7920;
 
@@ -1699,13 +1700,17 @@ public class TXTRenderer extends PrintRenderer {
     throws IOException {
         log.info("rendering areas to TEXT");
         currentStream = new TXTStream(outputStream);
-        String encoding = (String)options.get(encodingOptionName);
-        try {
-            byte buff[] = " ".getBytes(encoding);
-        } catch (java.io.UnsupportedEncodingException uee) {
-            log.warn("Encoding '"+encoding+"' is not a valid Java encoding. Use UTF-8.");
-            encoding = "UTF-8";
+        String encoding;
+        if (options != null && (encoding=(String)options.get(encodingOptionName))!=null) {
+            try {
+                byte buff[] = " ".getBytes(encoding);
+            } catch (java.io.UnsupportedEncodingException uee) {
+                log.warn("Encoding '"+encoding+"' is not supported, so defaulted to " + DEFAULT_ENCODING);
+                encoding = DEFAULT_ENCODING;
+            }
         }
+        else
+            encoding = DEFAULT_ENCODING;
         currentStream.setEncoding(encoding);
         firstPage=true;
     }