diff options
author | Jeremias Maerki <jeremias@apache.org> | 2011-02-01 16:04:41 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2011-02-01 16:04:41 +0000 |
commit | 941181b8e3bf0369f1803e9af89bff52c0c93c8f (patch) | |
tree | 0047b09b9a6564ff030fdf36f79f662d43ab0a94 /src/java/org/apache | |
parent | f540b00cf2c8cf1126f6d45e3a9062b2bccd7a58 (diff) | |
download | xmlgraphics-fop-941181b8e3bf0369f1803e9af89bff52c0c93c8f.tar.gz xmlgraphics-fop-941181b8e3bf0369f1803e9af89bff52c0c93c8f.zip |
Allow afp:no-operation to be added to fo:page-sequence (page group in AFP) and fo:declarations (document in AFP). Includes a test case.
Update QDox to avoid a bug with class private enums.
Connect some older test cases into the standard test suite.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1066078 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
6 files changed, 94 insertions, 32 deletions
diff --git a/src/java/org/apache/fop/afp/DataStream.java b/src/java/org/apache/fop/afp/DataStream.java index a437c3004..2794ae932 100644 --- a/src/java/org/apache/fop/afp/DataStream.java +++ b/src/java/org/apache/fop/afp/DataStream.java @@ -595,7 +595,13 @@ public class DataStream { * byte data */ public void createNoOperation(String content) { - currentPage.createNoOperation(content); + if (currentPage != null) { + currentPage.createNoOperation(content); + } else if (currentPageGroup != null) { + currentPageGroup.createNoOperation(content); + } else { + document.createNoOperation(content); + } } /** @@ -639,9 +645,9 @@ public class DataStream { currentPageGroup.endPageGroup(); tleSequence = currentPageGroup.getTleSequence(); document.addPageGroup(currentPageGroup); - document.writeToStream(outputStream); currentPageGroup = null; } + document.writeToStream(outputStream); //Flush objects } /** diff --git a/src/java/org/apache/fop/afp/modca/AbstractResourceGroupContainer.java b/src/java/org/apache/fop/afp/modca/AbstractResourceGroupContainer.java index 2c5e02328..f8c5a38d3 100644 --- a/src/java/org/apache/fop/afp/modca/AbstractResourceGroupContainer.java +++ b/src/java/org/apache/fop/afp/modca/AbstractResourceGroupContainer.java @@ -126,6 +126,7 @@ implements Streamable { // } /** {@inheritDoc} */ + @Override public void writeToStream(OutputStream os) throws IOException { if (!started) { writeStart(os); @@ -140,6 +141,7 @@ implements Streamable { } /** {@inheritDoc} */ + @Override protected void writeObjects(Collection/*<AbstractAFPObject>*/ objects, OutputStream os) throws IOException { writeObjects(objects, os, false); @@ -176,7 +178,7 @@ implements Streamable { * @return true if this object can be written */ protected boolean canWrite(AbstractAFPObject obj) { - if (obj instanceof AbstractPageObject) { + if (obj instanceof Completable) { return ((Completable)obj).isComplete(); } else { diff --git a/src/java/org/apache/fop/afp/modca/NoOperation.java b/src/java/org/apache/fop/afp/modca/NoOperation.java index cb5841346..cb6f4d60b 100644 --- a/src/java/org/apache/fop/afp/modca/NoOperation.java +++ b/src/java/org/apache/fop/afp/modca/NoOperation.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.OutputStream; import org.apache.fop.afp.AFPConstants; +import org.apache.fop.afp.Completable; import org.apache.fop.afp.util.BinaryUtils; /** @@ -35,7 +36,7 @@ import org.apache.fop.afp.util.BinaryUtils; * No Operation structured fields, no semantics should be attached to * the data carried by the No Operation structured field in interchange */ -public class NoOperation extends AbstractAFPObject { +public class NoOperation extends AbstractAFPObject implements Completable { /** Up to 32759 bytes of data with no architectural definition */ private static final int MAX_DATA_LEN = 32759; @@ -81,7 +82,7 @@ public class NoOperation extends AbstractAFPObject { data[1] = rl1[0]; data[2] = rl1[1]; - // Structured field ID for a TLE + // Structured field ID for a NOP data[3] = (byte) 0xD3; data[4] = (byte) 0xEE; data[5] = (byte) 0xEE; @@ -97,4 +98,20 @@ public class NoOperation extends AbstractAFPObject { os.write(data); } + /** {@inheritDoc} */ + public boolean isComplete() { + return true; //always complete + } + + /** {@inheritDoc} */ + public void setComplete(boolean complete) { + //ignore + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "NOP: " + content.substring(0, Math.min(64, content.length())); + } + }
\ No newline at end of file diff --git a/src/java/org/apache/fop/fo/FOValidationEventProducer.xml b/src/java/org/apache/fop/fo/FOValidationEventProducer.xml index c3e4b6b61..509f7c1d3 100644 --- a/src/java/org/apache/fop/fo/FOValidationEventProducer.xml +++ b/src/java/org/apache/fop/fo/FOValidationEventProducer.xml @@ -9,6 +9,7 @@ <message key="rule.childOfSPM">The element must be a child of fo:simple-page-master.</message> <message key="rule.childOfDeclarations">The element must be a child of fo:declarations.</message> <message key="rule.childOfSPMorDeclarations">The element must be a child of fo:declarations or fo:simple-page-master.</message> + <message key="rule.childOfSPMorPSorDeclarations">The element must be a child of fo:declarations, fo:simple-page-master or fo:page-sequence.</message> <message key="rule.childOfInstreamForeignObjectorExternalGraphic">The element must be a child of fo:instream-foreign-object or fo:external-graphic.</message> <message key="rule.childOfPageSequence">The element must be a child of fo:page-sequence.</message> <message key="rule.childOfPageSequenceOrSPM">The element must be a child of fo:page-sequence or fo:simple-page-master.</message> diff --git a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java index c37e0c37c..87651defd 100644 --- a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java +++ b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java @@ -77,17 +77,17 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler private DataStream dataStream; /** the map of page segments */ - private Map/*<String,PageSegmentDescriptor>*/pageSegmentMap - = new java.util.HashMap/*<String,PageSegmentDescriptor>*/(); + private Map<String, PageSegmentDescriptor> pageSegmentMap + = new java.util.HashMap<String, PageSegmentDescriptor>(); /** 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; + private static enum Location { + ELSEWHERE, IN_DOCUMENT_HEADER, FOLLOWING_PAGE_SEQUENCE, IN_PAGE_HEADER + } - private int location = LOC_ELSEWHERE; + private Location location = Location.ELSEWHERE; /** the shading mode for filled rectangles */ private AFPShadingMode shadingMode = AFPShadingMode.COLOR; @@ -117,6 +117,7 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler } /** {@inheritDoc} */ + @Override public void setDefaultFontInfo(FontInfo fontInfo) { FontManager fontManager = getUserAgent().getFactory().getFontManager(); FontCollection[] fontCollections = new FontCollection[] { @@ -152,6 +153,7 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler } /** {@inheritDoc} */ + @Override public void startDocument() throws IFException { super.startDocument(); try { @@ -165,11 +167,23 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler } } + + /** {@inheritDoc} */ + @Override + public void startDocumentHeader() throws IFException { + super.startDocumentHeader(); + this.location = Location.IN_DOCUMENT_HEADER; + } + /** {@inheritDoc} */ + @Override public void endDocumentHeader() throws IFException { + super.endDocumentHeader(); + this.location = Location.ELSEWHERE; } /** {@inheritDoc} */ + @Override public void endDocument() throws IFException { try { this.dataStream.endDocument(); @@ -189,7 +203,7 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler } catch (IOException ioe) { throw new IFException("I/O error in startPageSequence()", ioe); } - this.location = LOC_FOLLOWING_PAGE_SEQUENCE; + this.location = Location.FOLLOWING_PAGE_SEQUENCE; } /** {@inheritDoc} */ @@ -212,7 +226,7 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler /** {@inheritDoc} */ public void startPage(int index, String name, String pageMasterName, Dimension size) throws IFException { - this.location = LOC_ELSEWHERE; + this.location = Location.ELSEWHERE; paintingState.clear(); AffineTransform baseTransform = getBaseTransform(); @@ -232,14 +246,16 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler } /** {@inheritDoc} */ + @Override public void startPageHeader() throws IFException { super.startPageHeader(); - this.location = LOC_IN_PAGE_HEADER; + this.location = Location.IN_PAGE_HEADER; } /** {@inheritDoc} */ + @Override public void endPageHeader() throws IFException { - this.location = LOC_ELSEWHERE; + this.location = Location.ELSEWHERE; super.endPageHeader(); } @@ -272,17 +288,36 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler AFPPageSetup aps = (AFPPageSetup)extension; String element = aps.getElementName(); if (AFPElementMapping.TAG_LOGICAL_ELEMENT.equals(element)) { - if (this.location != LOC_IN_PAGE_HEADER - && this.location != LOC_FOLLOWING_PAGE_SEQUENCE) { + switch (this.location) { + case FOLLOWING_PAGE_SEQUENCE: + case IN_PAGE_HEADER: + String name = aps.getName(); + String value = aps.getValue(); + dataStream.createTagLogicalElement(name, value); + break; + default: throw new IFException( "TLE extension must be in the page header or between page-sequence" + " and the first page: " + aps, null); } - String name = aps.getName(); - String value = aps.getValue(); - dataStream.createTagLogicalElement(name, value); + } else if (AFPElementMapping.NO_OPERATION.equals(element)) { + switch (this.location) { + case IN_DOCUMENT_HEADER: + case FOLLOWING_PAGE_SEQUENCE: + case IN_PAGE_HEADER: + String content = aps.getContent(); + if (content != null) { + dataStream.createNoOperation(content); + } + break; + default: + throw new IFException( + "NOP extension must be in the document header, the page header" + + " or between page-sequence" + + " and the first page: " + aps, null); + } } else { - if (this.location != LOC_IN_PAGE_HEADER) { + if (this.location != Location.IN_PAGE_HEADER) { throw new IFException( "AFP page setup extension encountered outside the page header: " + aps, null); @@ -294,16 +329,11 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler String source = apse.getValue(); String uri = apse.getResourceSrc(); pageSegmentMap.put(source, new PageSegmentDescriptor(name, uri)); - } else if (AFPElementMapping.NO_OPERATION.equals(element)) { - String content = aps.getContent(); - if (content != null) { - dataStream.createNoOperation(content); - } } } } else if (extension instanceof AFPPageOverlay) { AFPPageOverlay ipo = (AFPPageOverlay)extension; - if (this.location != LOC_IN_PAGE_HEADER) { + if (this.location != Location.IN_PAGE_HEADER) { throw new IFException( "AFP page overlay extension encountered outside the page header: " + ipo, null); @@ -313,8 +343,8 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler dataStream.createIncludePageOverlay(overlay, ipo.getX(), ipo.getY()); } } else if (extension instanceof AFPInvokeMediumMap) { - if (this.location != LOC_FOLLOWING_PAGE_SEQUENCE - && this.location != LOC_IN_PAGE_HEADER) { + if (this.location != Location.FOLLOWING_PAGE_SEQUENCE + && this.location != Location.IN_PAGE_HEADER) { throw new IFException( "AFP IMM extension must be between page-sequence" @@ -401,7 +431,7 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler * @return the page segment descriptor or null if there's no page segment for the given URI */ PageSegmentDescriptor getPageSegmentNameFor(String uri) { - return (PageSegmentDescriptor)pageSegmentMap.get(uri); + return pageSegmentMap.get(uri); } } diff --git a/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java b/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java index 19f98f32a..b5b05191a 100644 --- a/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java +++ b/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java @@ -54,6 +54,7 @@ public class AFPPageSetupElement extends AbstractAFPExtensionObject { } /** {@inheritDoc} */ + @Override protected void startOfNode() throws FOPException { super.startOfNode(); if (AFPElementMapping.TAG_LOGICAL_ELEMENT.equals(getLocalName())) { @@ -63,14 +64,17 @@ public class AFPPageSetupElement extends AbstractAFPExtensionObject { "rule.childOfPageSequenceOrSPM"); } } else { - if (parent.getNameId() != Constants.FO_SIMPLE_PAGE_MASTER) { + if (parent.getNameId() != Constants.FO_SIMPLE_PAGE_MASTER + && parent.getNameId() != Constants.FO_PAGE_SEQUENCE + && parent.getNameId() != Constants.FO_DECLARATIONS) { invalidChildError(getLocator(), parent.getName(), getNamespaceURI(), getName(), - "rule.childOfSPM"); + "rule.childOfSPMorPSorDeclarations"); } } } /** {@inheritDoc} */ + @Override protected void characters(char[] data, int start, int length, PropertyList pList, Locator locator) throws FOPException { StringBuffer sb = new StringBuffer(); @@ -83,6 +87,7 @@ public class AFPPageSetupElement extends AbstractAFPExtensionObject { } /** {@inheritDoc} */ + @Override public void processNode(String elementName, Locator locator, Attributes attlist, PropertyList propertyList) throws FOPException { @@ -106,6 +111,7 @@ public class AFPPageSetupElement extends AbstractAFPExtensionObject { } /** {@inheritDoc} */ + @Override protected ExtensionAttachment instantiateExtensionAttachment() { return new AFPPageSetup(getLocalName()); } |