From 423453976de29088ee76156baec1a83bc58b9518 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Mon, 24 Jul 2006 13:15:33 +0000 Subject: Promoting the AFP renderer from sandbox to the main source tree. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@425037 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/render/afp/extensions/AFPAttribute.java | 61 +++++++++++ .../fop/render/afp/extensions/AFPElement.java | 66 ++++++++++++ .../render/afp/extensions/AFPElementMapping.java | 109 +++++++++++++++++++ .../fop/render/afp/extensions/AFPPageSetup.java | 90 ++++++++++++++++ .../render/afp/extensions/AFPPageSetupElement.java | 47 ++++++++ .../afp/extensions/AbstractAFPExtensionObject.java | 120 +++++++++++++++++++++ 6 files changed, 493 insertions(+) create mode 100755 src/java/org/apache/fop/render/afp/extensions/AFPAttribute.java create mode 100755 src/java/org/apache/fop/render/afp/extensions/AFPElement.java create mode 100755 src/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java create mode 100644 src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java create mode 100644 src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java create mode 100644 src/java/org/apache/fop/render/afp/extensions/AbstractAFPExtensionObject.java (limited to 'src/java/org/apache/fop/render/afp/extensions') diff --git a/src/java/org/apache/fop/render/afp/extensions/AFPAttribute.java b/src/java/org/apache/fop/render/afp/extensions/AFPAttribute.java new file mode 100755 index 000000000..421408902 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/extensions/AFPAttribute.java @@ -0,0 +1,61 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/* $Id$ */ + +package org.apache.fop.render.afp.extensions; + +import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.properties.Property; +import org.apache.fop.fo.properties.StringProperty; + +/** + * This class extends the org.apache.fop.fo.StringProperty.Maker inner class + * in order to provide a static property maker. The object faciliates + * extraction of attributes from formatted objects based on the static list + * as defined in the AFPElementMapping implementation. + *

+ */ +public class AFPAttribute extends StringProperty.Maker { + + /** + * The attribute property. + */ + private Property _property; + + /** + * Constructor for the AFPAttribute. + * @param name The attribute name + */ + protected AFPAttribute(String name) { + super(0); + _property = null; + } + + /** + * Overide the make method to return the property object + * @param propertyList the property list from which to make the property + * @return property The property object. + */ + public Property make(PropertyList propertyList) { + if (_property == null) { + _property = make(propertyList, "", propertyList.getParentFObj()); + } + return _property; + } + +} \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/extensions/AFPElement.java b/src/java/org/apache/fop/render/afp/extensions/AFPElement.java new file mode 100755 index 000000000..32868fd3c --- /dev/null +++ b/src/java/org/apache/fop/render/afp/extensions/AFPElement.java @@ -0,0 +1,66 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/* $Id$ */ + +package org.apache.fop.render.afp.extensions; +import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.ValidationException; +import org.apache.fop.fo.XMLObj; + +/** + * This class extends the org.apache.fop.extensions.ExtensionObj class. The + * object faciliates extraction of elements from formatted objects based on + * the static list as defined in the AFPElementMapping implementation. + *

+ */ +public class AFPElement extends AbstractAFPExtensionObject { + + /** + * Constructs an AFP object (called by Maker). + * + * @param parent the parent formatting object + * @param name the name of the afp element + */ + public AFPElement(FONode parent, String name) { + super(parent, name); + } + + /** @see org.apache.fop.fo.FONode#getNamespaceURI() */ + public String getNamespaceURI() { + return AFPElementMapping.NAMESPACE; + } + + /** @see org.apache.fop.fo.FONode#getNormalNamespacePrefix() */ + public String getNormalNamespacePrefix() { + return "afp"; + } + + /** @see org.apache.fop.fo.FONode#startOfNode() */ + protected void startOfNode() throws FOPException { + super.startOfNode(); + //if (!AFPElementMapping.NAMESPACE.equals(parent.getNamespaceURI()) + // || !AFPElementMapping.PAGE.equals(parent.getLocalName())) { + // throw new ValidationException(getName() + " must be a child of afp:page."); + //} + if (parent.getNameId() != Constants.FO_SIMPLE_PAGE_MASTER) { + throw new ValidationException(getName() + " must be a child of fo:simple-page-master."); + } + } + +} diff --git a/src/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java b/src/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java new file mode 100755 index 000000000..53421021e --- /dev/null +++ b/src/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java @@ -0,0 +1,109 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/* $Id$ */ + +package org.apache.fop.render.afp.extensions; + +import java.util.HashMap; + +import org.apache.fop.fo.ElementMapping; +import org.apache.fop.fo.FONode; + + +/** + * AFPElementMapping object provides the ability to extract information + * from the formatted object that reside in the afp namespace. This is used + * for custom AFP extensions not supported by the FO schema. Examples include + * adding overlays or indexing a document using the tag logical element + * structured field. + *

+ */ +public class AFPElementMapping extends ElementMapping { + + public static final String PAGE = "page"; + + public static final String PAGE_GROUP = "page-group"; + + public static final String TAG_LOGICAL_ELEMENT = "tag-logical-element"; + + public static final String INCLUDE_PAGE_OVERLAY = "include-page-overlay"; + + public static final String INCLUDE_PAGE_SEGMENT = "include-page-segment"; + + /** + * The namespace used for AFP extensions + */ + public static final String NAMESPACE = "http://xmlgraphics.apache.org/fop/extensions/afp"; + + /** + * The usual namespace prefix used for AFP extensions + */ + public static final String NAMESPACE_PREFIX = "afp"; + + /** Main constructor */ + public AFPElementMapping() { + this.namespaceURI = NAMESPACE; + } + + /** + * Private static synchronized method to set up the element and atribute + * HashMaps, this defines what elements and attributes are extracted. + */ + protected void initialize() { + + if (foObjs == null) { + foObjs = new HashMap(); + foObjs.put(PAGE, new AFPPageSetupMaker()); + // foObjs.put(PAGE_GROUP, new AFPMaker()); + foObjs.put( + TAG_LOGICAL_ELEMENT, + new AFPTagLogicalElementMaker()); + foObjs.put( + INCLUDE_PAGE_SEGMENT, + new AFPIncludePageSegmentMaker()); + foObjs.put( + INCLUDE_PAGE_OVERLAY, + new AFPIncludePageOverlayMaker()); + } + + } + + static class AFPPageSetupMaker extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new AFPPageSetupElement(parent); + } + } + + static class AFPIncludePageOverlayMaker extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new AFPElement(parent, INCLUDE_PAGE_OVERLAY); + } + } + + static class AFPIncludePageSegmentMaker extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new AFPElement(parent, INCLUDE_PAGE_SEGMENT); + } + } + + static class AFPTagLogicalElementMaker extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new AFPElement(parent, TAG_LOGICAL_ELEMENT); + } + } + +} diff --git a/src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java b/src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java new file mode 100644 index 000000000..a3984d2be --- /dev/null +++ b/src/java/org/apache/fop/render/afp/extensions/AFPPageSetup.java @@ -0,0 +1,90 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/* $Id$ */ + +package org.apache.fop.render.afp.extensions; + +import java.io.Serializable; + +import org.apache.fop.fo.extensions.ExtensionAttachment; + +/** + * This is the pass-through value object for the PostScript extension. + */ +public class AFPPageSetup implements ExtensionAttachment, Serializable { + + /** The category URI for this extension attachment. */ + public static final String CATEGORY = "apache:fop:extensions:afp"; + + private String elementName; + + private String name; + + private String value; + + /** + * Default constructor. + * @param name the name of the setup code object, may be null + */ + public AFPPageSetup(String name) { + this.elementName = name; + } + + /** @return the name */ + public String getElementName() { + return elementName; + } + + /** @return the name */ + public String getName() { + return name; + } + + /** + * Sets the name of the setup code object. + * @param name The name to set. + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the value + */ + public String getValue() { + return value; + } + + /** + * Sets the value + * @param source The value name to set. + */ + public void setValue(String source) { + this.value = source; + } + + /** @see org.apache.fop.fo.extensions.ExtensionAttachment#getCategory() */ + public String getCategory() { + return CATEGORY; + } + + /** @see java.lang.Object#toString() */ + public String toString() { + return "AFPPageSetup(element-name=" + getElementName() + " name=" + getName() + ")"; + } + +} diff --git a/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java b/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java new file mode 100644 index 000000000..cbdde917e --- /dev/null +++ b/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java @@ -0,0 +1,47 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/* $Id$ */ + +package org.apache.fop.render.afp.extensions; + +import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.ValidationException; + +/** + * Extension element for fox:ps-page-setup-code. + */ +public class AFPPageSetupElement extends AbstractAFPExtensionObject { + + /** + * Main constructor + * @param parent parent FO node + */ + public AFPPageSetupElement(FONode parent) { + super(parent, "page"); + } + + /** @see org.apache.fop.fo.FONode#startOfNode() */ + protected void startOfNode() throws FOPException { + super.startOfNode(); + if (parent.getNameId() != Constants.FO_SIMPLE_PAGE_MASTER) { + throw new ValidationException(getName() + " must be a child of fo:simple-page-master."); + } + } + +} diff --git a/src/java/org/apache/fop/render/afp/extensions/AbstractAFPExtensionObject.java b/src/java/org/apache/fop/render/afp/extensions/AbstractAFPExtensionObject.java new file mode 100644 index 000000000..b8dc7c740 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/extensions/AbstractAFPExtensionObject.java @@ -0,0 +1,120 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/* $Id$ */ + +package org.apache.fop.render.afp.extensions; + +// FOP +import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.ValidationException; +import org.apache.fop.fo.extensions.ExtensionAttachment; +import org.xml.sax.Attributes; +import org.xml.sax.Locator; + +/** + * Base class for the AFP-specific extension elements. + */ +public abstract class AbstractAFPExtensionObject extends FONode { + + private AFPPageSetup setupCode = null; + + private String _name = null; + + /** + * @see org.apache.fop.fo.FONode#FONode(FONode) + * @param parent the parent formatting object + * @param name the name of the afp element + */ + public AbstractAFPExtensionObject(FONode parent, String name) { + super(parent); + _name = name; + setupCode = new AFPPageSetup(name); + } + + /** + * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String) + * here, blocks XSL FO's from having non-FO parents. + */ + protected void validateChildNode(Locator loc, String nsURI, String localName) + throws ValidationException { + if (FO_URI.equals(nsURI)) { + invalidChildError(loc, nsURI, localName); + } + } + + /** @see org.apache.fop.fo.FONode */ + protected void addCharacters(char[] data, int start, int length, + PropertyList pList, Locator locator) { + } + + /** @see org.apache.fop.fo.FONode#getNamespaceURI() */ + public String getNamespaceURI() { + return AFPElementMapping.NAMESPACE; + } + + /**@see org.apache.fop.fo.FONode#getNormalNamespacePrefix() */ + public String getNormalNamespacePrefix() { + return AFPElementMapping.NAMESPACE_PREFIX; + } + + /** @see org.apache.fop.fo.FONode#processNode */ + public void processNode(String elementName, Locator locator, + Attributes attlist, PropertyList propertyList) + throws FOPException { + String name = attlist.getValue("name"); + if (name != null && name.length() > 0) { + setupCode.setName(name); + } else { + throw new FOPException(elementName + " must have a name attribute."); + } + if (AFPElementMapping.INCLUDE_PAGE_SEGMENT.equals(elementName)) { + name = attlist.getValue("src"); + if (name != null && name.length() > 0) { + setupCode.setValue(name); + } else { + throw new FOPException(elementName + " must have a src attribute."); + } + } + if (AFPElementMapping.TAG_LOGICAL_ELEMENT.equals(elementName)) { + name = attlist.getValue("value"); + if (name != null && name.length() > 0) { + setupCode.setValue(name); + } else { + throw new FOPException(elementName + " must have a value attribute."); + } + } + } + + /** @see org.apache.fop.fo.FONode#endOfNode() */ + protected void endOfNode() throws FOPException { + super.endOfNode(); + } + + /** @see org.apache.fop.fo.FONode#getExtensionAttachment() */ + public ExtensionAttachment getExtensionAttachment() { + return this.setupCode; + } + + /** @see org.apache.fop.fo.FONode#getLocalName() */ + public String getLocalName() { + return _name; + } + +} + -- cgit v1.2.3