private Map/*<String,String>*/pageSegmentMap
= new java.util.HashMap/*<String,String>*/();
+ /** Medium Map referenced on previous page **/
+ private String lastMediumMap;
+
private static final int LOC_ELSEWHERE = 0;
private static final int LOC_FOLLOWING_PAGE_SEQUENCE = 1;
private static final int LOC_IN_PAGE_HEADER = 2;
}
}
} else if (extension instanceof AFPInvokeMediumMap) {
- if (this.location != LOC_FOLLOWING_PAGE_SEQUENCE) {
+ if (this.location != LOC_FOLLOWING_PAGE_SEQUENCE
+ && this.location != LOC_IN_PAGE_HEADER) {
+
throw new IFException(
- "AFP IMM extension must be between page-sequence and the first page: "
- + extension, null);
+ "AFP IMM extension must be between page-sequence"
+ + " and the first page or child of page-header: "
+ + extension, null);
}
AFPInvokeMediumMap imm = (AFPInvokeMediumMap)extension;
String mediumMap = imm.getName();
- if (mediumMap != null) {
+ if (mediumMap != null && !mediumMap.equals(lastMediumMap)) {
dataStream.createInvokeMediumMap(mediumMap);
+ lastMediumMap = mediumMap;
}
} else if (extension instanceof AFPIncludeFormMap) {
AFPIncludeFormMap formMap = (AFPIncludeFormMap)extension;
/** the shading mode for filled rectangles */
private AFPShadingMode shadingMode = AFPShadingMode.COLOR;
+ /** medium map referenced used on previous page **/
+ private String lastMediumMap;
+
/**
* Constructor for AFPRenderer.
*/
int resolution = paintingState.getResolution();
+ // IMM should occur before BPG
+ renderInvokeMediumMap(pageViewport);
+
dataStream.startPage(pageWidth, pageHeight, pageRotation,
resolution, resolution);
return MimeConstants.MIME_AFP;
}
+ /**
+ * checks for IMM Extension and renders if found and different
+ * from previous page
+ *
+ * @param pageViewport the page object
+ */
+ private void renderInvokeMediumMap(PageViewport pageViewport) {
+ if (pageViewport.getExtensionAttachments() != null
+ && pageViewport.getExtensionAttachments().size() > 0) {
+ Iterator it = pageViewport.getExtensionAttachments().iterator();
+ while (it.hasNext()) {
+ ExtensionAttachment attachment = (ExtensionAttachment) it.next();
+ if (AFPExtensionAttachment.CATEGORY.equals(attachment.getCategory())) {
+ AFPExtensionAttachment aea = (AFPExtensionAttachment)attachment;
+ if (AFPElementMapping.INVOKE_MEDIUM_MAP.equals(aea.getElementName())) {
+ AFPInvokeMediumMap imm = (AFPInvokeMediumMap)attachment;
+ String mediumMap = imm.getName();
+ if (mediumMap != null) {
+ if (!mediumMap.equals(lastMediumMap)) {
+ dataStream.createInvokeMediumMap(mediumMap);
+ lastMediumMap = mediumMap;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
/**
* Method to render the page extension.
* <p>
while (it.hasNext()) {
ExtensionAttachment attachment = (ExtensionAttachment) it.next();
if (AFPPageSetup.CATEGORY.equals(attachment.getCategory())) {
- AFPPageSetup aps = (AFPPageSetup) attachment;
- String element = aps.getElementName();
- if (AFPElementMapping.INCLUDE_PAGE_OVERLAY.equals(element)) {
- String overlay = aps.getName();
- if (overlay != null) {
- dataStream.createIncludePageOverlay(overlay);
- }
- } else if (AFPElementMapping.INCLUDE_PAGE_SEGMENT
- .equals(element)) {
- String name = aps.getName();
- String source = aps.getValue();
- pageSegmentMap.put(source, name);
- } else if (AFPElementMapping.TAG_LOGICAL_ELEMENT
- .equals(element)) {
- String name = aps.getName();
- String value = aps.getValue();
- dataStream.createTagLogicalElement(name, value);
- } else if (AFPElementMapping.NO_OPERATION.equals(element)) {
- String content = aps.getContent();
- if (content != null) {
- dataStream.createNoOperation(content);
+ if (attachment instanceof AFPPageSetup) {
+ AFPPageSetup aps = (AFPPageSetup) attachment;
+ String element = aps.getElementName();
+ if (AFPElementMapping.INCLUDE_PAGE_OVERLAY.equals(element)) {
+ String overlay = aps.getName();
+ if (overlay != null) {
+ dataStream.createIncludePageOverlay(overlay);
+ }
+ } else if (AFPElementMapping.INCLUDE_PAGE_SEGMENT
+ .equals(element)) {
+ String name = aps.getName();
+ String source = aps.getValue();
+ pageSegmentMap.put(source, name);
+ } else if (AFPElementMapping.TAG_LOGICAL_ELEMENT
+ .equals(element)) {
+ String name = aps.getName();
+ String value = aps.getValue();
+ dataStream.createTagLogicalElement(name, value);
+ } else if (AFPElementMapping.NO_OPERATION.equals(element)) {
+ String content = aps.getContent();
+ if (content != null) {
+ dataStream.createNoOperation(content);
+ }
}
}
}
/**
* This class represents an AFP-specific extension element to embed Invoke Medium Map (IMM)
- * fields at the beginning of a page group. The element is optional and expected as a direct child
- * of an fo:page-sequence.
+ * fields at the beginning of a page group or just prior to a Page. The element is optional
+ * and expected as a direct child of an fo:page-sequence or fo:simple-page-master
*/
public class AFPInvokeMediumMapElement extends AbstractAFPExtensionObject {
/** {@inheritDoc} */
protected void startOfNode() throws FOPException {
super.startOfNode();
- if (parent.getNameId() != Constants.FO_PAGE_SEQUENCE) {
+ if (parent.getNameId() != Constants.FO_PAGE_SEQUENCE
+ && parent.getNameId() != Constants.FO_SIMPLE_PAGE_MASTER) {
+
invalidChildError(getLocator(), parent.getName(), getNamespaceURI(), getName(),
"rule.childOfPageSequence");
}