diff options
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFEmbeddedFiles.java | 66 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFNameTreeNode.java | 31 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFNames.java | 10 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java | 6 |
4 files changed, 74 insertions, 39 deletions
diff --git a/src/java/org/apache/fop/pdf/PDFEmbeddedFiles.java b/src/java/org/apache/fop/pdf/PDFEmbeddedFiles.java new file mode 100644 index 000000000..8e89f5ada --- /dev/null +++ b/src/java/org/apache/fop/pdf/PDFEmbeddedFiles.java @@ -0,0 +1,66 @@ +/* + * 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.pdf; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; +import java.util.Iterator; +import java.util.Map; +import java.util.SortedMap; + +/** + * Class representing an /EmbeddedFiles dictionary object (name tree). + */ +public class PDFEmbeddedFiles extends PDFNameTreeNode { + + /** + * Create a /EmbeddedFiles dictionary. + */ + public PDFEmbeddedFiles() { + super(); + } + + /** {@inheritDoc} */ + protected void writeDictionary(OutputStream out, Writer writer) throws IOException { + sortNames(); //Sort the names before writing them out + super.writeDictionary(out, writer); + } + + private void sortNames() { + PDFArray names = getNames(); + SortedMap map = new java.util.TreeMap(); + int i = 0; + int c = names.length(); + while (i < c) { + Comparable key = (Comparable)names.get(i++); //Key must be a Comparable for sorting + Object value = names.get(i++); + map.put(key, value); + } + names.clear(); + Iterator iter = map.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entry = (Map.Entry)iter.next(); + names.add(entry.getKey()); + names.add(entry.getValue()); + } + } +} + diff --git a/src/java/org/apache/fop/pdf/PDFNameTreeNode.java b/src/java/org/apache/fop/pdf/PDFNameTreeNode.java index f294b0f68..4e1f1b71b 100644 --- a/src/java/org/apache/fop/pdf/PDFNameTreeNode.java +++ b/src/java/org/apache/fop/pdf/PDFNameTreeNode.java @@ -19,13 +19,6 @@ package org.apache.fop.pdf; -import java.io.IOException; -import java.io.OutputStream; -import java.io.Writer; -import java.util.Iterator; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; /** * Class representing a PDF name tree node. @@ -124,29 +117,5 @@ public class PDFNameTreeNode extends PDFDictionary { return limits; } - /** {@inheritDoc} */ - protected void writeDictionary(OutputStream out, Writer writer) throws IOException { - sortNames(); //Sort the names before writing them out - super.writeDictionary(out, writer); - } - - private void sortNames() { - PDFArray names = getNames(); - SortedMap map = new TreeMap(); - int i = 0; - int c = names.length(); - while (i < c) { - String key = (String)names.get(i++); //Key must be a String - Object value = names.get(i++); - map.put(key, value); - } - names.clear(); - Iterator iter = map.entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry entry = (Map.Entry)iter.next(); - names.add(entry.getKey()); - names.add(entry.getValue()); - } - } } diff --git a/src/java/org/apache/fop/pdf/PDFNames.java b/src/java/org/apache/fop/pdf/PDFNames.java index aa6f64547..fbea0d3f5 100644 --- a/src/java/org/apache/fop/pdf/PDFNames.java +++ b/src/java/org/apache/fop/pdf/PDFNames.java @@ -55,16 +55,16 @@ public class PDFNames extends PDFDictionary { * Returns the EmbeddedFiles object * @return the EmbeddedFiles object, or null if it's not used */ - public PDFNameTreeNode getEmbeddedFiles() { - return (PDFNameTreeNode)get(EMBEDDED_FILES); + public PDFEmbeddedFiles getEmbeddedFiles() { + return (PDFEmbeddedFiles)get(EMBEDDED_FILES); } /** * Set the EmbeddedFiles object - * @param dests the EmbeddedFiles object + * @param embeddedFiles the EmbeddedFiles object */ - public void setEmbeddedFiles(PDFNameTreeNode dests) { - put(EMBEDDED_FILES, dests); + public void setEmbeddedFiles(PDFEmbeddedFiles embeddedFiles) { + put(EMBEDDED_FILES, embeddedFiles); } } diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java b/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java index b7ad9cf71..ae205a1e5 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java @@ -48,6 +48,7 @@ import org.apache.fop.pdf.PDFConformanceException; import org.apache.fop.pdf.PDFDictionary; import org.apache.fop.pdf.PDFDocument; import org.apache.fop.pdf.PDFEmbeddedFile; +import org.apache.fop.pdf.PDFEmbeddedFiles; import org.apache.fop.pdf.PDFEncryptionManager; import org.apache.fop.pdf.PDFEncryptionParams; import org.apache.fop.pdf.PDFFileSpec; @@ -55,7 +56,6 @@ import org.apache.fop.pdf.PDFICCBasedColorSpace; import org.apache.fop.pdf.PDFICCStream; import org.apache.fop.pdf.PDFInfo; import org.apache.fop.pdf.PDFMetadata; -import org.apache.fop.pdf.PDFNameTreeNode; import org.apache.fop.pdf.PDFNames; import org.apache.fop.pdf.PDFNumsArray; import org.apache.fop.pdf.PDFOutputIntent; @@ -463,9 +463,9 @@ class PDFRenderingUtil implements PDFConfigurationConstants { this.pdfDoc.registerObject(fileSpec); //Make sure there is an EmbeddedFiles in the Names dictionary - PDFNameTreeNode embeddedFiles = names.getEmbeddedFiles(); + PDFEmbeddedFiles embeddedFiles = names.getEmbeddedFiles(); if (embeddedFiles == null) { - embeddedFiles = new PDFNameTreeNode(); + embeddedFiles = new PDFEmbeddedFiles(); this.pdfDoc.assignObjectNumber(embeddedFiles); this.pdfDoc.addTrailerObject(embeddedFiles); names.setEmbeddedFiles(embeddedFiles); |