aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fop-core/src/main/java/org/apache/fop/afp/DataStream.java16
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java6
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java1
-rw-r--r--fop-core/src/test/java/org/apache/fop/afp/DataStreamTestCase.java10
-rw-r--r--fop-core/src/test/java/org/apache/fop/render/afp/AddToPreviousPageGroupTestCase.java81
-rw-r--r--fop-core/src/test/java/org/apache/fop/render/afp/PageOverlayTestCase.java2
6 files changed, 101 insertions, 15 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/afp/DataStream.java b/fop-core/src/main/java/org/apache/fop/afp/DataStream.java
index 226f431cc..3e75cc994 100644
--- a/fop-core/src/main/java/org/apache/fop/afp/DataStream.java
+++ b/fop-core/src/main/java/org/apache/fop/afp/DataStream.java
@@ -169,7 +169,7 @@ public class DataStream {
if (currentPageGroup != null) {
// End the current page group if necessary
- endPageGroup();
+ endPageGroup(true);
}
// Write out document
@@ -626,14 +626,16 @@ public class DataStream {
/**
* 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 the endPageGroup method must be invoked to mark the page
* group ending.
*
* @throws IOException thrown if an I/O exception of some sort has occurred
*/
- public void startPageGroup() throws IOException {
- endPageGroup();
- this.currentPageGroup = factory.createPageGroup();
+ public void startPageGroup(boolean endPageGroup) throws IOException {
+ endPageGroup(endPageGroup);
+ if (currentPageGroup == null) {
+ currentPageGroup = factory.createPageGroup();
+ }
}
/**
@@ -641,8 +643,8 @@ public class DataStream {
*
* @throws IOException thrown if an I/O exception of some sort has occurred
*/
- public void endPageGroup() throws IOException {
- if (currentPageGroup != null) {
+ public void endPageGroup(boolean endPageGroup) throws IOException {
+ if (currentPageGroup != null && endPageGroup) {
currentPageGroup.endPageGroup();
document.addPageGroup(currentPageGroup);
currentPageGroup = null;
diff --git a/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java b/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java
index 83a6f5c87..00d40b3a0 100644
--- a/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java
+++ b/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java
@@ -216,7 +216,9 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
public void startPageSequence(String id) throws IFException {
try {
if (!"false".equals(getContext().getForeignAttribute(AFPElementMapping.PAGE_GROUP))) {
- dataStream.startPageGroup();
+ boolean addToPreviousPageGroup =
+ "true".equals(getContext().getForeignAttribute(AFPElementMapping.ADD_TO_PREVIOUS_PAGE_GROUP));
+ dataStream.startPageGroup(!addToPreviousPageGroup);
}
} catch (IOException ioe) {
throw new IFException("I/O error in startPageSequence()", ioe);
@@ -240,7 +242,7 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
}
//End page sequence
- dataStream.endPageGroup();
+ dataStream.endPageGroup(false);
} catch (IOException ioe) {
throw new IFException("I/O error in endPageSequence()", ioe);
}
diff --git a/fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java b/fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java
index a3e25844d..481b6e4bb 100644
--- a/fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java
+++ b/fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java
@@ -59,6 +59,7 @@ public class AFPElementMapping extends ElementMapping {
public static final String NAMESPACE = "http://xmlgraphics.apache.org/fop/extensions/afp";
public static final QName PAGE_GROUP = new QName(NAMESPACE, null, "page-group");
+ public static final QName ADD_TO_PREVIOUS_PAGE_GROUP = new QName(NAMESPACE, null, "add-to-previous-page-group");
/**
* The usual namespace prefix used for AFP extensions
diff --git a/fop-core/src/test/java/org/apache/fop/afp/DataStreamTestCase.java b/fop-core/src/test/java/org/apache/fop/afp/DataStreamTestCase.java
index f178a815e..0f83e08b2 100644
--- a/fop-core/src/test/java/org/apache/fop/afp/DataStreamTestCase.java
+++ b/fop-core/src/test/java/org/apache/fop/afp/DataStreamTestCase.java
@@ -80,7 +80,7 @@ public class DataStreamTestCase {
ds.createShading(10, 10, 300, 300, Color.white);
ds.createIncludePageOverlay("testings", 10, 10);
ds.startDocument();
- ds.startPageGroup();
+ ds.startPageGroup(true);
ds.createInvokeMediumMap("test");
ds.createIncludePageSegment("test", 10, 10, 300, 300);
ds.createTagLogicalElement("test", "test", 0);
@@ -118,10 +118,10 @@ public class DataStreamTestCase {
ds = new DataStream(new Factory(), paintState, outStream);
ds.startDocument();
ds.createInvokeMediumMap("test");
- ds.startPageGroup();
+ ds.startPageGroup(true);
ds.startPage(1, 1, 0, 1, 1);
ds.endPage();
- ds.endPageGroup();
+ ds.endPageGroup(true);
ds.endDocument();
ByteArrayInputStream data = new ByteArrayInputStream(outStream.toByteArray());
data.skip(21);
@@ -134,10 +134,10 @@ public class DataStreamTestCase {
public void testMandatoryTripletIsAddedToAFP() throws Exception {
ds = new DataStream(new Factory(), paintState, outStream);
ds.startDocument();
- ds.startPageGroup();
+ ds.startPageGroup(true);
ds.startPage(1, 1, 0, 1, 1);
ds.endPage();
- ds.endPageGroup();
+ ds.endPageGroup(true);
ds.endDocument();
ByteArrayInputStream data = new ByteArrayInputStream(outStream.toByteArray());
data.skip(17); //skipping the begin document data
diff --git a/fop-core/src/test/java/org/apache/fop/render/afp/AddToPreviousPageGroupTestCase.java b/fop-core/src/test/java/org/apache/fop/render/afp/AddToPreviousPageGroupTestCase.java
new file mode 100644
index 000000000..8383efa16
--- /dev/null
+++ b/fop-core/src/test/java/org/apache/fop/render/afp/AddToPreviousPageGroupTestCase.java
@@ -0,0 +1,81 @@
+/*
+ * 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.
+ */
+package org.apache.fop.render.afp;
+
+import java.awt.Dimension;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.transform.stream.StreamResult;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.xmlgraphics.util.QName;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.render.afp.extensions.AFPElementMapping;
+import org.apache.fop.render.intermediate.IFContext;
+import org.apache.fop.render.intermediate.IFException;
+
+public class AddToPreviousPageGroupTestCase extends AbstractAFPTest {
+ @Test
+ public void testAddToPreviousPageGroup() throws Exception {
+ Assert.assertEquals("BEGIN DOCUMENT DOC00001 Triplets: 0x01,\n"
+ + "BEGIN PAGE_GROUP PGP00001\n"
+ + "BEGIN PAGE PGN00001\n"
+ + "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00001\n"
+ + "DESCRIPTOR PAGE\n"
+ + "MIGRATION PRESENTATION_TEXT\n"
+ + "END ACTIVE_ENVIRONMENT_GROUP AEG00001\n"
+ + "END PAGE PGN00001\n"
+ + "BEGIN PAGE PGN00002\n"
+ + "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00002\n"
+ + "DESCRIPTOR PAGE\n"
+ + "MIGRATION PRESENTATION_TEXT\n"
+ + "END ACTIVE_ENVIRONMENT_GROUP AEG00002\n"
+ + "END PAGE PGN00002\n"
+ + "END PAGE_GROUP PGP00001\n"
+ + "END DOCUMENT DOC00001\n", render());
+ }
+
+ private String render() throws IFException, IOException {
+ FOUserAgent ua = fopFactory.newFOUserAgent();
+ AFPDocumentHandler documentHandler = new AFPDocumentHandler(new IFContext(ua));
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ documentHandler.setResult(new StreamResult(outputStream));
+ documentHandler.startDocument();
+ documentHandler.startPageSequence("");
+ documentHandler.startPage(0, "", "", new Dimension());
+ documentHandler.endPage();
+ documentHandler.endPageSequence();
+ Map<QName, String> attributes = new HashMap<>();
+ attributes.put(AFPElementMapping.ADD_TO_PREVIOUS_PAGE_GROUP, "true");
+ documentHandler.getContext().setForeignAttributes(attributes);
+ documentHandler.startPageSequence("");
+ documentHandler.startPage(1, "", "", new Dimension());
+ documentHandler.endPage();
+ documentHandler.endPageSequence();
+ documentHandler.endDocument();
+ StringBuilder sb = new StringBuilder();
+ new AFPParser(false).read(new ByteArrayInputStream(outputStream.toByteArray()), sb);
+ return sb.toString();
+ }
+}
diff --git a/fop-core/src/test/java/org/apache/fop/render/afp/PageOverlayTestCase.java b/fop-core/src/test/java/org/apache/fop/render/afp/PageOverlayTestCase.java
index 9f60fd476..623a28b6e 100644
--- a/fop-core/src/test/java/org/apache/fop/render/afp/PageOverlayTestCase.java
+++ b/fop-core/src/test/java/org/apache/fop/render/afp/PageOverlayTestCase.java
@@ -42,7 +42,6 @@ public class PageOverlayTestCase {
public void testPageOverlay() throws Exception {
Assert.assertEquals(getPageOverlay(), "BEGIN DOCUMENT DOC00001 Triplets: 0x01,\n"
+ "BEGIN PAGE_GROUP PGP00001\n"
- + "END PAGE_GROUP PGP00001\n"
+ "BEGIN PAGE PGN00001\n"
+ "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00001\n"
+ "MAP PAGE_OVERLAY Triplets: FULLY_QUALIFIED_NAME,RESOURCE_LOCAL_IDENTIFIER,\n"
@@ -51,6 +50,7 @@ public class PageOverlayTestCase {
+ "END ACTIVE_ENVIRONMENT_GROUP AEG00001\n"
+ "INCLUDE PAGE_OVERLAY\n"
+ "END PAGE PGN00001\n"
+ + "END PAGE_GROUP PGP00001\n"
+ "END DOCUMENT DOC00001\n");
}