From aefb5934f6097c0691162a899372b9f9d4532201 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Thu, 20 May 2010 06:38:48 +0000 Subject: [PATCH] Bring error handling more in line with general recommendations and provide better error messages. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@946539 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/afp/fonts/CharacterSetBuilder.java | 24 ++++--------- .../render/afp/AFPRendererConfigurator.java | 36 ++++++++++++++----- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java b/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java index 6afd18b92..c05e408da 100644 --- a/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java +++ b/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java @@ -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. */ diff --git a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java index 27ffeae62..23f413813 100644 --- a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java +++ b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java @@ -202,8 +202,12 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator 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 extends PrintRendererConfigurator .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 extends PrintRendererConfigurator } 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 extends PrintRendererConfigurator 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. * -- 2.39.5