|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.fop.render.afp; |
| 18 | + |
| 19 | +import java.awt.Dimension; |
| 20 | +import java.io.ByteArrayInputStream; |
| 21 | +import java.io.ByteArrayOutputStream; |
| 22 | +import java.io.IOException; |
| 23 | +import java.util.HashMap; |
| 24 | +import java.util.Map; |
| 25 | + |
| 26 | +import javax.xml.transform.stream.StreamResult; |
| 27 | + |
| 28 | +import org.junit.Assert; |
| 29 | +import org.junit.Test; |
| 30 | + |
| 31 | +import org.apache.xmlgraphics.util.QName; |
| 32 | + |
| 33 | +import org.apache.fop.apps.FOUserAgent; |
| 34 | +import org.apache.fop.render.afp.extensions.AFPElementMapping; |
| 35 | +import org.apache.fop.render.intermediate.IFContext; |
| 36 | +import org.apache.fop.render.intermediate.IFException; |
| 37 | + |
| 38 | +public class AddToPreviousPageGroupTestCase extends AbstractAFPTest { |
| 39 | + @Test |
| 40 | + public void testAddToPreviousPageGroup() throws Exception { |
| 41 | + Assert.assertEquals("BEGIN DOCUMENT DOC00001 Triplets: 0x01,\n" |
| 42 | + + "BEGIN PAGE_GROUP PGP00001\n" |
| 43 | + + "BEGIN PAGE PGN00001\n" |
| 44 | + + "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00001\n" |
| 45 | + + "DESCRIPTOR PAGE\n" |
| 46 | + + "MIGRATION PRESENTATION_TEXT\n" |
| 47 | + + "END ACTIVE_ENVIRONMENT_GROUP AEG00001\n" |
| 48 | + + "END PAGE PGN00001\n" |
| 49 | + + "BEGIN PAGE PGN00002\n" |
| 50 | + + "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00002\n" |
| 51 | + + "DESCRIPTOR PAGE\n" |
| 52 | + + "MIGRATION PRESENTATION_TEXT\n" |
| 53 | + + "END ACTIVE_ENVIRONMENT_GROUP AEG00002\n" |
| 54 | + + "END PAGE PGN00002\n" |
| 55 | + + "END PAGE_GROUP PGP00001\n" |
| 56 | + + "END DOCUMENT DOC00001\n", render()); |
| 57 | + } |
| 58 | + |
| 59 | + private String render() throws IFException, IOException { |
| 60 | + FOUserAgent ua = fopFactory.newFOUserAgent(); |
| 61 | + AFPDocumentHandler documentHandler = new AFPDocumentHandler(new IFContext(ua)); |
| 62 | + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| 63 | + documentHandler.setResult(new StreamResult(outputStream)); |
| 64 | + documentHandler.startDocument(); |
| 65 | + documentHandler.startPageSequence(""); |
| 66 | + documentHandler.startPage(0, "", "", new Dimension()); |
| 67 | + documentHandler.endPage(); |
| 68 | + documentHandler.endPageSequence(); |
| 69 | + Map<QName, String> attributes = new HashMap<>(); |
| 70 | + attributes.put(AFPElementMapping.ADD_TO_PREVIOUS_PAGE_GROUP, "true"); |
| 71 | + documentHandler.getContext().setForeignAttributes(attributes); |
| 72 | + documentHandler.startPageSequence(""); |
| 73 | + documentHandler.startPage(1, "", "", new Dimension()); |
| 74 | + documentHandler.endPage(); |
| 75 | + documentHandler.endPageSequence(); |
| 76 | + documentHandler.endDocument(); |
| 77 | + StringBuilder sb = new StringBuilder(); |
| 78 | + new AFPParser(false).read(new ByteArrayInputStream(outputStream.toByteArray()), sb); |
| 79 | + return sb.toString(); |
| 80 | + } |
| 81 | +} |
0 commit comments