diff options
Diffstat (limited to 'src/java/org/apache/fop/apps/FopFactory.java')
-rw-r--r-- | src/java/org/apache/fop/apps/FopFactory.java | 148 |
1 files changed, 73 insertions, 75 deletions
diff --git a/src/java/org/apache/fop/apps/FopFactory.java b/src/java/org/apache/fop/apps/FopFactory.java index c196e1204..2d4029da8 100644 --- a/src/java/org/apache/fop/apps/FopFactory.java +++ b/src/java/org/apache/fop/apps/FopFactory.java @@ -59,37 +59,37 @@ import org.apache.fop.util.ContentHandlerFactoryRegistry; * found and managed in the FOUserAgent. */ public class FopFactory implements ImageContext { - + /** logger instance */ private static Log log = LogFactory.getLog(FopFactory.class); - + /** Factory for Renderers and FOEventHandlers */ private RendererFactory rendererFactory; - + /** Registry for XML handlers */ private XMLHandlerRegistry xmlHandlers; - + /** The registry for ElementMapping instances */ private ElementMappingRegistry elementMappingRegistry; - /** The registry for ContentHandlerFactory instance */ - private ContentHandlerFactoryRegistry contentHandlerFactoryRegistry + /** The registry for ContentHandlerFactory instance */ + private ContentHandlerFactoryRegistry contentHandlerFactoryRegistry = new ContentHandlerFactoryRegistry(); - + /** The resolver for user-supplied hyphenation patterns */ private HyphenationTreeResolver hyphResolver = null; private ColorSpaceCache colorSpaceCache = null; - + /** Image manager for loading and caching image objects */ private ImageManager imageManager; /** Font manager for font substitution, autodetection and caching **/ private FontManager fontManager; - + /** Configuration layer used to configure fop */ private FopFactoryConfigurator config = null; - + /** * The base URL for all URL resolutions, especially for * external-graphics. @@ -101,10 +101,10 @@ public class FopFactory implements ImageContext { /** * FOP has the ability, for some FO's, to continue processing even if the - * input XSL violates that FO's content model. This is the default + * input XSL violates that FO's content model. This is the default * behavior for FOP. However, this flag, if set, provides the user the * ability for FOP to halt on all content model violations if desired. - */ + */ private boolean strictFOValidation = FopFactoryConfigurator.DEFAULT_STRICT_FO_VALIDATION; /** @@ -113,7 +113,7 @@ public class FopFactory implements ImageContext { */ private boolean strictUserConfigValidation = FopFactoryConfigurator.DEFAULT_STRICT_USERCONFIG_VALIDATION; - + /** Source resolution in dpi */ private float sourceResolution = FopFactoryConfigurator.DEFAULT_SOURCE_RESOLUTION; @@ -122,7 +122,7 @@ public class FopFactory implements ImageContext { /** Page height */ private String pageHeight = FopFactoryConfigurator.DEFAULT_PAGE_HEIGHT; - + /** Page width */ private String pageWidth = FopFactoryConfigurator.DEFAULT_PAGE_WIDTH; @@ -136,7 +136,7 @@ public class FopFactory implements ImageContext { private Set ignoredNamespaces; private FOURIResolver foURIResolver; - + /** * Main constructor. */ @@ -144,13 +144,21 @@ public class FopFactory implements ImageContext { this.config = new FopFactoryConfigurator(this); this.elementMappingRegistry = new ElementMappingRegistry(this); this.foURIResolver = new FOURIResolver(validateUserConfigStrictly()); + this.fontManager = new FontManager() { + + /** {@inheritDoc} */ + public void setFontBaseURL(String fontBase) throws MalformedURLException { + super.setFontBaseURL(getFOURIResolver().checkBaseURL(fontBase)); + } + + }; this.colorSpaceCache = new ColorSpaceCache(foURIResolver); this.imageManager = new ImageManager(this); this.rendererFactory = new RendererFactory(); this.xmlHandlers = new XMLHandlerRegistry(); this.ignoredNamespaces = new java.util.HashSet(); } - + /** * Returns a new FopFactory instance. * @return the requested FopFactory instance. @@ -158,13 +166,13 @@ public class FopFactory implements ImageContext { public static FopFactory newInstance() { return new FopFactory(); } - + /** * Returns a new FOUserAgent instance. Use the FOUserAgent to configure special values that * are particular to a rendering run. Don't reuse instances over multiple rendering runs but * instead create a new one each time and reuse the FopFactory. * @return the newly created FOUserAgent instance initialized with default values - * @throws FOPException + * @throws FOPException */ public FOUserAgent newFOUserAgent() { FOUserAgent userAgent = new FOUserAgent(this); @@ -172,12 +180,12 @@ public class FopFactory implements ImageContext { } /** - * Returns a new {@link Fop} instance. FOP will be configured with a default user agent + * Returns a new {@link Fop} instance. FOP will be configured with a default user agent * instance. * <p> * MIME types are used to select the output format (ex. "application/pdf" for PDF). You can * use the constants defined in {@link MimeConstants}. - * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). + * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). * @return the new Fop instance * @throws FOPException when the constructor fails */ @@ -186,29 +194,29 @@ public class FopFactory implements ImageContext { } /** - * Returns a new {@link Fop} instance. Use this factory method if you want to configure this + * Returns a new {@link Fop} instance. Use this factory method if you want to configure this * very rendering run, i.e. if you want to set some metadata like the title and author of the - * document you want to render. In that case, create a new {@link FOUserAgent} + * document you want to render. In that case, create a new {@link FOUserAgent} * instance using {@link #newFOUserAgent()}. * <p> * MIME types are used to select the output format (ex. "application/pdf" for PDF). You can * use the constants defined in {@link MimeConstants}. * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). - * @param userAgent the user agent that will be used to control the rendering run + * @param userAgent the user agent that will be used to control the rendering run * @return the new Fop instance * @throws FOPException when the constructor fails */ public Fop newFop(String outputFormat, FOUserAgent userAgent) throws FOPException { return newFop(outputFormat, userAgent, null); } - + /** - * Returns a new {@link Fop} instance. FOP will be configured with a default user agent + * Returns a new {@link Fop} instance. FOP will be configured with a default user agent * instance. Use this factory method if your output type requires an output stream. * <p> * MIME types are used to select the output format (ex. "application/pdf" for PDF). You can * use the constants defined in {@link MimeConstants}. - * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). + * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). * @param stream the output stream * @return the new Fop instance * @throws FOPException when the constructor fails @@ -227,30 +235,30 @@ public class FopFactory implements ImageContext { * MIME types are used to select the output format (ex. "application/pdf" for PDF). You can * use the constants defined in {@link MimeConstants}. * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). - * @param userAgent the user agent that will be used to control the rendering run + * @param userAgent the user agent that will be used to control the rendering run * @param stream the output stream * @return the new Fop instance * @throws FOPException when the constructor fails */ - public Fop newFop(String outputFormat, FOUserAgent userAgent, OutputStream stream) + public Fop newFop(String outputFormat, FOUserAgent userAgent, OutputStream stream) throws FOPException { if (userAgent == null) { throw new NullPointerException("The userAgent parameter must not be null!"); } return new Fop(outputFormat, userAgent, stream); } - + /** * Returns a new {@link Fop} instance. Use this factory method if you want to supply your - * own {@link org.apache.fop.render.Renderer Renderer} or - * {@link org.apache.fop.fo.FOEventHandler FOEventHandler} + * own {@link org.apache.fop.render.Renderer Renderer} or + * {@link org.apache.fop.fo.FOEventHandler FOEventHandler} * instance instead of the default ones created internally by FOP. - * @param userAgent the user agent that will be used to control the rendering run + * @param userAgent the user agent that will be used to control the rendering run * @return the new Fop instance * @throws FOPException when the constructor fails */ public Fop newFop(FOUserAgent userAgent) throws FOPException { - if (userAgent.getRendererOverride() == null + if (userAgent.getRendererOverride() == null && userAgent.getFOEventHandlerOverride() == null) { throw new IllegalStateException("Either the overriding renderer or the overriding" + " FOEventHandler must be set when this factory method is used!"); @@ -267,7 +275,7 @@ public class FopFactory implements ImageContext { public XMLHandlerRegistry getXMLHandlerRegistry() { return this.xmlHandlers; } - + /** @return the element mapping registry */ public ElementMappingRegistry getElementMappingRegistry() { return this.elementMappingRegistry; @@ -310,7 +318,7 @@ public class FopFactory implements ImageContext { public LayoutManagerMaker getLayoutManagerMakerOverride() { return this.lmMakerOverride; } - + /** * Sets the base URL. * @param base the base URL @@ -327,7 +335,7 @@ public class FopFactory implements ImageContext { public String getBaseURL() { return this.base; } - + /** * Sets the font base URL. * @param fontBase font base URL @@ -367,10 +375,10 @@ public class FopFactory implements ImageContext { } this.hyphenBase = foURIResolver.checkBaseURL(hyphenBase); } - + /** * Sets the URI Resolver. It is used for resolving factory-level URIs like hyphenation - * patterns and as backup for URI resolution performed during a rendering run. + * patterns and as backup for URI resolution performed during a rendering run. * @param uriResolver the new URI resolver */ public void setURIResolver(URIResolver uriResolver) { @@ -397,7 +405,7 @@ public class FopFactory implements ImageContext { public HyphenationTreeResolver getHyphenationTreeResolver() { return this.hyphResolver; } - + /** * Sets the HyphenationTreeResolver to be used for resolving user-supplied hyphenation files. * @param hyphResolver the HyphenationTreeResolver instance @@ -424,7 +432,7 @@ public class FopFactory implements ImageContext { } /** - * @return true if the indent inheritance should be broken when crossing reference area + * @return true if the indent inheritance should be broken when crossing reference area * boundaries (for more info, see the javadoc for the relative member variable) */ public boolean isBreakIndentInheritanceOnReferenceAreaBoundary() { @@ -447,7 +455,7 @@ public class FopFactory implements ImageContext { public void setBreakIndentInheritanceOnReferenceAreaBoundary(boolean value) { this.breakIndentInheritanceOnReferenceAreaBoundary = value; } - + /** * @return true if kerning on base 14 fonts is enabled * @deprecated use getFontManager().isBase14KerningEnabled() instead @@ -455,7 +463,7 @@ public class FopFactory implements ImageContext { public boolean isBase14KerningEnabled() { return getFontManager().isBase14KerningEnabled(); } - + /** * Controls whether kerning is activated on base 14 fonts. * @param value true if kerning should be activated @@ -464,7 +472,7 @@ public class FopFactory implements ImageContext { public void setBase14KerningEnabled(boolean value) { getFontManager().setBase14KerningEnabled(value); } - + /** @return the resolution for resolution-dependant input */ public float getSourceResolution() { return this.sourceResolution; @@ -477,7 +485,7 @@ public class FopFactory implements ImageContext { * @see #getSourceResolution() */ public float getSourcePixelUnitToMillimeter() { - return 25.4f / getSourceResolution(); + return 25.4f / getSourceResolution(); } /** @@ -488,7 +496,7 @@ public class FopFactory implements ImageContext { public void setSourceResolution(float dpi) { this.sourceResolution = dpi; if (log.isDebugEnabled()) { - log.debug("source-resolution set to: " + sourceResolution + log.debug("source-resolution set to: " + sourceResolution + "dpi (px2mm=" + getSourcePixelUnitToMillimeter() + ")"); } } @@ -505,7 +513,7 @@ public class FopFactory implements ImageContext { * @see #getTargetResolution() */ public float getTargetPixelUnitToMillimeter() { - return 25.4f / this.targetResolution; + return 25.4f / this.targetResolution; } /** @@ -525,7 +533,7 @@ public class FopFactory implements ImageContext { public void setSourceResolution(int dpi) { setSourceResolution((float)dpi); } - + /** * Gets the default page-height to use as fallback, * in case page-height="auto" @@ -535,7 +543,7 @@ public class FopFactory implements ImageContext { public String getPageHeight() { return this.pageHeight; } - + /** * Sets the page-height to use as fallback, in case * page-height="auto" @@ -548,7 +556,7 @@ public class FopFactory implements ImageContext { log.debug("Default page-height set to: " + pageHeight); } } - + /** * Gets the default page-width to use as fallback, * in case page-width="auto" @@ -558,7 +566,7 @@ public class FopFactory implements ImageContext { public String getPageWidth() { return this.pageWidth; } - + /** * Sets the page-width to use as fallback, in case * page-width="auto" @@ -571,27 +579,27 @@ public class FopFactory implements ImageContext { log.debug("Default page-width set to: " + pageWidth); } } - + /** * Adds a namespace to the set of ignored namespaces. - * If FOP encounters a namespace which it cannot handle, it issues a warning except if this + * If FOP encounters a namespace which it cannot handle, it issues a warning except if this * namespace is in the ignored set. * @param namespaceURI the namespace URI */ public void ignoreNamespace(String namespaceURI) { this.ignoredNamespaces.add(namespaceURI); } - + /** * Adds a collection of namespaces to the set of ignored namespaces. - * If FOP encounters a namespace which it cannot handle, it issues a warning except if this + * If FOP encounters a namespace which it cannot handle, it issues a warning except if this * namespace is in the ignored set. * @param namespaceURIs the namespace URIs */ public void ignoreNamespaces(Collection namespaceURIs) { this.ignoredNamespaces.addAll(namespaceURIs); } - + /** * Indicates whether a namespace URI is on the ignored list. * @param namespaceURI the namespace URI @@ -600,14 +608,14 @@ public class FopFactory implements ImageContext { public boolean isNamespaceIgnored(String namespaceURI) { return this.ignoredNamespaces.contains(namespaceURI); } - + /** @return the set of namespaces that are ignored by FOP */ public Set getIgnoredNamespace() { return Collections.unmodifiableSet(this.ignoredNamespaces); } //------------------------------------------- Configuration stuff - + /** * Set the user configuration. * @param userConfigFile the configuration file @@ -627,11 +635,11 @@ public class FopFactory implements ImageContext { public void setUserConfig(String uri) throws SAXException, IOException { config.setUserConfig(uri); } - + /** * Set the user configuration. * @param userConfig configuration - * @throws FOPException if a configuration problem occurs + * @throws FOPException if a configuration problem occurs */ public void setUserConfig(Configuration userConfig) throws FOPException { config.setUserConfig(userConfig); @@ -690,25 +698,15 @@ public class FopFactory implements ImageContext { public FontCache getFontCache() { return getFontManager().getFontCache(); } - + /** * Returns the font manager. * @return the font manager */ public FontManager getFontManager() { - if (fontManager == null) { - this.fontManager = new FontManager() { - - /** {@inheritDoc} */ - public void setFontBaseURL(String fontBase) throws MalformedURLException { - super.setFontBaseURL(getFOURIResolver().checkBaseURL(fontBase)); - } - - }; - } return this.fontManager; } - + /** * Attempts to resolve the given URI. * Will use the configured resolver and if not successful fall back @@ -716,7 +714,7 @@ public class FopFactory implements ImageContext { * @param href URI to access * @param baseUri the base URI to resolve against * @return A {@link javax.xml.transform.Source} object, or null if the URI - * cannot be resolved. + * cannot be resolved. * @see org.apache.fop.apps.FOURIResolver */ public Source resolveURI(String href, String baseUri) { @@ -728,19 +726,19 @@ public class FopFactory implements ImageContext { } return source; } - + /** * Create (if needed) and return an ICC ColorSpace instance. * * The ICC profile source is taken from the src attribute of the color-profile FO element. * If the ICC ColorSpace is not yet in the cache a new one is created and stored in the cache. * - * The FOP URI resolver is used to try and locate the ICC file. + * The FOP URI resolver is used to try and locate the ICC file. * If that fails null is returned. * * @param baseUri a base URI to resolve relative URIs * @param iccProfileSrc ICC Profile source to return a ColorSpace for - * @return ICC ColorSpace object or null if ColorSpace could not be created + * @return ICC ColorSpace object or null if ColorSpace could not be created */ public ColorSpace getColorSpace(String baseUri, String iccProfileSrc) { return colorSpaceCache.get(baseUri, iccProfileSrc); |