You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ac...@apache.org on 2008/04/11 19:17:29 UTC
svn commit: r647228 [1/2] - in
/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp:
./ extensions/ modca/ modca/triplets/
Author: acumiskey
Date: Fri Apr 11 10:17:14 2008
New Revision: 647228
URL: http://svn.apache.org/viewvc?rev=647228&view=rev
Log:
Some fixes to apply but committed in preparation for http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback merge into trunk.
Added:
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/DataObjectInfo.java
- copied, changed from r644335, xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/DataObjectParameters.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ImageObjectInfo.java
- copied, changed from r644335, xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ImageObjectParameters.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ResourceInfo.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/ObjectTypeRegistry.java
- copied, changed from r644335, xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/Registry.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/ResourceObject.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/triplets/StrucFlgs.java
Removed:
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/DataObjectParameters.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ImageObjectParameters.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ResourceLevel.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/Registry.java
Modified:
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRenderer.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPSVGHandler.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPElement.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/IncludeObject.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/MapDataResource.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/PageSegment.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/PresentationTextData.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/ResourceEnvironmentGroup.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/ResourceGroup.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/triplets/FullyQualifiedNameTriplet.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/triplets/ObjectClassificationTriplet.java
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java?rev=647228&r1=647227&r2=647228&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPGraphics2DAdapter.java Fri Apr 11 10:17:14 2008
@@ -52,10 +52,12 @@
int resolution = (int)Math.round(context.getUserAgent().getTargetResolution());
BufferedImage bi = paintToBufferedImage(painter, wrappedContext, resolution, gray, false);
- //TODO: uri
- String uri = null;
- java.util.Map foreignAttributes = null;
- afp.drawBufferedImage(uri, bi, resolution, x, y, width, height, foreignAttributes);
+
+ //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);
}
}
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRenderer.java?rev=647228&r1=647227&r2=647228&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRenderer.java Fri Apr 11 10:17:14 2008
@@ -26,6 +26,7 @@
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.RenderedImage;
+import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -87,6 +88,7 @@
import org.apache.fop.render.afp.fonts.OutlineFont;
import org.apache.fop.render.afp.modca.AFPConstants;
import org.apache.fop.render.afp.modca.AFPDataStream;
+import org.apache.fop.render.afp.modca.AbstractNamedAFPObject;
import org.apache.fop.render.afp.modca.ImageObject;
import org.apache.fop.render.afp.modca.IncludeObject;
import org.apache.fop.render.afp.modca.PageObject;
@@ -969,7 +971,7 @@
} else if (img instanceof ImageRendered) {
ImageRendered imgRend = (ImageRendered)img;
RenderedImage ri = imgRend.getRenderedImage();
- drawBufferedImage(uri, ri, getResolution(),
+ drawBufferedImage(info, ri, getResolution(),
posInt.x + currentIPPosition,
posInt.y + currentBPPosition,
posInt.width,
@@ -983,17 +985,26 @@
int afpw = mpts2units(posInt.getWidth());
int afph = mpts2units(posInt.getHeight());
int afpres = getResolution();
- ImageObjectParameters params = new ImageObjectParameters(
- uri, afpx, afpy, afpw, afph, afpres, afpres,
- buf,
- ccitt.getSize().getWidthPx(),
- ccitt.getSize().getHeightPx(),
- colorImages, bitsPerPixel
- );
- params.setCompression(ccitt.getCompression());
- params.setResourceLevelFromForeignAttributes(foreignAttributes);
-// params.setData(buf);
- afpDataStream.createImageObject(params);
+
+ // create image object parameters
+ ImageObjectInfo imageObjectInfo = new ImageObjectInfo();
+ imageObjectInfo.setUri(uri);
+ imageObjectInfo.setMimeType(info.getMimeType());
+ imageObjectInfo.setX(afpx);
+ imageObjectInfo.setY(afpy);
+ imageObjectInfo.setWidth(afpw);
+ imageObjectInfo.setHeight(afph);
+ imageObjectInfo.setWidthRes(afpres);
+ imageObjectInfo.setHeightRes(afpres);
+ imageObjectInfo.setData(buf);
+ imageObjectInfo.setDataHeight(ccitt.getSize().getHeightPx());
+ imageObjectInfo.setDataWidth(ccitt.getSize().getWidthPx());
+ imageObjectInfo.setColor(colorImages);
+ imageObjectInfo.setBitsPerPixel(bitsPerPixel);
+ imageObjectInfo.setCompression(ccitt.getCompression());
+ imageObjectInfo.setResourceInfoFromForeignAttributes(foreignAttributes);
+
+ afpDataStream.createObject(imageObjectInfo);
// ImageObject io = afpDataStream.getImageObject(afpx, afpy, afpw, afph,
@@ -1193,7 +1204,7 @@
* @param h
* the height of the viewport (in mpt)
*/
- public void drawBufferedImage(String uri, RenderedImage image, int imageRes, int x,
+ public void drawBufferedImage(ImageInfo info, RenderedImage image, int imageRes, int x,
int y, int w, int h, Map foreignAttributes) {
// int afpx = mpts2units(x);
// int afpy = mpts2units(y);
@@ -1213,19 +1224,25 @@
// String uri = null;// = image.getProperty(name);
// String uri = image.getProperty(name);
// Generate image
- ImageObjectParameters params = new ImageObjectParameters(
- uri,
- mpts2units(x), mpts2units(y),
- mpts2units(w), mpts2units(h),
- imageRes, imageRes,
- baout.toByteArray(),
- image.getWidth(),
- image.getHeight(),
- colorImages,
- bitsPerPixel);
+
+ // create image object parameters
+ ImageObjectInfo imageObjectInfo = new ImageObjectInfo();
+ imageObjectInfo.setUri(info.getOriginalURI());
+ imageObjectInfo.setMimeType(info.getMimeType());
+ imageObjectInfo.setX(mpts2units(x));
+ imageObjectInfo.setY(mpts2units(y));
+ imageObjectInfo.setWidth(mpts2units(w));
+ imageObjectInfo.setHeight(mpts2units(h));
+ imageObjectInfo.setWidthRes(imageRes);
+ imageObjectInfo.setHeightRes(imageRes);
+ imageObjectInfo.setData(baout.toByteArray());
+ imageObjectInfo.setDataHeight(image.getHeight());
+ imageObjectInfo.setDataWidth(image.getWidth());
+ imageObjectInfo.setColor(colorImages);
+ imageObjectInfo.setBitsPerPixel(bitsPerPixel);
+ imageObjectInfo.setResourceInfoFromForeignAttributes(foreignAttributes);
- params.setResourceLevelFromForeignAttributes(foreignAttributes);
- IncludeObject io = afpDataStream.createImageObject(params);
+ AbstractNamedAFPObject obj = afpDataStream.createObject(imageObjectInfo);
// ImageObject io = afpDataStream.getImageObject(afpx, afpy, afpw,
// afph, afpres, afpres);
// io.setImageParameters(imageResolution, imageResolution,
@@ -1586,9 +1603,10 @@
if (content != null) {
afpDataStream.createNoOperation(content);
}
- } else if (AFPElementMapping.RESOURCE.equals(element)) {
- log.info("resource: " + attachment);
}
+// else if (AFPElementMapping.RESOURCE.equals(element)) {
+// log.info("resource: " + attachment);
+// }
}
}
}
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java?rev=647228&r1=647227&r2=647228&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java Fri Apr 11 10:17:14 2008
@@ -19,6 +19,7 @@
package org.apache.fop.render.afp;
+import java.io.File;
import java.util.List;
import org.apache.avalon.framework.configuration.Configuration;
@@ -224,7 +225,8 @@
LogUtil.handleException(log, e,
userAgent.getFactory().validateUserConfigStrictly());
}
-
+
+ // image information
Configuration imagesCfg = cfg.getChild("images");
if (!"color".equalsIgnoreCase(imagesCfg.getAttribute("mode", "b+w"))) {
afpRenderer.setBitsPerPixel(imagesCfg.getAttributeAsInteger("bits-per-pixel", 8));
@@ -232,35 +234,36 @@
afpRenderer.setColorImages(true);
}
+ // renderer resolution
Configuration rendererResolutionCfg = cfg.getChild("renderer-resolution", false);
if (rendererResolutionCfg != null) {
afpRenderer.setResolution(rendererResolutionCfg.getValueAsInteger(240));
}
+ // a default external resource group file setting
+ Configuration resourceGroupFileCfg = cfg.getChild("resource-group-file", false);
+ if (resourceGroupFileCfg != null) {
+ String resourceGroupDest = null;
+ try {
+ resourceGroupDest = resourceGroupFileCfg.getValue();
+ } catch (ConfigurationException e) {
+ LogUtil.handleException(log, e,
+ userAgent.getFactory().validateUserConfigStrictly());
+ }
+ File resourceGroupFile = new File(resourceGroupDest);
+ if (resourceGroupFile.canWrite()) {
+ afpRenderer.getAFPDataStream().setDefaultResourceGroupFile(resourceGroupFile);
+ } else {
+ log.warn("Unable to write to default external resource group file '"
+ + resourceGroupDest);
+ }
+ }
+
+ // goca enabled
Configuration gocaSupportCfg = cfg.getChild("goca-enabled", false);
if (gocaSupportCfg != null) {
afpRenderer.setGOCAEnabled(true);
}
-
-// Configuration resourceGroupsCfg = cfg.getChild("resource-groups", false);
-// if (resourceGroupsCfg != null) {
-// resourceGroupsCfg.getValue("print-file-level");
-// }
-// if (externalCfg != null) {
-// Configuration[] resourceGroups = externalCfg.getChildren("resource-groups");
-// for (int i = 0; i < resourceGroups.length; i++) {
-// String resourceresourceGroups[i].getAttribute("url", null);
-// Configuration resourceGroup = externalCfg.getChild("resource-group", false);
-// }
-// }
-// Configuration externalResourceGroupCfg = cfg.getChild("external-resource-group", false);
-// if (externalResourceGroupCfg != null) {
-//// afpRenderer.setExternalResources(true);
-// String resourceLibraryUrl = externalResourceGroupCfg.getAttribute("url", null);
-// if (resourceLibraryUrl != null) {
-// afpRenderer.setExternalResourceLibraryUrl(resourceLibraryUrl);
-// }
-// }
}
}
}
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPSVGHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPSVGHandler.java?rev=647228&r1=647227&r2=647228&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPSVGHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPSVGHandler.java Fri Apr 11 10:17:14 2008
@@ -159,20 +159,26 @@
int width = (int)Math.round((afpInfo.getWidth() * res) / 72000f);
int height = (int)Math.round((afpInfo.getHeight() * res) / 72000f);
- DataObjectParameters params = new DataObjectParameters(
- uri, x, y, width, height, res, res);
-
+ // set the data object parameters
+ DataObjectInfo info = new DataObjectInfo();
+ info.setUri(uri);
+ info.setX(x);
+ info.setY(y);
+ info.setWidth(width);
+ info.setHeight(height);
+ info.setWidthRes(res);
+ info.setHeightRes(res);
Map/*<QName, String>*/ foreignAttributes
= (Map/*<QName, String>*/)context.getProperty(
RendererContextConstants.FOREIGN_ATTRIBUTES);
-
if (foreignAttributes != null) {
- params.setResourceLevelFromForeignAttributes(foreignAttributes);
+ info.setResourceInfoFromForeignAttributes(foreignAttributes);
}
- IncludeObject includeObj = afpInfo.getAFPDataStream().createGraphicsObject(params);
- GraphicsObject graphicsObj = (GraphicsObject)includeObj.getReferencedObject();
- graphics.setGraphicsObject(graphicsObj);
+ //TODO: AC - fix
+// IncludeObject includeObj = afpInfo.getAFPDataStream().createObject(info);
+// GraphicsObject graphicsObj = (GraphicsObject)includeObj.getReferencedObject();
+// graphics.setGraphicsObject(graphicsObj);
try {
root.paint(graphics);
Copied: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/DataObjectInfo.java (from r644335, xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/DataObjectParameters.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/DataObjectInfo.java?p2=xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/DataObjectInfo.java&p1=xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/DataObjectParameters.java&r1=644335&r2=647228&rev=647228&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/DataObjectParameters.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/DataObjectInfo.java Fri Apr 11 10:17:14 2008
@@ -19,18 +19,21 @@
package org.apache.fop.render.afp;
+import java.io.File;
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;
/**
* A list of parameters associated with an AFP data objects
*/
-public class DataObjectParameters {
- private static final ResourceLevel DEFAULT_RESOURCE_LEVEL = new ResourceLevel();
+public class DataObjectInfo {
+ private static final ResourceInfo DEFAULT_RESOURCE_INFO = new ResourceInfo();
private String uri;
private int x;
@@ -39,31 +42,74 @@
private int height;
private int widthRes;
private int heightRes;
- private ResourceLevel resourceLevel = DEFAULT_RESOURCE_LEVEL;
+
+ // object type entry
+ private ObjectType objectTypeEntry;
+ private ResourceInfo resourceInfo = DEFAULT_RESOURCE_INFO;
/**
- * Main constructor
- *
+ * Sets the data object uri
* @param uri the data object uri
- * @param x the data object x coordinate
- * @param y the data object y coordinate
- * @param width the data object width
- * @param height the data object height
- * @param widthRes the data object width resolution
- * @param heightRes the data object height resolution
*/
- public DataObjectParameters(String uri, int x, int y, int width, int height,
- int widthRes, int heightRes) {
+ protected void setUri(String uri) {
this.uri = uri;
+ }
+
+ /**
+ * Sets the x position of the data object
+ * @param x the x position of the data object
+ */
+ protected void setX(int x) {
this.x = x;
+ }
+
+ /**
+ * Sets the y position of the data object
+ * @param y the y position of the data object
+ */
+ protected void setY(int y) {
this.y = y;
+ }
+
+ /**
+ * Sets the data object width
+ * @param width the width of the data object
+ */
+ protected void setWidth(int width) {
this.width = width;
+ }
+
+ /**
+ * Sets the data object height
+ * @param height the height of the data object
+ */
+ protected void setHeight(int height) {
this.height = height;
+ }
+
+ /**
+ * Sets the width resolution
+ * @param widthRes the width resolution
+ */
+ protected void setWidthRes(int widthRes) {
this.widthRes = widthRes;
+ }
+
+ /**
+ * Sets the height resolution
+ * @param heightRes the height resolution
+ */
+ protected void setHeightRes(int heightRes) {
this.heightRes = heightRes;
}
/**
+ * Default constructor
+ */
+ public DataObjectInfo() {
+ }
+
+ /**
* @return the uri of this data object
*/
public String getUri() {
@@ -113,40 +159,65 @@
}
/**
+ * Sets the object type entry
+ * @param entry the object type entry
+ */
+ public void setObjectType(ObjectTypeRegistry.ObjectType entry) {
+ this.objectTypeEntry = entry;
+ }
+
+ /**
+ * @return the object type entry
+ */
+ protected ObjectType getObjectTypeEntry() {
+ return objectTypeEntry;
+ }
+
+ /**
* @return returns the resource level at which this data object should reside
*/
- public ResourceLevel getResourceLevel() {
- return resourceLevel;
+ public ResourceInfo getResourceInfo() {
+ return resourceInfo;
}
/**
* Sets the resource level at which this object should reside
- * @param resourceLevel the resource level at which this data object should reside
+ * @param resourceInfo the resource level at which this data object should reside
*/
- public void setResourceLevel(ResourceLevel resourceLevel) {
- this.resourceLevel = resourceLevel;
+ public void setResourceInfo(ResourceInfo resourceInfo) {
+ 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 level using the given foreign attributes
+ * Sets the resource group settings using the given foreign attributes
* @param foreignAttributes a mapping of element attributes names to values
*/
- public void setResourceLevelFromForeignAttributes(Map/*<QName, String>*/ foreignAttributes) {
+ public void setResourceInfoFromForeignAttributes(Map/*<QName, String>*/ foreignAttributes) {
if (foreignAttributes != null) {
- QName resourceLevelKey = new QName(
- AFPElementMapping.NAMESPACE,
- "afp:resource-level");
+ this.resourceInfo = new ResourceInfo();
+ QName resourceNameKey = new QName(AFPElementMapping.NAMESPACE, RESOURCE_NAME);
+ String resourceName = (String)foreignAttributes.get(resourceNameKey);
+ if (resourceName != null) {
+ resourceInfo.setName(resourceName);
+ }
+ QName resourceLevelKey = new QName(AFPElementMapping.NAMESPACE, RESOURCE_LEVEL);
if (foreignAttributes.containsKey(resourceLevelKey)) {
String level = (String)foreignAttributes.get(resourceLevelKey);
- this.resourceLevel = new ResourceLevel();
- if (resourceLevel.setLevel(level)) {
- if (resourceLevel.isExternal()) {
- QName resourceDestKey = new QName(
- AFPElementMapping.NAMESPACE,
- "afp:resource-dest");
+ if (resourceInfo.setLevel(level)) {
+ if (resourceInfo.isExternal()) {
+ QName resourceGroupFileKey = new QName(AFPElementMapping.NAMESPACE,
+ RESOURCE_GROUP_FILE);
String resourceExternalDest
- = (String)foreignAttributes.get(resourceDestKey);
- resourceLevel.setExternalDest(resourceExternalDest);
+ = (String)foreignAttributes.get(resourceGroupFileKey);
+ File resourceExternalGroupFile = new File(resourceExternalDest);
+ if (resourceExternalGroupFile.canWrite()) {
+ resourceInfo.setExternalResourceGroupFile(resourceExternalGroupFile);
+ }
}
} else {
Log log = LogFactory.getLog("org.apache.fop.afp");
@@ -168,6 +239,7 @@
+ ", height=" + height
+ ", widthRes=" + widthRes
+ ", heightRes=" + heightRes
- + (resourceLevel != null ? ", resourceLevel=" + resourceLevel : "");
+ + (resourceInfo != null ? ", resourceInfo=" + resourceInfo : "")
+ + (objectTypeEntry != null ? ", objectTypeEntry=" + objectTypeEntry : "");
}
}
Copied: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ImageObjectInfo.java (from r644335, xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ImageObjectParameters.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ImageObjectInfo.java?p2=xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ImageObjectInfo.java&p1=xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ImageObjectParameters.java&r1=644335&r2=647228&rev=647228&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ImageObjectParameters.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ImageObjectInfo.java Fri Apr 11 10:17:14 2008
@@ -22,38 +22,55 @@
/**
* A list of parameters associated with an image
*/
-public class ImageObjectParameters extends DataObjectParameters {
+public class ImageObjectInfo extends DataObjectInfo {
private int bitsPerPixel;
private boolean color;
private int compression = -1;
- private byte[] imageData;
- private int imageDataWidth;
- private int imageDataHeight;
-
+ private byte[] data;
+ private int dataWidth;
+ private int dataHeight;
+ private String mimeType;
+
/**
- * Main constructor
- *
- * @param uri the image uri
- * @param x the image x coordinate
- * @param y the image y coordinate
- * @param width the image width
- * @param height the image height
- * @param widthRes the image width resolution
- * @param heightRes the image height resolution
- */
- public ImageObjectParameters(String uri, int x, int y, int width, int height,
- int widthRes, int heightRes, byte[] imageData,
- int imageDataWidth, int imageDataHeight, boolean color, int bitsPerPixel) {
- super(uri, x, y, width, height, widthRes, heightRes);
- this.imageData = imageData;
- this.imageDataWidth = imageDataWidth;
- this.imageDataHeight = imageDataHeight;
- this.color = color;
+ * Default constructor
+ */
+ public ImageObjectInfo() {
+ }
+
+ /**
+ * Sets the number of bits per pixel
+ * @param bitsPerPixel the number of bits per pixel
+ */
+ public void setBitsPerPixel(int bitsPerPixel) {
this.bitsPerPixel = bitsPerPixel;
}
/**
- * @return the numner of bits used per pixel
+ * Sets if this image is color
+ * @param color true if this is a color image
+ */
+ public void setColor(boolean color) {
+ this.color = color;
+ }
+
+ /**
+ * Sets the image data
+ * @param data the image data
+ */
+ public void setData(byte[] data) {
+ this.data = data;
+ }
+
+ /**
+ * Sets the image mime type
+ * @param mimeType the image mime type
+ */
+ public void setMimeType(String mimeType) {
+ this.mimeType = mimeType;
+ }
+
+ /**
+ * @return the number of bits used per pixel
*/
public int getBitsPerPixel() {
return bitsPerPixel;
@@ -70,7 +87,7 @@
* @return the image data
*/
public byte[] getData() {
- return imageData;
+ return data;
}
/**
@@ -98,40 +115,48 @@
/**
* @return the image data width
*/
- public int getImageDataWidth() {
- return imageDataWidth;
+ public int getDataWidth() {
+ return dataWidth;
}
/**
* Sets the image data width
* @param imageDataWidth the image data width
*/
- protected void setImageDataWidth(int imageDataWidth) {
- this.imageDataWidth = imageDataWidth;
+ public void setDataWidth(int imageDataWidth) {
+ this.dataWidth = imageDataWidth;
}
/**
* @return the image data height
*/
- public int getImageDataHeight() {
- return imageDataHeight;
+ public int getDataHeight() {
+ return dataHeight;
}
/**
* Sets the image data height
* @param imageDataHeight the image data height
*/
- protected void setImageDataHeight(int imageDataHeight) {
- this.imageDataHeight = imageDataHeight;
+ public void setDataHeight(int imageDataHeight) {
+ this.dataHeight = imageDataHeight;
}
-
+
+ /**
+ * @return the mime type of this image
+ */
+ public String getMimeType() {
+ return mimeType;
+ }
+
/**
* {@inheritDoc}
*/
public String toString() {
return super.toString()
- + ", imageDataWidth=" + imageDataWidth
- + ", imageDataHeight=" + imageDataHeight
+ + ", mimeType=" + mimeType
+ + ", dataWidth=" + dataWidth
+ + ", dataHeight=" + dataHeight
+ ", color=" + color
+ ", bitPerPixel=" + bitsPerPixel;
}
Added: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ResourceInfo.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ResourceInfo.java?rev=647228&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ResourceInfo.java (added)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ResourceInfo.java Fri Apr 11 10:17:14 2008
@@ -0,0 +1,164 @@
+/*
+ * 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;
+
+import java.io.File;
+
+/**
+ * The level at which a resource is to reside in the AFP output
+ */
+public class ResourceInfo {
+ private static final String LEVEL_EXTERNAL = "external";
+
+ private static final String LEVEL_PRINT_FILE = "print-file";
+
+ private static final String LEVEL_DOCUMENT = "document";
+
+ private static final String LEVEL_PAGE_GROUP = "page-group";
+
+ private static final String LEVEL_PAGE = "page";
+
+ /**
+ * the reference name of this resource
+ */
+ private String name = null;
+
+ /**
+ * where the resource will reside in the AFP output
+ */
+ private String level = LEVEL_PAGE; // default is page level
+
+ /**
+ * the external resource group file
+ */
+ private File externalResourceGroupFile = null;
+
+ /**
+ * @return true if this is a page level resource group
+ */
+ public boolean isPage() {
+ return level.equals(LEVEL_PAGE);
+ }
+
+ /**
+ * @return true if this is a page group level resource group
+ */
+ public boolean isPageGroup() {
+ return level.equals(LEVEL_PAGE_GROUP);
+ }
+
+ /**
+ * @return true if this is a document level resource group
+ */
+ public boolean isDocument() {
+ return level.equals(LEVEL_DOCUMENT);
+ }
+
+ /**
+ * @return true if this is an external level resource group
+ */
+ public boolean isExternal() {
+ return level.equals(LEVEL_EXTERNAL);
+ }
+
+ /**
+ * @return true if this is a print-file level resource group
+ */
+ public boolean isPrintFile() {
+ return level.equals(LEVEL_PRINT_FILE);
+ }
+
+ private boolean isValid(String lvl) {
+ return lvl.equals(LEVEL_EXTERNAL)
+ || lvl.equals(LEVEL_PRINT_FILE)
+ || lvl.equals(LEVEL_DOCUMENT)
+ || lvl.equals(LEVEL_PAGE_GROUP)
+ || lvl.equals(LEVEL_PAGE);
+ }
+
+ /**
+ * Sets the resource placement level within the AFP output
+ * @param lvl the resource level (page, page-group, document, print-file or external)
+ * @return true if the resource level was successfully set
+ */
+ public boolean setLevel(String lvl) {
+ if (isValid(lvl)) {
+ this.level = lvl;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @return the external resource group file of this resource
+ */
+ public File getExternalResourceGroupFile() {
+ return this.externalResourceGroupFile;
+ }
+
+ /**
+ * @return the destination file path of the external resource group file
+ */
+ public String getExternalResourceGroupDest() {
+ if (externalResourceGroupFile != null) {
+ return externalResourceGroupFile.getAbsolutePath();
+ }
+ return null;
+ }
+
+ /**
+ * @return true if this resource has a defined external resource group file destination
+ */
+ public boolean hasExternalResourceGroupFile() {
+ return getExternalResourceGroupFile() != null;
+ }
+
+ /**
+ * Sets the external destination of the resource
+ * @param file the external resource group file
+ */
+ public void setExternalResourceGroupFile(File file) {
+ this.externalResourceGroupFile = file;
+ }
+
+ /**
+ * Sets the resource reference name
+ * @param resourceName the resource reference name
+ */
+ public void setName(String resourceName) {
+ this.name = resourceName;
+ }
+
+ /**
+ * @return the resource reference name
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString() {
+ return "ResourceInfo(name=" + name + ", level=" + level
+ + (isExternal() ? ", externalResourceGroupFile=" + externalResourceGroupFile : "")
+ + ")";
+ }
+}
\ No newline at end of file
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPElement.java?rev=647228&r1=647227&r2=647228&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPElement.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPElement.java Fri Apr 11 10:17:14 2008
@@ -55,8 +55,7 @@
}
}
- protected ExtensionAttachment instantiateExtensionAttachment() {
- return new AFPPageSetup(getName());
- }
-
+ protected ExtensionAttachment instantiateExtensionAttachment() {
+ return new AFPPageSetup(getName());
+ }
}
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java?rev=647228&r1=647227&r2=647228&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java Fri Apr 11 10:17:14 2008
@@ -48,8 +48,8 @@
/** include page segment element */
public static final String INCLUDE_PAGE_SEGMENT = "include-page-segment";
- /** include resource element (external) */
- public static final String RESOURCE = "resource";
+// /** include resource element (external) */
+// public static final String RESOURCE = "resource";
/** NOP */
public static final String NO_OPERATION = "no-operation";
@@ -70,7 +70,7 @@
}
/**
- * Private static synchronized method to set up the element and atribute
+ * Private static synchronized method to set up the element and attribute
* HashMaps, this defines what elements and attributes are extracted.
*/
protected void initialize() {
@@ -79,8 +79,8 @@
super.foObjs = new java.util.HashMap();
foObjs.put(PAGE, new AFPPageSetupMaker());
// foObjs.put(
-// PAGE_GROUP,
-// new AFPPageGroupMaker()
+// PAGE_GROUP,
+// new AFPPageGroupMaker()
// );
foObjs.put(
TAG_LOGICAL_ELEMENT,
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java?rev=647228&r1=647227&r2=647228&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java Fri Apr 11 10:17:14 2008
@@ -20,6 +20,7 @@
package org.apache.fop.render.afp.modca;
import java.awt.Color;
+import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
@@ -29,9 +30,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.render.afp.AFPFontAttributes;
-import org.apache.fop.render.afp.DataObjectParameters;
-import org.apache.fop.render.afp.ImageObjectParameters;
-import org.apache.fop.render.afp.ResourceLevel;
+import org.apache.fop.render.afp.DataObjectInfo;
+import org.apache.fop.render.afp.ResourceInfo;
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;
@@ -146,9 +146,9 @@
private OutputStream outputStream = null;
/**
- * A mapping of external resource destinations to resource groups
+ * The external resource group manager
*/
- private Map/*<String,ResourceGroup>*/ externalResourceGroups = null;
+ private ExternalResourceGroupManager externalResourceGroupManager = null;
/**
* Default constructor for the AFPDataStream.
@@ -226,9 +226,7 @@
}
// Write out any external resource groups
- if (externalResourceGroups != null) {
- writeExternalResources();
- }
+ getExternalResourceGroupManager().writeExternalResources();
// Write out any print-file level resources
if (hasResources()) {
@@ -405,7 +403,7 @@
* the point size of the font
*/
public void createFont(int fontReference, AFPFont font, int size) {
- currentPage.createFont(fontReference, font, size);
+ getCurrentPage().createFont(fontReference, font, size);
}
/**
@@ -429,51 +427,37 @@
*/
public void createText(int fontReference, int x, int y, Color col, int vsci,
int ica, byte[] data) {
- currentPage.createText(fontReference, x + xOffset, y + yOffset, rotation,
+ getCurrentPage().createText(fontReference, x + xOffset, y + yOffset, rotation,
col, vsci, ica, data);
}
-
- /**
- * Returns true if the resource exists within this resource group,
- * false otherwise.
- *
- * @param uri the uri of the resource
- * @return true if the resource exists within this resource group
- */
- public boolean resourceExists(String uri) {
- return getResourceGroup().resourceExists(uri);
- }
-
- /**
- * Returns an IncludeObject referencing an image in the datastream.
- *
- * @param params
- * the unique uri of the image
- * @return
- * a new include object referencing an image object
- */
- public IncludeObject createImageObject(ImageObjectParameters params) {
- ResourceLevel resourceLevel = params.getResourceLevel();
- IncludeObject includeObj = getResourceGroup(resourceLevel).addObject(params);
- currentPage.addObject(includeObj);
- return includeObj;
- }
/**
- * Returns an IncludeObject referencing a graphic in the datastream.
- *
- * @param params
- * the data object parameters
+ * Creates a data object in the datastream. The data object resides according
+ * to its type, info and MO:DCA-L (resource) support.
+ *
+ * @param dataObjectInfo
+ * the data object info
* @return
- * a new include object referencing the graphics object
+ * a data object
*/
- public IncludeObject createGraphicsObject(DataObjectParameters params) {
- ResourceLevel resourceLevel = params.getResourceLevel();
- IncludeObject includeObj = getResourceGroup(resourceLevel).addObject(params);
- currentPage.addObject(includeObj);
- return includeObj;
+ public AbstractNamedAFPObject createObject(DataObjectInfo dataObjectInfo) {
+ ObjectTypeRegistry registry = ObjectTypeRegistry.getInstance();
+ ObjectTypeRegistry.ObjectType objectType = registry.getObjectType(dataObjectInfo);
+ 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);
+ }
+ return dataObj;
}
-
+
/**
* Sets the object view port taking into account rotation.
*
@@ -502,7 +486,7 @@
int heightRes;
switch (this.rotation) {
case 90:
- xOrigin = currentPage.getWidth() - y - yOffset;
+ xOrigin = getCurrentPage().getWidth() - y - yOffset;
yOrigin = x + xOffset;
width = h;
height = w;
@@ -510,8 +494,8 @@
heightRes = wr;
break;
case 180:
- xOrigin = currentPage.getWidth() - x - xOffset;
- yOrigin = currentPage.getHeight() - y - yOffset;
+ xOrigin = getCurrentPage().getWidth() - x - xOffset;
+ yOrigin = getCurrentPage().getHeight() - y - yOffset;
width = w;
height = h;
widthRes = wr;
@@ -519,7 +503,7 @@
break;
case 270:
xOrigin = y + yOffset;
- yOrigin = currentPage.getHeight() - x - xOffset;
+ yOrigin = getCurrentPage().getHeight() - x - xOffset;
width = h;
height = w;
widthRes = hr;
@@ -555,7 +539,7 @@
*/
public void createLine(int x1, int y1, int x2, int y2, int thickness,
Color col) {
- currentPage.createLine(x1 + xOffset, y1 + yOffset, x2 + xOffset, y2
+ getCurrentPage().createLine(x1 + xOffset, y1 + yOffset, x2 + xOffset, y2
+ yOffset, thickness, rotation, col);
}
@@ -581,7 +565,7 @@
*/
public void createShading(int x, int y, int w, int h, int red, int green,
int blue) {
- currentPage.createShading(x + xOffset, y + xOffset, w, h, red, green,
+ getCurrentPage().createShading(x + xOffset, y + xOffset, w, h, red, green,
blue);
}
@@ -622,23 +606,23 @@
int yOrigin;
switch (rotation) {
case 90:
- xOrigin = currentPage.getWidth() - y - yOffset;
+ xOrigin = getCurrentPage().getWidth() - y - yOffset;
yOrigin = x + xOffset;
break;
case 180:
- xOrigin = currentPage.getWidth() - x - xOffset;
- yOrigin = currentPage.getHeight() - y - yOffset;
+ xOrigin = getCurrentPage().getWidth() - x - xOffset;
+ yOrigin = getCurrentPage().getHeight() - y - yOffset;
break;
case 270:
xOrigin = y + yOffset;
- yOrigin = currentPage.getHeight() - x - xOffset;
+ yOrigin = getCurrentPage().getHeight() - x - xOffset;
break;
default:
xOrigin = x + xOffset;
yOrigin = y + yOffset;
break;
}
- currentPage.createIncludePageSegment(name, xOrigin, yOrigin);
+ getCurrentPage().createIncludePageSegment(name, xOrigin, yOrigin);
}
/**
@@ -681,7 +665,7 @@
if (currentPageGroup != null) {
currentPageGroup.createTagLogicalElement(name, value);
} else {
- currentPage.createTagLogicalElement(name, value);
+ getCurrentPage().createTagLogicalElement(name, value);
}
}
@@ -692,7 +676,7 @@
* byte data
*/
public void createNoOperation(String content) {
- currentPage.createNoOperation(content);
+ getCurrentPage().createNoOperation(content);
}
private PageGroup getCurrentPageGroup() {
@@ -719,7 +703,7 @@
public void endPageGroup() {
if (currentPageGroup != null) {
currentPageGroup.endPageGroup();
- document.addPageGroup(currentPageGroup);
+ getDocument().addPageGroup(currentPageGroup);
currentPageGroup = null;
}
}
@@ -758,70 +742,143 @@
}
}
+
/**
- * Writes out external AFP resources
+ * Returns the resource group for a given resource into
+ * @param resourceInfo resource info
+ * @return a resource group container for the given resource info
*/
- private void writeExternalResources() {
- // write any external resources
- Iterator it = getExternalResourceGroups().keySet().iterator();
- while (it.hasNext()) {
- String externalDest = (String)it.next();
- ResourceGroup resourceGroup
- = (ResourceGroup)getExternalResourceGroups().get(externalDest);
- OutputStream os = null;
- try {
- log.debug("Writing external AFP resource file " + externalDest);
- os = new java.io.FileOutputStream(externalDest);
- 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);
- } finally {
- if (os != null) {
- try {
- os.close();
- } catch (IOException e) {
- log.error("Failed to close outputstream for external AFP resource file "
- + externalDest);
- }
- }
- }
+ private ResourceGroup getResourceGroup(ResourceInfo resourceInfo) {
+ ResourceGroup resourceGroup = null;
+ if (resourceInfo.isPrintFile()) {
+ resourceGroup = getResourceGroup();
+ } else if (resourceInfo.isDocument()) {
+ resourceGroup = getDocument().getResourceGroup();
+ } else if (resourceInfo.isPageGroup()) {
+ resourceGroup = getCurrentPageGroup().getResourceGroup();
+ } else if (resourceInfo.isPage()) {
+ resourceGroup = getCurrentPage().getResourceGroup();
+ } else if (resourceInfo.isExternal()) {
+ resourceGroup = getExternalResourceGroupManager().getExternalResourceGroup(
+ resourceInfo);
}
+ return resourceGroup;
}
/**
- * Returns the resource group for a given resource level
- * @param resourceLevel a resource level
- * @return a resource group container for the given level
+ * Sets the default resource group file
+ * @param resourceGroupFile the default resource group file
*/
- private ResourceGroup getResourceGroup(ResourceLevel resourceLevel) {
- ResourceGroup resourceGroup = null;
- if (resourceLevel.isPrintFile()) {
- resourceGroup = this.getResourceGroup();
- } else if (resourceLevel.isDocument()) {
- resourceGroup = document.getResourceGroup();
- } else if (resourceLevel.isPageGroup()) {
- resourceGroup = getCurrentPageGroup().getResourceGroup();
- } else if (resourceLevel.isPage()) {
- resourceGroup = getCurrentPage().getResourceGroup();
- } else if (resourceLevel.isExternal()) {
- String externalDest = resourceLevel.getExternalDest();
- resourceGroup = (ResourceGroup)getExternalResourceGroups().get(externalDest);
- if (resourceGroup == null) {
- resourceGroup = new ResourceGroup();
- externalResourceGroups.put(externalDest, resourceGroup);
- }
+ public void setDefaultResourceGroupFile(File resourceGroupFile) {
+ getExternalResourceGroupManager().setDefaultResourceGroupFile(resourceGroupFile);
+ }
+
+ /**
+ * @return the resource group manager
+ */
+ protected ExternalResourceGroupManager getExternalResourceGroupManager() {
+ if (externalResourceGroupManager == null) {
+ this.externalResourceGroupManager = new ExternalResourceGroupManager(this);
}
- return resourceGroup;
+ return this.externalResourceGroupManager;
}
+
- private Map/*<String,ResourceGroup>*/ getExternalResourceGroups() {
- if (externalResourceGroups == null) {
- externalResourceGroups = new java.util.HashMap();
+ /**
+ * Manages the use of resource groups (external and internal)
+ */
+ 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;
}
- return externalResourceGroups;
+
+ /**
+ * 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()) {
+ String externalDest = (String)it.next();
+ ResourceGroup resourceGroup
+ = (ResourceGroup)getExternalResourceGroups().get(externalDest);
+ OutputStream os = null;
+ try {
+ log.debug("Writing external AFP resource file " + externalDest);
+ os = new java.io.FileOutputStream(externalDest);
+ 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);
+ } finally {
+ if (os != null) {
+ try {
+ os.close();
+ } catch (IOException e) {
+ log.error("Failed to close outputstream for external AFP resource file "
+ + externalDest);
+ }
+ }
+ }
+ }
+ }
+
+ private ResourceGroup getExternalResourceGroup(ResourceInfo resourceInfo) {
+ ResourceGroup resourceGroup;
+ // this resource info does not have a an external resource group file definition
+ if (!resourceInfo.hasExternalResourceGroupFile()) {
+ if (defaultResourceGroupFile != null) {
+ // fallback to default resource group file
+ resourceInfo.setExternalResourceGroupFile(defaultResourceGroupFile);
+ resourceGroup = getExternalResourceGroup(resourceInfo);
+ } else {
+ // use print-file level resource group in the absence
+ // of an external resource group file definition
+ resourceGroup = container.getResourceGroup();
+ }
+ } else {
+ File resourceGroupFile = resourceInfo.getExternalResourceGroupFile();
+ resourceGroup = (ResourceGroup)getExternalResourceGroups().get(resourceGroupFile);
+ if (resourceGroup == null) {
+ resourceGroup = new ResourceGroup(container);
+ externalResourceGroups.put(resourceGroupFile, resourceGroup);
+ }
+ }
+ return resourceGroup;
+ }
+
+ private Map/*<File, ResourceGroup>*/ getExternalResourceGroups() {
+ if (externalResourceGroups == null) {
+ externalResourceGroups = new java.util.HashMap/*<File, ResourceGroup>*/();
+ }
+ return externalResourceGroups;
+ }
}
}
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java?rev=647228&r1=647227&r2=647228&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java Fri Apr 11 10:17:14 2008
@@ -44,7 +44,7 @@
* DataStream objects must implement the writeDataStream()
* method to write its data to the given OutputStream
* @param os The outputsteam stream
- * @throws java.io.IOException
+ * @throws java.io.IOException an I/O exception of some sort has occurred.
*/
public abstract void writeDataStream(OutputStream os) throws IOException;
@@ -52,18 +52,16 @@
* 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
+ * @throws java.io.IOException an I/O exception of some sort has occurred.
*/
protected void writeObjects(Collection/*<AbstractAFPObject>*/ objects, OutputStream os)
throws IOException {
if (objects != null) {
for (Iterator it = objects.iterator(); it.hasNext();) {
- Object obj1 = it.next();
- AbstractAFPObject obj = (AbstractAFPObject)obj1;
+ AbstractAFPObject obj = (AbstractAFPObject)it.next();
obj.writeDataStream(os);
}
}
-
}
}
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java?rev=647228&r1=647227&r2=647228&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java Fri Apr 11 10:17:14 2008
@@ -81,5 +81,4 @@
public String getName() {
return name;
}
-
}
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java?rev=647228&r1=647227&r2=647228&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java Fri Apr 11 10:17:14 2008
@@ -432,10 +432,7 @@
protected void addObject(AbstractStructuredAFPObject obj) {
if (obj instanceof IncludeObject) {
IncludeObject includeObj = (IncludeObject)obj;
- AbstractStructuredAFPObject refObj = includeObj.getReferencedObject();
- if (refObj instanceof ImageObject || refObj instanceof GraphicsObject) {
- getActiveEnvironmentGroup().createResource(refObj);
- }
+ getActiveEnvironmentGroup().createResource(includeObj);
}
endPresentationObject();
super.addObject(obj);
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java?rev=647228&r1=647227&r2=647228&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java Fri Apr 11 10:17:14 2008
@@ -23,8 +23,11 @@
import java.io.OutputStream;
import java.util.Set;
-import org.apache.fop.render.afp.DataObjectParameters;
-import org.apache.fop.render.afp.ImageObjectParameters;
+import org.apache.fop.render.afp.DataObjectInfo;
+import org.apache.fop.render.afp.ImageObjectInfo;
+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;
/**
* An abstract container of resource objects
@@ -87,31 +90,165 @@
*/
protected ResourceGroup getResourceGroup() {
if (resourceGroup == null) {
- resourceGroup = new ResourceGroup();
+ resourceGroup = new ResourceGroup(this);
}
return resourceGroup;
}
+
+ /**
+ * Converts a byte array containing 24 bit RGB image data to a grayscale
+ * image.
+ *
+ * @param io
+ * the target image object
+ * @param raw
+ * the buffer containing the RGB image data
+ * @param width
+ * the width of the image in pixels
+ * @param height
+ * the height of the image in pixels
+ * @param bitsPerPixel
+ * the number of bits to use per pixel
+ *
+ * TODO: move this method somewhere appropriate in commons
+ */
+ private static void convertToGrayScaleImage(ImageObject io, byte[] raw, int width,
+ int height, int bitsPerPixel) {
+ int pixelsPerByte = 8 / bitsPerPixel;
+ int bytewidth = (width / pixelsPerByte);
+ if ((width % pixelsPerByte) != 0) {
+ bytewidth++;
+ }
+ byte[] bw = new byte[height * bytewidth];
+ byte ib;
+ for (int y = 0; y < height; y++) {
+ ib = 0;
+ int i = 3 * y * width;
+ for (int x = 0; x < width; x++, i += 3) {
+
+ // see http://www.jguru.com/faq/view.jsp?EID=221919
+ double greyVal = 0.212671d * ((int) raw[i] & 0xff) + 0.715160d
+ * ((int) raw[i + 1] & 0xff) + 0.072169d
+ * ((int) raw[i + 2] & 0xff);
+ switch (bitsPerPixel) {
+ case 1:
+ if (greyVal < 128) {
+ ib |= (byte) (1 << (7 - (x % 8)));
+ }
+ break;
+ case 4:
+ greyVal /= 16;
+ ib |= (byte) ((byte) greyVal << ((1 - (x % 2)) * 4));
+ break;
+ case 8:
+ ib = (byte) greyVal;
+ break;
+ default:
+ throw new UnsupportedOperationException(
+ "Unsupported bits per pixel: " + bitsPerPixel);
+ }
+
+ if ((x % pixelsPerByte) == (pixelsPerByte - 1)
+ || ((x + 1) == width)) {
+ bw[(y * bytewidth) + (x / pixelsPerByte)] = ib;
+ ib = 0;
+ }
+ }
+ }
+ io.setImageIDESize((byte) bitsPerPixel);
+ io.setImageData(bw);
+ }
+
+ private static final String IMAGE_NAME_PREFIX = "IMG";
+ private static final String GRAPHIC_NAME_PREFIX = "GRA";
+ private static final String PAGE_SEGMENT_NAME_PREFIX = "PSG";
+ // not currently used/implemented
+ private static final String BARCODE_NAME_PREFIX = "BAR";
+ private static final String OTHER_NAME_PREFIX = "OTH";
+
/**
* Helper method to create an image on the current container and to return
* the object.
- * @param params the image object parameters
- * @return the image object
+ * @param info the image object info
+ * @return a newly created image object
*/
- public IncludeObject createImageObject(ImageObjectParameters params) {
- return getResourceGroup().addObject(params);
+ protected ImageObject createImage(ImageObjectInfo info) {
+ String name = IMAGE_NAME_PREFIX
+ + StringUtils.lpad(String.valueOf(getResourceCount() + 1), '0', 5);
+ ImageObject imageObj = new ImageObject(name);
+ if (info.hasCompression()) {
+ int compression = info.getCompression();
+ switch (compression) {
+ case TIFFImage.COMP_FAX_G3_1D:
+ imageObj.setImageEncoding(ImageContent.COMPID_G3_MH);
+ break;
+ case TIFFImage.COMP_FAX_G3_2D:
+ imageObj.setImageEncoding(ImageContent.COMPID_G3_MR);
+ break;
+ case TIFFImage.COMP_FAX_G4_2D:
+ imageObj.setImageEncoding(ImageContent.COMPID_G3_MMR);
+ break;
+ default:
+ throw new IllegalStateException(
+ "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()) {
+ imageObj.setImageIDESize((byte)24);
+ imageObj.setImageData(info.getData());
+ } else {
+ convertToGrayScaleImage(imageObj, info.getData(),
+ info.getDataWidth(), info.getDataHeight(),
+ info.getBitsPerPixel());
+ }
+ return imageObj;
}
-
+
/**
* Helper method to create a graphic in the current container and to return
* the object.
- * @param params the data object parameters
- * @return the graphics object
+ * @return a newly created graphics object
*/
- public IncludeObject createGraphicsObject(DataObjectParameters params) {
- return getResourceGroup().addObject(params);
+ protected GraphicsObject createGraphic() {
+ String name = GRAPHIC_NAME_PREFIX
+ + StringUtils.lpad(String.valueOf(getResourceCount() + 1), '0', 5);
+ GraphicsObject graphicsObj = new GraphicsObject(name);
+ return graphicsObj;
}
-
+
+ /**
+ * Helper method to create a page segment in the current container and to return
+ * the object.
+ * @return a newly created page segment
+ */
+ protected PageSegment createPageSegment() {
+ String name = PAGE_SEGMENT_NAME_PREFIX
+ + StringUtils.lpad(String.valueOf(getResourceCount() + 1), '0', 5);
+ PageSegment pageSegment = new PageSegment(name);
+ return pageSegment;
+ }
+
+ /**
+ * Creates and returns a new data object
+ * @param info the data object parameters
+ * @return a newly created data object
+ */
+ public AbstractNamedAFPObject createObject(DataObjectInfo info) {
+ AbstractNamedAFPObject dataObject;
+ if (info instanceof ImageObjectInfo) {
+ dataObject = createImage((ImageObjectInfo)info);
+ } else {
+ dataObject = createGraphic();
+ }
+ return dataObject;
+ }
+
/**
* {@inheritDoc}
*/
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java?rev=647228&r1=647227&r2=647228&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java Fri Apr 11 10:17:14 2008
@@ -31,6 +31,7 @@
import org.apache.fop.render.afp.modca.triplets.MeasurementUnitsTriplet;
import org.apache.fop.render.afp.modca.triplets.ObjectAreaSizeTriplet;
import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet;
+import org.apache.fop.render.afp.modca.triplets.StrucFlgs;
import org.apache.fop.render.afp.modca.triplets.Triplet;
/**
@@ -58,6 +59,12 @@
* @return the triplet data length
*/
protected int getTripletDataLength() {
+ if (tripletData == null) {
+ try {
+ getTripletData();
+ } catch (IOException e) {
+ }
+ }
if (tripletData != null) {
return tripletData.length;
}
@@ -65,27 +72,18 @@
}
/**
- * Helper method to write the start of the Object.
- * @param os The stream to write to
- * @throws IOException an I/O exception if one occurred
+ * @return the triplet data
+ * @throws IOException throws an I/O exception if one occurred
*/
- protected void writeStart(OutputStream os) throws IOException {
- if (triplets != null) {
+ protected byte[] getTripletData() throws IOException {
+ if (tripletData == null && triplets != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writeObjects(triplets, baos);
this.tripletData = baos.toByteArray();
}
+ return this.tripletData;
}
-
- /**
- * Helper method to write the contents of the Object.
- * @param os The stream to write to
- * @throws IOException The stream to write to
- */
- protected void writeContent(OutputStream os) throws IOException {
- writeTriplets(os);
- }
-
+
/**
* Writes any triplet data
* @param os The stream to write to
@@ -98,6 +96,24 @@
writeObjects(triplets, os);
}
}
+
+ /**
+ * 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
+ */
+ protected void writeStart(OutputStream os) throws IOException {
+ getTripletData();
+ }
+
+ /**
+ * 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
+ */
+ protected void writeContent(OutputStream os) throws IOException {
+ writeTriplets(os);
+ }
/**
* Helper method to write the end of the Object.
@@ -176,9 +192,8 @@
* @param fqName the fully qualified name of this resource
*/
public void setFullyQualifiedName(byte fqnType, byte fqnFormat, String fqName) {
- byte[] fqNameBytes;
try {
- fqNameBytes = fqName.getBytes(AFPConstants.EBCIDIC_ENCODING);
+ byte[] fqNameBytes = fqName.getBytes(AFPConstants.EBCIDIC_ENCODING);
addTriplet(new FullyQualifiedNameTriplet(fqnType, fqnFormat, fqNameBytes));
} catch (UnsupportedEncodingException e) {
log.error(e.getMessage());
@@ -191,15 +206,17 @@
public String getFullyQualifiedName() {
FullyQualifiedNameTriplet fqNameTriplet
= (FullyQualifiedNameTriplet)getTriplet(Triplet.FULLY_QUALIFIED_NAME);
- byte[] nameBytes = fqNameTriplet.getFullyQualifiedName();
- if (nameBytes != null) {
- try {
- return new String(nameBytes, AFPConstants.EBCIDIC_ENCODING);
- } catch (UnsupportedEncodingException e) {
- log.error(e.getMessage());
+ if (fqNameTriplet != null) {
+ byte[] nameBytes = fqNameTriplet.getFullyQualifiedName();
+ if (nameBytes != null) {
+ try {
+ return new String(nameBytes, AFPConstants.EBCIDIC_ENCODING);
+ } catch (UnsupportedEncodingException e) {
+ log.error(e.getMessage());
+ }
+ } else {
+ log.warn(this + " has no fully qualified name");
}
- } else {
- log.warn(this + " has no fully qualified name");
}
return null;
}
@@ -207,12 +224,15 @@
/**
* Sets the objects classification
* @param objectClass the classification of the object
- * @param componentId the component Id of the object
- */
- public void setObjectClassification(byte objectClass, byte componentId) {
- addTriplet(new ObjectClassificationTriplet(objectClass, componentId));
+ * @param objectType the MOD:CA registry object type entry for the given
+ * 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,
+ StrucFlgs strucFlgs) {
+ addTriplet(new ObjectClassificationTriplet(objectClass, objectType, strucFlgs));
}
-
+
/**
* Specifies the extent of an object area in the X and Y directions
* @param x the x direction extent
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java?rev=647228&r1=647227&r2=647228&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java Fri Apr 11 10:17:14 2008
@@ -146,8 +146,8 @@
super.writeTriplets(os);
writeObjects(mapCodedFonts, os);
- writeObjects(mapPageOverlays, os);
writeObjects(mapDataResources, os);
+ writeObjects(mapPageOverlays, os);
if (pageDescriptor != null) {
pageDescriptor.writeDataStream(os);
@@ -258,12 +258,11 @@
}
}
-
/**
* Method to create a map data resource object
* @param obj creates a map data resource entry for a given AFP data resource object
*/
- public void createResource(AbstractStructuredAFPObject obj) {
+ public void createResource(IncludeObject obj) {
getMapDataResources().add(new MapDataResource(obj));
}
}
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/IncludeObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/IncludeObject.java?rev=647228&r1=647227&r2=647228&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/IncludeObject.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/IncludeObject.java Fri Apr 11 10:17:14 2008
@@ -19,9 +19,12 @@
package org.apache.fop.render.afp.modca;
+import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
+import org.apache.fop.render.afp.ResourceInfo;
+import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet;
import org.apache.fop.render.afp.tools.BinaryUtils;
/**
@@ -94,38 +97,84 @@
*/
private int yContentOffset = -1;
+// /**
+// * The object referenced by this include object
+// */
+// private Resource resourceObj = null;
+
/**
- * The object referenced by this include object
+ * the level at which this resource object resides
*/
- private AbstractStructuredAFPObject referencedObject = null;
+ private ResourceInfo level = null;
+
+ /**
+ * the referenced data object
+ */
+ private AbstractNamedAFPObject dataObj = 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 resourceObj the resource object wrapper
*/
- public IncludeObject(ResourceObject resourceObj) {
- super(resourceObj.getResource().getName());
- this.referencedObject = resourceObj.getResource();
- if (referencedObject instanceof ImageObject) {
+ public IncludeObject(AbstractNamedAFPObject dataObj) {
+ super(dataObj.getName());
+ this.dataObj = dataObj;
+// AbstractStructuredAFPObject referencedObject = resourceObj.getReferencedObject();
+ if (dataObj instanceof ImageObject) {
this.objectType = TYPE_IMAGE;
- } else if (referencedObject instanceof GraphicsObject) {
+ } else if (dataObj instanceof GraphicsObject) {
this.objectType = TYPE_GRAPHIC;
- } else if (referencedObject instanceof PageSegment) {
+ } else if (dataObj instanceof PageSegment) {
this.objectType = TYPE_PAGE_SEGMENT;
} else {
this.objectType = TYPE_OTHER;
}
+
+ // set data object reference triplet
+ ResourceInfo resourceInfo = getResourceInfo();
+ if (resourceInfo != null && resourceInfo.isExternal()) {
+ String dest = resourceInfo.getExternalResourceGroupDest();
+ super.setFullyQualifiedName(
+ FullyQualifiedNameTriplet.TYPE_DATA_OBJECT_EXTERNAL_RESOURCE_REF,
+ FullyQualifiedNameTriplet.FORMAT_URL, dest);
+ } else {
+ super.setFullyQualifiedName(
+ FullyQualifiedNameTriplet.TYPE_DATA_OBJECT_INTERNAL_RESOURCE_REF,
+ FullyQualifiedNameTriplet.FORMAT_CHARSTR, dataObj.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 the resource container object referenced by this include object
+// */
+// public Resource getResource() {
+// return this.resourceObj;
+// }
+
/**
- * @return the object referenced by this include object
+ * @return the actual resource data object referenced by this include object
*/
public AbstractStructuredAFPObject getReferencedObject() {
- return referencedObject;
+ return this.dataObj;
+ //getResource().getReferencedObject();
}
/**
@@ -167,12 +216,12 @@
/**
* {@inheritDoc}
*/
- public void writeDataStream(OutputStream os) throws IOException {
+ public void writeDataStream(OutputStream os) throws IOException {
byte[] data = new byte[36];
data[0] = 0x5A;
// Set the total record length
- byte[] len = BinaryUtils.convert(35, 2); //Ignore first byte
+ byte[] len = BinaryUtils.convert(35 + getTripletDataLength(), 2); //Ignore first byte
data[1] = len[0];
data[2] = len[1];
@@ -272,8 +321,13 @@
data[33] = (byte)0xFF;
data[34] = (byte)0xFF;
}
-
data[35] = 0x01;
+
+ // Write structured field data
os.write(data);
+
+ // Write triplet for FQN internal/external object reference
+ byte[] tripletData = super.getTripletData();
+ os.write(tripletData);
}
}
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/MapDataResource.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/MapDataResource.java?rev=647228&r1=647227&r2=647228&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/MapDataResource.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/MapDataResource.java Fri Apr 11 10:17:14 2008
@@ -22,7 +22,11 @@
import java.io.IOException;
import java.io.OutputStream;
+//import org.apache.fop.render.afp.ResourceLevel;
+import org.apache.fop.render.afp.ResourceInfo;
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.StrucFlgs;
import org.apache.fop.render.afp.tools.BinaryUtils;
/**
@@ -39,13 +43,42 @@
* Main constructor
* @param obj a map data resource for a given structured AFP object
*/
- public MapDataResource(AbstractStructuredAFPObject obj) {
- String fqName = obj.getFullyQualifiedName();
+ public MapDataResource(IncludeObject includeObj) {
+ AbstractStructuredAFPObject refObj = includeObj.getReferencedObject();
+// ResourceObject resObj = includeObj.getResource();
+ String fqName = refObj.getFullyQualifiedName();
+ ResourceInfo resourceInfo = includeObj.getResourceInfo();
if (fqName != null) {
- super.setFullyQualifiedName(
- FullyQualifiedNameTriplet.TYPE_BEGIN_RESOURCE_OBJECT_REF,
- FullyQualifiedNameTriplet.FORMAT_CHARSTR, fqName);
+ if (resourceInfo.isExternal()) {
+ String dest = resourceInfo.getExternalResourceGroupDest();
+ super.setFullyQualifiedName(
+ FullyQualifiedNameTriplet.TYPE_DATA_OBJECT_EXTERNAL_RESOURCE_REF,
+ FullyQualifiedNameTriplet.FORMAT_CHARSTR, dest);
+ } else {
+// super.setFullyQualifiedName(
+// FullyQualifiedNameTriplet.TYPE_DATA_OBJECT_INTERNAL_RESOURCE_REF,
+// FullyQualifiedNameTriplet.FORMAT_CHARSTR, fqName);
+ super.setFullyQualifiedName(
+ FullyQualifiedNameTriplet.TYPE_BEGIN_RESOURCE_OBJECT_REF,
+ FullyQualifiedNameTriplet.FORMAT_CHARSTR, fqName);
+ }
}
+// if (fqName != null) {
+// super.setFullyQualifiedName(
+// FullyQualifiedNameTriplet.TYPE_BEGIN_RESOURCE_OBJECT_REF,
+// FullyQualifiedNameTriplet.FORMAT_CHARSTR, fqName);
+// }
+ final boolean dataInContainer = true;
+ final boolean containerHasOEG = false;
+ final boolean dataInOCD = true;
+ StrucFlgs strucFlgs = new StrucFlgs(
+ dataInContainer, containerHasOEG, dataInOCD
+ );
+
+ //TODO: AC - fix
+// super.setObjectClassification(
+// ObjectClassificationTriplet.CLASS_TIME_VARIANT_PRESENTATION_OBJECT,
+// objectType, strucFlgs);
}
/**
@@ -54,8 +87,7 @@
public void writeStart(OutputStream os) throws IOException {
super.writeStart(os);
- // RGLength
- byte[] len = BinaryUtils.convert(8 + getTripletDataLength(), 2);
+ byte[] len = BinaryUtils.convert(10 + getTripletDataLength(), 2);
byte[] data = new byte[] {
0x5A, // Structured field identifier
len[0], // Length byte 1
@@ -68,5 +100,16 @@
0x00 // Reserved
};
os.write(data);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void writeContent(OutputStream os) throws IOException {
+ // RGLength
+ byte[] len = BinaryUtils.convert(2 + getTripletDataLength(), 2);
+ os.write(len);
+
+ super.writeTriplets(os);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org