org.apache.fop.apps

Class FopFactory

Implemented Interfaces:
ImageContext

public class FopFactory
extends java.lang.Object
implements ImageContext

Factory class which instantiates new Fop and FOUserAgent instances. This class also holds environmental information and configuration used by FOP. Information that may potentially be different for each rendering run can be found and managed in the FOUserAgent.

Constructor Summary

FopFactory()
Main constructor.

Method Summary

void
addElementMapping(ElementMapping elementMapping)
Add the element mapping with the given class name.
String
getBaseURL()
Returns the base URL.
ColorSpace
getColorSpace(String baseUri, String iccProfileSrc)
Create (if needed) and return an ICC ColorSpace instance.
ContentHandlerFactoryRegistry
getContentHandlerFactoryRegistry()
ElementMappingRegistry
getElementMappingRegistry()
String
getFontBaseURL()
FontCache
getFontCache()
Returns the font cache instance used by this factory.
String
getHyphenBaseURL()
HyphenationTreeResolver
getHyphenationTreeResolver()
Set
getIgnoredNamespace()
ImageManager
getImageManager()
Returns the image manager.
LayoutManagerMaker
getLayoutManagerMakerOverride()
Returns the overriding LayoutManagerMaker instance, if any.
String
getPageHeight()
Gets the default page-height to use as fallback, in case page-height="auto"
String
getPageWidth()
Gets the default page-width to use as fallback, in case page-width="auto"
RendererFactory
getRendererFactory()
float
getSourcePixelUnitToMillimeter()
Returns the conversion factor from pixel units to millimeters.
float
getSourceResolution()
float
getTargetPixelUnitToMillimeter()
Returns the conversion factor from pixel units to millimeters.
float
getTargetResolution()
URIResolver
getURIResolver()
Returns the URI Resolver.
Configuration
getUserConfig()
Get the user configuration.
XMLHandlerRegistry
getXMLHandlerRegistry()
void
ignoreNamespace(String namespaceURI)
Adds a namespace to the set of ignored namespaces.
void
ignoreNamespaces(Collection namespaceURIs)
Adds a collection of namespaces to the set of ignored namespaces.
boolean
isBase14KerningEnabled()
boolean
isBreakIndentInheritanceOnReferenceAreaBoundary()
boolean
isNamespaceIgnored(String namespaceURI)
Indicates whether a namespace URI is on the ignored list.
FOUserAgent
newFOUserAgent()
Returns a new FOUserAgent instance.
Fop
newFop(String outputFormat)
Returns a new Fop instance.
Fop
newFop(String outputFormat, OutputStream stream)
Returns a new Fop instance.
Fop
newFop(String outputFormat, FOUserAgent userAgent)
Returns a new Fop instance.
Fop
newFop(String outputFormat, FOUserAgent userAgent, OutputStream stream)
Returns a new Fop instance.
Fop
newFop(FOUserAgent userAgent)
Returns a new Fop instance.
static FopFactory
newInstance()
Returns a new FopFactory instance.
Source
resolveURI(String href, String baseUri)
Attempts to resolve the given URI.
void
setBase14KerningEnabled(boolean value)
Controls whether kerning is activated on base 14 fonts.
void
setBaseURL(String base)
Sets the base URL.
void
setBreakIndentInheritanceOnReferenceAreaBoundary(boolean value)
Controls whether to enable a feature that breaks indent inheritance when crossing reference area boundaries.
void
setFontBaseURL(String fontBase)
Sets the font base URL.
void
setHyphenBaseURL(String hyphenBase)
Sets the hyphen base URL.
void
setHyphenationTreeResolver(HyphenationTreeResolver hyphResolver)
Sets the HyphenationTreeResolver to be used for resolving user-supplied hyphenation files.
void
setLayoutManagerMakerOverride(LayoutManagerMaker lmMaker)
Sets an explicit LayoutManagerMaker instance which overrides the one defined by the AreaTreeHandler.
void
setPageHeight(String pageHeight)
Sets the page-height to use as fallback, in case page-height="auto"
void
setPageWidth(String pageWidth)
Sets the page-width to use as fallback, in case page-width="auto"
void
setSourceResolution(float dpi)
Sets the source resolution in dpi.
void
setSourceResolution(int dpi)
Sets the source resolution in dpi.
void
setStrictUserConfigValidation(boolean strictUserConfigValidation)
Is the user configuration to be validated?
void
setStrictValidation(boolean validateStrictly)
Activates strict XSL content model validation for FOP Default is false (FOP will continue processing where it can)
void
setTargetResolution(float dpi)
Sets the source resolution in dpi.
void
setURIResolver(URIResolver uriResolver)
Sets the URI Resolver.
void
setUseCache(boolean useCache)
Whether or not to cache results of font triplet detection/auto-config
void
setUserConfig(Configuration userConfig)
Set the user configuration.
void
setUserConfig(File userConfigFile)
Set the user configuration.
void
setUserConfig(String uri)
Set the user configuration from an URI.
boolean
useCache()
Cache results of font triplet detection/auto-config?
boolean
validateStrictly()
Returns whether FOP is strictly validating input XSL
boolean
validateUserConfigStrictly()
Is the user configuration to be validated?

Constructor Details

FopFactory

protected FopFactory()
Main constructor.

Method Details

addElementMapping

public void addElementMapping(ElementMapping elementMapping)
Add the element mapping with the given class name.
Parameters:
elementMapping - the class name representing the element mapping.

getBaseURL

public String getBaseURL()
Returns the base URL.
Returns:
the base URL

getColorSpace

public ColorSpace getColorSpace(String baseUri,
                                String iccProfileSrc)
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. If that fails null is returned.
Parameters:
baseUri - a base URI to resolve relative URIs
iccProfileSrc - ICC Profile source to return a ColorSpace for
Returns:
ICC ColorSpace object or null if ColorSpace could not be created

getContentHandlerFactoryRegistry

public ContentHandlerFactoryRegistry getContentHandlerFactoryRegistry()
Returns:
the content handler factory registry

getElementMappingRegistry

public ElementMappingRegistry getElementMappingRegistry()
Returns:
the element mapping registry

getFontBaseURL

public String getFontBaseURL()
Returns:
the font base URL

getFontCache

public FontCache getFontCache()
Returns the font cache instance used by this factory.
Returns:
the font cache

getHyphenBaseURL

public String getHyphenBaseURL()
Returns:
the hyphen base URL

getHyphenationTreeResolver

public HyphenationTreeResolver getHyphenationTreeResolver()
Returns:
the HyphenationTreeResolver for resolving user-supplied hyphenation patterns.

getIgnoredNamespace

public Set getIgnoredNamespace()
Returns:
the set of namespaces that are ignored by FOP

getImageManager

public ImageManager getImageManager()
Returns the image manager.
Returns:
the image manager

getLayoutManagerMakerOverride

public LayoutManagerMaker getLayoutManagerMakerOverride()
Returns the overriding LayoutManagerMaker instance, if any.
Returns:
the overriding LayoutManagerMaker or null

getPageHeight

public String getPageHeight()
Gets the default page-height to use as fallback, in case page-height="auto"
Returns:
the page-height, as a String

getPageWidth

public String getPageWidth()
Gets the default page-width to use as fallback, in case page-width="auto"
Returns:
the page-width, as a String

getRendererFactory

public RendererFactory getRendererFactory()
Returns:
the RendererFactory

getSourcePixelUnitToMillimeter

public float getSourcePixelUnitToMillimeter()
Returns the conversion factor from pixel units to millimeters. This depends on the desired source resolution.
Returns:
float conversion factor

getSourceResolution

public float getSourceResolution()
Returns:
the resolution for resolution-dependant input

getTargetPixelUnitToMillimeter

public float getTargetPixelUnitToMillimeter()
Returns the conversion factor from pixel units to millimeters. This depends on the desired target resolution.
Returns:
float conversion factor

getTargetResolution

public float getTargetResolution()
Returns:
the resolution for resolution-dependant output

getURIResolver

public URIResolver getURIResolver()
Returns the URI Resolver.
Returns:
the URI Resolver

getUserConfig

public Configuration getUserConfig()
Get the user configuration.
Returns:
the user configuration

getXMLHandlerRegistry

public XMLHandlerRegistry getXMLHandlerRegistry()
Returns:
the XML handler registry

ignoreNamespace

public void ignoreNamespace(String namespaceURI)
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 namespace is in the ignored set.
Parameters:
namespaceURI - the namespace URI

ignoreNamespaces

public void ignoreNamespaces(Collection namespaceURIs)
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 namespace is in the ignored set.
Parameters:
namespaceURIs - the namespace URIs

isBase14KerningEnabled

public boolean isBase14KerningEnabled()
Returns:
true if kerning on base 14 fonts is enabled

isBreakIndentInheritanceOnReferenceAreaBoundary

public boolean isBreakIndentInheritanceOnReferenceAreaBoundary()
Returns:
true if the indent inheritance should be broken when crossing reference area boundaries (for more info, see the javadoc for the relative member variable)

isNamespaceIgnored

public boolean isNamespaceIgnored(String namespaceURI)
Indicates whether a namespace URI is on the ignored list.
Parameters:
namespaceURI - the namespace URI
Returns:
true if the namespace is ignored by FOP

newFOUserAgent

public FOUserAgent newFOUserAgent()
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.
Returns:
the newly created FOUserAgent instance initialized with default values

newFop

public Fop newFop(String outputFormat)
            throws FOPException
Returns a new Fop instance. FOP will be configured with a default user agent instance.

MIME types are used to select the output format (ex. "application/pdf" for PDF). You can use the constants defined in MimeConstants.

Parameters:
outputFormat - the MIME type of the output format to use (ex. "application/pdf").
Returns:
the new Fop instance
Throws:
FOPException - when the constructor fails

newFop

public Fop newFop(String outputFormat,
                  OutputStream stream)
            throws FOPException
Returns a new Fop instance. FOP will be configured with a default user agent instance. Use this factory method if your output type requires an output stream.

MIME types are used to select the output format (ex. "application/pdf" for PDF). You can use the constants defined in MimeConstants.

Parameters:
outputFormat - the MIME type of the output format to use (ex. "application/pdf").
stream - the output stream
Returns:
the new Fop instance
Throws:
FOPException - when the constructor fails

newFop

public Fop newFop(String outputFormat,
                  FOUserAgent userAgent)
            throws FOPException
Returns a new 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 FOUserAgent instance using newFOUserAgent().

MIME types are used to select the output format (ex. "application/pdf" for PDF). You can use the constants defined in MimeConstants.

Parameters:
outputFormat - the MIME type of the output format to use (ex. "application/pdf").
userAgent - the user agent that will be used to control the rendering run
Returns:
the new Fop instance
Throws:
FOPException - when the constructor fails

newFop

public Fop newFop(String outputFormat,
                  FOUserAgent userAgent,
                  OutputStream stream)
            throws FOPException
Returns a new Fop instance. Use this factory method if your output type requires an output stream and 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 FOUserAgent instance using newFOUserAgent().

MIME types are used to select the output format (ex. "application/pdf" for PDF). You can use the constants defined in MimeConstants.

Parameters:
outputFormat - the MIME type of the output format to use (ex. "application/pdf").
userAgent - the user agent that will be used to control the rendering run
stream - the output stream
Returns:
the new Fop instance
Throws:
FOPException - when the constructor fails

newFop

public Fop newFop(FOUserAgent userAgent)
            throws FOPException
Returns a new Fop instance. Use this factory method if you want to supply your own Renderer or FOEventHandler instance instead of the default ones created internally by FOP.
Parameters:
userAgent - the user agent that will be used to control the rendering run
Returns:
the new Fop instance
Throws:
FOPException - when the constructor fails

newInstance

public static FopFactory newInstance()
Returns a new FopFactory instance.
Returns:
the requested FopFactory instance.

resolveURI

public Source resolveURI(String href,
                         String baseUri)
Attempts to resolve the given URI. Will use the configured resolver and if not successful fall back to the default resolver.
Parameters:
href - URI to access
baseUri - the base URI to resolve against
Returns:
A javax.xml.transform.Source object, or null if the URI cannot be resolved.

setBase14KerningEnabled

public void setBase14KerningEnabled(boolean value)
Controls whether kerning is activated on base 14 fonts.
Parameters:
value - true if kerning should be activated

setBaseURL

public void setBaseURL(String base)
            throws MalformedURLException
Sets the base URL.
Parameters:
base - base URL

setBreakIndentInheritanceOnReferenceAreaBoundary

public void setBreakIndentInheritanceOnReferenceAreaBoundary(boolean value)
Controls whether to enable a feature that breaks indent inheritance when crossing reference area boundaries.

This flag controls whether FOP will enable special code that breaks property inheritance for start-indent and end-indent when the evaluation of the inherited value would cross a reference area. This is described under http://wiki.apache.org/xmlgraphics-fop/IndentInheritance as is intended to improve interoperability with commercial FO implementations and to produce results that are more in line with the expectation of unexperienced FO users. Note: Enabling this features violates the XSL specification!

Parameters:
value - true to enable the feature

setFontBaseURL

public void setFontBaseURL(String fontBase)
            throws MalformedURLException
Sets the font base URL.
Parameters:
fontBase - font base URL

setHyphenBaseURL

public void setHyphenBaseURL(String hyphenBase)
            throws MalformedURLException
Sets the hyphen base URL.
Parameters:
hyphenBase - hythen base URL

setHyphenationTreeResolver

public void setHyphenationTreeResolver(HyphenationTreeResolver hyphResolver)
Sets the HyphenationTreeResolver to be used for resolving user-supplied hyphenation files.
Parameters:
hyphResolver - the HyphenationTreeResolver instance

setLayoutManagerMakerOverride

public void setLayoutManagerMakerOverride(LayoutManagerMaker lmMaker)
Sets an explicit LayoutManagerMaker instance which overrides the one defined by the AreaTreeHandler.
Parameters:
lmMaker - the LayoutManagerMaker instance

setPageHeight

public void setPageHeight(String pageHeight)
Sets the page-height to use as fallback, in case page-height="auto"
Parameters:
pageHeight - page-height as a String

setPageWidth

public void setPageWidth(String pageWidth)
Sets the page-width to use as fallback, in case page-width="auto"
Parameters:
pageWidth - page-width as a String

setSourceResolution

public void setSourceResolution(float dpi)
Sets the source resolution in dpi. This value is used to interpret the pixel size of source documents like SVG images and bitmap images without resolution information.
Parameters:
dpi - resolution in dpi

setSourceResolution

public void setSourceResolution(int dpi)
Sets the source resolution in dpi. This value is used to interpret the pixel size of source documents like SVG images and bitmap images without resolution information.
Parameters:
dpi - resolution in dpi

setStrictUserConfigValidation

public void setStrictUserConfigValidation(boolean strictUserConfigValidation)
Is the user configuration to be validated?
Parameters:
strictUserConfigValidation - strict user config validation

setStrictValidation

public void setStrictValidation(boolean validateStrictly)
Activates strict XSL content model validation for FOP Default is false (FOP will continue processing where it can)
Parameters:
validateStrictly - true to turn on strict validation

setTargetResolution

public void setTargetResolution(float dpi)
Sets the source resolution in dpi. This value is used to interpret the pixel size of source documents like SVG images and bitmap images without resolution information.
Parameters:
dpi - resolution in dpi

setURIResolver

public void setURIResolver(URIResolver uriResolver)
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.
Parameters:
uriResolver - the new URI resolver

setUseCache

public void setUseCache(boolean useCache)
Whether or not to cache results of font triplet detection/auto-config
Parameters:
useCache - use cache or not

setUserConfig

public void setUserConfig(Configuration userConfig)
            throws FOPException
Set the user configuration.
Parameters:
userConfig - configuration
Throws:
FOPException - if a configuration problem occurs

setUserConfig

public void setUserConfig(File userConfigFile)
            throws SAXException,
                   IOException
Set the user configuration.
Parameters:
userConfigFile - the configuration file

setUserConfig

public void setUserConfig(String uri)
            throws SAXException,
                   IOException
Set the user configuration from an URI.
Parameters:
uri - the URI to the configuration file

useCache

public boolean useCache()
Cache results of font triplet detection/auto-config?
Returns:
whether this factory is uses the cache

validateStrictly

public boolean validateStrictly()
Returns whether FOP is strictly validating input XSL
Returns:
true of strict validation turned on, false otherwise

validateUserConfigStrictly

public boolean validateUserConfigStrictly()
Is the user configuration to be validated?
Returns:
if the user configuration should be validated

Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.