Package org.apache.fop.afp
Class AFPResourceManager
- java.lang.Object
-
- org.apache.fop.afp.AFPResourceManager
-
public class AFPResourceManager extends java.lang.Object
Manages the creation and storage of document resources
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
AFPResourceManager.AbstractCachedObject
private class
AFPResourceManager.CachedObject
private class
AFPResourceManager.CachedPageSegment
-
Field Summary
Fields Modifier and Type Field Description private AFPDataObjectFactory
dataObjectFactory
private DataStream
dataStream
The AFP datastream (document tree)private Factory
factory
Resource creation factoryprotected boolean
includeCached
private java.util.Map<AFPResourceInfo,java.util.List<AFPResourceManager.AbstractCachedObject>>
includeObjectCache
Mapping of resourceInfo to AbstractCachedObjectprivate int
instreamObjectCount
Maintain a reference count of instream objects for referencing purposesprivate static org.apache.commons.logging.Log
log
logging instanceprivate AFPResourceLevelDefaults
resourceLevelDefaults
private AFPStreamer
streamer
-
Constructor Summary
Constructors Constructor Description AFPResourceManager(InternalResourceResolver resourceResolver)
Main constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addToCache(AFPResourceInfo resourceInfo, AFPResourceManager.AbstractCachedObject cachedObject)
DataStream
createDataStream(AFPPaintingState paintingState, java.io.OutputStream outputStream)
Sets the outputstreamvoid
createIncludedResource(java.lang.String resourceName, java.net.URI uri, AFPResourceAccessor accessor, byte resourceObjectType, boolean truetype, java.lang.String ttc)
Creates an included resource object by loading the contained object from a file.void
createIncludedResource(java.lang.String resourceName, AFPResourceAccessor accessor, byte resourceObjectType)
Creates an included resource object by loading the contained object from a file.void
createIncludedResourceFromExternal(java.lang.String resourceName, java.net.URI uri, AFPResourceAccessor accessor)
Creates an included resource extracting the named resource from an external source.void
createObject(AFPDataObjectInfo dataObjectInfo)
Creates a new data object in the AFP datastreamvoid
embedFont(AFPFont afpFont, CharacterSet charSet)
Handles font embedding.private byte[]
extractTTC(java.lang.String ttc, java.io.InputStream is)
DataStream
getDataStream()
Returns the AFP DataStreamAFPResourceLevelDefaults
getResourceLevelDefaults()
Returns the resource level defaults in use with this resource manager.boolean
includeCachedObject(AFPResourceInfo resourceInfo, AFPObjectAreaInfo areaInfo)
private void
includeObject(AFPDataObjectInfo dataObjectInfo, java.lang.String objectName)
private void
includeObject(AbstractNamedAFPObject namedObj, AFPDataObjectInfo dataObjectInfo)
private void
includePageSegment(AFPDataObjectInfo dataObjectInfo, java.lang.String pageSegmentName)
boolean
isObjectCached(AFPResourceInfo resourceInfo)
Returnstrue
if the passedAFPResourceInfo
instance is already cached.void
setDefaultResourceGroupUri(java.net.URI uri)
Sets the default resource group URI.void
setResourceLevelDefaults(AFPResourceLevelDefaults defaults)
Sets resource level defaults.boolean
tryIncludeObject(AFPDataObjectInfo dataObjectInfo)
Tries to create an include of a data object that has been previously added to the AFP data stream.private void
updateResourceInfoUri(AFPResourceInfo resourceInfo)
void
writeToStream()
Tells the streamer to write
-
-
-
Field Detail
-
log
private static org.apache.commons.logging.Log log
logging instance
-
dataStream
private DataStream dataStream
The AFP datastream (document tree)
-
factory
private final Factory factory
Resource creation factory
-
streamer
private final AFPStreamer streamer
-
dataObjectFactory
private final AFPDataObjectFactory dataObjectFactory
-
instreamObjectCount
private int instreamObjectCount
Maintain a reference count of instream objects for referencing purposes
-
includeObjectCache
private final java.util.Map<AFPResourceInfo,java.util.List<AFPResourceManager.AbstractCachedObject>> includeObjectCache
Mapping of resourceInfo to AbstractCachedObject
-
resourceLevelDefaults
private AFPResourceLevelDefaults resourceLevelDefaults
-
includeCached
protected boolean includeCached
-
-
Constructor Detail
-
AFPResourceManager
public AFPResourceManager(InternalResourceResolver resourceResolver)
Main constructor- Parameters:
resourceResolver
- the associatedInternalResourceResolver
instance
-
-
Method Detail
-
createDataStream
public DataStream createDataStream(AFPPaintingState paintingState, java.io.OutputStream outputStream) throws java.io.IOException
Sets the outputstream- Parameters:
paintingState
- the AFP painting stateoutputStream
- the outputstream- Returns:
- a new AFP DataStream
- Throws:
java.io.IOException
- thrown if an I/O exception of some sort has occurred
-
getDataStream
public DataStream getDataStream()
Returns the AFP DataStream- Returns:
- the AFP DataStream
-
writeToStream
public void writeToStream() throws java.io.IOException
Tells the streamer to write- Throws:
java.io.IOException
- thrown if an I/O exception of some sort has occurred.
-
setDefaultResourceGroupUri
public void setDefaultResourceGroupUri(java.net.URI uri)
Sets the default resource group URI.- Parameters:
uri
- the default resource group URI
-
tryIncludeObject
public boolean tryIncludeObject(AFPDataObjectInfo dataObjectInfo) throws java.io.IOException
Tries to create an include of a data object that has been previously added to the AFP data stream. If no such object was available, the method returns false which serves as a signal that the object has to be created.- Parameters:
dataObjectInfo
- the data object info- Returns:
- true if the inclusion succeeded, false if the object was not available
- Throws:
java.io.IOException
- thrown if an I/O exception of some sort has occurred.
-
createObject
public void createObject(AFPDataObjectInfo dataObjectInfo) throws java.io.IOException
Creates a new data object in the AFP datastream- Parameters:
dataObjectInfo
- the data object info- Throws:
java.io.IOException
- thrown if an I/O exception of some sort has occurred.
-
includeObject
private void includeObject(AbstractNamedAFPObject namedObj, AFPDataObjectInfo dataObjectInfo)
-
addToCache
private void addToCache(AFPResourceInfo resourceInfo, AFPResourceManager.AbstractCachedObject cachedObject)
-
isObjectCached
public boolean isObjectCached(AFPResourceInfo resourceInfo)
Returnstrue
if the passedAFPResourceInfo
instance is already cached.- Parameters:
resourceInfo
- the resource info to check- Returns:
true
if the object is cached
-
includeCachedObject
public boolean includeCachedObject(AFPResourceInfo resourceInfo, AFPObjectAreaInfo areaInfo)
- Parameters:
resourceInfo
- the resource info to checkareaInfo
- the area info to check- Returns:
true
if ...
-
updateResourceInfoUri
private void updateResourceInfoUri(AFPResourceInfo resourceInfo)
-
includeObject
private void includeObject(AFPDataObjectInfo dataObjectInfo, java.lang.String objectName)
-
embedFont
public void embedFont(AFPFont afpFont, CharacterSet charSet) throws java.io.IOException
Handles font embedding. If a font is embeddable and has not already been embedded it will be.- Parameters:
afpFont
- the AFP font to be checked for embeddingcharSet
- the associated character set- Throws:
java.io.IOException
- if there's a problem while embedding the external resources
-
includePageSegment
private void includePageSegment(AFPDataObjectInfo dataObjectInfo, java.lang.String pageSegmentName)
-
createIncludedResource
public void createIncludedResource(java.lang.String resourceName, AFPResourceAccessor accessor, byte resourceObjectType) throws java.io.IOException
Creates an included resource object by loading the contained object from a file.- Parameters:
resourceName
- the name of the resourceaccessor
- resource accessor to access the resource withresourceObjectType
- the resource object type (ResourceObject
.*)- Throws:
java.io.IOException
- if an I/O error occurs while loading the resource
-
createIncludedResource
public void createIncludedResource(java.lang.String resourceName, java.net.URI uri, AFPResourceAccessor accessor, byte resourceObjectType, boolean truetype, java.lang.String ttc) throws java.io.IOException
Creates an included resource object by loading the contained object from a file.- Parameters:
resourceName
- the name of the resourceuri
- the URI for the resourceaccessor
- resource accessor to access the resource withresourceObjectType
- the resource object type (ResourceObject
.*)- Throws:
java.io.IOException
- if an I/O error occurs while loading the resource
-
extractTTC
private byte[] extractTTC(java.lang.String ttc, java.io.InputStream is) throws java.io.IOException
- Throws:
java.io.IOException
-
createIncludedResourceFromExternal
public void createIncludedResourceFromExternal(java.lang.String resourceName, java.net.URI uri, AFPResourceAccessor accessor) throws java.io.IOException
Creates an included resource extracting the named resource from an external source.- Parameters:
resourceName
- the name of the resourceuri
- the URI for the resourceaccessor
- resource accessor to access the resource with- Throws:
java.io.IOException
- if an I/O error occurs while loading the resource
-
setResourceLevelDefaults
public void setResourceLevelDefaults(AFPResourceLevelDefaults defaults)
Sets resource level defaults. The existing defaults over merged with the ones passed in as parameter.- Parameters:
defaults
- the new defaults
-
getResourceLevelDefaults
public AFPResourceLevelDefaults getResourceLevelDefaults()
Returns the resource level defaults in use with this resource manager.- Returns:
- the resource level defaults
-
-