001: /**
002: * Copyright (c) 2005, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.pdmodel;
031:
032: import org.pdfbox.cos.COSBase;
033: import org.pdfbox.cos.COSDictionary;
034: import org.pdfbox.pdmodel.common.COSObjectable;
035:
036: /**
037: * This class holds all of the name trees that are available at the document level.
038: *
039: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
040: * @version $Revision: 1.3 $
041: */
042: public class PDDocumentNameDictionary implements COSObjectable {
043: private COSDictionary nameDictionary;
044: private PDDocumentCatalog catalog;
045:
046: /**
047: * Constructor.
048: *
049: * @param cat The document catalog that this dictionary is part of.
050: */
051: public PDDocumentNameDictionary(PDDocumentCatalog cat) {
052: nameDictionary = new COSDictionary();
053: catalog = cat;
054: }
055:
056: /**
057: * Constructor.
058: *
059: * @param cat The document that this dictionary is part of.
060: * @param names The names dictionary.
061: */
062: public PDDocumentNameDictionary(PDDocumentCatalog cat,
063: COSDictionary names) {
064: catalog = cat;
065: nameDictionary = names;
066: }
067:
068: /**
069: * Convert this standard java object to a COS object.
070: *
071: * @return The cos object that matches this Java object.
072: */
073: public COSBase getCOSObject() {
074: return nameDictionary;
075: }
076:
077: /**
078: * Convert this standard java object to a COS object.
079: *
080: * @return The cos dictionary for this object.
081: */
082: public COSDictionary getCOSDictionary() {
083: return nameDictionary;
084: }
085:
086: /**
087: * Get the destination named tree node. The value in this name tree will be PDDestination
088: * objects.
089: *
090: * @return The destination name tree node.
091: */
092: public PDDestinationNameTreeNode getDests() {
093: PDDestinationNameTreeNode dests = null;
094:
095: COSDictionary dic = (COSDictionary) nameDictionary
096: .getDictionaryObject("Dests");
097:
098: //The document catalog also contains the Dests entry sometimes
099: //so check there as well.
100: if (dic == null) {
101: dic = (COSDictionary) catalog.getCOSDictionary()
102: .getDictionaryObject("Dests");
103: }
104:
105: if (dic != null) {
106: dests = new PDDestinationNameTreeNode(dic);
107: }
108:
109: return dests;
110: }
111:
112: /**
113: * Set the named destinations that are associated with this document.
114: *
115: * @param dests The destination names.
116: */
117: public void setDests(PDDestinationNameTreeNode dests) {
118: nameDictionary.setItem("Dests", dests);
119: //The dests can either be in the document catalog or in the
120: //names dictionary, PDFBox will just maintain the one in the
121: //names dictionary for now unless there is a reason to do
122: //something else.
123: //clear the potentially out of date Dests reference.
124: catalog.getCOSDictionary().setItem("Dests",
125: (COSObjectable) null);
126: }
127:
128: /**
129: * Get the embedded files named tree node. The value in this name tree will be PDComplexFileSpecification
130: * objects.
131: *
132: * @return The embedded files name tree node.
133: */
134: public PDEmbeddedFilesNameTreeNode getEmbeddedFiles() {
135: PDEmbeddedFilesNameTreeNode retval = null;
136:
137: COSDictionary dic = (COSDictionary) nameDictionary
138: .getDictionaryObject("EmbeddedFiles");
139:
140: if (dic != null) {
141: retval = new PDEmbeddedFilesNameTreeNode(dic);
142: }
143:
144: return retval;
145: }
146:
147: /**
148: * Set the named embedded files that are associated with this document.
149: *
150: * @param ef The new embedded files
151: */
152: public void setEmbeddedFiles(PDEmbeddedFilesNameTreeNode ef) {
153: nameDictionary.setItem("EmbeddedFiles", ef);
154: }
155: }
|