aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdrian Cumiskey <acumiskey@apache.org>2008-04-16 12:03:15 +0000
committerAdrian Cumiskey <acumiskey@apache.org>2008-04-16 12:03:15 +0000
commit18e3a8208cc7e574e8fd4183efd99d4107ba19d0 (patch)
tree99a42f36c95de1225bbcfd8a529fe18b2e5f5cc1 /src
parent592835167ab8951f61d1590197f646984588d070 (diff)
downloadxmlgraphics-fop-18e3a8208cc7e574e8fd4183efd99d4107ba19d0.tar.gz
xmlgraphics-fop-18e3a8208cc7e574e8fd4183efd99d4107ba19d0.zip
Further reworking and refinements. Not a working model yet.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@648675 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/fop/render/afp/AFPGraphics2D.java14
-rw-r--r--src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java24
-rw-r--r--src/java/org/apache/fop/render/afp/AFPRenderer.java43
-rw-r--r--src/java/org/apache/fop/render/afp/AFPSVGHandler.java26
-rw-r--r--src/java/org/apache/fop/render/afp/DataObjectInfo.java68
-rw-r--r--src/java/org/apache/fop/render/afp/ResourceInfo.java2
-rw-r--r--src/java/org/apache/fop/render/afp/goca/GraphicsArea.java4
-rw-r--r--src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java17
-rw-r--r--src/java/org/apache/fop/render/afp/goca/GraphicsData.java9
-rw-r--r--src/java/org/apache/fop/render/afp/goca/GraphicsImageData.java5
-rw-r--r--src/java/org/apache/fop/render/afp/modca/AFPDataStream.java57
-rw-r--r--src/java/org/apache/fop/render/afp/modca/AFPDataStreamWriter.java36
-rw-r--r--src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java10
-rw-r--r--src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java3
-rw-r--r--src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java24
-rw-r--r--src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java8
-rw-r--r--src/java/org/apache/fop/render/afp/modca/AbstractPreparedObjectContainer.java (renamed from src/java/org/apache/fop/render/afp/goca/AbstractGraphicsContainer.java)39
-rw-r--r--src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java3
-rw-r--r--src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java13
-rw-r--r--src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java3
-rw-r--r--src/java/org/apache/fop/render/afp/modca/DataObjectAccessor.java31
-rw-r--r--src/java/org/apache/fop/render/afp/modca/GraphicsObject.java42
-rw-r--r--src/java/org/apache/fop/render/afp/modca/IncludeObject.java87
-rw-r--r--src/java/org/apache/fop/render/afp/modca/MapDataResource.java8
-rw-r--r--src/java/org/apache/fop/render/afp/modca/ObjectContainer.java133
-rw-r--r--src/java/org/apache/fop/render/afp/modca/Registry.java (renamed from src/java/org/apache/fop/render/afp/modca/ObjectTypeRegistry.java)68
-rw-r--r--src/java/org/apache/fop/render/afp/modca/ResourceGroup.java98
-rw-r--r--src/java/org/apache/fop/render/afp/modca/ResourceObject.java83
-rw-r--r--src/java/org/apache/fop/render/afp/modca/triplets/FullyQualifiedNameTriplet.java5
-rw-r--r--src/java/org/apache/fop/render/afp/modca/triplets/MeasurementUnitsTriplet.java3
-rw-r--r--src/java/org/apache/fop/render/afp/modca/triplets/ObjectAreaSizeTriplet.java3
-rw-r--r--src/java/org/apache/fop/render/afp/modca/triplets/ObjectClassificationTriplet.java84
-rw-r--r--src/java/org/apache/fop/render/afp/modca/triplets/Triplet.java19
33 files changed, 631 insertions, 441 deletions
diff --git a/src/java/org/apache/fop/render/afp/AFPGraphics2D.java b/src/java/org/apache/fop/render/afp/AFPGraphics2D.java
index 974155630..f8737d91a 100644
--- a/src/java/org/apache/fop/render/afp/AFPGraphics2D.java
+++ b/src/java/org/apache/fop/render/afp/AFPGraphics2D.java
@@ -486,13 +486,13 @@ public class AFPGraphics2D extends AbstractGraphics2D {
this.customTextHandler = handler;
}
- /**
- * Sets the SVG document URI
- * @param documentURI the SVG document URI
- */
- public void setDocumentURI(String documentURI) {
- this.documentURI = documentURI;
- }
+// /**
+// * Sets the SVG document URI
+// * @param documentURI the SVG document URI
+// */
+// public void setDocumentURI(String documentURI) {
+// this.documentURI = documentURI;
+// }
/**
* @return the GOCA graphics object
diff --git a/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java b/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java
index af8c7fedf..1531e6d86 100644
--- a/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java
+++ b/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java
@@ -22,8 +22,13 @@ package org.apache.fop.render.afp;
import java.awt.image.BufferedImage;
import java.io.IOException;
+import org.apache.xmlgraphics.image.loader.ImageException;
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageManager;
+import org.apache.xmlgraphics.image.loader.ImageSessionContext;
import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.render.AbstractGraphics2DAdapter;
import org.apache.fop.render.RendererContext;
@@ -48,16 +53,23 @@ public class AFPGraphics2DAdapter extends AbstractGraphics2DAdapter {
Boolean grayObj = (Boolean)context.getProperty(AFPRendererContextConstants.AFP_GRAYSCALE);
boolean gray = (grayObj != null ? grayObj.booleanValue() : false);
+ FOUserAgent userAgent = context.getUserAgent();
+
//Paint to a BufferedImage
- int resolution = (int)Math.round(context.getUserAgent().getTargetResolution());
+ int resolution = (int)Math.round(userAgent.getTargetResolution());
BufferedImage bi = paintToBufferedImage(painter, wrappedContext, resolution, gray, false);
+ ImageManager manager = userAgent.getFactory().getImageManager();
+ ImageSessionContext sessionContext = userAgent.getImageSessionContext();
//TODO: AC - fix
-// String uri = null;
-// java.util.Map foreignAttributes = null;
-// ImageInfo imageInfo = new ImageInfo();
-// afp.drawBufferedImage(uri, bi, resolution, x, y, width, height, foreignAttributes);
+ String uri = null;
+
+ try {
+ ImageInfo info = manager.getImageInfo(uri, sessionContext);
+ java.util.Map foreignAttributes = null;
+ afp.drawBufferedImage(info, bi, resolution, x, y, width, height, foreignAttributes);
+ } catch (ImageException e) {
+ }
}
-
}
diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java
index 629a7b62f..526fc43f3 100644
--- a/src/java/org/apache/fop/render/afp/AFPRenderer.java
+++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java
@@ -344,7 +344,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
public void startRenderer(OutputStream outputStream) throws IOException {
currentPageFonts = new java.util.HashMap();
currentColor = new Color(255, 255, 255);
- afpDataStream = new AFPDataStream();
+ this.afpDataStream = new AFPDataStream();
afpDataStream.setPortraitRotation(portraitRotation);
afpDataStream.setLandscapeRotation(landscapeRotation);
afpDataStream.setOutputStream(outputStream);
@@ -354,7 +354,8 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
* {@inheritDoc}
*/
public void stopRenderer() throws IOException {
- afpDataStream.write();
+ getAFPDataStream().write();
+ afpDataStream = null;
}
/**
@@ -391,7 +392,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
// renderPageGroupExtensions(page);
final int pageRotation = 0;
- this.afpDataStream.startPage(pageWidth, pageHeight, pageRotation,
+ getAFPDataStream().startPage(pageWidth, pageHeight, pageRotation,
getResolution(), getResolution());
renderPageObjectExtensions(page);
@@ -399,7 +400,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
if (this.pages == null) {
this.pages = new java.util.HashMap();
}
- this.pages.put(page, afpDataStream.savePage());
+ this.pages.put(page, getAFPDataStream().savePage());
}
@@ -620,13 +621,13 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
if (pages != null && pages.containsKey(pageViewport)) {
- this.afpDataStream.restorePage((PageObject) pages.remove(pageViewport));
+ getAFPDataStream().restorePage((PageObject) pages.remove(pageViewport));
} else {
// renderPageGroupExtensions(page);
final int pageRotation = 0;
- this.afpDataStream.startPage(pageWidth, pageHeight, pageRotation,
+ getAFPDataStream().startPage(pageWidth, pageHeight, pageRotation,
getResolution(), getResolution());
renderPageObjectExtensions(pageViewport);
@@ -641,14 +642,14 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
while (i.hasNext()) {
AFPFontAttributes afpFontAttributes = (AFPFontAttributes) i.next();
- afpDataStream.createFont(
+ getAFPDataStream().createFont(
(byte)afpFontAttributes.getFontReference(),
afpFontAttributes.getFont(),
afpFontAttributes.getPointSize());
}
- afpDataStream.endPage();
+ getAFPDataStream().endPage();
popViewPortPos();
}
@@ -702,7 +703,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
currentColor.getGreen(),
currentColor.getBlue());
*/
- afpDataStream.createLine(
+ getAFPDataStream().createLine(
pts2units(x),
pts2units(y),
pts2units(x + width),
@@ -722,6 +723,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
log.error("Negative extent received. Border won't be painted.");
return;
}
+
switch (style) {
case Constants.EN_DOUBLE:
if (horz) {
@@ -947,7 +949,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
String name = (String)getPageSegments().get(uri);
if (name != null) {
- afpDataStream.createIncludePageSegment(name, mpts2units(x), mpts2units(y));
+ getAFPDataStream().createIncludePageSegment(name, mpts2units(x), mpts2units(y));
} else {
ImageManager manager = getUserAgent().getFactory().getImageManager();
ImageInfo info = null;
@@ -1007,7 +1009,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
imageObjectInfo.setCompression(ccitt.getCompression());
imageObjectInfo.setResourceInfoFromForeignAttributes(foreignAttributes);
- afpDataStream.createObject(imageObjectInfo);
+ getAFPDataStream().createObject(imageObjectInfo);
// ImageObject io = afpDataStream.getImageObject(afpx, afpy, afpw, afph,
@@ -1251,7 +1253,8 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
imageObjectInfo.setBitsPerPixel(bitsPerPixel);
imageObjectInfo.setResourceInfoFromForeignAttributes(foreignAttributes);
- AbstractNamedAFPObject obj = afpDataStream.createObject(imageObjectInfo);
+ //AbstractNamedAFPObject obj =
+ getAFPDataStream().createObject(imageObjectInfo);
// ImageObject io = afpDataStream.getImageObject(afpx, afpy, afpw,
// afph, afpres, afpres);
// io.setImageParameters(imageResolution, imageResolution,
@@ -1379,7 +1382,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
}
try {
- afpDataStream.createText(
+ getAFPDataStream().createText(
afpFontAttributes.getFontReference(),
mpts2units(rx),
mpts2units(bl),
@@ -1596,7 +1599,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
if (AFPElementMapping.INCLUDE_PAGE_OVERLAY.equals(element)) {
String overlay = aps.getName();
if (overlay != null) {
- afpDataStream.createIncludePageOverlay(overlay);
+ getAFPDataStream().createIncludePageOverlay(overlay);
}
} else if (AFPElementMapping.INCLUDE_PAGE_SEGMENT
.equals(element)) {
@@ -1607,11 +1610,11 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
.equals(element)) {
String name = aps.getName();
String value = aps.getValue();
- afpDataStream.createTagLogicalElement(name, value);
+ getAFPDataStream().createTagLogicalElement(name, value);
} else if (AFPElementMapping.NO_OPERATION.equals(element)) {
String content = aps.getContent();
if (content != null) {
- afpDataStream.createNoOperation(content);
+ getAFPDataStream().createNoOperation(content);
}
}
// else if (AFPElementMapping.RESOURCE.equals(element)) {
@@ -1814,14 +1817,14 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
private void pushViewPortPos(ViewPortPos vpp) {
viewPortPositions.add(vpp);
- afpDataStream.setOffsets(vpp.x, vpp.y, vpp.rot);
+ getAFPDataStream().setOffsets(vpp.x, vpp.y, vpp.rot);
}
private void popViewPortPos() {
viewPortPositions.remove(viewPortPositions.size() - 1);
if (viewPortPositions.size() > 0) {
ViewPortPos vpp = (ViewPortPos)viewPortPositions.get(viewPortPositions.size() - 1);
- afpDataStream.setOffsets(vpp.x, vpp.y, vpp.rot);
+ getAFPDataStream().setOffsets(vpp.x, vpp.y, vpp.rot);
}
}
@@ -1913,7 +1916,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer {
/** {@inheritDoc} */
public void startPageSequence(LineArea seqTitle) {
- afpDataStream.endPageGroup();
- afpDataStream.startPageGroup();
+ getAFPDataStream().endPageGroup();
+ getAFPDataStream().startPageGroup();
}
}
diff --git a/src/java/org/apache/fop/render/afp/AFPSVGHandler.java b/src/java/org/apache/fop/render/afp/AFPSVGHandler.java
index 939892648..86c26d74f 100644
--- a/src/java/org/apache/fop/render/afp/AFPSVGHandler.java
+++ b/src/java/org/apache/fop/render/afp/AFPSVGHandler.java
@@ -30,15 +30,12 @@ import org.apache.batik.bridge.GVTBuilder;
import org.apache.batik.dom.AbstractDocument;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.gvt.GraphicsNode;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.fop.render.AbstractGenericSVGHandler;
import org.apache.fop.render.Renderer;
import org.apache.fop.render.RendererContext;
import org.apache.fop.render.RendererContextConstants;
import org.apache.fop.render.afp.modca.AFPDataStream;
import org.apache.fop.render.afp.modca.GraphicsObject;
-import org.apache.fop.render.afp.modca.IncludeObject;
import org.apache.fop.svg.SVGUserAgent;
import org.w3c.dom.Document;
@@ -60,10 +57,10 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler {
}
/**
- * Get the afp information from the render context.
+ * Get the AFP information from the render context.
*
* @param context the renderer context
- * @return the afp information retrieved from the context
+ * @return the AFP information retrieved from the context
*/
public static AFPInfo getAFPInfo(RendererContext context) {
AFPInfo afpi = new AFPInfo();
@@ -103,9 +100,6 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler {
graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
graphics.setAFPInfo(afpInfo);
- String uri = ((AbstractDocument)doc).getDocumentURI();
- graphics.setDocumentURI(uri);
-
GVTBuilder builder = new GVTBuilder();
boolean strokeText = false;
@@ -160,7 +154,9 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler {
// set the data object parameters
DataObjectInfo info = new DataObjectInfo();
- info.setUri(uri);
+
+ String docUri = ((AbstractDocument)doc).getDocumentURI();
+ info.setUri(docUri);
info.setX(x);
info.setY(y);
info.setWidth(width);
@@ -170,14 +166,11 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler {
Map/*<QName, String>*/ foreignAttributes
= (Map/*<QName, String>*/)context.getProperty(
RendererContextConstants.FOREIGN_ATTRIBUTES);
- if (foreignAttributes != null) {
- info.setResourceInfoFromForeignAttributes(foreignAttributes);
- }
+ info.setResourceInfoFromForeignAttributes(foreignAttributes);
- //TODO: AC - fix
-// IncludeObject includeObj = afpInfo.getAFPDataStream().createObject(info);
-// GraphicsObject graphicsObj = (GraphicsObject)includeObj.getReferencedObject();
-// graphics.setGraphicsObject(graphicsObj);
+ AFPDataStream afpDataStream = afpInfo.getAFPDataStream();
+ GraphicsObject graphicsObj = (GraphicsObject)afpDataStream.createObject(info);
+ graphics.setGraphicsObject(graphicsObj);
try {
root.paint(graphics);
@@ -203,5 +196,4 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler {
context.setProperty(AFPRendererContextConstants.AFP_GRAYSCALE,
Boolean.FALSE);
}
-
}
diff --git a/src/java/org/apache/fop/render/afp/DataObjectInfo.java b/src/java/org/apache/fop/render/afp/DataObjectInfo.java
index d363dd5ea..58fbd11b1 100644
--- a/src/java/org/apache/fop/render/afp/DataObjectInfo.java
+++ b/src/java/org/apache/fop/render/afp/DataObjectInfo.java
@@ -25,14 +25,20 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.render.afp.extensions.AFPElementMapping;
-import org.apache.fop.render.afp.modca.ObjectTypeRegistry;
-import org.apache.fop.render.afp.modca.ObjectTypeRegistry.ObjectType;
-import org.apache.fop.util.QName;
+import org.apache.fop.render.afp.modca.Registry;
+import org.apache.fop.render.afp.modca.Registry.ObjectType;
+import org.apache.xmlgraphics.util.QName;
/**
* A list of parameters associated with an AFP data objects
*/
public class DataObjectInfo {
+ private static final Log log = LogFactory.getLog("org.apache.fop.afp");
+
+ private static final String RESOURCE_NAME = "afp:resource-name";
+ private static final String RESOURCE_LEVEL = "afp:resource-level";
+ private static final String RESOURCE_GROUP_FILE = "afp:resource-group-file";
+
private static final ResourceInfo DEFAULT_RESOURCE_INFO = new ResourceInfo();
private String uri;
@@ -42,16 +48,19 @@ public class DataObjectInfo {
private int height;
private int widthRes;
private int heightRes;
+ private int rotation = 0;
- // object type entry
- private ObjectType objectTypeEntry;
+ /** object type entry */
+ private ObjectType objectType;
+
+ /** resource info */
private ResourceInfo resourceInfo = DEFAULT_RESOURCE_INFO;
/**
* Sets the data object uri
* @param uri the data object uri
*/
- protected void setUri(String uri) {
+ public void setUri(String uri) {
this.uri = uri;
}
@@ -159,18 +168,33 @@ public class DataObjectInfo {
}
/**
- * Sets the object type entry
- * @param entry the object type entry
+ * @return the rotation of this data object
+ */
+ public int getRotation() {
+ return rotation;
+ }
+
+ /**
+ * Sets the data object rotation
+ * @param rotation the data object rotation
+ */
+ protected void setRotation(int rotation) {
+ this.rotation = rotation;
+ }
+
+ /**
+ * Sets the object type
+ * @param objectType the object type
*/
- public void setObjectType(ObjectTypeRegistry.ObjectType entry) {
- this.objectTypeEntry = entry;
+ public void setObjectType(Registry.ObjectType objectType) {
+ this.objectType = objectType;
}
/**
* @return the object type entry
*/
- protected ObjectType getObjectTypeEntry() {
- return objectTypeEntry;
+ protected ObjectType getObjectType() {
+ return objectType;
}
/**
@@ -188,17 +212,12 @@ public class DataObjectInfo {
this.resourceInfo = resourceInfo;
}
-
- private static final String RESOURCE_NAME = "afp:resource-name";
- private static final String RESOURCE_LEVEL = "afp:resource-level";
- private static final String RESOURCE_GROUP_FILE = "afp:resource-group-file";
-
/**
* Sets the resource group settings using the given foreign attributes
* @param foreignAttributes a mapping of element attributes names to values
*/
public void setResourceInfoFromForeignAttributes(Map/*<QName, String>*/ foreignAttributes) {
- if (foreignAttributes != null) {
+ if (foreignAttributes != null && !foreignAttributes.isEmpty()) {
this.resourceInfo = new ResourceInfo();
QName resourceNameKey = new QName(AFPElementMapping.NAMESPACE, RESOURCE_NAME);
String resourceName = (String)foreignAttributes.get(resourceNameKey);
@@ -214,15 +233,19 @@ public class DataObjectInfo {
RESOURCE_GROUP_FILE);
String resourceExternalDest
= (String)foreignAttributes.get(resourceGroupFileKey);
+ if (resourceExternalDest == null) {
+ String msg = RESOURCE_GROUP_FILE + " not specified";
+ log.warn(msg);
+ throw new UnsupportedOperationException(msg);
+ }
File resourceExternalGroupFile = new File(resourceExternalDest);
if (resourceExternalGroupFile.canWrite()) {
resourceInfo.setExternalResourceGroupFile(resourceExternalGroupFile);
}
}
} else {
- Log log = LogFactory.getLog("org.apache.fop.afp");
- log.warn("invalid resource level '" + level
- + "', using default document level");
+ String msg = RESOURCE_LEVEL + " is null or not valid";
+ log.warn(msg);
}
}
}
@@ -239,7 +262,8 @@ public class DataObjectInfo {
+ ", height=" + height
+ ", widthRes=" + widthRes
+ ", heightRes=" + heightRes
+ + ", rotation=" + rotation
+ (resourceInfo != null ? ", resourceInfo=" + resourceInfo : "")
- + (objectTypeEntry != null ? ", objectTypeEntry=" + objectTypeEntry : "");
+ + (objectType != null ? ", objectTypeEntry=" + objectType : "");
}
}
diff --git a/src/java/org/apache/fop/render/afp/ResourceInfo.java b/src/java/org/apache/fop/render/afp/ResourceInfo.java
index 5c39d48b0..86add31d2 100644
--- a/src/java/org/apache/fop/render/afp/ResourceInfo.java
+++ b/src/java/org/apache/fop/render/afp/ResourceInfo.java
@@ -99,7 +99,7 @@ public class ResourceInfo {
* @return true if the resource level was successfully set
*/
public boolean setLevel(String lvl) {
- if (isValid(lvl)) {
+ if (lvl != null && isValid(lvl)) {
this.level = lvl;
return true;
}
diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsArea.java b/src/java/org/apache/fop/render/afp/goca/GraphicsArea.java
index c0d1040c8..46b343eb1 100644
--- a/src/java/org/apache/fop/render/afp/goca/GraphicsArea.java
+++ b/src/java/org/apache/fop/render/afp/goca/GraphicsArea.java
@@ -22,10 +22,12 @@ package org.apache.fop.render.afp.goca;
import java.io.IOException;
import java.io.OutputStream;
+import org.apache.fop.render.afp.modca.AbstractPreparedObjectContainer;
+
/**
* A GOCA graphics area (container for filled shapes/objects)
*/
-public final class GraphicsArea extends AbstractGraphicsContainer {
+public final class GraphicsArea extends AbstractPreparedObjectContainer {
/** draw boundary lines around this area */
private boolean drawBoundary = false;
diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java b/src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java
index f63aff1ea..ad8410b82 100644
--- a/src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java
+++ b/src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java
@@ -22,13 +22,14 @@ package org.apache.fop.render.afp.goca;
import java.io.IOException;
import java.io.OutputStream;
+import org.apache.fop.render.afp.modca.AbstractPreparedObjectContainer;
import org.apache.fop.render.afp.modca.PreparedAFPObject;
import org.apache.fop.render.afp.tools.BinaryUtils;
/**
* A GOCA graphics segment
*/
-public final class GraphicsChainedSegment extends AbstractGraphicsContainer {
+public final class GraphicsChainedSegment extends AbstractPreparedObjectContainer {
/**
* The maximum segment data length
@@ -91,10 +92,8 @@ public final class GraphicsChainedSegment extends AbstractGraphicsContainer {
}
private static final byte APPEND_NEW_SEGMENT = 0;
-
- private static final byte PROLOG = 4;
-
- private static final byte APPEND_TO_EXISING = 48;
+// private static final byte PROLOG = 4;
+// private static final byte APPEND_TO_EXISING = 48;
/**
* {@inheritDoc}
@@ -148,7 +147,7 @@ public final class GraphicsChainedSegment extends AbstractGraphicsContainer {
*/
protected void beginArea() {
this.currentArea = new GraphicsArea();
- super.addDrawingOrder(currentArea);
+ super.addObject(currentArea);
}
/**
@@ -161,11 +160,11 @@ public final class GraphicsChainedSegment extends AbstractGraphicsContainer {
/**
* {@inheritDoc}
*/
- protected PreparedAFPObject addDrawingOrder(PreparedAFPObject drawingOrder) {
+ public PreparedAFPObject addObject(PreparedAFPObject drawingOrder) {
if (currentArea != null) {
- currentArea.addDrawingOrder(drawingOrder);
+ currentArea.addObject(drawingOrder);
} else {
- super.addDrawingOrder(drawingOrder);
+ super.addObject(drawingOrder);
}
return drawingOrder;
}
diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsData.java b/src/java/org/apache/fop/render/afp/goca/GraphicsData.java
index 3c95bb245..d2626ccaf 100644
--- a/src/java/org/apache/fop/render/afp/goca/GraphicsData.java
+++ b/src/java/org/apache/fop/render/afp/goca/GraphicsData.java
@@ -22,6 +22,7 @@ package org.apache.fop.render.afp.goca;
import java.io.IOException;
import java.io.OutputStream;
+import org.apache.fop.render.afp.modca.AbstractPreparedObjectContainer;
import org.apache.fop.render.afp.modca.PreparedAFPObject;
import org.apache.fop.render.afp.tools.BinaryUtils;
import org.apache.fop.render.afp.tools.StringUtils;
@@ -29,7 +30,7 @@ import org.apache.fop.render.afp.tools.StringUtils;
/**
* A GOCA graphics data
*/
-public final class GraphicsData extends AbstractGraphicsContainer {
+public final class GraphicsData extends AbstractPreparedObjectContainer {
/**
* The maximum graphics data length
@@ -115,20 +116,20 @@ public final class GraphicsData extends AbstractGraphicsContainer {
} else {
this.currentSegment = new GraphicsChainedSegment(name, currentSegment);
}
- super.addDrawingOrder(currentSegment);
+ super.addObject(currentSegment);
return currentSegment;
}
/**
* {@inheritDoc}
*/
- public PreparedAFPObject addDrawingOrder(PreparedAFPObject drawingOrder) {
+ public PreparedAFPObject addObject(PreparedAFPObject drawingOrder) {
if (currentSegment == null
|| (currentSegment.getDataLength() + drawingOrder.getDataLength())
>= GraphicsChainedSegment.MAX_DATA_LEN) {
newSegment();
}
- currentSegment.addDrawingOrder(drawingOrder);
+ currentSegment.addObject(drawingOrder);
return drawingOrder;
}
diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsImageData.java b/src/java/org/apache/fop/render/afp/goca/GraphicsImageData.java
index b17c3d7d4..1fc7e2332 100644
--- a/src/java/org/apache/fop/render/afp/goca/GraphicsImageData.java
+++ b/src/java/org/apache/fop/render/afp/goca/GraphicsImageData.java
@@ -41,10 +41,13 @@ public final class GraphicsImageData extends AbstractPreparedAFPObject {
if (startIndex + MAX_DATA_LEN >= imageData.length) {
dataLen = imageData.length - startIndex - 1;
}
- super.data = new byte[dataLen + 2];
+
+ byte[] data = new byte[dataLen + 2];
data[0] = (byte) 0x92; // GIMD
data[1] = BinaryUtils.convert(dataLen, 1)[0]; // LENGTH
System.arraycopy(imageData, startIndex, data, 2, dataLen);
+
+ super.setData(data);
}
/**
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 e6790e91c..c556fa82d 100644
--- a/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java
+++ b/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java
@@ -431,6 +431,9 @@ public class AFPDataStream extends AbstractResourceGroupContainer {
col, vsci, ica, data);
}
+ /** Maintain a reference count of instream objects */
+ private int instreamObjectCount = 0;
+
/**
* Creates a data object in the datastream. The data object resides according
* to its type, info and MO:DCA-L (resource) support.
@@ -441,20 +444,35 @@ public class AFPDataStream extends AbstractResourceGroupContainer {
* a data object
*/
public AbstractNamedAFPObject createObject(DataObjectInfo dataObjectInfo) {
- ObjectTypeRegistry registry = ObjectTypeRegistry.getInstance();
- ObjectTypeRegistry.ObjectType objectType = registry.getObjectType(dataObjectInfo);
+ String uri = dataObjectInfo.getUri();
+
+ // if this is an instream data object adjust uri to ensure that it is unique
+ if (uri.endsWith("/")) {
+ uri += "#" + (++instreamObjectCount);
+ dataObjectInfo.setUri(uri);
+ }
+
+ Registry.ObjectType objectType = Registry.getInstance().getObjectType(dataObjectInfo);
+ // recognised object type
if (objectType != null) {
dataObjectInfo.setObjectType(objectType);
- }
- AbstractNamedAFPObject dataObj;
- // can this data object use the include object (IOB) mechanism?
- if (objectType.canBeIncluded()) {
- ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo();
- ResourceGroup resourceGroup = getResourceGroup(resourceInfo);
- dataObj = resourceGroup.createObject(dataObjectInfo);
- } else {
- dataObj = getCurrentPage().createObject(dataObjectInfo);
+
+ // can this data object use the include object (IOB) referencing mechanism?
+ if (objectType.canBeIncluded()) {
+ ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo();
+ ResourceGroup resourceGroup = getResourceGroup(resourceInfo);
+ IncludeObject includeObject = resourceGroup.createObject(dataObjectInfo);
+
+ // add include to current page
+ getCurrentPage().addObject(includeObject);
+ return includeObject.getDataObject();
+ } else {
+ log.warn(uri + "cannot be included so will embed directly");
+ }
}
+ // unrecognised/unsupported object type so create/embed data object directly in current page
+ AbstractNamedAFPObject dataObj = getCurrentPage().createObject(dataObjectInfo);
+ getCurrentPage().addObject(dataObj);
return dataObj;
}
@@ -822,28 +840,27 @@ public class AFPDataStream extends AbstractResourceGroupContainer {
// write any external resources
Iterator it = getExternalResourceGroups().keySet().iterator();
while (it.hasNext()) {
- String externalDest = (String)it.next();
+ File resourceGroupFile = (File)it.next();
ResourceGroup resourceGroup
- = (ResourceGroup)getExternalResourceGroups().get(externalDest);
+ = (ResourceGroup)getExternalResourceGroups().get(resourceGroupFile);
OutputStream os = null;
try {
- log.debug("Writing external AFP resource file " + externalDest);
- os = new java.io.FileOutputStream(externalDest);
+ log.debug("Writing external AFP resource file "
+ + resourceGroupFile.getAbsolutePath());
+
+ os = new java.io.FileOutputStream(resourceGroupFile);
resourceGroup.writeDataStream(os);
- } catch (FileNotFoundException e) {
- log.error("Failed to open external AFP resource file "
- + externalDest);
} catch (IOException e) {
log.error(
"An error occurred when attempting to write external AFP resource file "
- + externalDest);
+ + resourceGroupFile.getAbsolutePath());
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
log.error("Failed to close outputstream for external AFP resource file "
- + externalDest);
+ + resourceGroupFile.getAbsolutePath());
}
}
}
diff --git a/src/java/org/apache/fop/render/afp/modca/AFPDataStreamWriter.java b/src/java/org/apache/fop/render/afp/modca/AFPDataStreamWriter.java
new file mode 100644
index 000000000..35b651fa2
--- /dev/null
+++ b/src/java/org/apache/fop/render/afp/modca/AFPDataStreamWriter.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id: $ */
+
+package org.apache.fop.render.afp.modca;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Implementing object is able to write to an AFPDataStream
+ */
+public interface AFPDataStreamWriter {
+ /**
+ * DataStream objects must implement the writeDataStream()
+ * method to write its data to the given OutputStream
+ * @param os The outputsteam stream
+ * @throws java.io.IOException an I/O exception of some sort has occurred.
+ */
+ void writeDataStream(OutputStream os) throws IOException;
+}
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 60cfeb623..27fe3121e 100644
--- a/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java
+++ b/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java
@@ -33,7 +33,7 @@ import org.apache.commons.logging.LogFactory;
* AFP format.
*
*/
-public abstract class AbstractAFPObject {
+public abstract class AbstractAFPObject implements AFPDataStreamWriter {
/**
* Static logging instance
@@ -41,14 +41,6 @@ public abstract class AbstractAFPObject {
protected static final Log log = LogFactory.getLog("org.apache.fop.render.afp.modca");
/**
- * DataStream objects must implement the writeDataStream()
- * method to write its data to the given OutputStream
- * @param os The outputsteam stream
- * @throws java.io.IOException an I/O exception of some sort has occurred.
- */
- public abstract void writeDataStream(OutputStream os) throws IOException;
-
- /**
* 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
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 aa97065d1..f6473cfdc 100644
--- a/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java
+++ b/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java
@@ -22,13 +22,12 @@ package org.apache.fop.render.afp.modca;
import java.io.IOException;
import java.io.OutputStream;
-import org.apache.fop.render.afp.goca.AbstractGraphicsContainer;
/**
* Abstract base class used by the ImageObject and GraphicsObject which both
* have define an ObjectEnvironmentGroup
*/
-public abstract class AbstractDataObject extends AbstractGraphicsContainer {
+public abstract class AbstractDataObject extends AbstractPreparedObjectContainer {
/**
* The object environment group
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 95dd303b2..41cf78162 100644
--- a/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java
+++ b/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java
@@ -410,22 +410,6 @@ public abstract class AbstractPageObject extends AbstractResourceGroupContainer
writeObjects(objects, os);
}
-// /**
-// * {@inheritDoc}
-// */
-// public IncludeObject createImageObject(ImageObjectParameters params) {
-// endPresentationObject();
-// return super.createImageObject(params);
-// }
-//
-// /**
-// * {@inheritDoc}
-// */
-// public IncludeObject createGraphicsObject(DataObjectParameters params) {
-// endPresentationObject();
-// return super.createGraphicsObject(params);
-// }
-
/**
* {@inheritDoc}
*/
@@ -437,12 +421,4 @@ public abstract class AbstractPageObject extends AbstractResourceGroupContainer
endPresentationObject();
super.addObject(obj);
}
-
-// /**
-// * {@inheritDoc}
-// */
-// protected void addObject(AbstractStructuredAFPObject obj) {
-// endPresentationObject();
-// super.addObject(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 e40aa1b4f..d707384ed 100644
--- a/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java
+++ b/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java
@@ -80,4 +80,12 @@ implements PreparedAFPObject {
protected int getLength() {
return getStartDataLength() + getTripletDataLength() + getDataLength();
}
+
+ /**
+ * Sets the data
+ * @param data the data
+ */
+ protected void setData(byte[] data) {
+ this.data = data;
+ }
} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/afp/goca/AbstractGraphicsContainer.java b/src/java/org/apache/fop/render/afp/modca/AbstractPreparedObjectContainer.java
index e6966d5d3..3c2b3981d 100644
--- a/src/java/org/apache/fop/render/afp/goca/AbstractGraphicsContainer.java
+++ b/src/java/org/apache/fop/render/afp/modca/AbstractPreparedObjectContainer.java
@@ -17,38 +17,35 @@
/* $Id: $ */
-package org.apache.fop.render.afp.goca;
+package org.apache.fop.render.afp.modca;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.List;
-import org.apache.fop.render.afp.modca.AbstractNamedAFPObject;
-import org.apache.fop.render.afp.modca.PreparedAFPObject;
-
/**
- * A base class container of GOCA structured objects
+ * A base container of prepared structured AFP objects
*/
-public abstract class AbstractGraphicsContainer extends AbstractNamedAFPObject
+public abstract class AbstractPreparedObjectContainer extends AbstractNamedAFPObject
implements PreparedAFPObject {
/**
* list of objects contained within this container
*/
- protected List objects = null;
+ protected List/*<PreparedAFPObject>*/ objects = null;
/**
* Default constructor
*/
- protected AbstractGraphicsContainer() {
+ protected AbstractPreparedObjectContainer() {
}
/**
* Named constructor
* @param name the name of the container
*/
- protected AbstractGraphicsContainer(String name) {
+ protected AbstractPreparedObjectContainer(String name) {
super(name);
}
@@ -60,24 +57,28 @@ implements PreparedAFPObject {
super.writeObjects(objects, os);
}
}
+
+ private List/*<PreparedAFPObject>*/ getObjects() {
+ if (objects == null) {
+ this.objects = new java.util.ArrayList/*<PreparedAFPObject>*/();
+ }
+ return this.objects;
+ }
/**
- * Adds a given graphics drawing order to this container
- * @param drawingOrder the graphics drawing order
+ * Adds a given prepared object to this container
+ * @param preparedObject the prepared object
* @return the drawingOrder if it was added, null otherwise
*/
- protected PreparedAFPObject addDrawingOrder(PreparedAFPObject drawingOrder) {
- log.debug(this + " adding " + drawingOrder);
- if (objects == null) {
- this.objects = new java.util.ArrayList();
- }
- objects.add(drawingOrder);
- return drawingOrder;
+ public PreparedAFPObject addObject(PreparedAFPObject preparedObject) {
+ log.debug(this + " adding " + preparedObject);
+ getObjects().add(preparedObject);
+ return preparedObject;
}
/**
* @return the current data length of this container including
- * all enclosed GOCA drawing objects (and their containers)
+ * all enclosed objects (and their containers)
*/
public int getDataLength() {
int dataLen = 0;
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 eac4b778f..ea6ca4b2e 100644
--- a/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java
+++ b/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java
@@ -91,6 +91,9 @@ public abstract class AbstractResourceEnvironmentGroupContainer
}
}
+ /**
+ * @return the resource environment group
+ */
private ResourceEnvironmentGroup getResourceEnvironmentGroup() {
if (resourceEnvironmentGroup == null) {
this.resourceEnvironmentGroup = new ResourceEnvironmentGroup();
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 896771cd7..25dc547fb 100644
--- a/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java
+++ b/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java
@@ -194,9 +194,6 @@ public abstract class AbstractResourceGroupContainer extends AbstractNamedAFPObj
"Invalid compression scheme: " + compression);
}
}
- imageObj.setFullyQualifiedName(
- FullyQualifiedNameTriplet.TYPE_BEGIN_RESOURCE_OBJECT_REF,
- FullyQualifiedNameTriplet.FORMAT_URL, info.getUri());
imageObj.setImageParameters(info.getWidthRes(), info.getHeightRes(),
info.getDataWidth(), info.getDataHeight());
if (info.isColor()) {
@@ -213,9 +210,10 @@ public abstract class AbstractResourceGroupContainer extends AbstractNamedAFPObj
/**
* 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
*/
- protected GraphicsObject createGraphic() {
+ protected GraphicsObject createGraphic(DataObjectInfo info) {
String name = GRAPHIC_NAME_PREFIX
+ StringUtils.lpad(String.valueOf(getResourceCount() + 1), '0', 5);
GraphicsObject graphicsObj = new GraphicsObject(name);
@@ -244,8 +242,13 @@ public abstract class AbstractResourceGroupContainer extends AbstractNamedAFPObj
if (info instanceof ImageObjectInfo) {
dataObject = createImage((ImageObjectInfo)info);
} else {
- dataObject = createGraphic();
+ dataObject = createGraphic(info);
}
+
+ dataObject.setFullyQualifiedName(
+ FullyQualifiedNameTriplet.TYPE_BEGIN_RESOURCE_OBJECT_REF,
+ FullyQualifiedNameTriplet.FORMAT_URL, info.getUri());
+
return dataObject;
}
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 6ec3a6d63..e82371a81 100644
--- a/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java
+++ b/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java
@@ -63,6 +63,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject {
try {
getTripletData();
} catch (IOException e) {
+ log.error("failed to get triplet data");
}
}
if (tripletData != null) {
@@ -228,7 +229,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject {
* object/component type of the object
* @param strucFlgs information on the structure of the object and its container
*/
- public void setObjectClassification(byte objectClass, ObjectTypeRegistry.ObjectType objectType,
+ public void setObjectClassification(byte objectClass, Registry.ObjectType objectType,
StrucFlgs strucFlgs) {
addTriplet(new ObjectClassificationTriplet(objectClass, objectType, strucFlgs));
}
diff --git a/src/java/org/apache/fop/render/afp/modca/DataObjectAccessor.java b/src/java/org/apache/fop/render/afp/modca/DataObjectAccessor.java
new file mode 100644
index 000000000..c8c55bebc
--- /dev/null
+++ b/src/java/org/apache/fop/render/afp/modca/DataObjectAccessor.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id: $ */
+
+package org.apache.fop.render.afp.modca;
+
+/**
+ * A common interface of ResourceObject and ContainerObject
+ */
+public interface DataObjectAccessor extends AFPDataStreamWriter {
+
+ /**
+ * @return the actual data object referenced in this envelope
+ */
+ AbstractNamedAFPObject getDataObject();
+}
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 7e5f12877..823353375 100644
--- a/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java
+++ b/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java
@@ -127,13 +127,13 @@ public class GraphicsObject extends AbstractDataObject {
/**
* {@inheritDoc}
*/
- protected PreparedAFPObject addDrawingOrder(PreparedAFPObject drawingOrder) {
+ public PreparedAFPObject addObject(PreparedAFPObject drawingOrder) {
if (graphicsData == null
|| (graphicsData.getDataLength() + drawingOrder.getDataLength())
>= GraphicsData.MAX_DATA_LEN) {
newData();
}
- graphicsData.addDrawingOrder(drawingOrder);
+ graphicsData.addObject(drawingOrder);
return drawingOrder;
}
@@ -154,7 +154,7 @@ public class GraphicsObject extends AbstractDataObject {
*/
private GraphicsData newData() {
this.graphicsData = new GraphicsData();
- super.addDrawingOrder(graphicsData);
+ super.addObject(graphicsData);
return graphicsData;
}
@@ -163,7 +163,7 @@ public class GraphicsObject extends AbstractDataObject {
* @param col the active color to use
*/
public void setColor(Color col) {
- addDrawingOrder(new GraphicsSetProcessColor(col));
+ addObject(new GraphicsSetProcessColor(col));
}
/**
@@ -171,7 +171,7 @@ public class GraphicsObject extends AbstractDataObject {
* @param coords the x and y coordinates of the current position
*/
public void setCurrentPosition(int[] coords) {
- addDrawingOrder(new GraphicsSetCurrentPosition(coords));
+ addObject(new GraphicsSetCurrentPosition(coords));
}
/**
@@ -180,7 +180,7 @@ public class GraphicsObject extends AbstractDataObject {
*/
public void setLineWidth(int multiplier) {
GraphicsSetLineWidth lw = new GraphicsSetLineWidth(multiplier);
- addDrawingOrder(lw);
+ addObject(lw);
}
/**
@@ -189,7 +189,7 @@ public class GraphicsObject extends AbstractDataObject {
*/
public void setLineType(byte type) {
GraphicsSetLineType lt = new GraphicsSetLineType(type);
- addDrawingOrder(lt);
+ addObject(lt);
}
/**
@@ -201,7 +201,7 @@ public class GraphicsObject extends AbstractDataObject {
fill ? GraphicsSetPatternSymbol.SOLID_FILL
: GraphicsSetPatternSymbol.NO_FILL
);
- addDrawingOrder(pat);
+ addObject(pat);
}
/**
@@ -209,7 +209,7 @@ public class GraphicsObject extends AbstractDataObject {
* @param fontReference the character set (font) reference
*/
public void setCharacterSet(int fontReference) {
- addDrawingOrder(new GraphicsSetCharacterSet(fontReference));
+ addObject(new GraphicsSetCharacterSet(fontReference));
}
/**
@@ -217,7 +217,7 @@ public class GraphicsObject extends AbstractDataObject {
* @param coords the x/y coordinates (can be a series)
*/
public void addLine(int[] coords) {
- addDrawingOrder(new GraphicsLine(coords));
+ addObject(new GraphicsLine(coords));
}
/**
@@ -225,7 +225,7 @@ public class GraphicsObject extends AbstractDataObject {
* @param coords the x/y coordinates
*/
public void addBox(int[] coords) {
- addDrawingOrder(new GraphicsBox(coords));
+ addObject(new GraphicsBox(coords));
}
/**
@@ -233,7 +233,7 @@ public class GraphicsObject extends AbstractDataObject {
* @param coords the x/y coordinates
*/
public void addFillet(int[] coords) {
- addDrawingOrder(new GraphicsFillet(coords));
+ addObject(new GraphicsFillet(coords));
}
/**
@@ -244,7 +244,7 @@ public class GraphicsObject extends AbstractDataObject {
* @param ymaj the maximum value of the y coordinate
*/
public void setArcParams(int xmaj, int ymin, int xmin, int ymaj) {
- addDrawingOrder(new GraphicsSetArcParameters(xmaj, ymin, xmin, ymaj));
+ addObject(new GraphicsSetArcParameters(xmaj, ymin, xmin, ymaj));
}
/**
@@ -255,7 +255,7 @@ public class GraphicsObject extends AbstractDataObject {
* @param mhr the fractional portion of the multiplier
*/
public void addFullArc(int x, int y, int mh, int mhr) {
- addDrawingOrder(new GraphicsFullArc(x, y, mh, mhr));
+ addObject(new GraphicsFullArc(x, y, mh, mhr));
}
/**
@@ -264,16 +264,16 @@ public class GraphicsObject extends AbstractDataObject {
* @param y the y coordinate
* @param width the image width
* @param height the image height
- * @param rawData the image data
+ * @param imgData the image data
*/
- public void addImage(int x, int y, int width, int height, byte[] rawData) {
- addDrawingOrder(new GraphicsImageBegin(x, y, width, height));
+ public void addImage(int x, int y, int width, int height, byte[] imgData) {
+ addObject(new GraphicsImageBegin(x, y, width, height));
for (int startIndex = 0;
- startIndex <= rawData.length;
+ startIndex <= imgData.length;
startIndex += GraphicsImageData.MAX_DATA_LEN) {
- addDrawingOrder(new GraphicsImageData(rawData, startIndex));
+ addObject(new GraphicsImageData(imgData, startIndex));
}
- addDrawingOrder(new GraphicsImageEnd());
+ addObject(new GraphicsImageEnd());
}
/**
@@ -283,7 +283,7 @@ public class GraphicsObject extends AbstractDataObject {
* @param y the y coordinate
*/
public void addString(String str, int x, int y) {
- addDrawingOrder(new GraphicsString(str, x, y));
+ addObject(new GraphicsString(str, x, y));
}
/**
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 799578966..92244d66a 100644
--- a/src/java/org/apache/fop/render/afp/modca/IncludeObject.java
+++ b/src/java/org/apache/fop/render/afp/modca/IncludeObject.java
@@ -19,7 +19,6 @@
package org.apache.fop.render.afp.modca;
-import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
@@ -40,7 +39,7 @@ import org.apache.fop.render.afp.tools.BinaryUtils;
* data objects in the page segment.
* </p>
*/
-public class IncludeObject extends AbstractNamedAFPObject {
+public class IncludeObject extends AbstractNamedAFPObject implements DataObjectAccessor {
/**
* the include object is of type page segment
@@ -96,45 +95,69 @@ public class IncludeObject extends AbstractNamedAFPObject {
* The Y-axis origin defined in the object
*/
private int yContentOffset = -1;
-
-// /**
-// * The object referenced by this include object
-// */
-// private Resource resourceObj = null;
-
+
/**
- * the level at which this resource object resides
+ * the resource info
*/
- private ResourceInfo level = null;
+ private ResourceInfo resourceInfo = null;
/**
* the referenced data object
*/
- private AbstractNamedAFPObject dataObj = null;
+ private DataObjectAccessor dataObjectAccessor = null;
/**
* Constructor for the include object with the specified name, the name must
* be a fixed length of eight characters and is the name of the referenced
* object.
*
- * @param resourceObj the resource object wrapper
+ * @param name the name of this include object
+ * @param dataObjectAccessor the data object accessor
+ * @param resourceInfo the resource information
*/
- public IncludeObject(AbstractNamedAFPObject dataObj) {
- super(dataObj.getName());
- this.dataObj = dataObj;
-// AbstractStructuredAFPObject referencedObject = resourceObj.getReferencedObject();
- if (dataObj instanceof ImageObject) {
+ public IncludeObject(String name, DataObjectAccessor dataObjectAccessor,
+ ResourceInfo resourceInfo) {
+ super(name);
+
+ setDataObjectAccessor(dataObjectAccessor);
+ setResourceInfo(resourceInfo);
+ }
+
+ /**
+ * Sets the data object accessor and the object type
+ * @param dataObjectAccessor the data object accessor
+ */
+ private void setDataObjectAccessor(DataObjectAccessor dataObjectAccessor) {
+ this.dataObjectAccessor = dataObjectAccessor;
+
+ AbstractNamedAFPObject dataObject = dataObjectAccessor.getDataObject();
+
+ if (dataObject instanceof ImageObject) {
this.objectType = TYPE_IMAGE;
- } else if (dataObj instanceof GraphicsObject) {
+ } else if (dataObject instanceof GraphicsObject) {
this.objectType = TYPE_GRAPHIC;
- } else if (dataObj instanceof PageSegment) {
+ } else if (dataObject instanceof PageSegment) {
this.objectType = TYPE_PAGE_SEGMENT;
} else {
this.objectType = TYPE_OTHER;
}
+ }
+ /**
+ * @return the data object accessor
+ */
+ private DataObjectAccessor getDataObjectAccessor() {
+ return this.dataObjectAccessor;
+ }
+
+ /**
+ * Sets the resource level for this resource object
+ * @param resourceInfo the resource information
+ */
+ private void setResourceInfo(ResourceInfo resourceInfo) {
+ this.resourceInfo = resourceInfo;
+
// set data object reference triplet
- ResourceInfo resourceInfo = getResourceInfo();
if (resourceInfo != null && resourceInfo.isExternal()) {
String dest = resourceInfo.getExternalResourceGroupDest();
super.setFullyQualifiedName(
@@ -143,38 +166,22 @@ public class IncludeObject extends AbstractNamedAFPObject {
} else {
super.setFullyQualifiedName(
FullyQualifiedNameTriplet.TYPE_DATA_OBJECT_INTERNAL_RESOURCE_REF,
- FullyQualifiedNameTriplet.FORMAT_CHARSTR, dataObj.getName());
+ FullyQualifiedNameTriplet.FORMAT_CHARSTR, getDataObject().getName());
}
}
-
- /**
- * Sets the resource level for this resource object
- * @param level the resource level
- */
- public void setResourceInfo(ResourceInfo level) {
- this.level = level;
- }
/**
* @return the resource info of this resource object
*/
public ResourceInfo getResourceInfo() {
- return this.level;
+ return this.resourceInfo;
}
-// /**
-// * @return the resource container object referenced by this include object
-// */
-// public Resource getResource() {
-// return this.resourceObj;
-// }
-
/**
* @return the actual resource data object referenced by this include object
*/
- public AbstractStructuredAFPObject getReferencedObject() {
- return this.dataObj;
- //getResource().getReferencedObject();
+ public AbstractNamedAFPObject getDataObject() {
+ return getDataObjectAccessor().getDataObject();
}
/**
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 3ccfd450a..01db7b9d8 100644
--- a/src/java/org/apache/fop/render/afp/modca/MapDataResource.java
+++ b/src/java/org/apache/fop/render/afp/modca/MapDataResource.java
@@ -41,12 +41,12 @@ public class MapDataResource extends AbstractStructuredAFPObject {
/**
* Main constructor
- * @param obj a map data resource for a given structured AFP object
+ * @param includeObj a map data resource for a given structured AFP object
*/
public MapDataResource(IncludeObject includeObj) {
- AbstractStructuredAFPObject refObj = includeObj.getReferencedObject();
+ AbstractStructuredAFPObject dataObject = includeObj.getDataObject();
// ResourceObject resObj = includeObj.getResource();
- String fqName = refObj.getFullyQualifiedName();
+ String fqName = dataObject.getFullyQualifiedName();
ResourceInfo resourceInfo = includeObj.getResourceInfo();
if (fqName != null) {
if (resourceInfo.isExternal()) {
@@ -75,7 +75,7 @@ public class MapDataResource extends AbstractStructuredAFPObject {
dataInContainer, containerHasOEG, dataInOCD
);
- //TODO: AC - fix
+ //
// super.setObjectClassification(
// ObjectClassificationTriplet.CLASS_TIME_VARIANT_PRESENTATION_OBJECT,
// objectType, strucFlgs);
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 59e770d6d..909476772 100644
--- a/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java
+++ b/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java
@@ -31,40 +31,56 @@ 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 {
+public class ObjectContainer extends AbstractPreparedAFPObject implements DataObjectAccessor {
+
+ /**
+ * the data object
+ */
+ private AbstractDataObject dataObj = null;
/**
- * the object container data
+ * the object data
*/
- private ObjectContainerData objectContainerData;
-
+ private byte[] objectData = null;
+
/**
* Main constructor
* @param name the name of this object container
- * @param dataObj the data object to reside within this object container
- * @param info the data object info about the data object
+ * @param dataObjectInfo the data object info
*/
- public ObjectContainer(String name, AbstractDataObject dataObj, DataObjectInfo info) {
+ public ObjectContainer(String name, DataObjectInfo dataObjectInfo) {
super(name);
-
final boolean dataInContainer = true;
final boolean containerHasOEG = false;
final boolean dataInOCD = true;
StrucFlgs strucFlgs = new StrucFlgs(
dataInContainer, containerHasOEG, dataInOCD
);
- ObjectTypeRegistry registry = ObjectTypeRegistry.getInstance();
- ObjectTypeRegistry.ObjectType entry = registry.getObjectType(info);
- super.setObjectClassification(
- ObjectClassificationTriplet.CLASS_TIME_VARIANT_PRESENTATION_OBJECT,
- entry, strucFlgs
- );
-
- // write data object to object container data
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- // TODO: AC - fix
-// dataObj.writeDataStream(bos);
- this.objectContainerData = new ObjectContainerData(bos.toByteArray());
+ Registry registry = Registry.getInstance();
+ Registry.ObjectType objectType = registry.getObjectType(dataObjectInfo);
+ if (objectType != null) {
+ super.setObjectClassification(
+ ObjectClassificationTriplet.CLASS_TIME_VARIANT_PRESENTATION_OBJECT,
+ objectType, strucFlgs
+ );
+ } else {
+ log.warn("no object type for " + dataObjectInfo.getUri());
+ }
+ }
+
+ /**
+ * 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;
}
/**
@@ -73,8 +89,13 @@ public class ObjectContainer extends AbstractNamedAFPObject {
protected void writeStart(OutputStream os) throws IOException {
super.writeStart(os);
+ // create object data from data object
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ dataObj.writeDataStream(bos);
+ this.objectData = bos.toByteArray();
+
// Set the total record length
- byte[] len = BinaryUtils.convert(18 + getTripletDataLength(), 2);
+ byte[] len = BinaryUtils.convert(18 + getTripletDataLength() + objectData.length, 2);
byte[] data = new byte[] {
0x5A, // Structured field identifier
len[0], // Length byte 1
@@ -92,23 +113,24 @@ public class ObjectContainer extends AbstractNamedAFPObject {
nameBytes[4],
nameBytes[5],
nameBytes[6],
- nameBytes[7],
- 0x00, // Reserved
- 0x00, // Reserved
+ nameBytes[7]
};
os.write(data);
}
-
+
/**
* {@inheritDoc}
*/
protected void writeContent(OutputStream os) throws IOException {
- super.writeContent(os); // write triplets
- if (objectContainerData != null) {
+ super.writeContent(os);
+
+ // write out object data in chunks of object container data
+ for (int i = 0; i <= objectData.length; i += ObjectContainerData.MAX_DATA_LEN) {
+ ObjectContainerData objectContainerData = new ObjectContainerData(objectData, i);
objectContainerData.writeDataStream(os);
}
}
-
+
/**
* {@inheritDoc}
*/
@@ -135,37 +157,50 @@ public class ObjectContainer extends AbstractNamedAFPObject {
os.write(data);
}
- private class ObjectContainerData extends AbstractStructuredAFPObject {
- /** the object data */
- private byte[] objData = null;
+ /**
+ * An Object Container Data holds a chunk of the data object
+ */
+ private class ObjectContainerData extends AbstractPreparedAFPObject {
+
+ /**
+ * 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) {
- this.objData = objData;
+ public ObjectContainerData(byte[] objData, int startIndex) {
+ int dataLen = MAX_DATA_LEN;
+ if (startIndex + MAX_DATA_LEN >= objData.length) {
+ dataLen = objData.length - startIndex - 1;
+ }
+ byte[] len = BinaryUtils.convert(8 + dataLen, 2);
+ byte[] data = new byte[9 + dataLen];
+ data[0] = 0x5A; // Structured field identifier
+ data[1] = len[0]; // Length byte 1
+ 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[6] = 0x00; // Flags
+ data[7] = 0x00; // Reserved
+ data[8] = 0x00; // Reserved
+
+ // copy object data chunk
+ System.arraycopy(data, startIndex, data, 9, dataLen);
+
+ super.setData(data);
}
/**
* {@inheritDoc}
*/
- public void writeDataStream(OutputStream os) throws IOException {
- // Set the total record length
- byte[] len = BinaryUtils.convert(8 + objData.length, 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)0xEE, // Structured field id byte 2
- (byte)0x92, // Structured field id byte 3
- 0x00, // Flags
- 0x00, // Reserved
- 0x00, // Reserved
- };
-
- os.write(data);
+ public String toString() {
+ return "ObjectContainerData("
+ + (data != null ? "" + (data.length - 2) : "null")
+ + ")";
}
}
}
diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectTypeRegistry.java b/src/java/org/apache/fop/render/afp/modca/Registry.java
index 278a56732..c81b4a289 100644
--- a/src/java/org/apache/fop/render/afp/modca/ObjectTypeRegistry.java
+++ b/src/java/org/apache/fop/render/afp/modca/Registry.java
@@ -19,18 +19,17 @@
package org.apache.fop.render.afp.modca;
-import java.io.UnsupportedEncodingException;
import java.util.Collections;
-import org.apache.commons.logging.LogFactory;
import org.apache.fop.render.afp.DataObjectInfo;
import org.apache.fop.render.afp.ImageObjectInfo;
import org.apache.xmlgraphics.util.MimeConstants;
/**
- * MOD:CA object type registry
+ * MOD:CA Registry of object types
*/
-public final class ObjectTypeRegistry {
+public final class Registry {
+
/** IOB supported object types */
private static final byte COMPID_GIF = 22;
private static final byte COMPID_JFIF = 23; // jpeg file interchange format
@@ -42,26 +41,26 @@ public final class ObjectTypeRegistry {
private static final byte COMPID_TIFF = 14;
/** mime type entry mapping */
- private java.util.Map/*<String, ObjectTypeRegistry.Entry>*/ mimeEntryMap
+ private java.util.Map/*<String, Registry.ObjectType>*/ mimeEntryMap
= Collections.synchronizedMap(
- Collections.unmodifiableMap(
- new java.util.HashMap/*<String, ObjectTypeRegistry.Entry>*/()));
+ new java.util.HashMap/*<String, Registry.ObjectType>*/());
- private static ObjectTypeRegistry instance = null;
+ /** singleton instance */
+ private static Registry instance = null;
/**
- * @return a single instance of Registry
+ * @return a single instance of an ObjectTypeRegistry
*/
- public static ObjectTypeRegistry getInstance() {
- synchronized (instance) {
+ public static Registry getInstance() {
+ synchronized (Registry.class) {
if (instance == null) {
- instance = new ObjectTypeRegistry();
- }
+ instance = new Registry();
+ }
}
return instance;
}
- private ObjectTypeRegistry() {
+ private Registry() {
init();
}
@@ -122,18 +121,17 @@ public final class ObjectTypeRegistry {
}
/**
- * Returns the registry Entry for a given data object info
+ * Returns the Registry ObjectType for a given data object info
*
- * @param info
- * the data object info
- * @return the registry Entry for a given data object info
+ * @param dataObjectInfo the data object info
+ * @return the Registry ObjectType for a given data object info
*/
- public ObjectType getObjectType(DataObjectInfo info) {
+ public Registry.ObjectType getObjectType(DataObjectInfo dataObjectInfo) {
ObjectType entry = null;
- if (info instanceof ImageObjectInfo) {
- ImageObjectInfo imageInfo = (ImageObjectInfo)info;
+ if (dataObjectInfo instanceof ImageObjectInfo) {
+ ImageObjectInfo imageInfo = (ImageObjectInfo)dataObjectInfo;
String mimeType = imageInfo.getMimeType();
- entry = (ObjectType)mimeEntryMap.get(mimeType);
+ entry = (Registry.ObjectType)mimeEntryMap.get(mimeType);
}
return entry;
}
@@ -144,30 +142,21 @@ public final class ObjectTypeRegistry {
public class ObjectType {
private byte componentId;
private byte[] oid;
- private byte[] name;
+ private String name;
private boolean canBeIncluded;
/**
* Main constructor
* @param componentId the component id of this object type
* @param oid the object id of this object type
- * @param objectTypeName the object type name
+ * @param name the object type name
* @param canBeIncluded true if this object can be included with an IOB structured field
*/
- public ObjectType(byte componentId, byte[] oid, String objectTypeName,
+ public ObjectType(byte componentId, byte[] oid, String name,
boolean canBeIncluded) {
this.componentId = componentId;
this.oid = oid;
- try {
- this.name = objectTypeName.getBytes(AFPConstants.EBCIDIC_ENCODING);
- } catch (UnsupportedEncodingException e) {
- // should never happen!
- LogFactory.getLog("org.apache.fop.render.afp.modca.Registry.Entry").error(
- "character encoding error occurred on componentId "
- + componentId
- + " : "
- + e.getMessage());
- }
+ this.name = name;
this.canBeIncluded = canBeIncluded;
}
@@ -183,7 +172,7 @@ public final class ObjectTypeRegistry {
/**
* @return the object type name for the given componentId
*/
- public byte[] getName() {
+ public String getName() {
return this.name;
}
@@ -200,5 +189,12 @@ public final class ObjectTypeRegistry {
public boolean canBeIncluded() {
return this.canBeIncluded;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString() {
+ return this.getName();
+ }
}
}
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 38b9524e6..18026a6b3 100644
--- a/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java
+++ b/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java
@@ -30,7 +30,6 @@ import org.apache.fop.render.afp.ImageObjectInfo;
import org.apache.fop.render.afp.ResourceInfo;
import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet;
import org.apache.fop.render.afp.tools.StringUtils;
-import org.apache.xmlgraphics.image.codec.tiff.TIFFImage;
/**
* A Resource Group contains a set of overlays.
@@ -45,7 +44,7 @@ public final class ResourceGroup extends AbstractNamedAFPObject {
/**
* Mapping of resource uri to data resource object (image/graphic)
*/
- private Map/*<String,IncludeObject>*/ resourceMap = null;
+ private Map/*<String, DataObjectAccessor>*/ resourceMap = null;
/**
* This resource groups container
@@ -64,6 +63,7 @@ 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
+ * @param container the parent resource group container
*/
public ResourceGroup(String name, AbstractResourceGroupContainer container) {
super(name);
@@ -71,8 +71,7 @@ public final class ResourceGroup extends AbstractNamedAFPObject {
}
private static final String RESOURCE_NAME_PREFIX = "RES";
- private static final String INCLUDE_NAME_PREFIX = "INC";
-
+
/**
* Helper method to create a new resource object in the current container and to return
* the object.
@@ -84,68 +83,50 @@ public final class ResourceGroup extends AbstractNamedAFPObject {
ResourceObject resource = new ResourceObject(name);
return resource;
}
-
-// /**
-// * Helper method to create a new resource object in the current container and to return
-// * the object.
-// * @return a newly created resource object
-// */
-// private IncludeObject createIncludeObject() {
-// String name = INCLUDE_NAME_PREFIX
-// + StringUtils.lpad(String.valueOf(getResourceCount() + 1), '0', 5);
-// IncludeObject includeObj = new IncludeObject(name);
-// return includeObj;
-// }
+
+ private AbstractResourceGroupContainer getContainer() {
+ return this.container;
+ }
/**
* Creates a data object in this resource group
- * @param info the data object info
+ * @param dataObjectInfo the data object info
* @return an include object reference
*/
- public IncludeObject createObject(DataObjectInfo info) {
- IncludeObject includeObj = (IncludeObject)getResourceMap().get(info.getUri());
- if (includeObj == null) {
- AbstractDataObject dataObj;
- if (info instanceof ImageObjectInfo) {
- dataObj = container.createImage((ImageObjectInfo)info);
+ public IncludeObject createObject(DataObjectInfo dataObjectInfo) {
+ DataObjectAccessor dataObjectAccessor
+ = (DataObjectAccessor)getResourceMap().get(dataObjectInfo.getUri());
+ ResourceInfo resourceInfo = dataObjectInfo.getResourceInfo();
+ AbstractDataObject dataObj;
+ if (dataObjectAccessor == null) {
+ if (dataObjectInfo instanceof ImageObjectInfo) {
+ dataObj = getContainer().createImage((ImageObjectInfo)dataObjectInfo);
} else {
- dataObj = container.createGraphic();
+ dataObj = getContainer().createGraphic(dataObjectInfo);
}
- ResourceInfo resourceInfo = info.getResourceInfo();
- String resourceName = resourceInfo.getName();
- if (resourceInfo.isExternal()) {
- ObjectContainer objectContainer = new ObjectContainer(resourceName, dataObj, info);
- } else {
-
- }
-
- // Wrap the data object in a page segment
- PageSegment pageSegment = container.createPageSegment();
- pageSegment.addObject(dataObj);
+ dataObj.setViewport(dataObjectInfo.getX(), dataObjectInfo.getY(),
+ dataObjectInfo.getWidth(), dataObjectInfo.getHeight(),
+ dataObjectInfo.getWidthRes(), dataObjectInfo.getHeightRes(),
+ dataObjectInfo.getRotation());
+ String resourceName = resourceInfo.getName();
+ ObjectContainer objectContainer = new ObjectContainer(resourceName, dataObjectInfo);
+ objectContainer.setDataObject(dataObj);
- // TODO: AC - rotation?
- int rotation = 0;
- dataObj.setViewport(info.getX(), info.getY(),
- info.getWidth(), info.getHeight(),
- info.getWidthRes(), info.getHeightRes(), rotation);
-
- includeObj.setResourceInfo(resourceInfo);
-
- // If resource is to be stored externally,
- // wrap the page segment in a resource object
+ // When externally located, Wrap data object in a resource object
if (resourceInfo.isExternal()) {
- ResourceObject resource = createResourceObject();
- resource.setReferencedObject(pageSegment);
- includeObj = new IncludeObject(resource);
- } else {
- includeObj = new IncludeObject(pageSegment);
+ ResourceObject resourceObj = createResourceObject();
+ resourceObj.setObjectContainer(objectContainer);
+ dataObjectAccessor = resourceObj;
+ } else { // no wrappers just container
+ dataObjectAccessor = objectContainer;
}
- // Add include object to resource map
- getResourceMap().put(info.getUri(), includeObj);
+ getResourceMap().put(dataObjectInfo.getUri(), dataObjectAccessor);
}
- //includeObj.setObjectAreaSize(params.getX(), params.getY());
+ AbstractNamedAFPObject dataObject = dataObjectAccessor.getDataObject();
+ String name = dataObject.getName();
+ IncludeObject includeObj = new IncludeObject(name, dataObjectAccessor, resourceInfo);
return includeObj;
}
@@ -174,9 +155,9 @@ public final class ResourceGroup extends AbstractNamedAFPObject {
* Returns the list of resources
* @return the list of resources
*/
- public Map/*<String,AbstractAFPObject>*/ getResourceMap() {
+ public Map/*<String, DataObjectAccessor>*/ getResourceMap() {
if (resourceMap == null) {
- resourceMap = new java.util.HashMap/*<String,AbstractAFPObject>*/();
+ resourceMap = new java.util.HashMap/*<String, DataObjectAccessor>*/();
}
return resourceMap;
}
@@ -189,9 +170,8 @@ public final class ResourceGroup extends AbstractNamedAFPObject {
Collection includes = resourceMap.values();
Iterator it = includes.iterator();
while (it.hasNext()) {
- IncludeObject includeObj = (IncludeObject)it.next();
- AbstractStructuredAFPObject obj = includeObj.getReferencedObject();
- obj.writeDataStream(os);
+ DataObjectAccessor dataObjectAccessor = (DataObjectAccessor)it.next();
+ dataObjectAccessor.writeDataStream(os);
}
}
}
@@ -240,6 +220,6 @@ public final class ResourceGroup extends AbstractNamedAFPObject {
* {@inheritDoc}
*/
public String toString() {
- return this.name + " " + this.resourceMap;
+ return this.name + " " + 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 c0d4d88df..57d7f0105 100644
--- a/src/java/org/apache/fop/render/afp/modca/ResourceObject.java
+++ b/src/java/org/apache/fop/render/afp/modca/ResourceObject.java
@@ -22,7 +22,6 @@ package org.apache.fop.render.afp.modca;
import java.io.IOException;
import java.io.OutputStream;
-import org.apache.fop.render.afp.ResourceInfo;
import org.apache.fop.render.afp.modca.triplets.Triplet;
import org.apache.fop.render.afp.tools.BinaryUtils;
@@ -30,34 +29,17 @@ 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 {
+public class ResourceObject extends AbstractPreparedAFPObject implements DataObjectAccessor {
/**
- * Resource object types
+ * the object container of this resource object
*/
- 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;
-
- /**
- * the referenced data object
- */
- private AbstractNamedAFPObject dataObj = null;
+ private ObjectContainer objectContainer;
/**
* Default constructor
*
* @param name the name of this resource (reference id)
- * @param dataObj the resource object to be added
*/
public ResourceObject(String name) {
super(name);
@@ -65,32 +47,41 @@ public class ResourceObject extends AbstractPreparedAFPObject {
/**
* Sets the data object referenced by this resource object
- * @param dataObj the data object
+ * @param objectContainer the object container
*/
- public void setReferencedObject(AbstractNamedAFPObject dataObj) {
- this.dataObj = dataObj;
- setResourceObjectType(dataObj);
+ public void setObjectContainer(ObjectContainer objectContainer) {
+ this.objectContainer = objectContainer;
+ setResourceObjectType(objectContainer);
}
-
+
/**
- * @return the resource object contained in this envelope
+ * {@inheritDoc}
*/
- public AbstractNamedAFPObject getReferencedObject() {
- return this.dataObj;
+ public AbstractNamedAFPObject getDataObject() {
+ if (objectContainer != null) {
+ return objectContainer.getDataObject();
+ }
+ return null;
}
- private void setResourceObjectType(AbstractNamedAFPObject resourceObj) {
+ /**
+ * Sets the resource object type
+ * @param resourceObj the resource object
+ */
+ public void setResourceObjectType(AbstractNamedAFPObject resourceObj) {
byte type;
- if (resourceObj instanceof ImageObject) {
- type = IMAGE_OBJECT;
+ if (resourceObj instanceof ObjectContainer) {
+ type = ResourceObjectTypeTriplet.OBJECT_CONTAINER;
+ } else if (resourceObj instanceof ImageObject) {
+ type = ResourceObjectTypeTriplet.IMAGE_OBJECT;
} else if (resourceObj instanceof GraphicsObject) {
- type = GRAPHICS_OBJECT;
+ type = ResourceObjectTypeTriplet.GRAPHICS_OBJECT;
} else if (resourceObj instanceof Document) {
- type = DOCUMENT_OBJECT;
+ type = ResourceObjectTypeTriplet.DOCUMENT_OBJECT;
} else if (resourceObj instanceof PageSegment) {
- type = PAGE_SEGMENT_OBJECT;
+ type = ResourceObjectTypeTriplet.PAGE_SEGMENT_OBJECT;
} else if (resourceObj instanceof Overlay) {
- type = OVERLAY_OBJECT;
+ type = ResourceObjectTypeTriplet.OVERLAY_OBJECT;
} else {
throw new UnsupportedOperationException(
"Unsupported resource object type " + resourceObj);
@@ -135,8 +126,8 @@ public class ResourceObject extends AbstractPreparedAFPObject {
*/
protected void writeContent(OutputStream os) throws IOException {
super.writeContent(os); // write triplets
- if (dataObj != null) {
- dataObj.writeDataStream(os);
+ if (objectContainer != null) {
+ objectContainer.writeDataStream(os);
}
}
@@ -178,6 +169,22 @@ public class ResourceObject extends AbstractPreparedAFPObject {
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/triplets/FullyQualifiedNameTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/FullyQualifiedNameTriplet.java
index e1a36b4da..21dbaa99f 100644
--- a/src/java/org/apache/fop/render/afp/modca/triplets/FullyQualifiedNameTriplet.java
+++ b/src/java/org/apache/fop/render/afp/modca/triplets/FullyQualifiedNameTriplet.java
@@ -96,12 +96,15 @@ public class FullyQualifiedNameTriplet extends Triplet {
*/
public FullyQualifiedNameTriplet(byte type, byte format, byte[] name) {
super(FULLY_QUALIFIED_NAME);
+
this.nameBytes = name;
- super.data = new byte[2 + name.length];
+ byte[] data = new byte[2 + name.length];
data[0] = type;
data[1] = format;
// FQName
System.arraycopy(name, 0, data, 2, name.length);
+
+ super.setData(data);
}
/**
diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/MeasurementUnitsTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/MeasurementUnitsTriplet.java
index e99045292..7350db27f 100644
--- a/src/java/org/apache/fop/render/afp/modca/triplets/MeasurementUnitsTriplet.java
+++ b/src/java/org/apache/fop/render/afp/modca/triplets/MeasurementUnitsTriplet.java
@@ -38,7 +38,7 @@ public class MeasurementUnitsTriplet extends Triplet {
//TODO: units correct?
byte[] xUnits = BinaryUtils.convert(1, 2);
byte[] yUnits = BinaryUtils.convert(1, 2);
- super.data = new byte[] {
+ byte[] data = new byte[] {
TEN_INCHES, // XoaBase
TEN_INCHES, // YoaBase
xUnits[0], // XoaUnits (x units per unit base)
@@ -46,5 +46,6 @@ public class MeasurementUnitsTriplet extends Triplet {
yUnits[0], // YoaUnits (y units per unit base)
yUnits[1]
};
+ super.setData(data);
}
}
diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/ObjectAreaSizeTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/ObjectAreaSizeTriplet.java
index bd026763d..caf6e86fa 100644
--- a/src/java/org/apache/fop/render/afp/modca/triplets/ObjectAreaSizeTriplet.java
+++ b/src/java/org/apache/fop/render/afp/modca/triplets/ObjectAreaSizeTriplet.java
@@ -36,7 +36,7 @@ public class ObjectAreaSizeTriplet extends Triplet {
super(Triplet.OBJECT_AREA_SIZE);
byte[] xOASize = BinaryUtils.convert(x, 3);
byte[] yOASize = BinaryUtils.convert(y, 3);
- super.data = new byte[] {
+ byte[] data = new byte[] {
0x02, // SizeType
xOASize[0], // XoaSize - Object area extent for X axis
xOASize[1],
@@ -45,5 +45,6 @@ public class ObjectAreaSizeTriplet extends Triplet {
yOASize[1],
yOASize[2]
};
+ super.setData(data);
}
}
diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/ObjectClassificationTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/ObjectClassificationTriplet.java
index 28c3dca4e..45e08eaab 100644
--- a/src/java/org/apache/fop/render/afp/modca/triplets/ObjectClassificationTriplet.java
+++ b/src/java/org/apache/fop/render/afp/modca/triplets/ObjectClassificationTriplet.java
@@ -19,7 +19,11 @@
package org.apache.fop.render.afp.modca.triplets;
-import org.apache.fop.render.afp.modca.ObjectTypeRegistry;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.fop.render.afp.modca.AFPConstants;
+import org.apache.fop.render.afp.modca.Registry;
+import org.apache.fop.render.afp.tools.StringUtils;
/**
* The Object Classification is used to classify and identify object data.
@@ -65,15 +69,45 @@ public class ObjectClassificationTriplet extends Triplet {
*
* @param objectClass
* the object class type
- * @param entry
+ * @param objectType
* the object type registry entry
* @param strucFlgs
* the structured flags pertaining to this object classification triplet
*/
- public ObjectClassificationTriplet(byte objectClass, ObjectTypeRegistry.ObjectType entry,
+ public ObjectClassificationTriplet(byte objectClass, Registry.ObjectType objectType,
StrucFlgs strucFlgs) {
+ // no object level or company name specified
+ this(objectClass, objectType, strucFlgs, null, null);
+ }
+
+
+ private static final int OBJECT_LEVEL_LEN = 8;
+ private static final int OBJECT_TYPE_NAME_LEN = 32;
+ private static final int COMPANY_NAME_LEN = 32;
+
+ /**
+ * Fully parameterized constructor
+ *
+ * @param objectClass
+ * the object class type
+ * @param objectType
+ * the object type registry entry
+ * @param strucFlgs
+ * the structured flags pertaining to this object classification triplet
+ * @param objLev
+ * the release level or version number of the object type
+ * @param compName
+ * the name of the company or organization that owns the object definition
+ */
+ public ObjectClassificationTriplet(byte objectClass, Registry.ObjectType objectType,
+ StrucFlgs strucFlgs, String objLev, String compName) {
super(OBJECT_CLASSIFICATION);
- byte[] data = new byte[93];
+
+ if (objectType == null) {
+ throw new UnsupportedOperationException("MO:DCA Registry object type is null");
+ }
+
+ byte[] data = new byte[94];
data[0] = 0x00; // reserved (must be zero)
data[1] = objectClass; // ObjClass
data[2] = 0x00; // reserved (must be zero)
@@ -81,21 +115,41 @@ public class ObjectClassificationTriplet extends Triplet {
// StrucFlgs - Information on the structure of the object container
data[4] = strucFlgs.getValue();
data[5] = 0x00; // StrucFlgs
-
- if (entry == null) {
- throw new UnsupportedOperationException("Unknown registry entry");
- }
-
- byte[] oid = entry.getOID();
+
+ byte[] oid = objectType.getOID();
// RegObjId - MOD:CA-registered ASN.1 OID for object type (8-23)
System.arraycopy(oid, 0, data, 6, oid.length);
- byte[] objectTypeName = entry.getName();
// ObjTpName - name of object type (24-55)
- System.arraycopy(objectTypeName, 0, data, 22, objectTypeName.length);
+ byte[] objTpName;
+ try {
+ objTpName = StringUtils.rpad(objectType.getName(), ' ', OBJECT_TYPE_NAME_LEN).getBytes(
+ AFPConstants.EBCIDIC_ENCODING);
+ System.arraycopy(objTpName, 0, data, 22, objTpName.length);
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalArgumentException("an encoding exception occurred");
+ }
- // ObjLev (not specified) - Release level or version number of object type (56-63)
-
- // CompName (not specified) - Name of company or org that owns object definition (64-95)
+ // ObjLev - release level or version number of object type (56-63)
+ byte[] objectLevel;
+ try {
+ objectLevel = StringUtils.rpad(objLev, ' ', OBJECT_LEVEL_LEN).getBytes(
+ AFPConstants.EBCIDIC_ENCODING);
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalArgumentException("an encoding exception occurred");
+ }
+ System.arraycopy(objectLevel, 0, data, 54, objectLevel.length);
+
+ // CompName - name of company or org that owns object definition (64-95)
+ byte[] companyName;
+ try {
+ companyName = StringUtils.rpad(compName, ' ', COMPANY_NAME_LEN).getBytes(
+ AFPConstants.EBCIDIC_ENCODING);
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalArgumentException("an encoding exception occurred");
+ }
+ System.arraycopy(companyName, 0, data, 62, companyName.length);
+
+ super.setData(data);
}
} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/Triplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/Triplet.java
index bcf6f22c3..9467c522a 100644
--- a/src/java/org/apache/fop/render/afp/modca/triplets/Triplet.java
+++ b/src/java/org/apache/fop/render/afp/modca/triplets/Triplet.java
@@ -31,6 +31,8 @@ import org.apache.fop.render.afp.modca.AbstractAFPObject;
*/
public class Triplet extends AbstractAFPObject {
public static final byte CODED_GRAPHIC_CHARACTER_SET_GLOBAL_IDENTIFIER = 0x01;
+
+ /** Triplet identifiers */
public static final byte FULLY_QUALIFIED_NAME = 0x02;
public static final byte MAPPING_OPTION = 0x04;
public static final byte OBJECT_CLASSIFICATION = 0x10;
@@ -89,21 +91,21 @@ public class Triplet extends AbstractAFPObject {
/**
* the triplet identifier
*/
- protected byte id;
+ private byte id;
/**
* the triplet's data contents
*/
- protected byte[] data;
+ private byte[] data;
/**
* Main constructor
* @param id the triplet identifier (see static definitions above)
- * @param contents the data item contained in this triplet
+ * @param data the data item contained in this triplet
*/
- public Triplet(byte id, byte[] contents) {
+ public Triplet(byte id, byte[] data) {
this(id);
- this.data = contents;
+ setData(data);
}
/**
@@ -150,9 +152,10 @@ public class Triplet extends AbstractAFPObject {
}
/**
- * @return the contents of the triplet
+ * Sets the data contents of this triplet
+ * @param data the data contents
*/
- public byte[] getData() {
- return this.data;
+ protected void setData(byte[] data) {
+ this.data = data;
}
}