xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r946539 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop: afp/fonts/CharacterSetBuilder.java render/afp/AFPRendererConfigurator.java
Date Thu, 20 May 2010 06:38:49 GMT
Author: jeremias
Date: Thu May 20 06:38:48 2010
New Revision: 946539

URL: http://svn.apache.org/viewvc?rev=946539&view=rev
Log:
Bring error handling more in line with general recommendations and provide better error messages.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java?rev=946539&r1=946538&r2=946539&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java Thu May
20 06:38:48 2010
@@ -24,14 +24,15 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.Map;
 import java.util.List;
+import java.util.Map;
 import java.util.WeakHashMap;
 
-import org.apache.xmlgraphics.image.loader.util.SoftMapCache;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import org.apache.xmlgraphics.image.loader.util.SoftMapCache;
+
 import org.apache.fop.afp.AFPConstants;
 import org.apache.fop.afp.util.ResourceAccessor;
 import org.apache.fop.afp.util.StructuredFieldReader;
@@ -183,9 +184,10 @@ public class CharacterSetBuilder {
      * @param encoding encoding name
      * @param accessor used to load codepage and characterset
      * @return CharacterSet object
+     * @throws IOException if an I/O error occurs
      */
     public CharacterSet build(String characterSetName, String codePageName,
-            String encoding, ResourceAccessor accessor) {
+            String encoding, ResourceAccessor accessor) throws IOException {
 
         // check for cached version of the characterset
         String descriptor = characterSetName + "_" + encoding + "_" + codePageName;
@@ -253,22 +255,10 @@ public class CharacterSetBuilder {
                     characterSet.addCharacterSetOrientation(characterSetOrientations[i]);
                 }
             } else {
-
-                    String msg = "Failed to load the character set metrics for code page
"
-                        + codePageName;
-                    LOG.error(msg);
-                    throw new RuntimeException("Failed to read font control structured field"
-                            + "in character set " + characterSetName);
-
+                throw new IOException("Missing D3AE89 Font Control structured field.");
             }
 
-        } catch (IOException e) {
-            String msg = "Failed to load the character set metrics for code page " + codePageName;
-            LOG.error(msg);
-            throw new RuntimeException("Failed to read font control structured field"
-                    + "in character set " + characterSetName);
         } finally {
-
             closeInputStream(inputStream);
         }
         characterSetsCache.put(descriptor, characterSet);
@@ -652,7 +642,7 @@ public class CharacterSetBuilder {
             return nominalFontSize;
         }
     }
-    
+
     /**
      * Double-byte (CID Keyed font (Type 0)) implementation of AFPFontReader.
      */

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java?rev=946539&r1=946538&r2=946539&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
Thu May 20 06:38:48 2010
@@ -202,8 +202,12 @@ public class AFPRendererConfigurator ext
                         log.error(msg);
                     }
                 } else {
-                    font.addCharacterSet(sizeMpt, CharacterSetBuilder.getInstance()
-                            .build(characterset, codepage, encoding, accessor));
+                    try {
+                        font.addCharacterSet(sizeMpt, CharacterSetBuilder.getInstance()
+                                .build(characterset, codepage, encoding, accessor));
+                    } catch (IOException ioe) {
+                        toConfigurationException(codepage, characterset, ioe);
+                    }
                 }
             }
             return font;
@@ -227,17 +231,21 @@ public class AFPRendererConfigurator ext
                                         .build(characterset, codepage, encoding, tf);
                     } catch (Exception ie) {
                         String msg = "The base 14 font class " + clazz.getName()
-                        + " could not be instantiated";
+                                + " could not be instantiated";
                         log.error(msg);
                     }
                 } catch (ClassNotFoundException cnfe) {
                     String msg = "The base 14 font class for " + characterset
-                    + " could not be found";
+                            + " could not be found";
                     log.error(msg);
                 }
             } else {
-                characterSet = CharacterSetBuilder.getInstance().build(
-                        characterset, codepage, encoding, accessor);
+                try {
+                    characterSet = CharacterSetBuilder.getInstance().build(
+                            characterset, codepage, encoding, accessor);
+                } catch (IOException ioe) {
+                    toConfigurationException(codepage, characterset, ioe);
+                }
             }
             // Return new font object
             return new OutlineFont(name, characterSet);
@@ -250,8 +258,12 @@ public class AFPRendererConfigurator ext
             }
             String name = afpFontCfg.getAttribute("name", characterset);
             CharacterSet characterSet = null;
-            characterSet = CharacterSetBuilder.getDoubleByteInstance()
-                            .build(characterset, codepage, encoding, accessor);
+            try {
+                characterSet = CharacterSetBuilder.getDoubleByteInstance()
+                                .build(characterset, codepage, encoding, accessor);
+            } catch (IOException ioe) {
+                toConfigurationException(codepage, characterset, ioe);
+            }
 
             // Create a new font object
             DoubleByteFont font = new DoubleByteFont(name, characterSet);
@@ -264,6 +276,14 @@ public class AFPRendererConfigurator ext
         return null;
     }
 
+    private void toConfigurationException(String codepage, String characterset, IOException
ioe)
+            throws ConfigurationException {
+        String msg = "Failed to load the character set metrics " + characterset
+            + " with code page " + codepage
+            + ". I/O error: " + ioe.getMessage();
+        throw new ConfigurationException(msg, ioe);
+    }
+
     /**
      * Builds a list of AFPFontInfo objects for use with the setup() method.
      *



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message