diff options
author | Vincent Hennebert <vhennebert@apache.org> | 2014-06-18 19:28:32 +0000 |
---|---|---|
committer | Vincent Hennebert <vhennebert@apache.org> | 2014-06-18 19:28:32 +0000 |
commit | 4d524ac15230182525ce2ba8d4c8048765a87ba8 (patch) | |
tree | 398cc53494fcc63b0d290e93d836a0ea81e76762 /src/java/org/apache/fop/render | |
parent | b0f0730ed264e1cf00ba0d4d823d76f249dbf1e4 (diff) | |
download | xmlgraphics-fop-4d524ac15230182525ce2ba8d4c8048765a87ba8.tar.gz xmlgraphics-fop-4d524ac15230182525ce2ba8d4c8048765a87ba8.zip |
FOP-2385: Add ability to specify custom properties in the Document Information Dictionary
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1603596 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render')
9 files changed, 168 insertions, 1 deletions
diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java b/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java index 4352dae6c..411916c74 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java @@ -455,6 +455,11 @@ class PDFRenderingUtil { if (((PDFPageExtension) extension).matchesPageNumber(currentPage.getPageIndex() + 1)) { augmentDictionary(currentPage, extension); } + } else if (type == PDFDictionaryType.Info) { + PDFInfo info = pdfDoc.getInfo(); + for (PDFCollectionEntryExtension entry : extension.getEntries()) { + info.put(entry.getKey(), entry.getValueAsString()); + } } else { throw new IllegalStateException(); } diff --git a/src/java/org/apache/fop/render/pdf/extensions/PDFDictionaryElement.java b/src/java/org/apache/fop/render/pdf/extensions/PDFDictionaryElement.java index 9dc127da6..26b03d5bc 100644 --- a/src/java/org/apache/fop/render/pdf/extensions/PDFDictionaryElement.java +++ b/src/java/org/apache/fop/render/pdf/extensions/PDFDictionaryElement.java @@ -56,6 +56,8 @@ public class PDFDictionaryElement extends PDFCollectionEntryElement { return new PDFNavigatorExtension(); } else if (type == PDFDictionaryType.Page) { return new PDFPageExtension(); + } else if (type == PDFDictionaryType.Info) { + return new PDFDocumentInformationExtension(); } else { return new PDFDictionaryExtension(type); } @@ -103,6 +105,8 @@ public class PDFDictionaryElement extends PDFCollectionEntryElement { // handled in PDFNavigattorElement subclass } else if (localName.equals("page")) { // handled in PDFPageElement subclass + } else if (localName.equals("info")) { + // handled in PDFDocumentInformationElement subclass } else if (localName.equals("dictionary")) { if (!PDFDictionaryType.hasValueOfElementName(parent.getLocalName()) && !PDFObjectType.Array.elementName().equals(parent.getLocalName())) { invalidChildError(getLocator(), parent.getName(), getNamespaceURI(), getName(), null); diff --git a/src/java/org/apache/fop/render/pdf/extensions/PDFDictionaryType.java b/src/java/org/apache/fop/render/pdf/extensions/PDFDictionaryType.java index a49a5fc8c..1a3387aa0 100644 --- a/src/java/org/apache/fop/render/pdf/extensions/PDFDictionaryType.java +++ b/src/java/org/apache/fop/render/pdf/extensions/PDFDictionaryType.java @@ -30,7 +30,9 @@ public enum PDFDictionaryType { Dictionary("dictionary"), // generic (nested) dictionary element Layer("layer", true), // optional content group dictionary element Navigator("navigator", true), // navigation node dictionary element - Page("page"); // page dictionary element + Page("page"), // page dictionary element + /** Document Information Dictionary */ + Info("info"); private String elementName; private boolean usesIDAttribute; diff --git a/src/java/org/apache/fop/render/pdf/extensions/PDFDocumentInformationElement.java b/src/java/org/apache/fop/render/pdf/extensions/PDFDocumentInformationElement.java new file mode 100644 index 000000000..7aae57602 --- /dev/null +++ b/src/java/org/apache/fop/render/pdf/extensions/PDFDocumentInformationElement.java @@ -0,0 +1,75 @@ +/* + * 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.pdf.extensions; + +import org.xml.sax.Attributes; +import org.xml.sax.Locator; + +import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.ValidationException; +import org.apache.fop.pdf.PDFInfo; + +public class PDFDocumentInformationElement extends PDFDictionaryElement { + + PDFDocumentInformationElement(FONode parent) { + super(parent, PDFDictionaryType.Info); + } + + @Override + public void processNode(String elementName, Locator locator, Attributes attlist, + PropertyList propertyList) throws FOPException { + setLocator(locator); + super.processNode(elementName, locator, attlist, propertyList); + } + + @Override + public void startOfNode() throws FOPException { + super.startOfNode(); + if (parent.getNameId() != Constants.FO_DECLARATIONS) { + invalidChildError(getLocator(), parent.getName(), getNamespaceURI(), getName(), "rule.childOfDeclarations"); + } + } + + @Override + protected void validateChildNode(Locator loc, String namespaceURI, String localName) + throws ValidationException { + if (!(PDFElementMapping.NAMESPACE.equals(namespaceURI) && "name".equals(localName))) { + invalidChildError(loc, namespaceURI, localName); + } + } + + @Override + protected void addChildNode(FONode child) throws FOPException { + assert child instanceof PDFCollectionEntryElement; + PDFCollectionEntryElement name = (PDFCollectionEntryElement) child; + PDFInfo.StandardKey standardKey = PDFInfo.StandardKey.get(name.getExtension().getKey()); + if (standardKey == null) { + super.addChildNode(child); + } else { + PDFExtensionEventProducer eventProducer = getUserAgent().getEventBroadcaster() + .getEventProducerFor(PDFExtensionEventProducer.class); + eventProducer.reservedKeyword(this, getLocator(), standardKey.getName()); + } + } + +} diff --git a/src/java/org/apache/fop/render/pdf/extensions/PDFDocumentInformationExtension.java b/src/java/org/apache/fop/render/pdf/extensions/PDFDocumentInformationExtension.java new file mode 100644 index 000000000..ed77c2746 --- /dev/null +++ b/src/java/org/apache/fop/render/pdf/extensions/PDFDocumentInformationExtension.java @@ -0,0 +1,28 @@ +/* + * 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.pdf.extensions; + +public class PDFDocumentInformationExtension extends PDFDictionaryExtension { + + PDFDocumentInformationExtension() { + super(PDFDictionaryType.Info); + } + +} diff --git a/src/java/org/apache/fop/render/pdf/extensions/PDFElementMapping.java b/src/java/org/apache/fop/render/pdf/extensions/PDFElementMapping.java index 1fba80796..f0e838f78 100644 --- a/src/java/org/apache/fop/render/pdf/extensions/PDFElementMapping.java +++ b/src/java/org/apache/fop/render/pdf/extensions/PDFElementMapping.java @@ -67,6 +67,8 @@ public class PDFElementMapping extends ElementMapping { foObjs.put(PDFObjectType.Reference.elementName(), new PDFReferenceElementMaker()); // pdf:string foObjs.put(PDFObjectType.String.elementName(), new PDFCollectionEntryElementMaker(PDFObjectType.String)); + // pdf:info + foObjs.put(PDFDictionaryType.Info.elementName(), new PDFDocumentInformationElementMaker()); } } @@ -88,6 +90,12 @@ public class PDFElementMapping extends ElementMapping { } } + static class PDFDocumentInformationElementMaker extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new PDFDocumentInformationElement(parent); + } + } + static class PDFDictionaryElementMaker extends ElementMapping.Maker { public FONode make(FONode parent) { return new PDFDictionaryElement(parent, PDFDictionaryType.Dictionary); diff --git a/src/java/org/apache/fop/render/pdf/extensions/PDFExtensionEventProducer.java b/src/java/org/apache/fop/render/pdf/extensions/PDFExtensionEventProducer.java new file mode 100644 index 000000000..f4338c6a5 --- /dev/null +++ b/src/java/org/apache/fop/render/pdf/extensions/PDFExtensionEventProducer.java @@ -0,0 +1,37 @@ +/* + * 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.pdf.extensions; + +import org.xml.sax.Locator; + +import org.apache.fop.events.EventProducer; + +public interface PDFExtensionEventProducer extends EventProducer { + + /** Reserved keyword. + * + * @param source the object source + * @param locator the location in the source + * @param keyword the offending keyword + * @event.severity ERROR + */ + void reservedKeyword(Object source, Locator locator, String keyword); + +} diff --git a/src/java/org/apache/fop/render/pdf/extensions/PDFExtensionEventProducer.xml b/src/java/org/apache/fop/render/pdf/extensions/PDFExtensionEventProducer.xml new file mode 100644 index 000000000..57abcc185 --- /dev/null +++ b/src/java/org/apache/fop/render/pdf/extensions/PDFExtensionEventProducer.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<catalogue xml:lang="en"> + <message key="locator">[ (See position {locator})| (See {#gatherContextInfo})| (No context info available)]</message> + <message key="reservedKeyword">{keyword} is a reserved keyword{{locator}}. Please use a different keyword for you custom property.</message> +</catalogue> diff --git a/src/java/org/apache/fop/render/pdf/extensions/PDFExtensionHandler.java b/src/java/org/apache/fop/render/pdf/extensions/PDFExtensionHandler.java index 2fd14058e..700f056a6 100644 --- a/src/java/org/apache/fop/render/pdf/extensions/PDFExtensionHandler.java +++ b/src/java/org/apache/fop/render/pdf/extensions/PDFExtensionHandler.java @@ -107,6 +107,9 @@ public class PDFExtensionHandler extends DefaultHandler implements ContentHandle page.setProperty(PDFPageExtension.PROPERTY_PAGE_NUMBERS, pageNumbers); } collections.push(page); + } else if (PDFDictionaryType.Info.elementName().equals(localName)) { + PDFDocumentInformationExtension info = new PDFDocumentInformationExtension(); + collections.push(info); } else if (PDFObjectType.hasValueOfElementName(localName)) { PDFCollectionEntryExtension entry; if (PDFObjectType.Reference.elementName().equals(localName)) { |