From 208afa6c7df69e98c16e766aa815e603c53c293b Mon Sep 17 00:00:00 2001 From: Chris Bowditch Date: Fri, 5 Oct 2007 08:36:48 +0000 Subject: Bugzilla #43070 Postscript extension : comment before and after page Submitted by Adrian Cumiskey git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@582124 13f79535-47bb-0310-9956-ffa450edef68 --- .../ps/extensions/AbstractPSCommentElement.java | 54 ++++++++++++++++++++++ .../fop/render/ps/extensions/PSCommentAfter.java | 53 +++++++++++++++++++++ .../ps/extensions/PSCommentAfterElement.java | 54 ++++++++++++++++++++++ .../fop/render/ps/extensions/PSCommentBefore.java | 53 +++++++++++++++++++++ .../ps/extensions/PSCommentBeforeElement.java | 52 +++++++++++++++++++++ .../ps/extensions/PSExtensionElementMapping.java | 14 ++++++ .../render/ps/extensions/PSExtensionHandler.java | 8 +++- 7 files changed, 287 insertions(+), 1 deletion(-) create mode 100644 src/java/org/apache/fop/render/ps/extensions/AbstractPSCommentElement.java create mode 100644 src/java/org/apache/fop/render/ps/extensions/PSCommentAfter.java create mode 100644 src/java/org/apache/fop/render/ps/extensions/PSCommentAfterElement.java create mode 100644 src/java/org/apache/fop/render/ps/extensions/PSCommentBefore.java create mode 100644 src/java/org/apache/fop/render/ps/extensions/PSCommentBeforeElement.java (limited to 'src/java/org/apache/fop/render/ps/extensions') diff --git a/src/java/org/apache/fop/render/ps/extensions/AbstractPSCommentElement.java b/src/java/org/apache/fop/render/ps/extensions/AbstractPSCommentElement.java new file mode 100644 index 000000000..a6e77fb13 --- /dev/null +++ b/src/java/org/apache/fop/render/ps/extensions/AbstractPSCommentElement.java @@ -0,0 +1,54 @@ +/* + * 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. + */ + +/* $Id$ */ + +package org.apache.fop.render.ps.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; + +/** + * Base postscript commment element class + */ +public abstract class AbstractPSCommentElement extends AbstractPSExtensionElement { + + /** + * Default constructor + * + * @param parent parent of this node + * @see org.apache.fop.fo.FONode#FONode(FONode) + */ + public AbstractPSCommentElement(FONode parent) { + super(parent); + } + + /** + * @throws FOPException if there's a problem during processing + * @see org.apache.fop.fo.FONode#startOfNode() + */ + protected void startOfNode() throws FOPException { + if (parent.getNameId() != Constants.FO_DECLARATIONS + && parent.getNameId() != Constants.FO_SIMPLE_PAGE_MASTER) { + throw new ValidationException(getName() + + " must be a child of fo:declarations or fo:simple-page-master."); + } + } + +} diff --git a/src/java/org/apache/fop/render/ps/extensions/PSCommentAfter.java b/src/java/org/apache/fop/render/ps/extensions/PSCommentAfter.java new file mode 100644 index 000000000..60c47b29c --- /dev/null +++ b/src/java/org/apache/fop/render/ps/extensions/PSCommentAfter.java @@ -0,0 +1,53 @@ +/* + * 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. + */ + +/* $Id$ */ + +package org.apache.fop.render.ps.extensions; + +/** + * Custom postscript comment after class + */ +public class PSCommentAfter extends PSExtensionAttachment { + + /** + * Element name + */ + protected static final String ELEMENT = "ps-comment-after"; + + /** + * Default constructor + */ + public PSCommentAfter() { + super(); + } + + /** + * Constructor + * @param content comment + */ + public PSCommentAfter(String content) { + super(content); + } + + /** + * @return the element name + */ + protected String getElement() { + return ELEMENT; + } +} diff --git a/src/java/org/apache/fop/render/ps/extensions/PSCommentAfterElement.java b/src/java/org/apache/fop/render/ps/extensions/PSCommentAfterElement.java new file mode 100644 index 000000000..2dbbf1f36 --- /dev/null +++ b/src/java/org/apache/fop/render/ps/extensions/PSCommentAfterElement.java @@ -0,0 +1,54 @@ +/* + * 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. + */ + +/* $Id$ */ + +package org.apache.fop.render.ps.extensions; + +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.extensions.ExtensionAttachment; + +/** + * Comment after element + */ +public class PSCommentAfterElement extends AbstractPSCommentElement { + + /** + * Main constructor + * @param parent node + */ + public PSCommentAfterElement(FONode parent) { + super(parent); + } + + /** + * @return local name + * @see org.apache.fop.fo.FONode#getLocalName() + */ + public String getLocalName() { + return "ps-comment-after"; + } + + /** + * @return instance of its extension attachment object + * @see org.apache.fop.render.ps.extensions.AbstractPSExtensionElement + * #instantiateExtensionAttachment() + */ + protected ExtensionAttachment instantiateExtensionAttachment() { + return new PSCommentAfter(); + } +} diff --git a/src/java/org/apache/fop/render/ps/extensions/PSCommentBefore.java b/src/java/org/apache/fop/render/ps/extensions/PSCommentBefore.java new file mode 100644 index 000000000..60b6f2e4f --- /dev/null +++ b/src/java/org/apache/fop/render/ps/extensions/PSCommentBefore.java @@ -0,0 +1,53 @@ +/* + * 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. + */ + +/* $Id$ */ + +package org.apache.fop.render.ps.extensions; + +/** + * Custom postscript comment before class + */ +public class PSCommentBefore extends PSExtensionAttachment { + + /** + * Element name + */ + protected static final String ELEMENT = "ps-comment-before"; + + /** + * Default constructor + * @param content the actual comment + */ + public PSCommentBefore(String content) { + super(content); + } + + /** + * Constructor + */ + public PSCommentBefore() { + super(); + } + + /** + * @return element name + */ + protected String getElement() { + return ELEMENT; + } +} diff --git a/src/java/org/apache/fop/render/ps/extensions/PSCommentBeforeElement.java b/src/java/org/apache/fop/render/ps/extensions/PSCommentBeforeElement.java new file mode 100644 index 000000000..7abb67007 --- /dev/null +++ b/src/java/org/apache/fop/render/ps/extensions/PSCommentBeforeElement.java @@ -0,0 +1,52 @@ +/* + * 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. + */ + +/* $Id$ */ + +package org.apache.fop.render.ps.extensions; + +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.extensions.ExtensionAttachment; + +/** + * Comment before element + */ +public class PSCommentBeforeElement extends AbstractPSCommentElement { + + /** + * Main constructor + * @param parent parent node + */ + public PSCommentBeforeElement(FONode parent) { + super(parent); + } + + /** + * @return local name + * @see org.apache.fop.fo.FONode#getLocalName() + */ + public String getLocalName() { + return "ps-comment-before"; + } + + /** + * @return instance of its extension attachment object + */ + protected ExtensionAttachment instantiateExtensionAttachment() { + return new PSCommentBefore(); + } +} diff --git a/src/java/org/apache/fop/render/ps/extensions/PSExtensionElementMapping.java b/src/java/org/apache/fop/render/ps/extensions/PSExtensionElementMapping.java index a90af2a9c..bfb402d29 100644 --- a/src/java/org/apache/fop/render/ps/extensions/PSExtensionElementMapping.java +++ b/src/java/org/apache/fop/render/ps/extensions/PSExtensionElementMapping.java @@ -42,6 +42,8 @@ public class PSExtensionElementMapping extends ElementMapping { foObjs.put("ps-setup-code", new PSSetupCodeMaker()); foObjs.put("ps-page-setup-code", new PSPageSetupCodeMaker()); foObjs.put("ps-setpagedevice", new PSSetPageDeviceMaker()); + foObjs.put("ps-comment-before", new PSCommentBeforeMaker()); + foObjs.put("ps-comment-after", new PSCommentAfterMaker()); } } @@ -62,4 +64,16 @@ public class PSExtensionElementMapping extends ElementMapping { return new PSSetPageDeviceElement(parent); } } + + static class PSCommentBeforeMaker extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new PSCommentBeforeElement(parent); + } + } + + static class PSCommentAfterMaker extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new PSCommentAfterElement(parent); + } + } } diff --git a/src/java/org/apache/fop/render/ps/extensions/PSExtensionHandler.java b/src/java/org/apache/fop/render/ps/extensions/PSExtensionHandler.java index 6cc41f8cc..72f665a0f 100644 --- a/src/java/org/apache/fop/render/ps/extensions/PSExtensionHandler.java +++ b/src/java/org/apache/fop/render/ps/extensions/PSExtensionHandler.java @@ -50,7 +50,9 @@ public class PSExtensionHandler extends DefaultHandler lastAttributes = attributes; handled = false; if (localName.equals(PSSetupCode.ELEMENT) - || localName.equals(PSSetPageDevice.ELEMENT)) { + || localName.equals(PSSetPageDevice.ELEMENT) + || localName.equals(PSCommentBefore.ELEMENT) + || localName.equals(PSCommentAfter.ELEMENT)) { //handled in endElement handled = true; } @@ -75,6 +77,10 @@ public class PSExtensionHandler extends DefaultHandler } else if (PSSetPageDevice.ELEMENT.equals(localName)) { String name = lastAttributes.getValue("name"); this.returnedObject = new PSSetPageDevice(name, content.toString()); + } else if (PSCommentBefore.ELEMENT.equals(localName)) { + this.returnedObject = new PSCommentBefore(content.toString()); + } else if (PSCommentAfter.ELEMENT.equals(localName)) { + this.returnedObject = new PSCommentAfter(content.toString()); } } content.setLength(0); //Reset text buffer (see characters()) -- cgit v1.2.3