diff options
Diffstat (limited to 'src/java/org/apache/fop/render/afp/modca')
49 files changed, 1259 insertions, 1452 deletions
diff --git a/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java b/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java index 8c2c1b958..8d640b998 100644 --- a/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java +++ b/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java @@ -20,7 +20,6 @@ package org.apache.fop.render.afp.modca; import java.awt.Color; -import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.util.Iterator; @@ -32,9 +31,11 @@ import org.apache.commons.logging.LogFactory; import org.apache.fop.render.afp.AFPFontAttributes; import org.apache.fop.render.afp.AFPTextDataInfo; import org.apache.fop.render.afp.DataObjectInfo; +import org.apache.fop.render.afp.ExternalResourceGroupManager; import org.apache.fop.render.afp.ObjectAreaInfo; import org.apache.fop.render.afp.ResourceInfo; import org.apache.fop.render.afp.ResourceLevel; +import org.apache.fop.render.afp.DataObjectCache; import org.apache.fop.render.afp.fonts.AFPFont; import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; import org.apache.fop.render.afp.tools.StringUtils; @@ -56,11 +57,8 @@ import org.apache.fop.render.afp.tools.StringUtils; */ public class AFPDataStream extends AbstractResourceGroupContainer { - /** - * Static logging instance - */ - protected static Log log = LogFactory - .getLog("org.apache.fop.render.afp.modca"); + /** Static logging instance */ + protected static Log log = LogFactory.getLog("org.apache.fop.render.afp.modca"); /** * Boolean completion indicator @@ -192,15 +190,7 @@ public class AFPDataStream extends AbstractResourceGroupContainer { this.outputStream = outputStream; } - /** - * The document is written/ended by invoking this method which creates an - * instance of the AFP Document object and registers the start with a - * validation map which ensures that methods are not invoked out of the - * correct sequence. - * - * @throws java.io.IOException - * throws an I/O exception of some sort has occurred - */ + /** {@inheritDoc} */ public void write() throws IOException { if (complete) { String msg = "Invalid state - document already ended."; @@ -220,7 +210,7 @@ public class AFPDataStream extends AbstractResourceGroupContainer { if (interchangeSet.supportsLevel2()) { // Write out any external resource groups - getExternalResourceGroupManager().writeExternalResources(); + getExternalResourceGroupManager().write(); // Write out any print-file level resources if (hasResources()) { @@ -241,6 +231,8 @@ public class AFPDataStream extends AbstractResourceGroupContainer { this.document = null; this.outputStream = null; + + DataObjectCache.getInstance().clear(); } /** @@ -295,18 +287,13 @@ public class AFPDataStream extends AbstractResourceGroupContainer { String overlayName = "OVL" + StringUtils.lpad(String.valueOf(++overlayCount), '0', 5); - this.currentOverlay = new Overlay(overlayName, width, height, widthRes, - heightRes, overlayRotation); - - if (interchangeSet.supportsLevel2()) { - ResourceObject resourceObject = new ResourceObject(overlayName); - resourceObject.setDataObject(currentOverlay); - getResourceGroup().addObject(resourceObject); - } + DataObjectCache cache = DataObjectCache.getInstance(); + DataObjectFactory factory = cache.getFactory(); + this.currentOverlay = factory.createOverlay( + overlayName, width, height, widthRes, heightRes, overlayRotation); currentPageObject.createIncludePageOverlay(overlayName, x, y, 0); currentPage = currentOverlay; -// setOffsets(0, 0, 0); } /** @@ -439,10 +426,10 @@ public class AFPDataStream extends AbstractResourceGroupContainer { * * @param dataObjectInfo * the data object info - * @return a data object */ - public AbstractNamedAFPObject createObject(DataObjectInfo dataObjectInfo) { - String uri = dataObjectInfo.getUri(); + public void createObject(DataObjectInfo dataObjectInfo) { + ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); + String uri = resourceInfo.getUri(); if (uri == null) { uri = "/"; @@ -451,40 +438,50 @@ public class AFPDataStream extends AbstractResourceGroupContainer { // unique if (uri.endsWith("/")) { uri += "#" + (++instreamObjectCount); - dataObjectInfo.setUri(uri); + resourceInfo.setUri(uri); } - //Update placement with current state + // Update placement with current state ObjectAreaInfo areaInfo = dataObjectInfo.getObjectAreaInfo(); areaInfo.setX(areaInfo.getX()); areaInfo.setY(areaInfo.getY()); areaInfo.setRotation(this.rotation); + // Do we have a recognised/registered object type? Registry registry = Registry.getInstance(); Registry.ObjectType objectType = registry.getObjectType(dataObjectInfo); - // recognised object type if (objectType != null) { dataObjectInfo.setObjectType(objectType); + } + + DataObjectCache cache = DataObjectCache.getInstance(); + String includeName = cache.put(dataObjectInfo); - ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); + if (objectType != null) { + ResourceLevel resourceLevel = resourceInfo.getLevel(); // is MO:DCA-L available? if (interchangeSet.supportsLevel2()) { - // can this data object use the include object (IOB) referencing + + // Can this data object use the include object (IOB) referencing // mechanism? if (objectType.canBeIncluded()) { + + // Create and return include + DataObjectFactory factory = cache.getFactory(); + IncludeObject includeObj = factory.createInclude(includeName, dataObjectInfo); + getCurrentPage().addObject(includeObj); + + // Record the resource cache key (uri) in the ResourceGroup ResourceGroup resourceGroup = getResourceGroup(resourceLevel); - IncludeObject includeObject = resourceGroup.createObject(dataObjectInfo); - - // add include to current page - getCurrentPage().addObject(includeObject); - return includeObject.getDataObject(); + resourceGroup.addObject(resourceInfo); + return; } else { - log.warn("data object located at '" + uri + "'" + log.warn("Data object located at '" + uri + "'" + " of type '" + objectType.getMimeType() + "'" + " cannot be included with an IOB so it will be embedded directly"); - } + } } else { if (resourceLevel.isExternal()) { log.warn(interchangeSet @@ -492,11 +489,8 @@ public class AFPDataStream extends AbstractResourceGroupContainer { } } } - // unrecognised/unsupported object type so create/embed data object - // directly in current page - AbstractNamedAFPObject dataObj = currentPageObject.createObject(dataObjectInfo); - getCurrentPage().addObject(dataObj); - return dataObj; + // Unrecognised/unsupported object type so add object reference directly in current page + currentPageObject.addObject(resourceInfo); } // /** @@ -713,6 +707,11 @@ public class AFPDataStream extends AbstractResourceGroupContainer { getCurrentPage().createNoOperation(content); } + /** + * Returns the current page group + * + * @return the current page group + */ private PageGroup getCurrentPageGroup() { if (currentPageGroup == null) { String pageGroupName = "PGP" @@ -747,8 +746,7 @@ public class AFPDataStream extends AbstractResourceGroupContainer { * Sets the rotation to be used for portrait pages, valid values are 0 * (default), 90, 180, 270. * - * @param pageRotation - * The rotation in degrees. + * @param pageRotation the rotation in degrees. */ public void setPortraitRotation(int pageRotation) { if (pageRotation == 0 || pageRotation == 90 || pageRotation == 180 @@ -764,8 +762,7 @@ public class AFPDataStream extends AbstractResourceGroupContainer { * Sets the rotation to be used for landscape pages, valid values are 0, 90, * 180, 270 (default). * - * @param pageRotation - * The rotation in degrees. + * @param pageRotation the rotation in degrees. */ public void setLandscapeRotation(int pageRotation) { if (pageRotation == 0 || pageRotation == 90 || pageRotation == 180 @@ -778,164 +775,57 @@ public class AFPDataStream extends AbstractResourceGroupContainer { } /** - * Returns the resource group for a given resource into - * - * @param level - * resource info - * @return a resource group container for the given resource info - */ - private ResourceGroup getResourceGroup(ResourceLevel level) { - ResourceGroup resourceGroup = null; - if (level.isPrintFile()) { - resourceGroup = getResourceGroup(); - } else if (level.isDocument()) { - resourceGroup = getDocument().getResourceGroup(); - } else if (level.isPageGroup()) { - resourceGroup = getCurrentPageGroup().getResourceGroup(); - } else if (level.isPage()) { - resourceGroup = currentPageObject.getResourceGroup(); - } else if (level.isExternal()) { - resourceGroup = getExternalResourceGroupManager() - .getExternalResourceGroup(level); - } - return resourceGroup; - } - - /** * Sets the default resource group file * - * @param resourceGroupFile - * the default resource group file + * @param filePath the default resource group file path */ - public void setDefaultResourceGroupFile(File resourceGroupFile) { - getExternalResourceGroupManager().setDefaultResourceGroupFile( - resourceGroupFile); + public void setDefaultResourceGroupFilePath(String filePath) { + getExternalResourceGroupManager().setDefaultResourceGroupFilePath(filePath); } /** + * Returns the external resource group manager + * * @return the resource group manager */ protected ExternalResourceGroupManager getExternalResourceGroupManager() { if (externalResourceGroupManager == null) { - this.externalResourceGroupManager = new ExternalResourceGroupManager(this); + this.externalResourceGroupManager = new ExternalResourceGroupManager(); } return this.externalResourceGroupManager; } /** - * Manages the use of resource groups (external and internal) + * Returns the resource group for a given resource info + * + * @param level a resource level + * @return a resource group for the given resource info */ - private final class ExternalResourceGroupManager { - /** - * A mapping of external resource destinations to resource groups - */ - private Map/*<File,ResourceGroup>*/externalResourceGroups = null; - - /** sets the default resource group file */ - private File defaultResourceGroupFile; - - /** the container of this manager */ - private AbstractResourceGroupContainer container; - - /** - * Main constructor - * - * @param container - * the container of this manager - */ - private ExternalResourceGroupManager( - AbstractResourceGroupContainer container) { - this.container = container; - } - - /** - * Sets the default resource group file - * - * @param resourceGroupFile - * the default resource group file - */ - private void setDefaultResourceGroupFile(File resourceGroupFile) { - this.defaultResourceGroupFile = resourceGroupFile; - } - - /** - * Writes out external AFP resources - */ - private void writeExternalResources() { - // write any external resources - Iterator it = getExternalResourceGroups().keySet().iterator(); - while (it.hasNext()) { - File resourceGroupFile = (File) it.next(); - ResourceGroup resourceGroup = (ResourceGroup) getExternalResourceGroups() - .get(resourceGroupFile); - OutputStream os = null; - try { - log.debug("Writing external AFP resource file " - + resourceGroupFile.getAbsolutePath()); - - os = new java.io.FileOutputStream(resourceGroupFile); - resourceGroup.write(os); - } catch (IOException e) { - log.error( - "An error occurred when attempting to write external AFP resource file " - + resourceGroupFile.getAbsolutePath()); - } finally { - if (os != null) { - try { - os.close(); - } catch (IOException e) { - log.error("Failed to close outputstream for external AFP resource file " - + resourceGroupFile.getAbsolutePath()); - } - } - } - } - } - - /** - * Returns the corresponding resource group for the given resource level - * - * @param level - * the resource level - * @return the corresponding resource group for the given resource level - */ - private ResourceGroup getExternalResourceGroup(ResourceLevel level) { - ResourceGroup resourceGroup; - // this resource info does not have an external resource group - // file definition - if (!level.hasExternalResourceGroupFile()) { - if (defaultResourceGroupFile != null) { - // fallback to default resource group file - level.setExternalResourceGroupFile(defaultResourceGroupFile); - resourceGroup = getExternalResourceGroup(level); - } else { - // use print-file level resource group in the absence - // of an external resource group file definition - resourceGroup = container.getResourceGroup(); - } - } else { - File resourceGroupFile = level - .getExternalResourceGroupFile(); - resourceGroup = (ResourceGroup)getExternalResourceGroups().get(resourceGroupFile); - if (resourceGroup == null) { - resourceGroup = new ResourceGroup(); - externalResourceGroups - .put(resourceGroupFile, resourceGroup); - } - } - return resourceGroup; - } - - private Map/*<File,ResourceGroup>*/getExternalResourceGroups() { - if (externalResourceGroups == null) { - externalResourceGroups = new java.util.HashMap/*<File,ResourceGroup>*/(); + private ResourceGroup getResourceGroup(ResourceLevel level) { + ResourceGroup resourceGroup = null; + if (level.isExternal()) { + resourceGroup = getExternalResourceGroupManager().getResourceGroup(level); + // use print-file level resource group in the absence + // of an external resource group file definition + if (resourceGroup == null) { + level.setLevel(ResourceLevel.PRINT_FILE); } - return externalResourceGroups; } + if (level.isPrintFile()) { + resourceGroup = getResourceGroup(); + } else if (level.isDocument()) { + resourceGroup = getDocument().getResourceGroup(); + } else if (level.isPageGroup()) { + resourceGroup = getCurrentPageGroup().getResourceGroup(); + } else if (level.isPage()) { + resourceGroup = currentPageObject.getResourceGroup(); + } + return resourceGroup; } /** * Sets the MO:DCA interchange set to use + * * @param interchangeSet the MO:DCA interchange set */ public void setInterchangeSet(InterchangeSet interchangeSet) { @@ -943,6 +833,8 @@ public class AFPDataStream extends AbstractResourceGroupContainer { } /** + * Returns the MO:DCA interchange set in use + * * @return the MO:DCA interchange set in use */ public InterchangeSet getInterchangeSet() { diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java index 9cad38ef5..d9f3d6d1a 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java @@ -35,13 +35,52 @@ import org.apache.commons.logging.LogFactory; */ public abstract class AbstractAFPObject implements Writable { + /** Static logging instance */ + protected static final Log log = LogFactory.getLog("org.apache.fop.render.afp.modca"); + + private static final byte SF_CLASS = (byte)0xD3; + + private static final byte[] SF = new byte[] { + 0x5A, // Structured field identifier + 0x00, // Length byte 1 + 0x10, // Length byte 2 + (byte) SF_CLASS, // Structured field id byte 1 + (byte) 0x00, // Structured field id byte 2 + (byte) 0x00, // Structured field id byte 3 + 0x00, // Flags + 0x00, // Reserved + 0x00, // Reserved + }; + /** - * Static logging instance + * Copies the template structured field data array to the given byte array + * + * @param data the structured field data byte array + * @param type the type code + * @param category the category code */ - protected static final Log log = LogFactory.getLog("org.apache.fop.render.afp.modca"); + protected void copySF(byte[] data, byte type, byte category) { + copySF(data, SF_CLASS, type, category); + } + + /** + * Copies the template structured field data array to the given byte array + * + * @param data the structured field data byte array + * @param clazz the class code + * @param type the type code + * @param category the category code + */ + protected void copySF(byte[] data, byte clazz, byte type, byte category) { + System.arraycopy(SF, 0, data, 0, SF.length); + data[3] = clazz; + data[4] = type; + data[5] = category; + } /** * Help method to write a set of AFPObjects to the AFP datastream. + * * @param objects a list of AFPObjects * @param os The stream to write to * @throws java.io.IOException an I/O exception of some sort has occurred. @@ -55,5 +94,146 @@ public abstract class AbstractAFPObject implements Writable { } } } + + /** structured field type codes */ + interface Type { + + // Attribute + byte ATTRIBUTE = (byte)0x0A; + + // Copy Count + byte COPY_COUNT = (byte)0xA2; + + // Descriptor + byte DESCRIPTOR = (byte)0xA6; + + // Control + byte CONTROL = (byte)0xA7; + + // Begin + byte BEGIN = (byte)0xA8; + + // End + byte END = (byte)0xA9; + + // Map + byte MAP = (byte)0xAB; + + // Position + byte POSITION = (byte)0xAC; + + // Process + byte PROCESS = (byte)0xAD; + + // Include + byte INCLUDE = (byte)0xAF; + + // Table + byte TABLE = (byte)0xB0; + + // Migration + byte MIGRATION = (byte)0xB1; + + // Variable + byte VARIABLE = (byte)0xB2; + + // Link + byte LINK = (byte)0xB4; + + // Data + byte DATA = (byte)0xEE; + } + + /** structured field category codes */ + interface Category { + + // Page Segment + byte PAGE_SEGMENT = (byte)0x5F; + + // Object Area + byte OBJECT_AREA = (byte)0x6B; + + // Color Attribute Table + byte COLOR_ATTRIBUTE_TABLE = (byte)0x77; + + // IM Image + byte IM_IMAGE = (byte)0x7B; + + // Medium + byte MEDIUM = (byte)0x88; + + // Coded Font + byte CODED_FONT = (byte)0x8A; + + // Process Element + byte PROCESS_ELEMENT = (byte)0x90; + + // Object Container + byte OBJECT_CONTAINER = (byte)0x92; + + // Presentation Text + byte PRESENTATION_TEXT = (byte)0x9B; + + // Index + byte INDEX = (byte)0xA7; + + // Document + byte DOCUMENT = (byte)0xA8; + + // Page Group + byte PAGE_GROUP = (byte)0xAD; + + // Page + byte PAGE = (byte)0xAF; + + // Graphics + byte GRAPHICS = (byte)0xBB; + + // Data Resource + byte DATA_RESOURCE = (byte)0xC3; + + // Document Environment Group (DEG) + byte DOCUMENT_ENVIRONMENT_GROUP = (byte)0xC4; + + // Resource Group + byte RESOURCE_GROUP = (byte)0xC6; + + // Object Environment Group (OEG) + byte OBJECT_ENVIRONMENT_GROUP = (byte)0xC7; + + // Active Environment Group (AEG) + byte ACTIVE_ENVIRONMENT_GROUP = (byte)0xC9; + + // Medium Map + byte MEDIUM_MAP = (byte)0xCC; + + // Form Map + byte FORM_MAP = (byte)0xCD; + + // Name Resource + byte NAME_RESOURCE = (byte)0xCE; + + // Page Overlay + byte PAGE_OVERLAY = (byte)0xD8; + + // Resource Environment Group (REG) + byte RESOURCE_ENVIROMENT_GROUP = (byte)0xD9; + + // Overlay + byte OVERLAY = (byte)0xDF; + + // Data Suppression + byte DATA_SUPRESSION = (byte)0xEA; + + // Bar Code + byte BARCODE = (byte)0xEB; + + // No Operation + byte NO_OPERATION = (byte)0xEE; + + // Image + byte IMAGE = (byte)0xFB; + } + } diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java index f52047b62..f666de38b 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java @@ -24,20 +24,18 @@ import java.io.OutputStream; import org.apache.fop.render.afp.ObjectAreaInfo; - /** * Abstract base class used by the ImageObject and GraphicsObject which both * have define an ObjectEnvironmentGroup */ public abstract class AbstractDataObject extends AbstractPreparedObjectContainer { - /** - * The object environment group - */ + /** The object environment group */ protected ObjectEnvironmentGroup objectEnvironmentGroup = null; /** * Named constructor + * * @param name data object name */ public AbstractDataObject(String name) { @@ -56,6 +54,7 @@ public abstract class AbstractDataObject extends AbstractPreparedObjectContainer /** * Gets the ObjectEnvironmentGroup + * * @return the object environment group */ protected ObjectEnvironmentGroup getObjectEnvironmentGroup() { @@ -67,15 +66,14 @@ public abstract class AbstractDataObject extends AbstractPreparedObjectContainer /** * Sets the ObjectEnvironmentGroup. + * * @param objectEnvironmentGroup The objectEnvironmentGroup to set */ public void setObjectEnvironmentGroup(ObjectEnvironmentGroup objectEnvironmentGroup) { this.objectEnvironmentGroup = objectEnvironmentGroup; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { if (objectEnvironmentGroup != null) { objectEnvironmentGroup.write(os); diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java b/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java index 6d827766e..f5bc933a3 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java @@ -35,6 +35,7 @@ public abstract class AbstractDescriptor extends AbstractAFPObject { /** * Constructor a PresentationTextDescriptor for the specified * width and height. + * * @param width The width of the page. * @param height The height of the page. * @param widthResolution The width resolution of the page. diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractEnvironmentGroup.java b/src/java/org/apache/fop/render/afp/modca/AbstractEnvironmentGroup.java index 3f371d628..7e81e4934 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractEnvironmentGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractEnvironmentGroup.java @@ -36,6 +36,7 @@ public abstract class AbstractEnvironmentGroup extends AbstractNamedAFPObject { /** * Main constructor + * * @param name the object name */ public AbstractEnvironmentGroup(String name) { @@ -52,6 +53,7 @@ public abstract class AbstractEnvironmentGroup extends AbstractNamedAFPObject { /** * Actually creates the MPO object. * Also creates the supporting object (an IPO) + * * @param name the name of the overlay to be used */ public void createOverlay(String name) { @@ -78,6 +80,7 @@ public abstract class AbstractEnvironmentGroup extends AbstractNamedAFPObject { /** * Getter method for the most recent MapPageOverlay added to the * Active Environment Group (returns null if no MapPageOverlay exist) + * * @return the most recent Map Coded Font */ private MapPageOverlay getCurrentMapPageOverlay() { @@ -88,9 +91,7 @@ public abstract class AbstractEnvironmentGroup extends AbstractNamedAFPObject { } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); if (mapPageOverlays != null) { diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java index 8e6127b8a..6ed3411bc 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java @@ -35,11 +35,6 @@ public abstract class AbstractNamedAFPObject extends AbstractStructuredAFPObject protected String name = null; /** - * The name of the object in EBCIDIC bytes - */ - protected byte[] nameBytes; - - /** * Default constructor */ protected AbstractNamedAFPObject() { @@ -48,16 +43,26 @@ public abstract class AbstractNamedAFPObject extends AbstractStructuredAFPObject /** * Constructor for the ActiveEnvironmentGroup, this takes a * name parameter which should be 8 characters long. + * * @param name the object name */ protected AbstractNamedAFPObject(String name) { this.name = name; - if (name.length() < 8) { - name = (name + " ").substring(0, 8); - } else if (name.length() > 8) { - log.warn("Constructor:: name truncated to 8 chars" + name); - name = name.substring(0, 8); + } + + /** + * Returns the name as a byte array in EBCIDIC encoding + * + * @return the name as a byte array in EBCIDIC encoding + */ + protected byte[] getNameBytes() { + if (name.length() < DEFAULT_NAME_LENGTH) { + name = (name + " ").substring(0, DEFAULT_NAME_LENGTH); + } else if (name.length() > DEFAULT_NAME_LENGTH) { + log.warn("Constructor:: name truncated to " + DEFAULT_NAME_LENGTH + " chars" + name); + name = name.substring(0, DEFAULT_NAME_LENGTH); } + byte[] nameBytes = null; try { nameBytes = name.getBytes(AFPConstants.EBCIDIC_ENCODING); } catch (UnsupportedEncodingException usee) { @@ -66,17 +71,20 @@ public abstract class AbstractNamedAFPObject extends AbstractStructuredAFPObject "Constructor:: UnsupportedEncodingException translating the name " + name); } + return nameBytes; } - /** - * @return the name length of this object - */ - protected int getNameLength() { - return DEFAULT_NAME_LENGTH; + /** {@inheritDoc} */ + protected void copySF(byte[] data, byte type, byte category) { + super.copySF(data, type, category); + byte[] nameData = getNameBytes(); + System.arraycopy(nameData, 0, data, 9, nameData.length); } /** - * @return the name of the page group + * Returns the name of this object + * + * @return the name of this object */ public String getName() { return name; diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java index c5b2f3ea2..73c4b6821 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java @@ -22,9 +22,12 @@ package org.apache.fop.render.afp.modca; import java.awt.Color; import java.io.IOException; import java.io.OutputStream; +import java.util.Iterator; import java.util.List; import org.apache.fop.render.afp.AFPTextDataInfo; +import org.apache.fop.render.afp.DataObjectCache; +import org.apache.fop.render.afp.ResourceInfo; import org.apache.fop.render.afp.fonts.AFPFont; /** @@ -112,6 +115,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { /** * Named constructor + * * @param name the name of this page object */ public AbstractPageObject(String name) { @@ -218,6 +222,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { /** * Helper method to create a presentation text object * on the current page and to return the object. + * * @return the presentation text object */ private PresentationTextObject getPresentationTextObject() { @@ -305,6 +310,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { /** * Returns an indication if the page is complete + * * @return whether this page is complete */ public boolean isComplete() { @@ -313,6 +319,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { /** * Returns the height of the page + * * @return the height of the page */ public int getHeight() { @@ -321,6 +328,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { /** * Returns the width of the page + * * @return the width of the page */ public int getWidth() { @@ -329,15 +337,14 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { /** * Returns the rotation of the page + * * @return the rotation of the page */ public int getRotation() { return rotation; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); if (this instanceof PageObject || this instanceof Overlay) { @@ -345,23 +352,37 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { } writeObjects(this.includePageSegments, os); writeObjects(this.tagLogicalElements, os); - writeObjects(this.objects, os); + + DataObjectCache cache = DataObjectCache.getInstance(); + + // Write objects from cache + Iterator it = objects.iterator(); + while (it.hasNext()) { + Object obj = it.next(); + if (obj instanceof Writable) { + Writable writableObject = (Writable)obj; + writableObject.write(os); + } else if (obj instanceof ResourceInfo) { + ResourceInfo resourceInfo = (ResourceInfo)obj; + byte[] data = cache.get(resourceInfo); + os.write(data); + } + } } /** - * Adds an AFP object to the resource group in this container + * Adds an AFP object reference to this page + * * @param obj an AFP object */ - protected void addObject(AbstractAFPObject obj) { + protected void addObject(Object obj) { if (objects == null) { - this.objects = new java.util.ArrayList/*<AbstractAFPObject>*/(); + this.objects = new java.util.ArrayList(); } objects.add(obj); } -// /** -// * {@inheritDoc} -// */ +// /** {@inheritDoc} */ // protected void addObject(AbstractAFPObject obj) { // if (obj instanceof DataObjectAccessor) { // DataObjectAccessor dataObjectAccessor = (DataObjectAccessor)obj; diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java index d707384ed..16ed036f2 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java @@ -41,15 +41,14 @@ implements PreparedAFPObject { /** * Named constructor + * * @param name the name of this AFP object */ public AbstractPreparedAFPObject(String name) { super(name); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); // write triplets if (this.data != null) { @@ -83,6 +82,7 @@ implements PreparedAFPObject { /** * Sets the data + * * @param data the data */ protected void setData(byte[] data) { diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractPreparedObjectContainer.java b/src/java/org/apache/fop/render/afp/modca/AbstractPreparedObjectContainer.java index 3c2b3981d..03e646913 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractPreparedObjectContainer.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractPreparedObjectContainer.java @@ -30,9 +30,7 @@ import java.util.List; public abstract class AbstractPreparedObjectContainer extends AbstractNamedAFPObject implements PreparedAFPObject { - /** - * list of objects contained within this container - */ + /** list of objects contained within this container */ protected List/*<PreparedAFPObject>*/ objects = null; /** @@ -43,15 +41,14 @@ implements PreparedAFPObject { /** * Named constructor + * * @param name the name of the container */ protected AbstractPreparedObjectContainer(String name) { super(name); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { if (objects != null) { super.writeObjects(objects, os); @@ -67,16 +64,19 @@ implements PreparedAFPObject { /** * Adds a given prepared object to this container + * * @param preparedObject the prepared object * @return the drawingOrder if it was added, null otherwise */ public PreparedAFPObject addObject(PreparedAFPObject preparedObject) { - log.debug(this + " adding " + preparedObject); +// log.debug(this + " adding " + preparedObject); getObjects().add(preparedObject); return preparedObject; } /** + * Returns the current data length + * * @return the current data length of this container including * all enclosed objects (and their containers) */ diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java b/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java index 4a5785981..d56ebef9b 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java @@ -36,6 +36,7 @@ public abstract class AbstractResourceEnvironmentGroupContainer /** * Main constructor + * * @param name the name of this resource container */ public AbstractResourceEnvironmentGroupContainer(String name) { @@ -44,6 +45,7 @@ public abstract class AbstractResourceEnvironmentGroupContainer /** * Adds a page to the resource container. + * * @param page - the Page object */ public void addPage(PageObject page) { @@ -52,6 +54,7 @@ public abstract class AbstractResourceEnvironmentGroupContainer /** * Adds a PageGroup to the resource container. + * * @param pageGroup the PageGroup object */ public void addPageGroup(PageGroup pageGroup) { @@ -68,9 +71,7 @@ public abstract class AbstractResourceEnvironmentGroupContainer addObject(new InvokeMediumMap(name)); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); if (resourceEnvironmentGroup != null) { @@ -79,6 +80,8 @@ public abstract class AbstractResourceEnvironmentGroupContainer } /** + * Returns the resource environment group + * * @return the resource environment group */ protected ResourceEnvironmentGroup getResourceEnvironmentGroup() { diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java b/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java index 71cc4698b..55f3a89b1 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java @@ -22,7 +22,7 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.render.afp.DataObjectInfo; +//import org.apache.fop.render.afp.DataObjectInfo; /** * An abstract container of resource objects @@ -34,11 +34,6 @@ public abstract class AbstractResourceGroupContainer extends AbstractPageObject private ResourceGroup resourceGroup = null; /** - * The data object factory - */ - private DataObjectFactory dataObjectFactory = new DataObjectFactory(); - - /** * Default constructor */ public AbstractResourceGroupContainer() { @@ -47,6 +42,7 @@ public abstract class AbstractResourceGroupContainer extends AbstractPageObject /** * Named constructor + * * @param name the name of this resource container */ public AbstractResourceGroupContainer(String name) { @@ -102,14 +98,14 @@ public abstract class AbstractResourceGroupContainer extends AbstractPageObject return resourceGroup; } - /** - * Creates and returns a new data object - * @param dataObjectInfo the data object info - * @return a newly created data object - */ - public AbstractNamedAFPObject createObject(DataObjectInfo dataObjectInfo) { - return dataObjectFactory.create(dataObjectInfo); - } +// /** +// * Creates and returns a new data object +// * @param dataObjectInfo the data object info +// * @return a newly created data object +// */ +// public AbstractNamedAFPObject createObject(DataObjectInfo dataObjectInfo) { +// return dataObjectFactory.create(dataObjectInfo); +// } /** * {@inheritDoc} diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java index 1a23511f5..b3a3c7afb 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java @@ -38,8 +38,7 @@ import org.apache.fop.render.afp.modca.triplets.Triplet; /** * An abstract class encapsulating an MODCA structured object */ -public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { - +public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * list of object triplets */ @@ -57,6 +56,8 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { } /** + * Returns the triplet data length + * * @return the triplet data length */ protected int getTripletDataLength() { @@ -74,6 +75,8 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { } /** + * Returns the triplet data + * * @return the triplet data * @throws IOException throws an I/O exception if one occurred */ @@ -88,6 +91,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Writes any triplet data + * * @param os The stream to write to * @throws IOException The stream to write to */ @@ -101,6 +105,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Helper method to write the start of the Object. + * * @param os The stream to write to * @throws IOException throws an I/O exception if one occurred */ @@ -109,7 +114,17 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { } /** + * Helper method to write the end of the Object. + * + * @param os The stream to write to + * @throws IOException an I/O exception if one occurred + */ + protected void writeEnd(OutputStream os) throws IOException { + } + + /** * Helper method to write the contents of the Object. + * * @param os The stream to write to * @throws IOException throws an I/O exception if one occurred */ @@ -118,15 +133,8 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { } /** - * Helper method to write the end of the Object. - * @param os The stream to write to - * @throws IOException an I/O exception if one occurred - */ - protected void writeEnd(OutputStream os) throws IOException { - } - - /** - * Accessor method to write the AFP datastream for the Image Object + * Accessor method to write the AFP datastream for this structure field object + * * @param os The stream to write to * @throws IOException in the event that an I/O exception occurred */ @@ -137,7 +145,8 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { } /** - * Returns the first matching triplet found in the structured field triplet list + * Returns the first matching triplet found in the structured field triplet list + * * @param tripletId the triplet identifier */ private Triplet getTriplet(byte tripletId) { @@ -152,6 +161,8 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { } /** + * Returns true of this structured field has the given triplet + * * @param tripletId the triplet identifier * @return true if the structured field has the given triplet */ @@ -161,6 +172,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Adds a triplet to this structured object + * * @param triplet the triplet to add */ private void addTriplet(Triplet triplet) { @@ -169,6 +181,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Adds a list of triplets to the triplets contained within this structured field + * * @param tripletCollection a collection of triplets */ private void addTriplets(Collection/*<Triplet>*/ tripletCollection) { @@ -177,9 +190,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { } } - /** - * @return the triplet list pertaining to this resource - */ + /** @return the triplet list pertaining to this resource */ protected List/*<Triplet>*/ getTriplets() { if (triplets == null) { triplets = new java.util.ArrayList(); @@ -189,6 +200,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Sets the fully qualified name of this resource + * * @param fqnType the fully qualified name type of this resource * @param fqnFormat the fully qualified name format of this resource * @param fqName the fully qualified name of this resource @@ -197,9 +209,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { addTriplet(new FullyQualifiedNameTriplet(fqnType, fqnFormat, fqName)); } - /** - * @return the fully qualified name of this triplet or null if it does not exist - */ + /** @return the fully qualified name of this triplet or null if it does not exist */ public String getFullyQualifiedName() { FullyQualifiedNameTriplet fqNameTriplet = (FullyQualifiedNameTriplet)getTriplet(Triplet.FULLY_QUALIFIED_NAME); @@ -212,6 +222,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Sets the objects classification + * * @param objectClass the classification of the object * @param objectType the MOD:CA registry object type entry for the given * object/component type of the object @@ -224,6 +235,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Sets the objects classification with the default structure flags + * * @param objectClass the classification of the object * @param objectType the MOD:CA registry object type entry for the given * object/component type of the object @@ -234,6 +246,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Sets the extent of an object area in the X and Y directions + * * @param x the x direction extent * @param y the y direction extent */ @@ -243,6 +256,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Sets the measurement units used to specify the units of measure + * * @param xRes units per base on the x-axis * @param yRes units per base on the y-axis */ @@ -252,6 +266,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Sets the mapping option + * * @param optionValue the mapping option value */ public void setMappingOption(byte optionValue) { @@ -260,6 +275,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { /** * Sets a comment on this resource + * * @param comment a comment string */ public void setComment(String comment) { diff --git a/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java b/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java index 4dd735ccc..916544603 100644 --- a/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java @@ -77,6 +77,7 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { /** * Default constructor for the ActiveEnvironmentGroup. + * * @param width the page width * @param height the page height * @param widthRes the page width resolution @@ -89,6 +90,7 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { /** * Constructor for the ActiveEnvironmentGroup, this takes a * name parameter which must be 8 characters long. + * * @param name the active environment group name * @param width the page width * @param height the page height @@ -112,6 +114,7 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { /** * Set the position of the object area + * * @param x the x offset * @param y the y offset * @param rotation the rotation @@ -124,6 +127,7 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { /** * Accessor method to obtain the PageDescriptor object of the * active environment group. + * * @return the page descriptor object */ public PageDescriptor getPageDescriptor() { @@ -133,15 +137,14 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { /** * Accessor method to obtain the PresentationTextDataDescriptor object of * the active environment group. + * * @return the presentation text descriptor */ public PresentationTextDescriptor getPresentationTextDataDescriptor() { return presentationTextDataDescriptor; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void writeContent(OutputStream os) throws IOException { super.writeTriplets(os); @@ -161,43 +164,17 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0xC9; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.ACTIVE_ENVIRONMENT_GROUP); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0xC9; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.ACTIVE_ENVIRONMENT_GROUP); os.write(data); } @@ -208,15 +185,16 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { return mapCodedFonts; } - private List getMapDataResources() { - if (mapDataResources == null) { - mapDataResources = new java.util.ArrayList(); - } - return mapDataResources; - } +// private List getMapDataResources() { +// if (mapDataResources == null) { +// mapDataResources = new java.util.ArrayList(); +// } +// return mapDataResources; +// } /** * Method to create a map coded font object + * * @param fontRef the font number used as the resource identifier * @param font the font * @param size the point size of the font @@ -247,6 +225,7 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { /** * Getter method for the most recent MapCodedFont added to the * Active Environment Group (returns null if no MapCodedFonts exist) + * * @return the most recent Map Coded Font. */ private MapCodedFont getCurrentMapCodedFont() { @@ -258,11 +237,11 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { } } - /** - * Method to create a map data resource object - * @param dataObjectAccessor a data object accessor - */ - protected void createMapDataResource(DataObjectAccessor dataObjectAccessor) { - getMapDataResources().add(new MapDataResource(dataObjectAccessor)); - } +// /** +// * Method to create a map data resource object +// * @param dataObjectAccessor a data object accessor +// */ +// protected void createMapDataResource(DataObjectAccessor dataObjectAccessor) { +// getMapDataResources().add(new MapDataResource(dataObjectAccessor)); +// } }
\ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/DataObjectFactory.java b/src/java/org/apache/fop/render/afp/modca/DataObjectFactory.java index 7e3f41a53..0a5fb5bbe 100644 --- a/src/java/org/apache/fop/render/afp/modca/DataObjectFactory.java +++ b/src/java/org/apache/fop/render/afp/modca/DataObjectFactory.java @@ -19,24 +19,45 @@ package org.apache.fop.render.afp.modca; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.fop.render.afp.DataObjectInfo; +import org.apache.fop.render.afp.GraphicsObjectInfo; +import org.apache.fop.render.afp.GraphicsObjectPainter; import org.apache.fop.render.afp.ImageObjectInfo; import org.apache.fop.render.afp.ObjectAreaInfo; +import org.apache.fop.render.afp.ResourceInfo; +import org.apache.fop.render.afp.ResourceLevel; +import org.apache.fop.render.afp.modca.Registry.ObjectType; import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; +import org.apache.fop.render.afp.modca.triplets.MappingOptionTriplet; +import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet; import org.apache.fop.render.afp.tools.StringUtils; import org.apache.xmlgraphics.image.codec.tiff.TIFFImage; /** - * Creator of MO;DCA data objects + * Creator of MO:DCA data objects */ public class DataObjectFactory { private static final String IMAGE_NAME_PREFIX = "IMG"; private static final String GRAPHIC_NAME_PREFIX = "GRA"; // private static final String BARCODE_NAME_PREFIX = "BAR"; // private static final String OTHER_NAME_PREFIX = "OTH"; + private static final String OBJECT_CONTAINER_NAME_PREFIX = "OC"; + private static final String RESOURCE_NAME_PREFIX = "RES"; private int imageCount = 0; private int graphicCount = 0; + private int objectContainerCount = 0; + private int resourceCount = 0; + + private Map/*<ResourceInfo,IncludeObject>*/ includeMap + = new java.util.HashMap/*<ResourceInfo,IncludeObject>*/(); + + /** Static logging instance */ + private static final Log log = LogFactory.getLog(DataObjectFactory.class); /** * Converts a byte array containing 24 bit RGB image data to a grayscale @@ -102,10 +123,11 @@ public class DataObjectFactory { /** * Helper method to create an image on the current container and to return * the object. + * * @param imageObjectInfo the image object info * @return a newly created image object */ - protected ImageObject createImage(ImageObjectInfo imageObjectInfo) { + private ImageObject createImage(ImageObjectInfo imageObjectInfo) { String name = IMAGE_NAME_PREFIX + StringUtils.lpad(String.valueOf(++imageCount), '0', 5); ImageObject imageObj = new ImageObject(name); @@ -144,36 +166,215 @@ public class DataObjectFactory { } /** - * Helper method to create a graphic in the current container and to return - * the object. - * @param info the data object info - * @return a newly created graphics object + * Creates and returns a new graphics object. + * + * @param graphicsObjectInfo the graphics object info + * @return a new graphics object */ - protected GraphicsObject createGraphic(DataObjectInfo info) { + private GraphicsObject createGraphic(GraphicsObjectInfo graphicsObjectInfo) { String name = GRAPHIC_NAME_PREFIX + StringUtils.lpad(String.valueOf(++graphicCount), '0', 5); GraphicsObject graphicsObj = new GraphicsObject(name); + + // paint the graphic using batik + GraphicsObjectPainter painter = graphicsObjectInfo.getPainter(); + painter.paint(graphicsObj); + return graphicsObj; } /** + * Creates and returns a new include object. + * + * @param name the name of this include object + * @param dataObjectInfo a data object info + * + * @return a new include object + */ + public IncludeObject createInclude(String name, DataObjectInfo dataObjectInfo) { + ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); + IncludeObject includeObj = (IncludeObject)includeMap.get(resourceInfo); + if (includeObj == null) { + includeObj = new IncludeObject(name); + + Registry.ObjectType objectType = dataObjectInfo.getObjectType(); + if (objectType.isImage()) { + includeObj.setDataObjectType(IncludeObject.TYPE_IMAGE); + } else if (objectType.isGraphic()) { + includeObj.setDataObjectType(IncludeObject.TYPE_GRAPHIC); + // } else if (dataObject instanceof PageSegment) { + // includeObj.setDataObjectType(IncludeObject.TYPE_PAGE_SEGMENT); + } else { + includeObj.setDataObjectType(IncludeObject.TYPE_OTHER); + // Strip any object container + // AbstractNamedAFPObject dataObject = dataObjectAccessor.getDataObject(); + // if (dataObject instanceof ObjectContainer) { + // ObjectContainer objectContainer = (ObjectContainer)dataObject; + // dataObject = objectContainer.getDataObject(); + // } + } + +// includeObj.setFullyQualifiedName( +// FullyQualifiedNameTriplet.TYPE_REPLACE_FIRST_GID_NAME, +// FullyQualifiedNameTriplet.FORMAT_CHARSTR, +// dataObjectInfo.getUri()); + + includeObj.setObjectClassification( + ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, + objectType); + + ObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); + + includeObj.setObjectArea(objectAreaInfo.getX(), objectAreaInfo.getY()); + + includeObj.setObjectAreaSize( + objectAreaInfo.getWidth(), objectAreaInfo.getHeight()); + + includeObj.setMeasurementUnits( + objectAreaInfo.getWidthRes(), objectAreaInfo.getHeightRes()); + + includeObj.setMappingOption(MappingOptionTriplet.SCALE_TO_FIT); + + includeMap.put(resourceInfo, includeObj); + } + + return includeObj; + } + + /** + * Creates and returns a new object container + * + * @return a new object container + */ + private ObjectContainer createObjectContainer() { + String name = OBJECT_CONTAINER_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++objectContainerCount), '0', 6); + return new ObjectContainer(name); + } + + /** + * Creates and returns a new resource object + * + * @param resourceName the resource name + * @return a new resource object + */ + private ResourceObject createResource(String resourceName) { + return new ResourceObject(resourceName); + } + + /** + * Creates and returns a new resource object + * + * @return a new resource object + */ + private ResourceObject createResource() { + String name = RESOURCE_NAME_PREFIX + + StringUtils.lpad(String.valueOf(++resourceCount ), '0', 5); + return createResource(name); + } + + /** + * Creates and returns a new Overlay. + * + * @param overlayName + * the name of the overlay + * @param width + * the width of the overlay + * @param height + * the height of the overlay + * @param widthRes + * the width resolution of the overlay + * @param heightRes + * the height resolution of the overlay + * @param overlayRotation + * the rotation of the overlay + * + * @return a new overlay object + */ + public Overlay createOverlay(String overlayName, int width, int height, + int widthRes, int heightRes, int overlayRotation) { + Overlay overlay = new Overlay(overlayName, width, height, + overlayRotation, widthRes, heightRes); + return overlay; + } + + /** * Creates and returns a new data object + * * @param dataObjectInfo the data object info + * * @return a newly created data object */ - public AbstractDataObject create(DataObjectInfo dataObjectInfo) { - AbstractDataObject dataObject; + public AbstractNamedAFPObject createObject(DataObjectInfo dataObjectInfo) { + AbstractNamedAFPObject dataObj; + if (dataObjectInfo instanceof ImageObjectInfo) { - dataObject = createImage((ImageObjectInfo)dataObjectInfo); + dataObj = createImage((ImageObjectInfo)dataObjectInfo); + } else if (dataObjectInfo instanceof GraphicsObjectInfo) { + dataObj = createGraphic((GraphicsObjectInfo)dataObjectInfo); } else { - dataObject = createGraphic(dataObjectInfo); + throw new IllegalArgumentException("Unknown data object type: " + dataObjectInfo); } - dataObject.setViewport(dataObjectInfo.getObjectAreaInfo()); + + if (dataObj instanceof AbstractDataObject) { + ((AbstractDataObject)dataObj).setViewport(dataObjectInfo.getObjectAreaInfo()); + } + + dataObj.setFullyQualifiedName( + FullyQualifiedNameTriplet.TYPE_DATA_OBJECT_INTERNAL_RESOURCE_REF, + FullyQualifiedNameTriplet.FORMAT_CHARSTR, dataObj.getName()); - dataObject.setFullyQualifiedName( - FullyQualifiedNameTriplet.TYPE_DATA_OBJECT_INTERNAL_RESOURCE_REF, - FullyQualifiedNameTriplet.FORMAT_CHARSTR, dataObject.getName()); + ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); + ResourceLevel resourceLevel = resourceInfo.getLevel(); - return dataObject; - } + if (resourceLevel.isPrintFile() || resourceLevel.isExternal()) { + + ObjectType objectType = dataObjectInfo.getObjectType(); + + if (objectType != null && objectType.canBeIncluded()) { + + // Wrap newly created data object in a resource object + // if it is to reside within a resource group at print-file or external level + if (resourceLevel.isPrintFile() || resourceLevel.isExternal()) { + ResourceObject resourceObj = null; + String resourceName = resourceInfo.getName(); + if (resourceName != null) { + resourceObj = createResource(resourceName); + } else { + resourceObj = createResource(); + } + + if (dataObj instanceof ObjectContainer) { + resourceObj.setType(ResourceObject.OBJECT_CONTAINER); + } else if (dataObj instanceof ImageObject) { + resourceObj.setType(ResourceObject.IMAGE_OBJECT); + } else if (dataObj instanceof GraphicsObject) { + resourceObj.setType(ResourceObject.GRAPHICS_OBJECT); + } else if (dataObj instanceof Document) { + resourceObj.setType(ResourceObject.DOCUMENT_OBJECT); + } else if (dataObj instanceof PageSegment) { + resourceObj.setType(ResourceObject.PAGE_SEGMENT_OBJECT); + } else if (dataObj instanceof Overlay) { + resourceObj.setType(ResourceObject.OVERLAY_OBJECT); + } else { + throw new UnsupportedOperationException( + "Unsupported resource object type " + dataObj); + } + + resourceObj.setObjectClassification( + ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, + objectType); + + resourceObj.setDataObject(dataObj); + dataObj = resourceObj; + } + } else { + String uri = dataObjectInfo.getUri(); + log.warn("Data object '" + uri + "' not supported at " + + resourceLevel.toString() + " level, will be embedded in page."); + } + } + + return dataObj; + } } diff --git a/src/java/org/apache/fop/render/afp/modca/Document.java b/src/java/org/apache/fop/render/afp/modca/Document.java index efa022952..ae4a4b9fe 100644 --- a/src/java/org/apache/fop/render/afp/modca/Document.java +++ b/src/java/org/apache/fop/render/afp/modca/Document.java @@ -83,6 +83,7 @@ public final class Document extends AbstractResourceEnvironmentGroupContainer { /** * Returns an indication if the page group is complete + * * @return whether or not this page group is complete */ public boolean isComplete() { @@ -91,6 +92,7 @@ public final class Document extends AbstractResourceEnvironmentGroupContainer { /** * Accessor method to write the AFP datastream for document. + * * @param os The stream to write to * @throws java.io.IOException thrown if an I/O exception of some sort has occurred */ @@ -100,49 +102,21 @@ public final class Document extends AbstractResourceEnvironmentGroupContainer { } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0xA8; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.DOCUMENT); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0xA8; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.DOCUMENT); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return this.name; } diff --git a/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java b/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java index a73c9fc70..ccf05aa19 100644 --- a/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java +++ b/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java @@ -48,9 +48,7 @@ import org.apache.fop.render.afp.goca.GraphicsString; */ public class GraphicsObject extends AbstractDataObject { - /** - * The graphics data - */ + /** The graphics data */ private GraphicsData graphicsData = null; /** @@ -62,9 +60,7 @@ public class GraphicsObject extends AbstractDataObject { super(name); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void setViewport(ObjectAreaInfo objectAreaInfo) { super.setViewport(objectAreaInfo); getObjectEnvironmentGroup().setGraphicsData( @@ -76,62 +72,26 @@ public class GraphicsObject extends AbstractDataObject { objectAreaInfo.getY() + objectAreaInfo.getHeight()); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ + protected byte getCategoryCode() { + return (byte)0xBB; + } + + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { - super.writeStart(os); - byte[] data = new byte[] { - 0x5A, // Structured field identifier - 0x00, //sfLen[0], // Length byte 1 - 0x10, //sfLen[1], // Length byte 2 - (byte) 0xD3, // Structured field id byte 1 - (byte) 0xA8, // Structured field id byte 2 - (byte) 0xBB, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - super.nameBytes[0], // gdoName - super.nameBytes[1], - super.nameBytes[2], - super.nameBytes[3], - super.nameBytes[4], - super.nameBytes[5], - super.nameBytes[6], - super.nameBytes[7] - }; + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.GRAPHICS); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[] { - 0x5A, // Structured field identifier - 0x00, // sfLen[0], // Length byte 1 - 0x10, // sfLen[1], // Length byte 2 - (byte) 0xD3, // Structured field id byte 1 - (byte) 0xA9, // Structured field id byte 2 - (byte) 0xBB, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - super.nameBytes[0], // gdoName - super.nameBytes[1], - super.nameBytes[2], - super.nameBytes[3], - super.nameBytes[4], - super.nameBytes[5], - super.nameBytes[6], - super.nameBytes[7] - }; + byte[] data = new byte[17]; + copySF(data, Type.END, Category.GRAPHICS); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public PreparedAFPObject addObject(PreparedAFPObject drawingOrder) { if (graphicsData == null || (graphicsData.getDataLength() + drawingOrder.getDataLength()) @@ -144,6 +104,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Gets the current graphics data, creating a new one if necessary + * * @return the current graphics data */ private GraphicsData getData() { @@ -155,6 +116,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Creates a new graphics data + * * @return a newly created graphics data */ private GraphicsData newData() { @@ -165,6 +127,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Sets the current color + * * @param col the active color to use */ public void setColor(Color col) { @@ -173,6 +136,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Sets the current position + * * @param coords the x and y coordinates of the current position */ public void setCurrentPosition(int[] coords) { @@ -181,6 +145,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Sets the line width + * * @param multiplier the line width multiplier */ public void setLineWidth(int multiplier) { @@ -190,6 +155,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Sets the line type + * * @param type the line type */ public void setLineType(byte type) { @@ -199,6 +165,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Sets whether to fill the next shape + * * @param fill whether to fill the next shape */ public void setFill(boolean fill) { @@ -211,6 +178,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Sets the character set to use + * * @param fontReference the character set (font) reference */ public void setCharacterSet(int fontReference) { @@ -219,6 +187,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Adds a line at the given x/y coordinates + * * @param coords the x/y coordinates (can be a series) */ public void addLine(int[] coords) { @@ -227,6 +196,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Adds a box at the given coordinates + * * @param coords the x/y coordinates */ public void addBox(int[] coords) { @@ -235,6 +205,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Adds a fillet (curve) at the given coordinates + * * @param coords the x/y coordinates */ public void addFillet(int[] coords) { @@ -242,7 +213,8 @@ public class GraphicsObject extends AbstractDataObject { } /** - * Sets the arc parameters + * Sets the arc parameters + * * @param xmaj the maximum value of the x coordinate * @param ymin the minimum value of the y coordinate * @param xmin the minimum value of the x coordinate @@ -254,6 +226,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Adds an arc + * * @param x the x coordinate * @param y the y coordinate * @param mh the integer portion of the multiplier @@ -265,6 +238,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Adds an image + * * @param x the x coordinate * @param y the y coordinate * @param width the image width @@ -283,6 +257,7 @@ public class GraphicsObject extends AbstractDataObject { /** * Adds a string + * * @param str the string * @param x the x coordinate * @param y the y coordinate @@ -310,9 +285,7 @@ public class GraphicsObject extends AbstractDataObject { } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return "GraphicsObject: " + getName(); } diff --git a/src/java/org/apache/fop/render/afp/modca/IMImageObject.java b/src/java/org/apache/fop/render/afp/modca/IMImageObject.java index 73abb2843..3af8b5c28 100644 --- a/src/java/org/apache/fop/render/afp/modca/IMImageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/IMImageObject.java @@ -60,6 +60,7 @@ public class IMImageObject extends AbstractNamedAFPObject { /** * Constructor for the image object with the specified name, * the name must be a fixed length of eight characters. + * * @param name The name of the image. */ public IMImageObject(String name) { @@ -68,6 +69,7 @@ public class IMImageObject extends AbstractNamedAFPObject { /** * Sets the ImageOutputControl. + * * @param imageOutputControl The imageOutputControl to set */ public void setImageOutputControl(ImageOutputControl imageOutputControl) { @@ -76,6 +78,7 @@ public class IMImageObject extends AbstractNamedAFPObject { /** * Sets the ImageCellPosition. + * * @param imageCellPosition The imageCellPosition to set */ public void setImageCellPosition(ImageCellPosition imageCellPosition) { @@ -84,6 +87,7 @@ public class IMImageObject extends AbstractNamedAFPObject { /** * Sets the ImageInputDescriptor. + * * @param imageInputDescriptor The imageInputDescriptor to set */ public void setImageInputDescriptor(ImageInputDescriptor imageInputDescriptor) { @@ -92,15 +96,14 @@ public class IMImageObject extends AbstractNamedAFPObject { /** * Sets the ImageRastorData. + * * @param imageRasterData The imageRasterData to set */ public void setImageRasterData(ImageRasterData imageRasterData) { this.imageRasterData = imageRasterData; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); if (imageOutputControl != null) { @@ -117,43 +120,17 @@ public class IMImageObject extends AbstractNamedAFPObject { } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0x7B; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.IM_IMAGE); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0x7B; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.IM_IMAGE); os.write(data); } } diff --git a/src/java/org/apache/fop/render/afp/modca/ImageCellPosition.java b/src/java/org/apache/fop/render/afp/modca/ImageCellPosition.java index c0eb77953..5f1f95932 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageCellPosition.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageCellPosition.java @@ -69,26 +69,14 @@ public class ImageCellPosition extends AbstractAFPObject { yOffset = y; } - /** - * Accessor method to write the AFP datastream for the Image Cell Position - * @param os The stream to write to - * @throws java.io.IOException if an I/O exception occurred - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] data = new byte[21]; - - data[0] = 0x5A; - - data[1] = 0x00; + copySF(data, Type.POSITION, Category.IM_IMAGE); + + data[1] = 0x00; // length data[2] = 0x14; - data[3] = (byte) 0xD3; - data[4] = (byte) 0xAC; - data[5] = (byte) 0x7B; - data[6] = 0x00; - data[7] = 0x00; - data[8] = 0x00; - /** * Specifies the offset along the Xp direction, in image points, * of this image cell from the IM image object area origin. diff --git a/src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java b/src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java index 45c029f71..243765727 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java @@ -27,35 +27,29 @@ import org.apache.fop.render.afp.tools.BinaryUtils; */ public class ImageDataDescriptor extends AbstractAFPObject { - private int _xresol = 0; - private int _yresol = 0; - private int _width = 0; - private int _height = 0; - + private int widthRes = 0; + private int heightRes = 0; + private int width = 0; + private int height = 0; + /** * Constructor for a ImageDataDescriptor for the specified * resolution, width and height. - * @param xresol The horizontal resolution of the image. - * @param yresol The vertical resolution of the image. + * + * @param widthRes The horizontal resolution of the image. + * @param heightRes The vertical resolution of the image. * @param width The width of the image. * @param height The height of the height. */ - public ImageDataDescriptor(int xresol, int yresol, int width, int height) { - - _xresol = xresol; - _yresol = yresol; - _width = width; - _height = height; - + public ImageDataDescriptor(int widthRes, int heightRes, int width, int height) { + this.widthRes = widthRes; + this.heightRes = heightRes; + this.width = width; + this.height = height; } - /** - * Accessor method to write the AFP datastream for the Image Data Descriptor - * @param os The stream to write to - * @throws java.io.IOException - */ - public void write(OutputStream os) - throws IOException { + /** {@inheritDoc} */ + public void write(OutputStream os) throws IOException { byte[] data = new byte[] { 0x5A, @@ -86,24 +80,22 @@ public class ImageDataDescriptor extends AbstractAFPObject { data[1] = l[0]; data[2] = l[1]; - byte[] x = BinaryUtils.convert(_xresol, 2); + byte[] x = BinaryUtils.convert(widthRes, 2); data[10] = x[0]; data[11] = x[1]; - byte[] y = BinaryUtils.convert(_yresol, 2); + byte[] y = BinaryUtils.convert(heightRes, 2); data[12] = y[0]; data[13] = y[1]; - byte[] w = BinaryUtils.convert(_width, 2); + byte[] w = BinaryUtils.convert(width, 2); data[14] = w[0]; data[15] = w[1]; - byte[] h = BinaryUtils.convert(_height, 2); + byte[] h = BinaryUtils.convert(height, 2); data[16] = h[0]; data[17] = h[1]; os.write(data); - } - } diff --git a/src/java/org/apache/fop/render/afp/modca/ImageInputDescriptor.java b/src/java/org/apache/fop/render/afp/modca/ImageInputDescriptor.java index a9aef38b9..370ec773d 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageInputDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageInputDescriptor.java @@ -36,11 +36,7 @@ public class ImageInputDescriptor extends AbstractAFPObject { private int resolution = 240; - /** - * Accessor method to write the AFP datastream for the Image Input Descriptor - * @param os The stream to write to - * @throws java.io.IOException if an I/O exception occurred - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] data = new byte[45]; diff --git a/src/java/org/apache/fop/render/afp/modca/ImageObject.java b/src/java/org/apache/fop/render/afp/modca/ImageObject.java index 928a9790c..67935cb2c 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageObject.java @@ -38,6 +38,7 @@ public class ImageObject extends AbstractDataObject { /** * Constructor for the image object with the specified name, * the name must be a fixed length of eight characters. + * * @param name The name of the image. */ public ImageObject(String name) { @@ -46,6 +47,7 @@ public class ImageObject extends AbstractDataObject { /** * Set the dimensions of the image. + * * @param xresol the x resolution of the image * @param yresol the y resolution of the image * @param width the image width @@ -61,6 +63,7 @@ public class ImageObject extends AbstractDataObject { /** * Sets the image encoding. + * * @param encoding The image encoding. */ public void setImageEncoding(byte encoding) { @@ -72,6 +75,7 @@ public class ImageObject extends AbstractDataObject { /** * Sets the image compression. + * * @param compression The image compression. */ public void setImageCompression(byte compression) { @@ -83,6 +87,7 @@ public class ImageObject extends AbstractDataObject { /** * Sets the image IDE size. + * * @param size The IDE size. */ public void setImageIDESize(byte size) { @@ -94,6 +99,7 @@ public class ImageObject extends AbstractDataObject { /** * Sets the image IDE color model. + * * @param colorModel the IDE color model. */ public void setImageIDEColorModel(byte colorModel) { @@ -105,6 +111,7 @@ public class ImageObject extends AbstractDataObject { /** * Set the data of the image. + * * @param data The image data */ public void setImageData(byte[] data) { @@ -116,6 +123,7 @@ public class ImageObject extends AbstractDataObject { /** * Helper method to return the start of the image object. + * * @param len the length of this ipd start * @return byte[] The data stream. */ @@ -135,9 +143,14 @@ public class ImageObject extends AbstractDataObject { return data; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ + protected void writeStart(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.IMAGE); + os.write(data); + } + + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); if (imageSegment != null) { @@ -154,45 +167,10 @@ public class ImageObject extends AbstractDataObject { } } - /** - * {@inheritDoc} - */ - protected void writeStart(OutputStream os) throws IOException { - byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0xFB; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } - os.write(data); - } - - /** - * Helper method to write the end of the Image Object. - * @param os The stream to write to - * @throws IOException in the event - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0xFB; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.IMAGE); os.write(data); } } diff --git a/src/java/org/apache/fop/render/afp/modca/ImageOutputControl.java b/src/java/org/apache/fop/render/afp/modca/ImageOutputControl.java index 0c38273de..4ba78f161 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageOutputControl.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageOutputControl.java @@ -67,17 +67,11 @@ public class ImageOutputControl extends AbstractAFPObject { * The Y-axis offset. */ public ImageOutputControl(int x, int y) { - xCoord = x; yCoord = y; - } - /** - * Accessor method to write the AFP datastream for the Image Output Control - * @param os The stream to write to - * @throws java.io.IOException if an I/O exception occured - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] data = new byte[33]; @@ -170,7 +164,6 @@ public class ImageOutputControl extends AbstractAFPObject { data[32] = (byte) 0xFF; os.write(data); - } /** diff --git a/src/java/org/apache/fop/render/afp/modca/ImageRasterData.java b/src/java/org/apache/fop/render/afp/modca/ImageRasterData.java index dd9c5f699..7bdadb6b6 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageRasterData.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageRasterData.java @@ -58,11 +58,7 @@ public class ImageRasterData extends AbstractAFPObject { this.rasterData = data; } - /** - * Accessor method to write the AFP datastream for the Image Raster Data - * @param os The stream to write to - * @throws java.io.IOException if an I/O exception occurred - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] data = new byte[9]; diff --git a/src/java/org/apache/fop/render/afp/modca/ImageSegment.java b/src/java/org/apache/fop/render/afp/modca/ImageSegment.java index 813dffed2..9a6c25ea0 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageSegment.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageSegment.java @@ -18,6 +18,7 @@ /* $Id$ */ package org.apache.fop.render.afp.modca; + import java.io.IOException; import java.io.OutputStream; @@ -59,16 +60,14 @@ public class ImageSegment extends AbstractNamedAFPObject { super(name); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected int getNameLength() { return 4; } /** - * Sets the image size parameters - * resolution, hsize and vsize. + * Sets the image size parameters resolution, hsize and vsize. + * * @param hresol The horizontal resolution of the image. * @param vresol The vertical resolution of the image. * @param hsize The horizontal size of the image. @@ -83,6 +82,7 @@ public class ImageSegment extends AbstractNamedAFPObject { /** * Sets the image encoding. + * * @param encoding The image encoding. */ public void setImageEncoding(byte encoding) { @@ -94,6 +94,7 @@ public class ImageSegment extends AbstractNamedAFPObject { /** * Sets the image compression. + * * @param compression The image compression. */ public void setImageCompression(byte compression) { @@ -105,6 +106,7 @@ public class ImageSegment extends AbstractNamedAFPObject { /** * Sets the image IDE size. + * * @param size The IDE size. */ public void setImageIDESize(byte size) { @@ -116,6 +118,7 @@ public class ImageSegment extends AbstractNamedAFPObject { /** * Sets the image IDE color model. + * * @param colorModel the IDE color model. */ public void setImageIDEColorModel(byte colorModel) { @@ -127,6 +130,7 @@ public class ImageSegment extends AbstractNamedAFPObject { /** * Set the data of the image. + * * @param data the image data */ public void setImageData(byte[] data) { @@ -136,19 +140,16 @@ public class ImageSegment extends AbstractNamedAFPObject { imageContent.setImageData(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void writeContent(OutputStream os) throws IOException { if (imageContent != null) { imageContent.write(os); } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { + byte[] nameBytes = getNameBytes(); byte[] data = new byte[] { 0x70, // ID 0x04, // Length @@ -160,11 +161,8 @@ public class ImageSegment extends AbstractNamedAFPObject { os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[] { 0x71, // ID 0x00, // Length diff --git a/src/java/org/apache/fop/render/afp/modca/ImageSizeParameter.java b/src/java/org/apache/fop/render/afp/modca/ImageSizeParameter.java index f66b76853..0506b7bdc 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageSizeParameter.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageSizeParameter.java @@ -48,11 +48,7 @@ public class ImageSizeParameter extends AbstractAFPObject { this.vSize = vsize; } - /** - * Accessor method to write the AFP datastream for the Image Size Parameter - * @param os The stream to write to - * @throws java.io.IOException if an I/O exception occured - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] data = new byte[] { (byte)0x94, // ID = Image Size Parameter diff --git a/src/java/org/apache/fop/render/afp/modca/IncludeObject.java b/src/java/org/apache/fop/render/afp/modca/IncludeObject.java index 85cb283a8..807d66421 100644 --- a/src/java/org/apache/fop/render/afp/modca/IncludeObject.java +++ b/src/java/org/apache/fop/render/afp/modca/IncludeObject.java @@ -22,11 +22,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.render.afp.DataObjectInfo; -import org.apache.fop.render.afp.ObjectAreaInfo; -import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; -import org.apache.fop.render.afp.modca.triplets.MappingOptionTriplet; -import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet; import org.apache.fop.render.afp.tools.BinaryUtils; /** @@ -42,32 +37,32 @@ import org.apache.fop.render.afp.tools.BinaryUtils; * data objects in the page segment. * </p> */ -public class IncludeObject extends AbstractNamedAFPObject implements DataObjectAccessor { +public class IncludeObject extends AbstractNamedAFPObject { /** * the include object is of type page segment */ - protected static final byte TYPE_PAGE_SEGMENT = (byte)0x5F; + public static final byte TYPE_PAGE_SEGMENT = (byte)0x5F; /** * the include object is of type other */ - protected static final byte TYPE_OTHER = (byte)0x92; + public static final byte TYPE_OTHER = (byte)0x92; /** * the include object is of type graphic */ - protected static final byte TYPE_GRAPHIC = (byte)0xBB; + public static final byte TYPE_GRAPHIC = (byte)0xBB; /** * the included object is of type barcode */ - protected static final byte TYPE_BARCODE = (byte)0xEB; + public static final byte TYPE_BARCODE = (byte)0xEB; /** * the included object is of type image */ - protected static final byte TYPE_IMAGE = (byte)0xFB; + public static final byte TYPE_IMAGE = (byte)0xFB; /** * The object type (default is other) @@ -99,10 +94,10 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA */ private int yContentOffset = 0; - /** - * the referenced data object - */ - private DataObjectAccessor dataObjectAccessor = null; +// /** +// * the referenced data object +// */ +// private DataObjectAccessor dataObjectAccessor = null; /** * Constructor for the include object with the specified name, the name must @@ -112,69 +107,69 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA * @param name the name of this include object * @param dataObjectAccessor the data object accessor */ - public IncludeObject(String name, DataObjectAccessor dataObjectAccessor) { + public IncludeObject(String name/*, DataObjectAccessor dataObjectAccessor*/) { super(name); - this.dataObjectAccessor = dataObjectAccessor; - - AbstractNamedAFPObject dataObject = dataObjectAccessor.getDataObject(); - if (dataObject instanceof ImageObject) { - this.dataObjectType = TYPE_IMAGE; - } else if (dataObject instanceof GraphicsObject) { - this.dataObjectType = TYPE_GRAPHIC; - } else if (dataObject instanceof PageSegment) { - this.dataObjectType = TYPE_PAGE_SEGMENT; - } else { - this.dataObjectType = TYPE_OTHER; - // Strip any object container - if (dataObject instanceof ObjectContainer) { - ObjectContainer objectContainer = (ObjectContainer)dataObject; - dataObject = objectContainer.getDataObject(); - } - } - - DataObjectInfo dataObjectInfo = dataObjectAccessor.getDataObjectInfo(); - ObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); - setObjectArea(objectAreaInfo.getX(), objectAreaInfo.getY()); - - super.setFullyQualifiedName( - FullyQualifiedNameTriplet.TYPE_REPLACE_FIRST_GID_NAME, - FullyQualifiedNameTriplet.FORMAT_CHARSTR, - dataObjectInfo.getUri()); - - Registry registry = Registry.getInstance(); - Registry.ObjectType objectType = registry.getObjectType(dataObjectInfo); - super.setObjectClassification( - ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, - objectType); +// this.dataObjectAccessor = dataObjectAccessor; - super.setMeasurementUnits(objectAreaInfo.getWidthRes(), objectAreaInfo.getHeightRes()); - - super.setMappingOption(MappingOptionTriplet.SCALE_TO_FIT); - - super.setObjectAreaSize(objectAreaInfo.getWidth(), objectAreaInfo.getHeight()); +// AbstractNamedAFPObject dataObject = dataObjectAccessor.getDataObject(); +// if (dataObject instanceof ImageObject) { +// this.dataObjectType = TYPE_IMAGE; +// } else if (dataObject instanceof GraphicsObject) { +// this.dataObjectType = TYPE_GRAPHIC; +// } else if (dataObject instanceof PageSegment) { +// this.dataObjectType = TYPE_PAGE_SEGMENT; +// } else { +// this.dataObjectType = TYPE_OTHER; +// // Strip any object container +// if (dataObject instanceof ObjectContainer) { +// ObjectContainer objectContainer = (ObjectContainer)dataObject; +// dataObject = objectContainer.getDataObject(); +// } +// } + +// DataObjectInfo dataObjectInfo = dataObjectAccessor.getDataObjectInfo(); +// ObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); +// setObjectArea(objectAreaInfo.getX(), objectAreaInfo.getY()); +// +// super.setFullyQualifiedName( +// FullyQualifiedNameTriplet.TYPE_REPLACE_FIRST_GID_NAME, +// FullyQualifiedNameTriplet.FORMAT_CHARSTR, +// dataObjectInfo.getUri()); +// +// Registry registry = Registry.getInstance(); +// Registry.ObjectType objectType = registry.getObjectType(dataObjectInfo); +// super.setObjectClassification( +// ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, +// objectType); +// +// super.setMeasurementUnits(objectAreaInfo.getWidthRes(), objectAreaInfo.getHeightRes()); +// +// super.setMappingOption(MappingOptionTriplet.SCALE_TO_FIT); +// +// super.setObjectAreaSize(objectAreaInfo.getWidth(), objectAreaInfo.getHeight()); } - /** - * {@inheritDoc} - */ - public AbstractNamedAFPObject getDataObject() { - return dataObjectAccessor.getDataObject(); - } - - /** - * {@inheritDoc} - */ - public DataObjectInfo getDataObjectInfo() { - return dataObjectAccessor.getDataObjectInfo(); - } - - /** - * {@inheritDoc} - */ - public void setDataObjectInfo(DataObjectInfo dataObjectInfo) { - dataObjectAccessor.setDataObjectInfo(dataObjectInfo); - } +// /** +// * {@inheritDoc} +// */ +// public AbstractNamedAFPObject getDataObject() { +// return dataObjectAccessor.getDataObject(); +// } +// +// /** +// * {@inheritDoc} +// */ +// public DataObjectInfo getDataObjectInfo() { +// return dataObjectAccessor.getDataObjectInfo(); +// } +// +// /** +// * {@inheritDoc} +// */ +// public void setDataObjectInfo(DataObjectInfo dataObjectInfo) { +// dataObjectAccessor.setDataObjectInfo(dataObjectInfo); +// } /** * Sets the orientation to use for the Include Object. @@ -194,6 +189,7 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA /** * Sets the x and y offset to the origin in the object area + * * @param x the X-axis origin of the object area * @param y the Y-axis origin of the object area */ @@ -203,7 +199,8 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA } /** - * Sets the x and y offset of the content area to the object area + * Sets the x and y offset of the content area to the object area + * * @param x the X-axis origin defined in the object * @param y the Y-axis origin defined in the object */ @@ -213,30 +210,24 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA } /** - * {@inheritDoc} + * Sets the data object type + * + * @param type the data object type */ + public void setDataObjectType(byte type) { + this.dataObjectType = type; + } + + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] data = new byte[36]; - data[0] = 0x5A; + super.copySF(data, Type.INCLUDE, Category.DATA_RESOURCE); // Set the total record length byte[] len = BinaryUtils.convert(35 + getTripletDataLength(), 2); //Ignore first byte data[1] = len[0]; data[2] = len[1]; - // Structured field ID for a IOB - data[3] = (byte) 0xD3; - data[4] = (byte) 0xAF; - data[5] = (byte) 0xC3; - - data[6] = 0x00; // Reserved - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } - data[17] = 0x00; // reserved data[18] = dataObjectType; @@ -330,9 +321,7 @@ public class IncludeObject extends AbstractNamedAFPObject implements DataObjectA os.write(tripletData); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return "IOB: " + this.getName(); } diff --git a/src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java b/src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java index 31021392e..540ebe7df 100644 --- a/src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java +++ b/src/java/org/apache/fop/render/afp/modca/IncludePageOverlay.java @@ -56,6 +56,7 @@ public class IncludePageOverlay extends AbstractNamedAFPObject { /** * Constructor for the Include Page Overlay + * * @param overlayName Name of the page segment * @param x The x position * @param y The y position @@ -63,6 +64,7 @@ public class IncludePageOverlay extends AbstractNamedAFPObject { */ public IncludePageOverlay(String overlayName, int x, int y, int orientation) { super(overlayName); + this.x = x; this.y = y; setOrientation(orientation); @@ -84,40 +86,25 @@ public class IncludePageOverlay extends AbstractNamedAFPObject { } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] data = new byte[25]; //(9 +16) - data[0] = 0x5A; + copySF(data, Type.INCLUDE, Category.PAGE_OVERLAY); // Set the total record length byte[] len = BinaryUtils.convert(24, 2); //Ignore first byte data[1] = len[0]; data[2] = len[1]; - // Structured field ID for a IPO - data[3] = (byte) 0xD3; - data[4] = (byte) 0xAF; - data[5] = (byte) 0xD8; - - data[6] = 0x00; // Reserved - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } - - byte[] xcoord = BinaryUtils.convert(x, 3); - data[17] = xcoord[0]; // x coordinate - data[18] = xcoord[1]; - data[19] = xcoord[2]; + byte[] xPos = BinaryUtils.convert(x, 3); + data[17] = xPos[0]; // x coordinate + data[18] = xPos[1]; + data[19] = xPos[2]; - byte[] ycoord = BinaryUtils.convert(y, 3); - data[20] = ycoord[0]; // y coordinate - data[21] = ycoord[1]; - data[22] = ycoord[2]; + byte[] yPos = BinaryUtils.convert(y, 3); + data[20] = yPos[0]; // y coordinate + data[21] = yPos[1]; + data[22] = yPos[2]; switch (orientation) { case 90: diff --git a/src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java b/src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java index 4183b6717..b069f4f7a 100644 --- a/src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java +++ b/src/java/org/apache/fop/render/afp/modca/IncludePageSegment.java @@ -45,56 +45,46 @@ public class IncludePageSegment extends AbstractNamedAFPObject { /** * The x position where we need to put this object on the page */ - private byte[] x; - + private int x; + /** * The y position where we need to put this object on the page */ - private byte[] y; - + private int y; + /** * Constructor for the Include Page Segment + * * @param name Name of the page segment * @param x The x position * @param y The y position */ public IncludePageSegment(String name, int x, int y) { super(name); - this.x = BinaryUtils.convert(x, 3); - this.y = BinaryUtils.convert(y, 3); + + this.x = x; + this.y = y; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { - byte[] data = new byte[23]; //(9 +14) - - data[0] = 0x5A; + copySF(data, Type.INCLUDE, Category.PAGE_SEGMENT); // Set the total record length byte[] len = BinaryUtils.convert(22, 2); //Ignore first byte data[1] = len[0]; data[2] = len[1]; - // Structured field ID for a IPS - data[3] = (byte) 0xD3; - data[4] = (byte) 0xAF; - data[5] = (byte) 0x5F; - data[6] = 0x00; // Reserved - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved + byte[] xPos = BinaryUtils.convert(x, 3); + data[17] = xPos[0]; // x coordinate + data[18] = xPos[1]; + data[19] = xPos[2]; - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } - data[17] = x[0]; // x coordinate - data[18] = x[1]; - data[19] = x[2]; - data[20] = y[0]; // y coordinate - data[21] = y[1]; - data[22] = y[2]; + byte[] yPos = BinaryUtils.convert(y, 3); + data[20] = yPos[0]; // y coordinate + data[21] = yPos[1]; + data[22] = yPos[2]; os.write(data); } diff --git a/src/java/org/apache/fop/render/afp/modca/InterchangeSet.java b/src/java/org/apache/fop/render/afp/modca/InterchangeSet.java index 1ef72b3cf..4d52df3d3 100644 --- a/src/java/org/apache/fop/render/afp/modca/InterchangeSet.java +++ b/src/java/org/apache/fop/render/afp/modca/InterchangeSet.java @@ -46,6 +46,8 @@ public class InterchangeSet { private int value; /** + * Returns the interchange set value of a given string + * * @param str an interchange set value * @return an interchange set */ @@ -60,6 +62,7 @@ public class InterchangeSet { throw new IllegalArgumentException("Invalid MO:DCA interchange set :" + str); } } + /** * Main constructor * @@ -70,6 +73,8 @@ public class InterchangeSet { } /** + * Returns true if complies with MOD:CA interchange set 1 + * * @return true if complies with MOD:CA interchange set 1 */ protected boolean is1() { @@ -77,6 +82,8 @@ public class InterchangeSet { } /** + * Returns true if complies with MOD:CA interchange set 2 + * * @return true if complies with MOD:CA interchange set 2 */ public boolean is2() { @@ -84,20 +91,22 @@ public class InterchangeSet { } /** + * Returns true if complies with MOD:CA resource set + * * @return true if complies with MOD:CA resource set */ public boolean isResource() { return value == RESOURCE_SET; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return NAMES[value]; } /** + * Returns true if MOD:CA interchange set 2 (resource groups) is supported + * * @return true if MOD:CA interchange set 2 (resource groups) is supported */ public boolean supportsLevel2() { diff --git a/src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.java b/src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.java index f72ee4e23..fd41ce305 100644 --- a/src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.java +++ b/src/java/org/apache/fop/render/afp/modca/InvokeMediumMap.java @@ -34,38 +34,24 @@ public class InvokeMediumMap extends AbstractNamedAFPObject { /** * Constructor for the Invoke Medium Map + * * @param name the name of the medium map */ public InvokeMediumMap(String name) { super(name); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] data = new byte[17]; - - data[0] = 0x5A; + copySF(data, Type.MAP, Category.MEDIUM_MAP); // Set the total record length byte[] len = BinaryUtils.convert(16, 2); //Ignore first byte data[1] = len[0]; data[2] = len[1]; - // Structured field ID for a IPO - data[3] = (byte) 0xD3; - data[4] = (byte) 0xAB; - data[5] = (byte) 0xCC; - - data[6] = 0x00; // Reserved - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } os.write(data); } }
\ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/MapCodedFont.java b/src/java/org/apache/fop/render/afp/modca/MapCodedFont.java index 4518be9f1..13c76083f 100644 --- a/src/java/org/apache/fop/render/afp/modca/MapCodedFont.java +++ b/src/java/org/apache/fop/render/afp/modca/MapCodedFont.java @@ -56,9 +56,7 @@ public class MapCodedFont extends AbstractStructuredAFPObject { fontList = new java.util.ArrayList(); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { byte[] startData = new byte[] { 0x5A, diff --git a/src/java/org/apache/fop/render/afp/modca/MapDataResource.java b/src/java/org/apache/fop/render/afp/modca/MapDataResource.java index 9b1abe06c..ae9df023f 100644 --- a/src/java/org/apache/fop/render/afp/modca/MapDataResource.java +++ b/src/java/org/apache/fop/render/afp/modca/MapDataResource.java @@ -34,6 +34,7 @@ import org.apache.fop.render.afp.tools.BinaryUtils; * required for presentation. */ public class MapDataResource extends AbstractStructuredAFPObject { + /** * Static default generated name reference */ @@ -41,6 +42,7 @@ public class MapDataResource extends AbstractStructuredAFPObject { /** * Main constructor + * * @param dataObjectAccessor a data object accessor */ public MapDataResource(DataObjectAccessor dataObjectAccessor) { @@ -49,7 +51,7 @@ public class MapDataResource extends AbstractStructuredAFPObject { ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); ResourceLevel resourceLevel = resourceInfo.getLevel(); if (resourceLevel.isExternal()) { - String url = resourceLevel.getExternalResourceGroupFilePath(); + String url = resourceLevel.getExternalFilePath(); if (url != null) { super.setFullyQualifiedName( FullyQualifiedNameTriplet.TYPE_DATA_OBJECT_EXTERNAL_RESOURCE_REF, @@ -69,30 +71,20 @@ public class MapDataResource extends AbstractStructuredAFPObject { objectType); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void writeStart(OutputStream os) throws IOException { super.writeStart(os); + byte[] data = new byte[9]; + copySF(data, Type.MAP, Category.DATA_RESOURCE); byte[] len = BinaryUtils.convert(10 + getTripletDataLength(), 2); - byte[] data = new byte[] { - 0x5A, // Structured field identifier - len[0], // Length byte 1 - len[1], // Length byte 2 - (byte) 0xD3, // Structured field id byte 1 - (byte) 0xAB, // Structured field id byte 2 - (byte) 0xC3, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00 // Reserved - }; + data[1] = len[0]; + data[2] = len[1]; + os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void writeContent(OutputStream os) throws IOException { // RGLength byte[] len = BinaryUtils.convert(2 + getTripletDataLength(), 2); diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java b/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java index 95f7b0c45..dabe4ec20 100644 --- a/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java @@ -33,6 +33,7 @@ public class ObjectAreaDescriptor extends AbstractDescriptor { /** * Construct an object area descriptor for the specified object width * and object height. + * * @param width The page width. * @param height The page height. * @param widthResolution The page width resolution. @@ -42,13 +43,8 @@ public class ObjectAreaDescriptor extends AbstractDescriptor { super(width, height, widthResolution, heightResolution); } - /** - * Accessor method to write the AFP datastream for the Object Area Descriptor - * @param os The stream to write to - * @throws java.io.IOException thrown if an I/O exception of some sort has occurred - */ - public void write(OutputStream os) - throws IOException { + /** {@inheritDoc} */ + public void write(OutputStream os) throws IOException { byte[] data = new byte[29]; data[0] = 0x5A; diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectAreaPosition.java b/src/java/org/apache/fop/render/afp/modca/ObjectAreaPosition.java index 7ef00dede..d853be72a 100644 --- a/src/java/org/apache/fop/render/afp/modca/ObjectAreaPosition.java +++ b/src/java/org/apache/fop/render/afp/modca/ObjectAreaPosition.java @@ -33,9 +33,12 @@ public class ObjectAreaPosition extends AbstractAFPObject { private int x; private int y; private int rotation; - + private int xOffset; + private int yOffset; + /** * Construct an object area position for the specified object y, y position. + * * @param x The x coordinate. * @param y The y coordinate. * @param rotation The coordinate system rotation (must be 0, 90, 180, 270). @@ -46,50 +49,52 @@ public class ObjectAreaPosition extends AbstractAFPObject { this.rotation = rotation; } - /** - * Accessor method to write the AFP datastream for the Object Area Position - * @param os The stream to write to - * @throws java.io.IOException in the event that an I/O exception of some sort has occurred. - */ + /** {@inheritDoc} */ public void write(OutputStream os) throws IOException { + byte[] data = new byte[33]; + copySF(data, Type.POSITION, Category.OBJECT_AREA); + byte[] len = BinaryUtils.convert(32, 2); + data[1] = len[0]; // Length + data[2] = len[1]; + + data[9] = 0x01; // OAPosID = 1 + data[10] = 0x17; // RGLength = 23 + byte[] xcoord = BinaryUtils.convert(x, 3); + data[11] = xcoord[0]; // XoaOSet + data[12] = xcoord[1]; + data[13] = xcoord[2]; + byte[] ycoord = BinaryUtils.convert(y, 3); - byte[] data = new byte[] { - 0x5A, - len[0], // Length - len[1], // Length - (byte) 0xD3, - (byte) 0xAC, - (byte) 0x6B, - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - 0x01, // OAPosID = 1 - 0x17, // RGLength = 23 - xcoord[0], // XoaOSet - xcoord[1], - xcoord[2], - ycoord[0], // YoaOSet - ycoord[1], - ycoord[2], - (byte)(rotation / 2), // XoaOrent - 0x00, - (byte)(rotation / 2 + 45), // YoaOrent - 0x00, - 0x00, // Reserved - 0x00, // XocaOSet - 0x00, - 0x00, - 0x00, // YocaOSet - 0x00, - 0x00, - 0x00, // XocaOrent - 0x00, - 0x2D, // YocaOrent - 0x00, - 0x00, // RefCSys - }; + data[14] = ycoord[0]; // YoaOSet + data[15] = ycoord[1]; + data[16] = ycoord[2]; + + byte xorient = (byte)(rotation / 2); + data[17] = xorient; // XoaOrent + + byte yorient = (byte)(rotation / 2 + 45); + data[19] = yorient; // YoaOrent + + byte[] xoffset = BinaryUtils.convert(xOffset, 3); + data[22] = xoffset[0]; // XocaOSet + data[23] = xoffset[1]; + data[24] = xoffset[2]; + + byte[] yoffset = BinaryUtils.convert(yOffset, 3); + data[25] = yoffset[0]; // YocaOSet + data[26] = yoffset[1]; + data[27] = yoffset[2]; + + data[28] = 0x00; // XocaOrent + data[29] = 0x00; + + data[30] = 0x2D; // YocaOrent + data[31] = 0x00; + + data[32] = 0x01; // RefCSys + os.write(data); } }
\ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java b/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java index 599cb0b40..fc9edc4b7 100644 --- a/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java +++ b/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java @@ -31,24 +31,18 @@ import org.apache.fop.render.afp.tools.BinaryUtils; /** * Object containers are MO:DCA objects that envelop and carry object data. */ -public class ObjectContainer extends AbstractNamedAFPObject implements DataObjectAccessor { +public class ObjectContainer extends AbstractNamedAFPObject /*implements DataObjectAccessor*/ { private static final String DEFAULT_NAME = "OC000001"; - /** - * the data object - */ + /** the data object */ private AbstractDataObject dataObj = null; - /** - * the object data - */ + /** the object data */ private byte[] objectData = null; - /** - * the data object info - */ - private DataObjectInfo dataObjectInfo; +// /** the data object info */ +// private DataObjectInfo dataObjectInfo; /** * Default constructor @@ -59,6 +53,7 @@ public class ObjectContainer extends AbstractNamedAFPObject implements DataObjec /** * Main constructor + * * @param name the name of this object container */ public ObjectContainer(String name) { @@ -67,85 +62,61 @@ public class ObjectContainer extends AbstractNamedAFPObject implements DataObjec /** * Sets the data object for this object container + * * @param dataObj the data object to reside within this object container */ public void setDataObject(AbstractDataObject dataObj) { this.dataObj = dataObj; } - /** - * {@inheritDoc} - */ - public AbstractNamedAFPObject getDataObject() { - return this.dataObj; - } - - /** - * {@inheritDoc} - */ - public DataObjectInfo getDataObjectInfo() { - return this.dataObjectInfo; - } +// /** {@inheritDoc} */ +// public AbstractNamedAFPObject getDataObject() { +// return this.dataObj; +// } +// +// /** {@inheritDoc} */ +// public DataObjectInfo getDataObjectInfo() { +// return this.dataObjectInfo; +// } - /** - * {@inheritDoc} - */ - public void setDataObjectInfo(DataObjectInfo dataObjectInfo) { - this.dataObjectInfo = dataObjectInfo; - - Registry registry = Registry.getInstance(); - Registry.ObjectType objectType = registry.getObjectType(dataObjectInfo); - if (objectType != null) { - super.setObjectClassification( - ObjectClassificationTriplet.CLASS_TIME_VARIANT_PRESENTATION_OBJECT, - objectType); - } else { - log.warn("no object type for " + dataObjectInfo.getUri()); - } - super.setFullyQualifiedName( - FullyQualifiedNameTriplet.TYPE_REPLACE_FIRST_GID_NAME, - FullyQualifiedNameTriplet.FORMAT_CHARSTR, - dataObjectInfo.getUri()); - } +// /** {@inheritDoc} */ +// public void setDataObjectInfo(DataObjectInfo dataObjectInfo) { +// this.dataObjectInfo = dataObjectInfo; +// +// Registry registry = Registry.getInstance(); +// Registry.ObjectType objectType = registry.getObjectType(dataObjectInfo); +// if (objectType != null) { +// super.setObjectClassification( +// ObjectClassificationTriplet.CLASS_TIME_VARIANT_PRESENTATION_OBJECT, +// objectType); +// } else { +// log.warn("no object type for " + dataObjectInfo.getUri()); +// } +// super.setFullyQualifiedName( +// FullyQualifiedNameTriplet.TYPE_REPLACE_FIRST_GID_NAME, +// FullyQualifiedNameTriplet.FORMAT_CHARSTR, +// dataObjectInfo.getUri()); +// } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { - super.writeStart(os); - // create object data from data object ByteArrayOutputStream bos = new ByteArrayOutputStream(); dataObj.write(bos); this.objectData = bos.toByteArray(); + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.OBJECT_CONTAINER); + // Set the total record length byte[] len = BinaryUtils.convert(16 + getTripletDataLength(), 2); - byte[] data = new byte[] { - 0x5A, // Structured field identifier - len[0], // Length byte 1 - len[1], // Length byte 2 - (byte)0xD3, // Structured field id byte 1 - (byte)0xA8, // Structured field id byte 2 - (byte)0x92, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - nameBytes[0], - nameBytes[1], - nameBytes[2], - nameBytes[3], - nameBytes[4], - nameBytes[5], - nameBytes[6], - nameBytes[7] - }; + data[1] = len[0]; // Length byte 1 + data[2] = len[1]; // Length byte 2 + os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); @@ -156,29 +127,10 @@ public class ObjectContainer extends AbstractNamedAFPObject implements DataObjec } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[] { - 0x5A, // Structured field identifier - 0x00, // Length byte 1 - 0x10, // Length byte 2 - (byte)0xD3, // Structured field id byte 1 - (byte)0xA9, // Structured field id byte 2 - (byte)0x92, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - nameBytes[0], - nameBytes[1], - nameBytes[2], - nameBytes[3], - nameBytes[4], - nameBytes[5], - nameBytes[6], - nameBytes[7], - }; + byte[] data = new byte[17]; + copySF(data, Type.END, Category.OBJECT_CONTAINER); os.write(data); } @@ -187,13 +139,12 @@ public class ObjectContainer extends AbstractNamedAFPObject implements DataObjec */ private class ObjectContainerData extends AbstractPreparedAFPObject { - /** - * The maximum object container data length - */ + /** The maximum object container data length */ private static final int MAX_DATA_LEN = 32759; /** * Main constructor + * * @param objData the object data */ public ObjectContainerData(byte[] objData, int startIndex) { @@ -208,7 +159,7 @@ public class ObjectContainer extends AbstractNamedAFPObject implements DataObjec data[2] = len[1]; // Length byte 2 data[3] = (byte)0xD3; // Structured field id byte 1 data[4] = (byte)0xEE; // Structured field id byte 2 - data[5] = (byte)0x92; // Structured field id byte 3 + data[5] = getCategoryCode(); // Structured field id byte 3 data[6] = 0x00; // Flags data[7] = 0x00; // Reserved data[8] = 0x00; // Reserved @@ -219,13 +170,21 @@ public class ObjectContainer extends AbstractNamedAFPObject implements DataObjec super.setData(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return "ObjectContainerData(" + (data != null ? "" + (data.length - 2) : "null") + ")"; } + + /** {@inheritDoc} */ + protected byte getCategoryCode() { + return (byte)0x92; + } + } + + /** {@inheritDoc} */ + protected byte getCategoryCode() { + return (byte)0x92; } } diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java b/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java index 4b31da1f1..b2ef4fa20 100644 --- a/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java @@ -73,6 +73,7 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { /** * Constructor for the ObjectEnvironmentGroup, this takes a * name parameter which must be 8 characters long. + * * @param name the object environment group name */ public ObjectEnvironmentGroup(String name) { @@ -81,6 +82,7 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { /** * Sets the object area parameters. + * * @param info the object area info */ public void setObjectArea(ObjectAreaInfo info) { @@ -93,6 +95,7 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { /** * Set the dimensions of the image. + * * @param xresol the x resolution of the image * @param yresol the y resolution of the image * @param width the image width @@ -104,6 +107,7 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { /** * Set the graphics data descriptor. + * * @param xresol the x resolution of the graphics window * @param yresol the y resolution of the graphics window * @param xlwind the left edge of the graphics window @@ -117,35 +121,14 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { xlwind, xrwind, ybwind, ytwind); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { - byte[] data = new byte[] { - 0x5A, // Structured field identifier - 0x00, // Length byte 1 - 0x10, // Length byte 2 - (byte) 0xD3, // Structured field id byte 1 - (byte) 0xA8, // Structured field id byte 2 - (byte) 0xC7, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - nameBytes[0], // Name - nameBytes[1], // - nameBytes[2], // - nameBytes[3], // - nameBytes[4], // - nameBytes[5], // - nameBytes[6], // - nameBytes[7] // - }; + byte[] data = new byte[17]; + copySF(data, Type.BEGIN, Category.OBJECT_ENVIRONMENT_GROUP); os.write(data); } - - /** - * {@inheritDoc} - */ + + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); @@ -160,30 +143,11 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { graphicsDataDescriptor.write(os); } } - - /** - * {@inheritDoc} - */ + + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[] { - 0x5A, // Structured field identifier - 0x00, // Length byte 1 - 0x10, // Length byte 2 - (byte) 0xD3, // Structured field id byte 1 - (byte) 0xA9, // Structured field id byte 2 - (byte) 0xC7, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - nameBytes[0], // Name - nameBytes[1], // - nameBytes[2], // - nameBytes[3], // - nameBytes[4], // - nameBytes[5], // - nameBytes[6], // - nameBytes[7], // - }; + byte[] data = new byte[17]; + copySF(data, Type.END, Category.OBJECT_ENVIRONMENT_GROUP); os.write(data); } } diff --git a/src/java/org/apache/fop/render/afp/modca/Overlay.java b/src/java/org/apache/fop/render/afp/modca/Overlay.java index e7d3b87d0..74b42a281 100644 --- a/src/java/org/apache/fop/render/afp/modca/Overlay.java +++ b/src/java/org/apache/fop/render/afp/modca/Overlay.java @@ -53,43 +53,17 @@ public class Overlay extends AbstractPageObject { super(name, width, height, rotation, widthResolution, heightResolution); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0xDF; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.OVERLAY); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0xDF; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.OVERLAY); os.write(data); } } diff --git a/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java b/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java index e38c576d4..0ac029b99 100644 --- a/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java @@ -33,6 +33,7 @@ public class PageDescriptor extends AbstractDescriptor { /** * Construct a page descriptor for the specified page width * and page height. + * * @param width The page width. * @param height The page height. * @param widthResolution The page width resolution @@ -42,13 +43,8 @@ public class PageDescriptor extends AbstractDescriptor { super(width, height, widthResolution, heightResolution); } - /** - * Accessor method to write the AFP datastream for the Page Descriptor - * @param os The stream to write to - * @throws java.io.IOException in the event that an I/O Exception occurred - */ - public void write(OutputStream os) - throws IOException { + /** {@inheritDoc} */ + public void write(OutputStream os) throws IOException { log.debug("width=" + width); log.debug("height=" + height); diff --git a/src/java/org/apache/fop/render/afp/modca/PageGroup.java b/src/java/org/apache/fop/render/afp/modca/PageGroup.java index 8131eb7b0..b1f3aabc1 100644 --- a/src/java/org/apache/fop/render/afp/modca/PageGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/PageGroup.java @@ -91,57 +91,27 @@ public class PageGroup extends AbstractResourceEnvironmentGroupContainer { return complete; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { writeObjects(tagLogicalElements, os); super.writeContent(os); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0xAD; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.PAGE_GROUP); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0xAD; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.PAGE_GROUP); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return this.getName(); } diff --git a/src/java/org/apache/fop/render/afp/modca/PageObject.java b/src/java/org/apache/fop/render/afp/modca/PageObject.java index 1db9c4c41..c80f21deb 100644 --- a/src/java/org/apache/fop/render/afp/modca/PageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/PageObject.java @@ -225,49 +225,21 @@ public class PageObject extends AbstractResourceGroupContainer { addObject(imImageObject); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0xAF; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.PAGE); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0xAF; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.PAGE); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return this.getName(); } diff --git a/src/java/org/apache/fop/render/afp/modca/PageSegment.java b/src/java/org/apache/fop/render/afp/modca/PageSegment.java index 92d3c4470..292deb1b1 100644 --- a/src/java/org/apache/fop/render/afp/modca/PageSegment.java +++ b/src/java/org/apache/fop/render/afp/modca/PageSegment.java @@ -35,6 +35,7 @@ public class PageSegment extends AbstractNamedAFPObject { /** * Main constructor + * * @param name the name of this object */ public PageSegment(String name) { @@ -42,6 +43,8 @@ public class PageSegment extends AbstractNamedAFPObject { } /** + * Returns a list of objects contained withing this page segment + * * @return a list of objects contained within this page segment */ public List/*<AbstractAFPObject>*/ getObjects() { @@ -53,63 +56,34 @@ public class PageSegment extends AbstractNamedAFPObject { /** * Adds a resource object (image/graphic) to this page segment + * * @param object the resource objec to add to this page segment */ public void addObject(AbstractAFPObject object) { getObjects().add(object); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0x5F; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.PAGE_SEGMENT); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); writeObjects(objects, os); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0x5F; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.PAGE_SEGMENT); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return this.name; } diff --git a/src/java/org/apache/fop/render/afp/modca/PreprocessPresentationObject.java b/src/java/org/apache/fop/render/afp/modca/PreprocessPresentationObject.java index 688b9a28f..75442fb08 100644 --- a/src/java/org/apache/fop/render/afp/modca/PreprocessPresentationObject.java +++ b/src/java/org/apache/fop/render/afp/modca/PreprocessPresentationObject.java @@ -41,6 +41,7 @@ public class PreprocessPresentationObject extends AbstractStructuredAFPObject { /** * Main constructor + * * @param prePresObj the presentation object to be preprocessed */ public PreprocessPresentationObject(AbstractStructuredAFPObject prePresObj) { @@ -66,6 +67,7 @@ public class PreprocessPresentationObject extends AbstractStructuredAFPObject { /** * Sets the object orientations relative to media leading edge + * * @param orientation the object orientations relative to media leading edge */ public void setOrientation(byte orientation) { @@ -74,6 +76,7 @@ public class PreprocessPresentationObject extends AbstractStructuredAFPObject { /** * Sets the X axis origin for object content + * * @param xOffset the X axis origin for object content */ public void setXOffset(int xOffset) { @@ -82,15 +85,14 @@ public class PreprocessPresentationObject extends AbstractStructuredAFPObject { /** * Sets the Y axis origin for object content + * * @param yOffset the Y axis origin for object content */ public void setYOffset(int yOffset) { this.objYOffset = yOffset; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void writeStart(OutputStream os) throws IOException { super.writeStart(os); @@ -109,9 +111,7 @@ public class PreprocessPresentationObject extends AbstractStructuredAFPObject { os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void writeContent(OutputStream os) throws IOException { byte[] data = new byte[12]; byte[] l = BinaryUtils.convert(12 + getTripletDataLength(), 2); @@ -146,4 +146,9 @@ public class PreprocessPresentationObject extends AbstractStructuredAFPObject { // Triplets super.writeContent(os); } + + /** {@inheritDoc} */ + protected byte getCategoryCode() { + return (byte)0xC3; + } } diff --git a/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java b/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java index 10af1536e..706548d1a 100644 --- a/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java @@ -50,6 +50,7 @@ public class PresentationTextDescriptor extends AbstractDescriptor { /** * Constructor a PresentationTextDescriptor for the specified * width and height. + * * @param width The width of the page. * @param height The height of the page. * @param widthResolution The width resolution of the page. @@ -60,13 +61,8 @@ public class PresentationTextDescriptor extends AbstractDescriptor { super(width, height, widthResolution, heightResolution); } - /** - * Accessor method to write the AFP datastream for the Presentation Text Descriptor - * @param os The stream to write to - * @throws java.io.IOException thrown if an I/O exception of some sort has occurred - */ - public void write(OutputStream os) - throws IOException { + /** {@inheritDoc} */ + public void write(OutputStream os) throws IOException { byte[] data = new byte[23]; data[0] = 0x5A; diff --git a/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java b/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java index 290a1e46a..88e29851f 100644 --- a/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java +++ b/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java @@ -171,6 +171,7 @@ public class PresentationTextObject extends AbstractNamedAFPObject { /** * Accessor method to write the AFP datastream for the PresentationTextObject. + * * @param os The stream to write to * @throws java.io.IOException thrown if an I/O exception of some sort has occurred */ @@ -182,49 +183,24 @@ public class PresentationTextObject extends AbstractNamedAFPObject { /** * Returns the name of this presentation text object + * * @return the name of this presentation text object */ public String getName() { return name; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0x9B; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.PRESENTATION_TEXT); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0x9B; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.PRESENTATION_TEXT); os.write(data); } @@ -247,9 +223,7 @@ public class PresentationTextObject extends AbstractNamedAFPObject { } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { if (presentationTextDataList != null) { return presentationTextDataList.toString(); diff --git a/src/java/org/apache/fop/render/afp/modca/Registry.java b/src/java/org/apache/fop/render/afp/modca/Registry.java index fcff8060c..dc2941ca8 100644 --- a/src/java/org/apache/fop/render/afp/modca/Registry.java +++ b/src/java/org/apache/fop/render/afp/modca/Registry.java @@ -128,6 +128,32 @@ public final class Registry { MimeConstants.MIME_PCL ) ); + mimeEntryMap.put( + MimeConstants.MIME_SVG, + new ObjectType( + COMPID_EPS, + null, // no component id + "Scaleable Vector Graphics", + false, + MimeConstants.MIME_SVG + ) + ); + } + + /** + * Returns the Registry ObjectType for a given mimetype + * + * @param mimeType the object mime type + * @return the Registry ObjectType for a given data object info + */ + public Registry.ObjectType getObjectType(String mimeType) { + ObjectType entry = null; + if (mimeType != null) { + entry = (Registry.ObjectType)mimeEntryMap.get(mimeType); + } else { + log.info("mimetype '" + mimeType + "' not found"); + } + return entry; } /** @@ -141,15 +167,11 @@ public final class Registry { if (dataObjectInfo instanceof ImageObjectInfo) { ImageObjectInfo imageInfo = (ImageObjectInfo)dataObjectInfo; String mimeType = imageInfo.getMimeType(); - if (mimeType != null) { - entry = (Registry.ObjectType)mimeEntryMap.get(mimeType); - } else { - log.info("mimetype for " + dataObjectInfo + " is null"); - } + return getObjectType(mimeType); } return entry; } - + /** * Encapsulates a MOD:CA Registry Object Type entry */ @@ -215,6 +237,22 @@ public final class Registry { } /** + * @return true if this is an image type + */ + public boolean isImage() { + return mimeType == MimeConstants.MIME_TIFF + || mimeType == MimeConstants.MIME_GIF + || mimeType == MimeConstants.MIME_JPEG; + } + + /** + * @return true if this is a graphic type + */ + public boolean isGraphic() { + return mimeType == MimeConstants.MIME_SVG; + } + + /** * {@inheritDoc} */ public String toString() { diff --git a/src/java/org/apache/fop/render/afp/modca/ResourceEnvironmentGroup.java b/src/java/org/apache/fop/render/afp/modca/ResourceEnvironmentGroup.java index 219dfd8cb..1d66f560f 100644 --- a/src/java/org/apache/fop/render/afp/modca/ResourceEnvironmentGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/ResourceEnvironmentGroup.java @@ -103,58 +103,32 @@ public class ResourceEnvironmentGroup extends AbstractEnvironmentGroup { /** * Returns an indication if the resource environment group is complete + * * @return whether or not this resource environment group is complete or not */ public boolean isComplete() { return complete; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0xD9; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.RESOURCE_ENVIROMENT_GROUP); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ + protected void writeEnd(OutputStream os) throws IOException { + byte[] data = new byte[17]; + copySF(data, Type.END, Category.RESOURCE_ENVIROMENT_GROUP); + os.write(data); + } + + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { writeObjects(mapDataResources, os); writeObjects(mapPageOverlays, os); writeObjects(preProcessPresentationObjects, os); } - /** - * {@inheritDoc} - */ - protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0xD9; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } - os.write(data); - } } diff --git a/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java b/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java index 1860d8ce7..baeefafd3 100644 --- a/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java @@ -24,7 +24,9 @@ import java.io.OutputStream; import java.util.Collection; import java.util.Iterator; import java.util.Map; +import java.util.Set; +import org.apache.fop.render.afp.DataObjectCache; import org.apache.fop.render.afp.DataObjectInfo; import org.apache.fop.render.afp.ResourceInfo; import org.apache.fop.render.afp.ResourceLevel; @@ -35,15 +37,11 @@ import org.apache.fop.render.afp.tools.StringUtils; */ public final class ResourceGroup extends AbstractNamedAFPObject { - /** - * Default name for the resource group - */ + /** Default name for the resource group */ private static final String DEFAULT_NAME = "RG000001"; - /** - * Mapping of resource uri to data resource object (image/graphic) - */ - private Map/*<String,Writeable>*/ resourceMap = null; + /** Set of resource uri */ + private Set/*<String>*/ resourceSet = new java.util.HashSet/*<String>*/(); /** * Default constructor @@ -55,67 +53,62 @@ public final class ResourceGroup extends AbstractNamedAFPObject { /** * Constructor for the ResourceGroup, this takes a * name parameter which must be 8 characters long. + * * @param name the resource group name */ public ResourceGroup(String name) { super(name); } - - private static final String OBJECT_CONTAINER_NAME_PREFIX = "OC"; - - private ObjectContainer createObjectContainer() { - String name = OBJECT_CONTAINER_NAME_PREFIX - + StringUtils.lpad(String.valueOf(getResourceCount() + 1), '0', 6); - return new ObjectContainer(name); - } - - private DataObjectFactory dataObjectFactory = new DataObjectFactory(); - /** - * Creates a data object in this resource group - * @param dataObjectInfo the data object info - * @return an include object reference - */ - public IncludeObject createObject(DataObjectInfo dataObjectInfo) { - DataObjectAccessor dataObjectAccessor - = (DataObjectAccessor)getResourceMap().get(dataObjectInfo.getUri()); - ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); - ResourceLevel resourceLevel = resourceInfo.getLevel(); - AbstractDataObject dataObj; - if (dataObjectAccessor == null) { - dataObj = dataObjectFactory.create(dataObjectInfo); - ObjectContainer objectContainer = null; - String resourceName = resourceInfo.getName(); - if (resourceName != null) { - objectContainer = new ObjectContainer(resourceName); - } else { - objectContainer = createObjectContainer(); - resourceName = objectContainer.getName(); - } - objectContainer.setDataObject(dataObj); - objectContainer.setDataObjectInfo(dataObjectInfo); - - // When located at print-file level or externally, - // wrap the object container in a resource object - if (resourceLevel.isPrintFile() || resourceLevel.isExternal()) { - ResourceObject resourceObject = new ResourceObject(resourceName); - resourceObject.setDataObject(objectContainer); - resourceObject.setDataObjectInfo(dataObjectInfo); - dataObjectAccessor = resourceObject; - } else { // Access data object through container - dataObjectAccessor = objectContainer; - } - - // Add to resource map - getResourceMap().put(dataObjectInfo.getUri(), dataObjectAccessor); - } - String name = dataObjectAccessor.getName(); - IncludeObject includeObj = new IncludeObject(name, dataObjectAccessor); - return includeObj; - } +// /** +// * Creates a data object in this resource group +// * +// * @param dataObjectInfo the data object info +// * @return an include object reference +// */ +// public IncludeObject createObject(DataObjectInfo dataObjectInfo) { +// String uri = dataObjectInfo.getUri(); +// resourceSet.get(); +// DataObjectAccessor dataObjectAccessor +// = (DataObjectAccessor)getResourceMap().getData(dataObjectInfo.getUri()); +// ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); +// ResourceLevel resourceLevel = resourceInfo.getLevel(); +// AbstractDataObject dataObj; +// if (dataObjectAccessor == null) { +// dataObj = dataObjectFactory.createObject(dataObjectInfo); +// ObjectContainer objectContainer = null; +// String resourceName = resourceInfo.getName(); +// if (resourceName != null) { +// objectContainer = new ObjectContainer(resourceName); +// } else { +// objectContainer = createObjectContainer(); +// resourceName = objectContainer.getName(); +// } +// objectContainer.setDataObject(dataObj); +// objectContainer.setDataObjectInfo(dataObjectInfo); +// +// // When located at print-file level or externally, +// // wrap the object container in a resource object +// if (resourceLevel.isPrintFile() || resourceLevel.isExternal()) { +// ResourceObject resourceObject = new ResourceObject(resourceName); +// resourceObject.setDataObject(objectContainer); +// resourceObject.setDataObjectInfo(dataObjectInfo); +// dataObjectAccessor = resourceObject; +// } else { // Access data object through container +// dataObjectAccessor = objectContainer; +// } +// +// // Add to resource map +// getResourceMap().put(dataObjectInfo.getUri(), dataObjectAccessor); +// } +// String name = dataObjectAccessor.getName(); +// IncludeObject includeObj = dataObjectFactory.createInclude(dataObjectInfo); +// return includeObj; +// } /** * Checks if a named object is of a valid type to be added to a resource group + * * @param namedObj a named object * @return true if the named object is of a valid type to be added to a resource group */ @@ -131,26 +124,23 @@ public final class ResourceGroup extends AbstractNamedAFPObject { // || namedObj instanceof BarcodeObject ); } + /** - * Adds a named object to this resource group - * @param namedObj a named AFP object + * Add this object cache resource info to this resource group + * + * @param resourceInfo the resource info */ - protected void addObject(AbstractNamedAFPObject namedObj) { - if (isValidObjectType(namedObj)) { - getResourceMap().put(namedObj.getName(), namedObj); - } else { - throw new IllegalArgumentException("invalid object type " + namedObj); - } + public void addObject(ResourceInfo resourceInfo) { + resourceSet.add(resourceInfo); } /** + * Returns the number of resources contained in this resource group + * * @return the number of resources contained in this resource group */ public int getResourceCount() { - if (resourceMap != null) { - return resourceMap.size(); - } - return 0; + return resourceSet.size(); } /** @@ -161,78 +151,42 @@ public final class ResourceGroup extends AbstractNamedAFPObject { * @return true if the resource exists within this resource group */ public boolean resourceExists(String uri) { - return getResourceMap().containsKey(uri); + return resourceSet.contains(uri); } - /** - * Returns the list of resources - * @return the list of resources - */ - public Map/*<String, DataObjectAccessor>*/ getResourceMap() { - if (resourceMap == null) { - resourceMap = new java.util.HashMap/*<String, Writeable>*/(); - } - return resourceMap; - } - - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void writeContent(OutputStream os) throws IOException { - if (resourceMap != null) { - Collection includes = resourceMap.values(); - Iterator it = includes.iterator(); + Iterator it = resourceSet.iterator(); + if (it.hasNext()) { + DataObjectCache cache = DataObjectCache.getInstance(); while (it.hasNext()) { - Writable dataObject = (Writable)it.next(); - dataObject.write(os); + ResourceInfo resourceInfo = (ResourceInfo)it.next(); + byte[] data = cache.get(resourceInfo); + if (data != null) { + os.write(data); + } else { + log.error("data was null"); + } } } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA8; // Structured field id byte 2 - data[5] = (byte) 0xC6; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.BEGIN, Category.RESOURCE_GROUP); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { byte[] data = new byte[17]; - data[0] = 0x5A; // Structured field identifier - data[1] = 0x00; // Length byte 1 - data[2] = 0x10; // Length byte 2 - data[3] = (byte) 0xD3; // Structured field id byte 1 - data[4] = (byte) 0xA9; // Structured field id byte 2 - data[5] = (byte) 0xC6; // Structured field id byte 3 - data[6] = 0x00; // Flags - data[7] = 0x00; // Reserved - data[8] = 0x00; // Reserved - for (int i = 0; i < nameBytes.length; i++) { - data[9 + i] = nameBytes[i]; - } + copySF(data, Type.END, Category.RESOURCE_GROUP); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { - return this.name + " " + getResourceMap(); + return this.name + " " + resourceSet/*getResourceMap()*/; } } diff --git a/src/java/org/apache/fop/render/afp/modca/ResourceObject.java b/src/java/org/apache/fop/render/afp/modca/ResourceObject.java index e0ba1b4b7..6894bd426 100644 --- a/src/java/org/apache/fop/render/afp/modca/ResourceObject.java +++ b/src/java/org/apache/fop/render/afp/modca/ResourceObject.java @@ -22,9 +22,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.render.afp.DataObjectInfo; -import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; -import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet; import org.apache.fop.render.afp.modca.triplets.Triplet; import org.apache.fop.render.afp.tools.BinaryUtils; @@ -32,18 +29,10 @@ import org.apache.fop.render.afp.tools.BinaryUtils; * This resource structured field begins an envelope that is used to carry * resource objects in print-file-level (external) resource groups. */ -public class ResourceObject extends AbstractPreparedAFPObject implements DataObjectAccessor { +public class ResourceObject extends AbstractPreparedAFPObject { - /** - * the object container of this resource object - */ private AbstractNamedAFPObject namedObject; - - /** - * the data object info - */ - private DataObjectInfo dataObjectInfo; - + /** * Default constructor * @@ -55,102 +44,71 @@ public class ResourceObject extends AbstractPreparedAFPObject implements DataObj /** * Sets the data object referenced by this resource object + * * @param obj the named data object */ public void setDataObject(AbstractNamedAFPObject obj) { - this.namedObject = obj; - - String fqn = obj.getFullyQualifiedName(); - if (fqn != null) { - super.setFullyQualifiedName( - FullyQualifiedNameTriplet.TYPE_REPLACE_FIRST_GID_NAME, - FullyQualifiedNameTriplet.FORMAT_CHARSTR, - fqn); - } - - byte type; - if (obj instanceof ObjectContainer) { - type = ResourceObjectTypeTriplet.OBJECT_CONTAINER; - } else if (obj instanceof ImageObject) { - type = ResourceObjectTypeTriplet.IMAGE_OBJECT; - } else if (obj instanceof GraphicsObject) { - type = ResourceObjectTypeTriplet.GRAPHICS_OBJECT; - } else if (obj instanceof Document) { - type = ResourceObjectTypeTriplet.DOCUMENT_OBJECT; - } else if (obj instanceof PageSegment) { - type = ResourceObjectTypeTriplet.PAGE_SEGMENT_OBJECT; - } else if (obj instanceof Overlay) { - type = ResourceObjectTypeTriplet.OVERLAY_OBJECT; - } else { - throw new UnsupportedOperationException( - "Unsupported resource object type " + obj); - } - getTriplets().add(new ResourceObjectTypeTriplet(type)); + this.namedObject = obj; +// +// String fqn = obj.getFullyQualifiedName(); +// if (fqn != null) { +// super.setFullyQualifiedName( +// FullyQualifiedNameTriplet.TYPE_REPLACE_FIRST_GID_NAME, +// FullyQualifiedNameTriplet.FORMAT_CHARSTR, +// fqn); +// } +// +// byte type; +// if (obj instanceof ObjectContainer) { +// type = ResourceObjectTypeTriplet.OBJECT_CONTAINER; +// } else if (obj instanceof ImageObject) { +// type = ResourceObjectTypeTriplet.IMAGE_OBJECT; +// } else if (obj instanceof GraphicsObject) { +// type = ResourceObjectTypeTriplet.GRAPHICS_OBJECT; +// } else if (obj instanceof Document) { +// type = ResourceObjectTypeTriplet.DOCUMENT_OBJECT; +// } else if (obj instanceof PageSegment) { +// type = ResourceObjectTypeTriplet.PAGE_SEGMENT_OBJECT; +// } else if (obj instanceof Overlay) { +// type = ResourceObjectTypeTriplet.OVERLAY_OBJECT; +// } else { +// throw new UnsupportedOperationException( +// "Unsupported resource object type " + obj); +// } +// getTriplets().add(new ResourceObjectTypeTriplet(type)); } - /** - * {@inheritDoc} - */ - public AbstractNamedAFPObject getDataObject() { - return namedObject; - } - - /** - * {@inheritDoc} - */ - public DataObjectInfo getDataObjectInfo() { - return this.dataObjectInfo; - } - - /** - * {@inheritDoc} - */ - public void setDataObjectInfo(DataObjectInfo dataObjectInfo) { - this.dataObjectInfo = dataObjectInfo; +// /** {@inheritDoc} */ +// public void setDataObjectInfo(DataObjectInfo dataObjectInfo) { +// this.dataObjectInfo = dataObjectInfo; +// +// if (namedObject instanceof ObjectContainer) { +// Registry.ObjectType objectType = dataObjectInfo.getObjectType(); +// super.setObjectClassification( +// ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, +// objectType); +// } +// } - if (namedObject instanceof ObjectContainer) { - Registry.ObjectType objectType = dataObjectInfo.getObjectType(); - super.setObjectClassification( - ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, - objectType); - } - } - - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { super.writeStart(os); - + + byte[] data = new byte[19]; + copySF(data, Type.BEGIN, Category.NAME_RESOURCE); + // Set the total record length byte[] len = BinaryUtils.convert(18 + getTripletDataLength(), 2); - byte[] data = new byte[] { - 0x5A, // Structured field identifier - len[0], // Length byte 1 - len[1], // Length byte 2 - (byte)0xD3, // Structured field id byte 1 - (byte)0xA8, // Structured field id byte 2 - (byte)0xCE, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - nameBytes[0], - nameBytes[1], - nameBytes[2], - nameBytes[3], - nameBytes[4], - nameBytes[5], - nameBytes[6], - nameBytes[7], - 0x00, // Reserved - 0x00, // Reserved - }; + data[1] = len[0]; // Length byte 1 + data[2] = len[1]; // Length byte 2 + + // Set reserved bits + data[17] = 0x00; // Reserved + data[18] = 0x00; // Reserved os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); // write triplets if (namedObject != null) { @@ -158,60 +116,48 @@ public class ResourceObject extends AbstractPreparedAFPObject implements DataObj } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected void writeEnd(OutputStream os) throws IOException { - byte[] data = new byte[] { - 0x5A, // Structured field identifier - 0x00, // Length byte 1 - 0x10, // Length byte 2 - (byte)0xD3, // Structured field id byte 1 - (byte)0xA9, // Structured field id byte 2 - (byte)0xCE, // Structured field id byte 3 - 0x00, // Flags - 0x00, // Reserved - 0x00, // Reserved - nameBytes[0], - nameBytes[1], - nameBytes[2], - nameBytes[3], - nameBytes[4], - nameBytes[5], - nameBytes[6], - nameBytes[7], - }; + byte[] data = new byte[17]; + copySF(data, Type.END, Category.NAME_RESOURCE); os.write(data); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public String toString() { return this.getName(); } + /** + * Sets Resource Object Type triplet + * + * @param type the resource object type + */ + public void setType(byte type) { + getTriplets().add(new ResourceObjectTypeTriplet(type)); + } + + /** + * Resource object types + */ + protected static final byte GRAPHICS_OBJECT = 0x03; +// private static final byte BARCODE_OBJECT = 0x05; + protected static final byte IMAGE_OBJECT = 0x06; +// private static final byte FONT_CHARACTER_SET_OBJECT = 0x40; +// private static final byte CODE_PAGE_OBJECT = 0x41; +// private static final byte CODED_FONT_OBJECT = 0x42; + protected static final byte OBJECT_CONTAINER = (byte) 0x92; + protected static final byte DOCUMENT_OBJECT = (byte) 0xA8; + protected static final byte PAGE_SEGMENT_OBJECT = (byte) 0xFB; + protected static final byte OVERLAY_OBJECT = (byte) 0xFC; +// private static final byte PAGEDEF_OBJECT = (byte) 0xFD; +// private static final byte FORMDEF_OBJECT = (byte) 0xFE; + private class ResourceObjectTypeTriplet extends Triplet { private static final byte RESOURCE_OBJECT = 0x21; /** - * Resource object types - */ - private static final byte GRAPHICS_OBJECT = 0x03; -// private static final byte BARCODE_OBJECT = 0x05; - private static final byte IMAGE_OBJECT = 0x06; -// private static final byte FONT_CHARACTER_SET_OBJECT = 0x40; -// private static final byte CODE_PAGE_OBJECT = 0x41; -// private static final byte CODED_FONT_OBJECT = 0x42; - private static final byte OBJECT_CONTAINER = (byte) 0x92; - private static final byte DOCUMENT_OBJECT = (byte) 0xA8; - private static final byte PAGE_SEGMENT_OBJECT = (byte) 0xFB; - private static final byte OVERLAY_OBJECT = (byte) 0xFC; -// private static final byte PAGEDEF_OBJECT = (byte) 0xFD; -// private static final byte FORMDEF_OBJECT = (byte) 0xFE; - - /** * Main constructor * * @param type diff --git a/src/java/org/apache/fop/render/afp/modca/Writable.java b/src/java/org/apache/fop/render/afp/modca/Writable.java index beaa6e21c..aa9de2d43 100644 --- a/src/java/org/apache/fop/render/afp/modca/Writable.java +++ b/src/java/org/apache/fop/render/afp/modca/Writable.java @@ -26,9 +26,11 @@ import java.io.OutputStream; * Implementing object is able to write to an AFPDataStream */ public interface Writable { + /** * DataStream objects must implement the write() * method to write its data to the given OutputStream + * * @param outputStream The outputsteam stream * @throws java.io.IOException an I/O exception of some sort has occurred. */ |