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/03/27 17:16:38 UTC
svn commit: r641873 [3/5] - in
/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop:
image/ render/afp/ render/afp/extensions/ render/afp/modca/
render/afp/modca/triplets/ render/pdf/ render/ps/extensions/
Added: 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/DataObjectParameters.java?rev=641873&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/DataObjectParameters.java (added)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/DataObjectParameters.java Thu Mar 27 09:16:30 2008
@@ -0,0 +1,173 @@
+/*
+ * 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.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.util.QName;
+
+/**
+ * A list of parameters associated with an AFP data objects
+ */
+public class DataObjectParameters {
+ private static final ResourceLevel DEFAULT_RESOURCE_LEVEL = new ResourceLevel();
+
+ private String uri;
+ private int x;
+ private int y;
+ private int width;
+ private int height;
+ private int widthRes;
+ private int heightRes;
+ private ResourceLevel resourceLevel = DEFAULT_RESOURCE_LEVEL;
+
+ /**
+ * Main constructor
+ *
+ * @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) {
+ this.uri = uri;
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ this.widthRes = widthRes;
+ this.heightRes = heightRes;
+ }
+
+ /**
+ * @return the uri of this data object
+ */
+ public String getUri() {
+ return uri;
+ }
+
+ /**
+ * @return the x coordinate of this data object
+ */
+ public int getX() {
+ return x;
+ }
+
+ /**
+ * @return the y coordinate of this data object
+ */
+ public int getY() {
+ return y;
+ }
+
+ /**
+ * @return the width of this data object
+ */
+ public int getWidth() {
+ return width;
+ }
+
+ /**
+ * @return the height of this data object
+ */
+ public int getHeight() {
+ return height;
+ }
+
+ /**
+ * @return the width resolution of this data object
+ */
+ public int getWidthRes() {
+ return widthRes;
+ }
+
+ /**
+ * @return the height resolution of this data object
+ */
+ public int getHeightRes() {
+ return heightRes;
+ }
+
+ /**
+ * @return returns the resource level at which this data object should reside
+ */
+ public ResourceLevel getResourceLevel() {
+ return resourceLevel;
+ }
+
+ /**
+ * Sets the resource level at which this object should reside
+ * @param resourceLevel the resource level at which this data object should reside
+ */
+ public void setResourceLevel(ResourceLevel resourceLevel) {
+ this.resourceLevel = resourceLevel;
+ }
+
+ /**
+ * Sets the resource level using the given foreign attributes
+ * @param foreignAttributes a mapping of element attributes names to values
+ */
+ public void setResourceLevelFromForeignAttributes(Map/*<QName, String>*/ foreignAttributes) {
+ if (foreignAttributes != null) {
+ QName resourceLevelKey = new QName(
+ AFPElementMapping.NAMESPACE,
+ "afp: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");
+ String resourceExternalDest
+ = (String)foreignAttributes.get(resourceDestKey);
+ resourceLevel.setExternalDest(resourceExternalDest);
+ }
+ } else {
+ Log log = LogFactory.getLog("org.apache.fop.afp");
+ log.warn("invalid resource level '" + level
+ + "', using default document level");
+ }
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString() {
+ return "uri=" + uri
+ + ", x=" + x
+ + ", y=" + y
+ + ", width=" + width
+ + ", height=" + height
+ + ", widthRes=" + widthRes
+ + ", heightRes=" + heightRes
+ + (resourceLevel != null ? ", resourceLevel=" + resourceLevel : "");
+ }
+}
Added: 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/ImageObjectParameters.java?rev=641873&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ImageObjectParameters.java (added)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ImageObjectParameters.java Thu Mar 27 09:16:30 2008
@@ -0,0 +1,138 @@
+/*
+ * 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;
+
+/**
+ * A list of parameters associated with an image
+ */
+public class ImageObjectParameters extends DataObjectParameters {
+ private int bitsPerPixel;
+ private boolean color;
+ private int compression = -1;
+ private byte[] imageData;
+ private int imageDataWidth;
+ private int imageDataHeight;
+
+ /**
+ * 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;
+ this.bitsPerPixel = bitsPerPixel;
+ }
+
+ /**
+ * @return the numner of bits used per pixel
+ */
+ public int getBitsPerPixel() {
+ return bitsPerPixel;
+ }
+
+ /**
+ * @return true if this is a color image
+ */
+ public boolean isColor() {
+ return color;
+ }
+
+ /**
+ * @return the image data
+ */
+ public byte[] getData() {
+ return imageData;
+ }
+
+ /**
+ * @return true of this image uses compression
+ */
+ public boolean hasCompression() {
+ return compression > -1;
+ }
+
+ /**
+ * @return the compression type
+ */
+ public int getCompression() {
+ return compression;
+ }
+
+ /**
+ * Sets the compression used with this image
+ * @param compression the type of compression used with this image
+ */
+ public void setCompression(int compression) {
+ this.compression = compression;
+ }
+
+ /**
+ * @return the image data width
+ */
+ public int getImageDataWidth() {
+ return imageDataWidth;
+ }
+
+ /**
+ * Sets the image data width
+ * @param imageDataWidth the image data width
+ */
+ protected void setImageDataWidth(int imageDataWidth) {
+ this.imageDataWidth = imageDataWidth;
+ }
+
+ /**
+ * @return the image data height
+ */
+ public int getImageDataHeight() {
+ return imageDataHeight;
+ }
+
+ /**
+ * Sets the image data height
+ * @param imageDataHeight the image data height
+ */
+ protected void setImageDataHeight(int imageDataHeight) {
+ this.imageDataHeight = imageDataHeight;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString() {
+ return super.toString()
+ + ", imageDataWidth=" + imageDataWidth
+ + ", imageDataHeight=" + imageDataHeight
+ + ", color=" + color
+ + ", bitPerPixel=" + bitsPerPixel;
+ }
+}
\ No newline at end of file
Added: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ResourceLevel.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ResourceLevel.java?rev=641873&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ResourceLevel.java (added)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/ResourceLevel.java Thu Mar 27 09:16:30 2008
@@ -0,0 +1,123 @@
+/*
+ * 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;
+
+/**
+ * The level at which a resource is to reside in the AFP output
+ */
+public class ResourceLevel {
+ private static final String EXTERNAL = "external";
+
+ private static final String PRINT_FILE = "print-file";
+
+ private static final String DOCUMENT = "document";
+
+ private static final String PAGE_GROUP = "page-group";
+
+ private static final String PAGE = "page";
+
+ /**
+ * where the resource will reside in the AFP output
+ */
+ private String level = PAGE; // default is page level
+
+ /**
+ * the destination location of the resource
+ */
+ private String dest = null;
+
+ /**
+ * @return true if this is a page level resource group
+ */
+ public boolean isPage() {
+ return level.equals(PAGE);
+ }
+
+ /**
+ * @return true if this is a page group level resource group
+ */
+ public boolean isPageGroup() {
+ return level.equals(PAGE_GROUP);
+ }
+
+ /**
+ * @return true if this is a document level resource group
+ */
+ public boolean isDocument() {
+ return level.equals(DOCUMENT);
+ }
+
+ /**
+ * @return true if this is an external level resource group
+ */
+ public boolean isExternal() {
+ return level.equals(EXTERNAL);
+ }
+
+ /**
+ * @return true if this is a print-file level resource group
+ */
+ public boolean isPrintFile() {
+ return level.equals(PRINT_FILE);
+ }
+
+ private boolean isValid(String lvl) {
+ return lvl.equals(EXTERNAL)
+ || lvl.equals(PRINT_FILE)
+ || lvl.equals(DOCUMENT)
+ || lvl.equals(PAGE_GROUP)
+ || lvl.equals(PAGE);
+ }
+
+ /**
+ * Sets the resource placement level within the AFP output
+ * @param level the resource level (page, page-group, document, print-file or external)
+ * @return true if the resource level was successfully set
+ */
+ public boolean setLevel(String level) {
+ if (isValid(level)) {
+ this.level = level;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @return the external destination of the resource
+ */
+ public String getExternalDest() {
+ return dest;
+ }
+
+ /**
+ * Sets the external destination of the resource
+ * @param dest the external destination of the resource
+ */
+ public void setExternalDest(String dest) {
+ this.dest = dest;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString() {
+ return "level=" + level + (isExternal() ? ", dest=" + dest : "");
+ }
+}
\ No newline at end of file
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPAttribute.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPAttribute.java?rev=641873&r1=641872&r2=641873&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPAttribute.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPAttribute.java Thu Mar 27 09:16:30 2008
@@ -19,14 +19,13 @@
package org.apache.fop.render.afp.extensions;
-import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.properties.Property;
import org.apache.fop.fo.properties.StringProperty;
/**
* This class extends the org.apache.fop.fo.StringProperty.Maker inner class
- * in order to provide a static property maker. The object faciliates
+ * in order to provide a static property maker. The object facilitates
* extraction of attributes from formatted objects based on the static list
* as defined in the AFPElementMapping implementation.
* <p/>
@@ -58,5 +57,4 @@
}
return property;
}
-
}
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=641873&r1=641872&r2=641873&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 Thu Mar 27 09:16:30 2008
@@ -23,6 +23,7 @@
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.ValidationException;
+import org.apache.fop.fo.extensions.ExtensionAttachment;
/**
* This class extends the org.apache.fop.extensions.ExtensionObj class. The
@@ -54,4 +55,7 @@
}
}
+ protected ExtensionAttachment instantiateExtensionAttachment() {
+ return null;
+ }
}
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=641873&r1=641872&r2=641873&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 Thu Mar 27 09:16:30 2008
@@ -50,6 +50,9 @@
/** include page segment element */
public static final String INCLUDE_PAGE_SEGMENT = "include-page-segment";
+ /** include resource element (external) */
+ public static final String RESOURCE = "resource";
+
/** NOP */
public static final String NO_OPERATION = "no-operation";
Added: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPExtensionAttachment.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPExtensionAttachment.java?rev=641873&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPExtensionAttachment.java (added)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPExtensionAttachment.java Thu Mar 27 09:16:30 2008
@@ -0,0 +1,155 @@
+/*
+ * 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.extensions;
+
+import java.io.Serializable;
+
+import org.apache.fop.fo.extensions.ExtensionAttachment;
+import org.apache.xmlgraphics.util.XMLizable;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * This is the pass-through value object for the AFP extension.
+ */
+public abstract class AFPExtensionAttachment
+ implements ExtensionAttachment, Serializable, XMLizable {
+ private static final long serialVersionUID = 7190606822558332901L;
+
+ /** The category URI for this extension attachment. */
+ public static final String CATEGORY = "apache:fop:extensions:afp";
+
+ /**
+ * the extension element name
+ */
+ protected String elementName;
+
+ /**
+ * the extension content
+ */
+ protected String content;
+
+ /**
+ * the extension name attribute
+ */
+ protected String name;
+
+ /**
+ * the extension value attribute
+ */
+ protected String value;
+
+ /**
+ * Default constructor.
+ *
+ * @param elementName the name of the afp extension attachment, may be null
+ */
+ public AFPExtensionAttachment(String elementName) {
+ this.elementName = elementName;
+ }
+
+ /** @return the name */
+ public String getElementName() {
+ return elementName;
+ }
+
+ /**
+ * @return true if this element has a name attribute
+ */
+ protected boolean hasName() {
+ return name != null;
+ }
+
+ /** @return the name */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name of the setup code object.
+ * @param name The name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the value
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Sets the value
+ * @param source The value name to set.
+ */
+ public void setValue(String source) {
+ this.value = source;
+ }
+
+ /** {@inheritDoc} */
+ public String getCategory() {
+ return CATEGORY;
+ }
+
+ /**
+ * @return the data
+ */
+ public String getContent() {
+ return content;
+ }
+
+ /**
+ * Sets the data
+ * @param content The byte data to set.
+ */
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ /**
+ * name attribute
+ */
+ protected static final String ATT_NAME = "name";
+
+ /**
+ * value attribute
+ */
+ protected static final String ATT_VALUE = "value";
+
+ /** {@inheritDoc} */
+ public void toSAX(ContentHandler handler) throws SAXException {
+ AttributesImpl atts = new AttributesImpl();
+ if (name != null && name.length() > 0) {
+ atts.addAttribute(null, ATT_NAME, ATT_NAME, "CDATA", name);
+ }
+ if (value != null && value.length() > 0) {
+ atts.addAttribute(null, ATT_VALUE, ATT_VALUE, "CDATA", value);
+ }
+ handler.startElement(CATEGORY, elementName, elementName, atts);
+ if (content != null && content.length() > 0) {
+ char[] chars = content.toCharArray();
+ handler.characters(chars, 0, chars.length);
+ }
+ handler.endElement(CATEGORY, elementName, elementName);
+ }
+}
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPExtensionHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPExtensionHandler.java?rev=641873&r1=641872&r2=641873&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPExtensionHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPExtensionHandler.java Thu Mar 27 09:16:30 2008
@@ -54,7 +54,9 @@
|| localName.equals(AFPElementMapping.INCLUDE_PAGE_OVERLAY)
|| localName.equals(AFPElementMapping.INCLUDE_PAGE_SEGMENT)
|| localName.equals(AFPElementMapping.PAGE)
- || localName.equals(AFPElementMapping.PAGE_GROUP)) {
+ || localName.equals(AFPElementMapping.PAGE_GROUP)
+ || localName.equals(AFPElementMapping.PAGE_GROUP)
+ || localName.equals(AFPResource.ELEMENT)) {
//handled in endElement
} else {
handled = false;
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java?rev=641873&r1=641872&r2=641873&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java Thu Mar 27 09:16:30 2008
@@ -19,33 +19,10 @@
package org.apache.fop.render.afp.extensions;
-import java.io.Serializable;
-
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.AttributesImpl;
-
-import org.apache.xmlgraphics.util.XMLizable;
-
-import org.apache.fop.fo.extensions.ExtensionAttachment;
-
/**
* This is the pass-through value object for the PostScript extension.
*/
-public class AFPPageSetup implements ExtensionAttachment, Serializable, XMLizable {
-
- private static final long serialVersionUID = 7190606822558332901L;
-
- /** The category URI for this extension attachment. */
- public static final String CATEGORY = "apache:fop:extensions:afp";
-
- private String elementName;
-
- private String name;
-
- private String value;
-
- private String content;
+public class AFPPageSetup extends AFPExtensionAttachment {
/**
* Default constructor.
@@ -53,85 +30,16 @@
* @param elementName the name of the setup code object, may be null
*/
public AFPPageSetup(String elementName) {
- this.elementName = elementName;
+ super(elementName);
}
- /** @return the name */
- public String getElementName() {
- return elementName;
- }
-
- /** @return the name */
- public String getName() {
- return name;
- }
+ private static final long serialVersionUID = -549941295384013190L;
/**
- * Sets the name of the setup code object.
- * @param name The name to set.
+ * {@inheritDoc}
*/
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * @return the value
- */
- public String getValue() {
- return value;
- }
-
- /**
- * Sets the value
- * @param source The value name to set.
- */
- public void setValue(String source) {
- this.value = source;
- }
-
- /** {@inheritDoc} */
- public String getCategory() {
- return CATEGORY;
- }
-
- /**
- * @return the data
- */
- public String getContent() {
- return content;
- }
-
- /**
- * Sets the data
- * @param content The byte data to set.
- */
- public void setContent(String content) {
- this.content = content;
- }
-
- /** {@inheritDoc} */
public String toString() {
return "AFPPageSetup(element-name=" + getElementName()
+ " name=" + getName() + " value=" + getValue() + ")";
- }
-
- private static final String ATT_NAME = "name";
- private static final String ATT_VALUE = "value";
-
- /** {@inheritDoc} */
- public void toSAX(ContentHandler handler) throws SAXException {
- AttributesImpl atts = new AttributesImpl();
- if (name != null && name.length() > 0) {
- atts.addAttribute(null, ATT_NAME, ATT_NAME, "CDATA", name);
- }
- if (value != null && value.length() > 0) {
- atts.addAttribute(null, ATT_VALUE, ATT_VALUE, "CDATA", value);
- }
- handler.startElement(CATEGORY, elementName, elementName, atts);
- if (content != null && content.length() > 0) {
- char[] chars = content.toCharArray();
- handler.characters(chars, 0, chars.length);
- }
- handler.endElement(CATEGORY, elementName, elementName);
}
}
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java?rev=641873&r1=641872&r2=641873&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java Thu Mar 27 09:16:30 2008
@@ -23,9 +23,10 @@
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.ValidationException;
+import org.apache.fop.fo.extensions.ExtensionAttachment;
/**
- * Extension element for fox:ps-page-setup-code.
+ * Extension element for afp:ps-page-setup-code.
*/
public class AFPPageSetupElement extends AbstractAFPExtensionObject {
@@ -45,4 +46,10 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
+ protected ExtensionAttachment instantiateExtensionAttachment() {
+ return new AFPPageSetup(this.name);
+ }
}
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AbstractAFPExtensionObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AbstractAFPExtensionObject.java?rev=641873&r1=641872&r2=641873&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AbstractAFPExtensionObject.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/extensions/AbstractAFPExtensionObject.java Thu Mar 27 09:16:30 2008
@@ -34,11 +34,14 @@
public abstract class AbstractAFPExtensionObject extends FONode {
/**
- * AFP setup code
+ * the AFP extension attachment
*/
- private AFPPageSetup setupCode;
+ protected AFPExtensionAttachment extensionAttachment;
- private String name;
+ /**
+ * the element name of this extension
+ */
+ protected String name;
/**
* @see org.apache.fop.fo.FONode#FONode(FONode)
@@ -48,10 +51,11 @@
public AbstractAFPExtensionObject(FONode parent, String name) {
super(parent);
this.name = name;
- this.setupCode = new AFPPageSetup(name);
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
protected void validateChildNode(Locator loc, String nsURI, String localName)
throws ValidationException {
if (FO_URI.equals(nsURI)) {
@@ -59,60 +63,85 @@
}
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
protected void addCharacters(char[] data, int start, int end,
- PropertyList pList, Locator locator) {
- setupCode.setContent(new String(data, start, end - start));
+ PropertyList pList, Locator locator) throws FOPException {
+ ((AFPExtensionAttachment)getExtensionAttachment()).setContent(
+ new String(data, start, end - start));
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String getNamespaceURI() {
return AFPElementMapping.NAMESPACE;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String getNormalNamespacePrefix() {
return AFPElementMapping.NAMESPACE_PREFIX;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void processNode(String elementName, Locator locator,
Attributes attlist, PropertyList propertyList)
throws FOPException {
- String name = attlist.getValue("name");
- if (name != null && name.length() > 0) {
- setupCode.setName(name);
+ getExtensionAttachment();
+ String attr = attlist.getValue("name");
+ if (attr != null && attr.length() > 0) {
+ extensionAttachment.setName(attr);
} else {
throw new FOPException(elementName + " must have a name attribute.");
}
if (AFPElementMapping.INCLUDE_PAGE_SEGMENT.equals(elementName)) {
- name = attlist.getValue("src");
- if (name != null && name.length() > 0) {
- setupCode.setValue(name);
+ attr = attlist.getValue("src");
+ if (attr != null && attr.length() > 0) {
+ extensionAttachment.setValue(attr);
} else {
throw new FOPException(elementName + " must have a src attribute.");
}
} else if (AFPElementMapping.TAG_LOGICAL_ELEMENT.equals(elementName)) {
- name = attlist.getValue("value");
- if (name != null && name.length() > 0) {
- setupCode.setValue(name);
+ attr = attlist.getValue("value");
+ if (attr != null && attr.length() > 0) {
+ extensionAttachment.setValue(attr);
} else {
throw new FOPException(elementName + " must have a value attribute.");
}
}
}
-
- /** {@inheritDoc} */
+
+ /**
+ * {@inheritDoc}
+ */
protected void endOfNode() throws FOPException {
super.endOfNode();
}
- /** {@inheritDoc} */
+ /**
+ * Instantiates extension attachment object
+ * @return extension attachment
+ */
+ protected abstract ExtensionAttachment instantiateExtensionAttachment();
+
+ /**
+ * {@inheritDoc}
+ */
public ExtensionAttachment getExtensionAttachment() {
- return this.setupCode;
+ if (extensionAttachment == null) {
+ this.extensionAttachment = (AFPExtensionAttachment)instantiateExtensionAttachment();
+ }
+ return this.extensionAttachment;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String getLocalName() {
return name;
}
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=641873&r1=641872&r2=641873&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 Thu Mar 27 09:16:30 2008
@@ -20,6 +20,7 @@
package org.apache.fop.render.afp.modca;
import java.awt.Color;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
@@ -28,7 +29,11 @@
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.fonts.AFPFont;
+import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet;
import org.apache.fop.render.afp.tools.StringUtils;
/**
@@ -47,7 +52,7 @@
* them.
*
*/
-public class AFPDataStream {
+public class AFPDataStream extends AbstractResourceGroupContainer {
/**
* Static logging instance
@@ -81,6 +86,11 @@
private PageObject currentPageObject = null;
/**
+ * The current resource group
+ */
+// private ResourceGroup currentResourceGroup = null;
+
+ /**
* The current overlay object
*/
private Overlay currentOverlay = null;
@@ -98,8 +108,7 @@
/**
* The page group count
*/
-// not used
-// private int pageGroupCount = 0;
+ private int pageGroupCount = 0;
/**
* The overlay count
@@ -135,40 +144,71 @@
* The outputstream for the data stream
*/
private OutputStream outputStream = null;
+
+ /**
+ * A mapping of external resource destinations to resource groups
+ */
+ private Map/*<String,ResourceGroup>*/ externalResourceGroups = null;
/**
* Default constructor for the AFPDataStream.
*/
public AFPDataStream() {
+ this.document = new Document();
+ }
+
+ private Document getDocument() {
+ return this.document;
+ }
+
+ private AbstractPageObject getCurrentPage() {
+ return this.currentPage;
}
/**
* The document is started by invoking this method which creates an instance
* of the AFP Document object.
*
- * @param docOutputStream
- * the outputStream which the document is written to.
+ * @param name
+ * the name of this document.
*/
- public void startDocument(OutputStream docOutputStream) {
- if (document != null) {
- String msg = "Invalid state - document already started.";
- log.warn("startDocument():: " + msg);
- throw new IllegalStateException(msg);
+ public void setDocumentName(String name) {
+// if (document != null) {
+// String msg = "Invalid state - document already started.";
+// log.warn("startDocument():: " + msg);
+// throw new IllegalStateException(msg);
+// }
+// if (document != null) {
+// String msg = "Invalid state - print file level document already started";
+// log.warn(msg);
+// throw new IllegalStateException(msg);
+// }
+
+ if (name != null) {
+ document.setFullyQualifiedName(
+ FullyQualifiedNameTriplet.TYPE_BEGIN_DOCUMENT_REF,
+ FullyQualifiedNameTriplet.FORMAT_CHARSTR,
+ name);
}
-
- this.document = new Document();
- this.outputStream = docOutputStream;
}
/**
- * The document is ended by invoking this method which creates an instance
+ * Sets the OutputStream
+ * @param outputStream the AFP OutputStream
+ */
+ public void setOutputStream(OutputStream outputStream) {
+ this.outputStream = outputStream;
+ }
+
+ /**
+ * The document is written/ended by invoking this method which creates an instance
* of the AFP Document object and registers the start with a validation map
* which ensures that methods are not invoked out of the correct sequence.
*
* @throws java.io.IOException
* throws an I/O exception of some sort has occurred
*/
- public void endDocument() throws IOException {
+ public void write() throws IOException {
if (complete) {
String msg = "Invalid state - document already ended.";
log.warn("endDocument():: " + msg);
@@ -185,8 +225,22 @@
endPageGroup();
}
- document.endDocument();
- document.writeDataStream(this.outputStream);
+ // Write out any external resource groups
+ if (externalResourceGroups != null) {
+ writeExternalResources();
+ }
+
+ // Write out any print-file level resources
+ if (hasResources()) {
+ getResourceGroup().writeDataStream(this.outputStream);
+ }
+
+ // Write out document
+ if (document != null) {
+ document.endDocument();
+ document.writeDataStream(this.outputStream);
+ }
+
this.outputStream.flush();
complete = true;
@@ -195,7 +249,7 @@
this.outputStream = null;
}
-
+
/**
* Start a new page. When processing has finished on the current page, the
* {@link #endPage()}method must be invoked to mark the page ending.
@@ -213,7 +267,6 @@
*/
public void startPage(int pageWidth, int pageHeight, int pageRotation,
int pageWidthRes, int pageHeightRes) {
-
String pageName = "PGN"
+ StringUtils.lpad(String.valueOf(pageCount++), '0', 5);
@@ -229,34 +282,30 @@
* the {@link #endOverlay()}method must be invoked to mark the overlay
* ending.
*
- * @param overlayX
+ * @param x
* the x position of the overlay on the page
- * @param overlayY
+ * @param y
* the y position of the overlay on the page
- * @param overlayWidth
+ * @param width
* the width of the overlay
- * @param overlayHeight
+ * @param height
* the height of the overlay
- * @param overlayWidthResolution
+ * @param widthRes
* the width resolution of the overlay
- * @param overlayHeightResolution
+ * @param heightRes
* the height resolution of the overlay
- * @param overlayRotation
+ * @param rotation
* the rotation of the overlay
*/
- public void startOverlay(int overlayX, int overlayY, int overlayWidth,
- int overlayHeight, int overlayWidthResolution,
- int overlayHeightResolution, int overlayRotation) {
-
+ public void startOverlay(int x, int y, int width, int height, int widthRes,
+ int heightRes, int rotation) {
String overlayName = "OVL"
+ StringUtils.lpad(String.valueOf(ovlCount++), '0', 5);
- currentOverlay = new Overlay(overlayName, overlayWidth, overlayHeight,
- overlayWidthResolution, overlayHeightResolution,
- overlayRotation);
- currentPageObject.addOverlay(currentOverlay);
- currentPageObject.createIncludePageOverlay(overlayName, overlayX,
- overlayY, 0);
+ currentOverlay = new Overlay(overlayName, width, height,
+ widthRes, heightRes, rotation);
+
+ currentPageObject.createIncludePageOverlay(overlayName, x, y, 0);
currentPage = currentOverlay;
setOffsets(0, 0, 0);
}
@@ -300,17 +349,13 @@
/**
* Helper method to mark the end of the current page.
- *
- * @throws java.io.IOException
- * thrown when an I/O exception of some sort has occurred
*/
- public void endPage() throws IOException {
+ public void endPage() {
currentPageObject.endPage();
if (currentPageGroup != null) {
currentPageGroup.addPage(currentPageObject);
} else {
document.addPage(currentPageObject);
- document.writeDataStream(this.outputStream);
}
currentPageObject = null;
currentPage = null;
@@ -363,7 +408,6 @@
currentPage.createFont(fontReference, font, size);
}
-
/**
* Helper method to create text on the current page, this method delegates
* to the current presentation text object in order to construct the text.
@@ -388,55 +432,46 @@
currentPage.createText(fontReference, x + xOffset, y + yOffset, rotation,
col, vsci, ica, data);
}
-
+
/**
- * Returns an ImageObject used to create an image in the datastream.
- *
- * @param x
- * the x position of the image
- * @param y
- * the y position of the image
- * @param width
- * the width of the image
- * @param height
- * the height of the image
- * @param widthRes
- * the resolution width of the image
- * @param heightRes
- * the resolution height of the image
+ * 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 image object
+ * a new include object referencing an image object
*/
- public ImageObject getImageObject(int x, int y, int width, int height,
- int widthRes, int heightRes) {
- ImageObject imageObj = currentPage.getImageObject();
- setObjectViewPort(imageObj, x, y, width, height, widthRes, heightRes);
- return imageObj;
+ public IncludeObject createImageObject(ImageObjectParameters params) {
+ ResourceLevel resourceLevel = params.getResourceLevel();
+ IncludeObject includeObj = getResourceGroup(resourceLevel).addObject(params);
+ currentPage.addObject(includeObj);
+ return includeObj;
}
/**
- * Returns an GraphicObject used to create an graphic in the datastream.
+ * Returns an IncludeObject referencing a graphic in the datastream.
*
- * @param x
- * the x position of the graphic
- * @param y
- * the y position of the graphic
- * @param width
- * the width of the graphic
- * @param height
- * the height of the graphic
- * @param widthRes
- * the resolution width of the graphic
- * @param heightRes
- * the resolution height of the graphic
+ * @param params
+ * the data object parameters
* @return
- * a new graphics object
+ * a new include object referencing the graphics object
*/
- public GraphicsObject getGraphicsObject(int x, int y, int width, int height,
- int widthRes, int heightRes) {
- GraphicsObject graphicsObj = currentPage.getGraphicsObject();
- setObjectViewPort(graphicsObj, x, y, width, height, widthRes, heightRes);
- return graphicsObj;
+ public IncludeObject createGraphicsObject(DataObjectParameters params) {
+ ResourceLevel resourceLevel = params.getResourceLevel();
+ IncludeObject includeObj = getResourceGroup(resourceLevel).addObject(params);
+ currentPage.addObject(includeObj);
+ return includeObj;
}
/**
@@ -559,9 +594,7 @@
*/
public void createIncludePageOverlay(String name) {
currentPageObject.createIncludePageOverlay(name, 0, 0, rotation);
- ActiveEnvironmentGroup aeg = currentPageObject
- .getActiveEnvironmentGroup();
- aeg.createOverlay(name);
+ currentPageObject.getActiveEnvironmentGroup().createOverlay(name);
}
/**
@@ -571,10 +604,7 @@
* the name of the medium map
*/
public void createInvokeMediumMap(String name) {
- if (currentPageGroup == null) {
- startPageGroup();
- }
- currentPageGroup.createInvokeMediumMap(name);
+ getCurrentPageGroup().createInvokeMediumMap(name);
}
/**
@@ -621,7 +651,7 @@
for (int i = 0; i < attributes.length; i++) {
String name = (String) attributes[i].getKey();
String value = (String) attributes[i].getValue();
- currentPage.createTagLogicalElement(name, value);
+ getCurrentPage().createTagLogicalElement(name, value);
}
}
@@ -635,7 +665,7 @@
for (int i = 0; i < attributes.length; i++) {
String name = (String) attributes[i].getKey();
String value = (String) attributes[i].getValue();
- currentPageGroup.createTagLogicalElement(name, value);
+ getCurrentPageGroup().createTagLogicalElement(name, value);
}
}
@@ -665,31 +695,33 @@
currentPage.createNoOperation(content);
}
+ private PageGroup getCurrentPageGroup() {
+ if (currentPageGroup == null) {
+ String pageGroupName = "PGP"
+ + StringUtils.lpad(String.valueOf(pageGroupCount++), '0', 5);
+ this.currentPageGroup = new PageGroup(pageGroupName);
+ }
+ return currentPageGroup;
+ }
+
/**
* Start a new page group. When processing has finished on the current page
* group the {@link #endPageGroup()}method must be invoked to mark the page
* group ending.
*/
public void startPageGroup() {
-
- String pageGroupName = "PGP"
- + StringUtils.lpad(String.valueOf(pageCount++), '0', 5);
-
- currentPageGroup = new PageGroup(pageGroupName);
-
+ getCurrentPageGroup();
}
/**
* Helper method to mark the end of the page group.
- * @throws IOException thrown if an I/O exception of some sort has occurred
*/
- public void endPageGroup() throws IOException {
-
- currentPageGroup.endPageGroup();
- document.addPageGroup(currentPageGroup);
- document.writeDataStream(outputStream);
- currentPageGroup = null;
-
+ public void endPageGroup() {
+ if (currentPageGroup != null) {
+ currentPageGroup.endPageGroup();
+ document.addPageGroup(currentPageGroup);
+ currentPageGroup = null;
+ }
}
/**
@@ -700,7 +732,6 @@
* The rotation in degrees.
*/
public void setPortraitRotation(int pageRotation) {
-
if (pageRotation == 0 || pageRotation == 90 || pageRotation == 180
|| pageRotation == 270) {
this.portraitRotation = pageRotation;
@@ -708,7 +739,6 @@
throw new IllegalArgumentException(
"The portrait rotation must be one of the values 0, 90, 180, 270");
}
-
}
/**
@@ -719,7 +749,6 @@
* The rotation in degrees.
*/
public void setLandscapeRotation(int pageRotation) {
-
if (pageRotation == 0 || pageRotation == 90 || pageRotation == 180
|| pageRotation == 270) {
this.landscapeRotation = pageRotation;
@@ -727,6 +756,72 @@
throw new IllegalArgumentException(
"The landscape rotation must be one of the values 0, 90, 180, 270");
}
+ }
+
+ /**
+ * 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);
+ }
+ }
+ }
+ }
+ }
+ /**
+ * Returns the resource group for a given resource level
+ * @param resourceLevel a resource level
+ * @return a resource group container for the given level
+ */
+ 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);
+ }
+ }
+ return resourceGroup;
+ }
+
+ private Map/*<String,ResourceGroup>*/ getExternalResourceGroups() {
+ if (externalResourceGroups == null) {
+ externalResourceGroups = new java.util.HashMap();
+ }
+ 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=641873&r1=641872&r2=641873&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 Thu Mar 27 09:16:30 2008
@@ -21,8 +21,8 @@
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Collection;
import java.util.Iterator;
-import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -50,16 +50,18 @@
/**
* Help method to write a set of AFPObjects to the AFP datastream.
- * @param afpObjects a list of AFPObjects
+ * @param objects a list of AFPObjects
* @param os The stream to write to
* @throws java.io.IOException in the event that an I/O exception occurred
*/
- protected void writeObjectList(List afpObjects, OutputStream os)
+ protected void writeObjects(Collection/*<AbstractAFPObject>*/ objects, OutputStream os)
throws IOException {
-
- Iterator it = afpObjects.iterator();
- while (it.hasNext()) {
- ((AbstractAFPObject)it.next()).writeDataStream(os);
+ if (objects != null) {
+ for (Iterator it = objects.iterator(); it.hasNext();) {
+ Object obj1 = it.next();
+ AbstractAFPObject obj = (AbstractAFPObject)obj1;
+ obj.writeDataStream(os);
+ }
}
}
-}
+}
\ No newline at end of file
Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java?rev=641873&r1=641872&r2=641873&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java Thu Mar 27 09:16:30 2008
@@ -22,7 +22,7 @@
import java.io.IOException;
import java.io.OutputStream;
-import org.apache.fop.render.afp.modca.goca.AbstractGraphicsContainer;
+import org.apache.fop.render.afp.goca.AbstractGraphicsContainer;
/**
* Abstract base class used by the ImageObject and GraphicsObject which both
Added: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractEnvironmentGroup.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractEnvironmentGroup.java?rev=641873&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractEnvironmentGroup.java (added)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractEnvironmentGroup.java Thu Mar 27 09:16:30 2008
@@ -0,0 +1,100 @@
+/*
+ * 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;
+import java.util.List;
+
+/**
+ * A base class that encapsulates common features of
+ * ActiveEnvironmentGroup and ResourceEnvironmentGroup
+ */
+public abstract class AbstractEnvironmentGroup extends AbstractNamedAFPObject {
+
+ /**
+ * The collection of MapPageOverlay objects
+ */
+ protected List mapPageOverlays = null;
+
+ /**
+ * Main constructor
+ * @param name the object name
+ */
+ public AbstractEnvironmentGroup(String name) {
+ super(name);
+ }
+
+ private List getMapPageOverlays() {
+ if (mapPageOverlays == null) {
+ mapPageOverlays = new java.util.ArrayList();
+ }
+ return mapPageOverlays;
+ }
+
+ /**
+ * Actually creates the MPO object.
+ * Also creates the supporting object (an IPO)
+ * @param name the name of the overlay to be used
+ */
+ public void createOverlay(String name) {
+ MapPageOverlay mpo = getCurrentMapPageOverlay();
+ if (mpo == null) {
+ mpo = new MapPageOverlay();
+ getMapPageOverlays().add(mpo);
+ }
+
+ try {
+ mpo.addOverlay(name);
+ } catch (MaximumSizeExceededException msee) {
+ mpo = new MapPageOverlay();
+ getMapPageOverlays().add(mpo);
+ try {
+ mpo.addOverlay(name);
+ } catch (MaximumSizeExceededException ex) {
+ // Should never happen (but log just in case)
+ log.error("createOverlay():: resulted in a MaximumSizeExceededException");
+ }
+ }
+ }
+
+ /**
+ * Getter method for the most recent MapPageOverlay added to the
+ * Active Environment Group (returns null if no MapPageOverlay exist)
+ * @return the most recent Map Coded Font
+ */
+ private MapPageOverlay getCurrentMapPageOverlay() {
+ if (mapPageOverlays != null && mapPageOverlays.size() > 0) {
+ return (MapPageOverlay) mapPageOverlays.get(mapPageOverlays.size() - 1);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void writeContent(OutputStream os) throws IOException {
+ super.writeContent(os);
+ if (mapPageOverlays != null) {
+ writeObjects(mapPageOverlays, 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=641873&r1=641872&r2=641873&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 Thu Mar 27 09:16:30 2008
@@ -18,14 +18,17 @@
/* $Id$ */
package org.apache.fop.render.afp.modca;
+
import java.io.UnsupportedEncodingException;
/**
* This is the base class for all named data stream objects.
* A named data stream object has an 8 byte EBCIDIC name.
*/
-public abstract class AbstractNamedAFPObject extends AbstractAFPObject {
-
+public abstract class AbstractNamedAFPObject extends AbstractStructuredAFPObject {
+
+ private static final int DEFAULT_NAME_LENGTH = 8;
+
/**
* The actual name of the object
*/
@@ -41,22 +44,13 @@
*/
protected AbstractNamedAFPObject() {
}
-
- private static final int DEFAULT_NAME_LENGTH = 8;
-
- /**
- * @return the name length of this object
- */
- protected int getNameLength() {
- return DEFAULT_NAME_LENGTH;
- }
-
+
/**
* Constructor for the ActiveEnvironmentGroup, this takes a
* name parameter which should be 8 characters long.
* @param name the object name
*/
- public AbstractNamedAFPObject(String name) {
+ protected AbstractNamedAFPObject(String name) {
int nameLen = getNameLength();
if (name.length() < nameLen) {
this.name = (name + " ").substring(0, nameLen);
@@ -66,19 +60,27 @@
} else {
this.name = name;
}
-
try {
-
this.nameBytes = name.getBytes(AFPConstants.EBCIDIC_ENCODING);
-
} catch (UnsupportedEncodingException usee) {
-
this.nameBytes = name.getBytes();
log.warn(
"Constructor:: UnsupportedEncodingException translating the name "
+ name);
-
}
-
+ }
+
+ /**
+ * @return the name length of this object
+ */
+ protected int getNameLength() {
+ return DEFAULT_NAME_LENGTH;
+ }
+
+ /**
+ * @return the name of the page group
+ */
+ 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=641873&r1=641872&r2=641873&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 Thu Mar 27 09:16:30 2008
@@ -20,7 +20,8 @@
package org.apache.fop.render.afp.modca;
import java.awt.Color;
-import java.util.ArrayList;
+import java.io.IOException;
+import java.io.OutputStream;
import java.util.List;
import org.apache.fop.render.afp.fonts.AFPFont;
@@ -46,32 +47,27 @@
* in page state.
*
*/
-public abstract class AbstractPageObject extends AbstractNamedAFPObject {
+public abstract class AbstractPageObject extends AbstractResourceGroupContainer {
/**
* The active environment group for the page
*/
- protected ActiveEnvironmentGroup activeEnvironmentGroup = null;
+ protected ActiveEnvironmentGroup activeEnvironmentGroup;
/**
* The presentation text object, we only have one per page
*/
- private PresentationTextObject presentationTextObject = null;
-
- /**
- * The list of objects within the page
- */
- protected List objects = new ArrayList();
+ private PresentationTextObject presentationTextObject;
/**
* The list of tag logical elements
*/
- protected ArrayList tagLogicalElements = new ArrayList();
+ protected List tagLogicalElements;
/**
* The list of the include page segments
*/
- protected ArrayList segments = new ArrayList();
+ protected List segments;
/**
* The page width
@@ -112,8 +108,8 @@
*/
public AbstractPageObject(String name, int width, int height, int rotation,
int widthRes, int heightRes) {
-
super(name);
+
this.width = width;
this.height = height;
this.rotation = rotation;
@@ -121,7 +117,8 @@
/**
* Every page object must have an ActiveEnvironmentGroup
*/
- activeEnvironmentGroup = new ActiveEnvironmentGroup(width, height, widthRes, heightRes);
+ this.activeEnvironmentGroup = new ActiveEnvironmentGroup(
+ width, height, widthRes, heightRes);
if (rotation != 0) {
switch (rotation) {
@@ -152,7 +149,7 @@
* the point size of the font
*/
public void createFont(int fontReference, AFPFont font, int size) {
- activeEnvironmentGroup.createFont(fontReference, font, size, 0);
+ getActiveEnvironmentGroup().createFont(fontReference, font, size, 0);
}
/**
@@ -183,7 +180,7 @@
* Helper method to create text on the current page, this method delegates
* to the presentation text object in order to construct the text.
*
- * @param fontReference
+ * @param fontRef
* the font number used as the resource identifier
* @param x
* the x coordinate of the text data
@@ -200,15 +197,15 @@
* @param data
* the text data to create
*/
- public void createText(int fontReference, int x, int y, int textRotation, Color col,
+ public void createText(int fontRef, int x, int y, int textRotation, Color col,
int vsci, int ica, byte[] data) {
getPresentationTextObject().createTextData(
- fontReference, x, y, textRotation, col, vsci, ica, data);
+ fontRef, x, y, textRotation, col, vsci, ica, data);
}
/**
* Helper method to mark the end of the page. This should end the control
- * sequence on the current presenation text object.
+ * sequence on the current presentation text object.
*/
public void endPage() {
if (presentationTextObject != null) {
@@ -237,14 +234,11 @@
* @param blue
* the blue value
*/
- public void createShading(int x, int y, int w, int h, int red, int green,
- int blue) {
-
+ public void createShading(int x, int y, int w, int h, int red, int green, int blue) {
int xCoord = 0;
int yCoord = 0;
int areaWidth = 0;
int areaHeight = 0;
-
switch (rotation) {
case 90:
xCoord = areaWidth - y - h;
@@ -278,7 +272,7 @@
int greyscale = Math.round((shade / 255) * 16);
String imageName = "IMG"
- + StringUtils.lpad(String.valueOf(objects.size() + 1),
+ + StringUtils.lpad(String.valueOf(getResourceCount() + 1),
'0', 5);
IMImageObject io = new IMImageObject(imageName);
@@ -291,17 +285,23 @@
icp.setYSize(8);
//defining this as a resource
- ImageRasterData ird = new ImageRasterData(ImageRasterPattern
- .getRasterData(greyscale));
+ ImageRasterData ird = new ImageRasterData(
+ ImageRasterPattern.getRasterData(greyscale));
io.setImageOutputControl(ioc);
io.setImageInputDescriptor(iid);
io.setImageCellPosition(icp);
io.setImageRasterData(ird);
- objects.add(io);
-
+ addObject(io);
}
+ private void endPresentationObject() {
+ if (presentationTextObject != null) {
+ presentationTextObject.endControlSequence();
+ presentationTextObject = null;
+ }
+ }
+
/**
* Helper method to create a presentation text object
* on the current page and to return the object.
@@ -310,49 +310,12 @@
private PresentationTextObject getPresentationTextObject() {
if (presentationTextObject == null) {
this.presentationTextObject = new PresentationTextObject();
- objects.add(this.presentationTextObject);
+ addObject(this.presentationTextObject);
}
return presentationTextObject;
}
/**
- * Helper method to create an image on the current page and to return
- * the object.
- * @return the image object
- */
- public ImageObject getImageObject() {
-
- if (presentationTextObject != null) {
- presentationTextObject.endControlSequence();
- presentationTextObject = null;
- }
- String imageName = "IMG"
- + StringUtils.lpad(String.valueOf(objects.size() + 1),
- '0', 5);
- ImageObject imageObj = new ImageObject(imageName);
- objects.add(imageObj);
- return imageObj;
- }
-
- /**
- * Helper method to create a graphic on the current page and to return
- * the object.
- * @return the graphics object
- */
- public GraphicsObject getGraphicsObject() {
- if (presentationTextObject != null) {
- presentationTextObject.endControlSequence();
- presentationTextObject = null;
- }
- String graphicName = "GRA"
- + StringUtils.lpad(String.valueOf(objects.size() + 1),
- '0', 5);
- GraphicsObject graphicsObj = new GraphicsObject(graphicName);
- objects.add(graphicsObj);
- return graphicsObj;
- }
-
- /**
* Creates a TagLogicalElement on the page.
*
* @param name
@@ -362,6 +325,9 @@
*/
public void createTagLogicalElement(String name, String value) {
TagLogicalElement tle = new TagLogicalElement(name, value);
+ if (tagLogicalElements == null) {
+ tagLogicalElements = new java.util.ArrayList();
+ }
tagLogicalElements.add(tle);
}
@@ -371,8 +337,7 @@
* @param content the byte data
*/
public void createNoOperation(String content) {
- NoOperation noOp = new NoOperation(content);
- objects.add(noOp);
+ addObject(new NoOperation(content));
}
/**
@@ -387,6 +352,9 @@
*/
public void createIncludePageSegment(String name, int xCoor, int yCoor) {
IncludePageSegment ips = new IncludePageSegment(name, xCoor, yCoor);
+ if (segments == null) {
+ segments = new java.util.ArrayList();
+ }
segments.add(ips);
}
@@ -430,4 +398,54 @@
public int getRotation() {
return rotation;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void writeContent(OutputStream os) throws IOException {
+ super.writeContent(os);
+ getActiveEnvironmentGroup().writeDataStream(os);
+ writeObjects(segments, os);
+ writeObjects(tagLogicalElements, os);
+ 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}
+ */
+ 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);
+ }
+ }
+ endPresentationObject();
+ super.addObject(obj);
+ }
+
+// /**
+// * {@inheritDoc}
+// */
+// protected void addObject(AbstractStructuredAFPObject obj) {
+// endPresentationObject();
+// super.addObject(obj);
+// }
}
Added: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java?rev=641873&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java (added)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java Thu Mar 27 09:16:30 2008
@@ -0,0 +1,83 @@
+/*
+ * 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;
+
+
+/**
+ * A base class that carries out early preparation of structured field data
+ * for the AFP object (so the data length can be pre-calculated)
+ */
+public abstract class AbstractPreparedAFPObject extends AbstractNamedAFPObject
+implements PreparedAFPObject {
+
+ /** structured field data to be written */
+ protected byte[] data = null;
+
+ /**
+ * Default constructor
+ */
+ public AbstractPreparedAFPObject() {
+ }
+
+ /**
+ * Named constructor
+ * @param name the name of this AFP object
+ */
+ public AbstractPreparedAFPObject(String name) {
+ super(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void writeContent(OutputStream os) throws IOException {
+ super.writeContent(os); // write triplets
+ if (this.data != null) {
+ os.write(this.data);
+ }
+ }
+
+ /**
+ * @return the start data length of this structured field
+ */
+ protected int getStartDataLength() {
+ return 0;
+ }
+
+ /**
+ * @return the data length of the structured field data of this AFP object
+ */
+ public int getDataLength() {
+ if (this.data != null) {
+ return this.data.length;
+ }
+ return 0;
+ }
+
+ /**
+ * @return the structured field length
+ */
+ protected int getLength() {
+ return getStartDataLength() + getTripletDataLength() + getDataLength();
+ }
+}
\ No newline at end of file
Added: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java?rev=641873&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java (added)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractResourceEnvironmentGroupContainer.java Thu Mar 27 09:16:30 2008
@@ -0,0 +1,108 @@
+/*
+ * 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;
+import java.util.Iterator;
+
+/**
+ * An abstract class which encapsulates the common features of
+ * Document and PageGroup resource containers
+ */
+public abstract class AbstractResourceEnvironmentGroupContainer
+ extends AbstractResourceGroupContainer {
+
+ /**
+ * The resource environment group used to store complex resources
+ */
+ protected ResourceEnvironmentGroup resourceEnvironmentGroup = null;
+
+ /**
+ * Main constructor
+ * @param name the name of this resource container
+ */
+ public AbstractResourceEnvironmentGroupContainer(String name) {
+ super(name);
+ }
+
+ /**
+ * Adds a page to the resource container.
+ * @param page - the Page object
+ */
+ public void addPage(PageObject page) {
+ addObject(page);
+ }
+
+ /**
+ * Adds a PageGroup to the resource container.
+ * @param pageGroup the PageGroup object
+ */
+ public void addPageGroup(PageGroup pageGroup) {
+ addObject(pageGroup);
+ }
+
+ /**
+ * Creates an InvokeMediaMap on the page.
+ *
+ * @param name
+ * the name of the media map
+ */
+ public void createInvokeMediumMap(String name) {
+ addObject(new InvokeMediumMap(name));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void writeContent(OutputStream os) throws IOException {
+ super.writeContent(os);
+ if (resourceEnvironmentGroup != null) {
+ resourceEnvironmentGroup.writeDataStream(os);
+ }
+ if (objects != null) {
+ for (Iterator it = objects.iterator(); it.hasNext();) {
+ AbstractAFPObject ao = (AbstractAFPObject)it.next();
+ if (ao instanceof PageObject && ((PageObject)ao).isComplete()
+ || ao instanceof PageGroup && ((PageGroup)ao).isComplete()) {
+ ao.writeDataStream(os);
+ it.remove();
+ } else {
+ break;
+ }
+ }
+ }
+ }
+
+ private ResourceEnvironmentGroup getResourceEnvironmentGroup() {
+ if (resourceEnvironmentGroup == null) {
+ this.resourceEnvironmentGroup = new ResourceEnvironmentGroup();
+ }
+ return this.resourceEnvironmentGroup;
+ }
+
+ /**
+ * Adds a resource mapping to this resource environment group
+ * @param obj a resource to be referenced in this resource environment group
+ */
+ protected void addResource(AbstractStructuredAFPObject obj) {
+ getResourceEnvironmentGroup().addObject(obj);
+ }
+}
Added: 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=641873&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java (added)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/AbstractResourceGroupContainer.java Thu Mar 27 09:16:30 2008
@@ -0,0 +1,124 @@
+/*
+ * 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;
+import java.util.Set;
+
+import org.apache.fop.render.afp.DataObjectParameters;
+import org.apache.fop.render.afp.ImageObjectParameters;
+
+/**
+ * An abstract container of resource objects
+ */
+public abstract class AbstractResourceGroupContainer extends AbstractNamedAFPObject {
+ /**
+ * The resource group object
+ */
+ private ResourceGroup resourceGroup = null;
+
+ /**
+ * The list of objects within this resource container
+ */
+ protected Set/*<AbstractStructuredAFPObject>*/ objects = null;
+
+ /**
+ * Unnamed constructor
+ */
+ public AbstractResourceGroupContainer() {
+ }
+
+ /**
+ * Named constructor
+ * @param name the name of this resource container
+ */
+ public AbstractResourceGroupContainer(String name) {
+ super(name);
+ }
+
+ /**
+ * @return the number of resources in this container
+ */
+ protected int getResourceCount() {
+ if (resourceGroup != null) {
+ return resourceGroup.getResourceCount();
+ }
+ return 0;
+ }
+
+ /**
+ * Adds an AFP object to the resource group in this container
+ * @param obj an AFP object
+ */
+ protected void addObject(AbstractAFPObject obj) {
+ if (objects == null) {
+ this.objects = new java.util.LinkedHashSet/*<AbstractAFPObject>*/();
+ }
+ objects.add(obj);
+ }
+
+ /**
+ * @return true if this resource group container contains resources
+ */
+ protected boolean hasResources() {
+ return resourceGroup != null && resourceGroup.getResourceCount() > 0;
+ }
+
+ /**
+ * @return the resource group in this resource group container
+ */
+ protected ResourceGroup getResourceGroup() {
+ if (resourceGroup == null) {
+ resourceGroup = new ResourceGroup();
+ }
+ return resourceGroup;
+ }
+
+ /**
+ * 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
+ */
+ public IncludeObject createImageObject(ImageObjectParameters params) {
+ return getResourceGroup().addObject(params);
+ }
+
+ /**
+ * 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
+ */
+ public IncludeObject createGraphicsObject(DataObjectParameters params) {
+ return getResourceGroup().addObject(params);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void writeContent(OutputStream os) throws IOException {
+ super.writeContent(os);
+ if (resourceGroup != null) {
+ resourceGroup.writeDataStream(os);
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org