/**
* Frequently used MIME types for various file formats used when working with Apache FOP.
*/
-public interface MimeConstants {
+public interface MimeConstants extends org.apache.xmlgraphics.util.MimeConstants {
- /** Portable Document Format */
- String MIME_PDF = "application/pdf";
-
- /** PostScript */
- String MIME_POSTSCRIPT = "application/postscript";
- /** Encapsulated PostScript (same MIME type as PostScript) */
- String MIME_EPS = MIME_POSTSCRIPT;
-
- /** HP's PCL */
- String MIME_PCL = "application/x-pcl";
- /** HP's PCL (alternative MIME type) */
- String MIME_PCL_ALT = "application/vnd.hp-PCL";
-
- /** IBM's AFP */
- String MIME_AFP = "application/x-afp";
- /** IBM's AFP (alternative MIME type) */
- String MIME_AFP_ALT = "application/vnd.ibm.modcap";
-
- /** Plain text */
- String MIME_PLAIN_TEXT = "text/plain";
-
- /** Rich text format */
- String MIME_RTF = "application/rtf";
- /** Rich text format (alternative 1) */
- String MIME_RTF_ALT1 = "text/richtext";
- /** Rich text format (alternative 2) */
- String MIME_RTF_ALT2 = "text/rtf";
-
- /** FrameMaker's MIF */
- String MIME_MIF = "application/mif";
-
- /** Scalable Vector Graphics */
- String MIME_SVG = "image/svg+xml";
-
- /** GIF images */
- String MIME_GIF = "image/gif";
- /** PNG images */
- String MIME_PNG = "image/png";
- /** JPEG images */
- String MIME_JPEG = "image/jpeg";
- /** TIFF images */
- String MIME_TIFF = "image/tiff";
-
/** Apache FOP's AWT preview (non-standard MIME type) */
String MIME_FOP_AWT_PREVIEW = "application/X-fop-awt-preview";
/** Apache FOP's Direct Printing (non-standard MIME type) */
/** Apache FOP's area tree XML */
String MIME_FOP_AREA_TREE = "application/X-fop-areatree";
- /** Proposed but non-registered MIME type for XSL-FO */
- String MIME_XSL_FO = "text/xsl";
-
}
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
-import java.util.Collections;
import java.util.Map;
import org.apache.commons.logging.Log;
/**
* A list of parameters associated with an AFP data objects
*/
-public class DataObjectInfo {
+public abstract class DataObjectInfo {
private static final Log log = LogFactory.getLog("org.apache.fop.afp");
private static final String RESOURCE_NAME = "afp:resource-name";
/** {@inheritDoc} */
public String toString() {
- return (objectAreaInfo != null ? ", objectAreaInfo=" + objectAreaInfo : "")
+ return "mimeType=" + getMimeType()
+ + (objectAreaInfo != null ? ", objectAreaInfo=" + objectAreaInfo : "")
+ (objectType != null ? ", objectType=" + objectType : "")
+ (resourceInfo != null ? ", resourceInfo=" + resourceInfo : "");
}
public void setUri(String uri) {
getResourceInfo().setUri(uri);
}
+
+ /**
+ * Returns the mime type of this data object
+ *
+ * @return the mime type of this data object
+ */
+ public abstract String getMimeType();
+
}
package org.apache.fop.render.afp;
+import org.apache.xmlgraphics.util.MimeConstants;
+
/**
* A graphics object info which contains necessary painting objects
*/
public void setPainter(GraphicsObjectPainter graphicsPainter) {
this.painter = graphicsPainter;
}
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return "GraphicsObjectInfo{" + super.toString() + "}";
+ }
+
+ /** {@inheritDoc} */
+ public String getMimeType() {
+ return MimeConstants.MIME_SVG;
+ }
}
this.dataHeight = imageDataHeight;
}
- /**
- * Returns the mime type of this image
- *
- * @return the mime type of this image
- */
+ /** {@inheritDoc} */
public String getMimeType() {
return mimeType;
}
/** {@inheritDoc} */
public String toString() {
- return super.toString()
- + ", mimeType=" + mimeType
+ return "ImageObjectInfo{" + super.toString()
+ ", dataWidth=" + dataWidth
+ ", dataHeight=" + dataHeight
+ ", color=" + color
- + ", bitPerPixel=" + bitsPerPixel;
+ + ", bitPerPixel=" + bitsPerPixel
+ + "}";
}
}
\ No newline at end of file
Registry.ObjectType objectType = registry.getObjectType(dataObjectInfo);
if (objectType != null) {
dataObjectInfo.setObjectType(objectType);
+ } else {
+ log.info("Unknown object type for '" + dataObjectInfo + "'");
}
DataObjectCache.Record record = cache.store(dataObjectInfo);
log.warn("Data object located at '" + uri + "'"
+ " of type '" + objectType.getMimeType() + "'"
+ " cannot be referenced with an include"
- + " so it will be embedded directly");
+ + " so it will be embedded directly in the page");
}
} else {
if (resourceLevel.isExternal()) {
resourceObj.setDataObject(dataObj);
dataObj = resourceObj;
}
- } else {
- String uri = dataObjectInfo.getUri();
- log.warn("Data object '" + uri + "' not supported at "
- + resourceLevel.toString() + " level, will be embedded in page.");
}
}
private static final byte COMPID_TIFF = 14;
/** mime type entry mapping */
- private java.util.Map/*<String, Registry.ObjectType>*/ mimeEntryMap
+ private java.util.Map/*<String, Registry.ObjectType>*/ mimeObjectTypeMap
= Collections.synchronizedMap(
new java.util.HashMap/*<String, Registry.ObjectType>*/());
}
private void init() {
- mimeEntryMap.put(
+ mimeObjectTypeMap.put(
MimeConstants.MIME_EPS,
new ObjectType(
COMPID_EPS,
MimeConstants.MIME_EPS
)
);
- mimeEntryMap.put(
+ mimeObjectTypeMap.put(
MimeConstants.MIME_TIFF,
new ObjectType(
COMPID_TIFF,
MimeConstants.MIME_TIFF
)
);
- mimeEntryMap.put(
+ mimeObjectTypeMap.put(
MimeConstants.MIME_GIF,
new ObjectType(
COMPID_GIF,
MimeConstants.MIME_GIF
)
);
- mimeEntryMap.put(
+ mimeObjectTypeMap.put(
MimeConstants.MIME_JPEG,
new ObjectType(
COMPID_JFIF,
MimeConstants.MIME_JPEG
)
);
- mimeEntryMap.put(MimeConstants.MIME_PDF,
+ mimeObjectTypeMap.put(MimeConstants.MIME_PDF,
new ObjectType(
COMPID_PDF_SINGLE_PAGE,
new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x19},
MimeConstants.MIME_PDF
)
);
- mimeEntryMap.put(
+ mimeObjectTypeMap.put(
MimeConstants.MIME_PCL,
new ObjectType(
COMPID_PCL_PAGE_OBJECT,
);
// Entries without component and object ids
- mimeEntryMap.put(
+ mimeObjectTypeMap.put(
MimeConstants.MIME_SVG,
new ObjectType(
"Scaleable Vector Graphics",
MimeConstants.MIME_SVG
)
);
- mimeEntryMap.put(
+ mimeObjectTypeMap.put(
MimeConstants.MIME_PNG,
new ObjectType(
"Portable Network Graphics",
);
}
- /**
- * Returns the Registry ObjectType for a given mimetype
- *
- * @param mimeType the object mime type
- * @return the Registry ObjectType for a given data object info
- */
- public Registry.ObjectType getObjectType(String mimeType) {
- ObjectType entry = null;
- if (mimeType != null) {
- entry = (Registry.ObjectType)mimeEntryMap.get(mimeType);
- } else {
- log.info("mimetype '" + mimeType + "' not found");
- }
- return entry;
- }
-
/**
* Returns the Registry ObjectType for a given data object info
*
* @return the Registry ObjectType for a given data object info
*/
public Registry.ObjectType getObjectType(DataObjectInfo dataObjectInfo) {
- ObjectType entry = null;
- if (dataObjectInfo instanceof ImageObjectInfo) {
- ImageObjectInfo imageInfo = (ImageObjectInfo)dataObjectInfo;
- String mimeType = imageInfo.getMimeType();
- return getObjectType(mimeType);
- }
- return entry;
+ String mimeType = dataObjectInfo.getMimeType();
+ ObjectType objectType = (Registry.ObjectType)mimeObjectTypeMap.get(mimeType);
+ return objectType;
}
/**