KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > pdmodel > PDDocumentNameDictionary


1 /**
2  * Copyright (c) 2005, www.pdfbox.org
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. Neither the name of pdfbox; nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * http://www.pdfbox.org
29  *
30  */

31 package org.pdfbox.pdmodel;
32
33 import org.pdfbox.cos.COSBase;
34 import org.pdfbox.cos.COSDictionary;
35 import org.pdfbox.pdmodel.common.COSObjectable;
36
37 /**
38  * This class holds all of the name trees that are available at the document level.
39  *
40  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
41  * @version $Revision: 1.3 $
42  */

43 public class PDDocumentNameDictionary implements COSObjectable
44 {
45     private COSDictionary nameDictionary;
46     private PDDocumentCatalog catalog;
47
48     /**
49      * Constructor.
50      *
51      * @param cat The document catalog that this dictionary is part of.
52      */

53     public PDDocumentNameDictionary( PDDocumentCatalog cat )
54     {
55         nameDictionary = new COSDictionary();
56         catalog = cat;
57     }
58  
59     /**
60      * Constructor.
61      *
62      * @param cat The document that this dictionary is part of.
63      * @param names The names dictionary.
64      */

65     public PDDocumentNameDictionary( PDDocumentCatalog cat, COSDictionary names )
66     {
67         catalog = cat;
68         nameDictionary = names;
69     }
70     
71     /**
72      * Convert this standard java object to a COS object.
73      *
74      * @return The cos object that matches this Java object.
75      */

76     public COSBase getCOSObject()
77     {
78         return nameDictionary;
79     }
80     
81     /**
82      * Convert this standard java object to a COS object.
83      *
84      * @return The cos dictionary for this object.
85      */

86     public COSDictionary getCOSDictionary()
87     {
88         return nameDictionary;
89     }
90     
91     /**
92      * Get the destination named tree node. The value in this name tree will be PDDestination
93      * objects.
94      *
95      * @return The destination name tree node.
96      */

97     public PDDestinationNameTreeNode getDests()
98     {
99         PDDestinationNameTreeNode dests = null;
100         
101         COSDictionary dic = (COSDictionary)nameDictionary.getDictionaryObject( "Dests" );
102         
103         //The document catalog also contains the Dests entry sometimes
104
//so check there as well.
105
if( dic == null )
106         {
107             dic = (COSDictionary)catalog.getCOSDictionary().getDictionaryObject( "Dests" );
108         }
109         
110         if( dic != null )
111         {
112             dests = new PDDestinationNameTreeNode( dic );
113         }
114         
115         
116         return dests;
117     }
118     
119     /**
120      * Set the named destinations that are associated with this document.
121      *
122      * @param dests The destination names.
123      */

124     public void setDests( PDDestinationNameTreeNode dests )
125     {
126         nameDictionary.setItem( "Dests", dests );
127         //The dests can either be in the document catalog or in the
128
//names dictionary, PDFBox will just maintain the one in the
129
//names dictionary for now unless there is a reason to do
130
//something else.
131
//clear the potentially out of date Dests reference.
132
catalog.getCOSDictionary().setItem( "Dests", (COSObjectable)null);
133     }
134     
135     /**
136      * Get the embedded files named tree node. The value in this name tree will be PDComplexFileSpecification
137      * objects.
138      *
139      * @return The embedded files name tree node.
140      */

141     public PDEmbeddedFilesNameTreeNode getEmbeddedFiles()
142     {
143         PDEmbeddedFilesNameTreeNode retval = null;
144         
145         COSDictionary dic = (COSDictionary)nameDictionary.getDictionaryObject( "EmbeddedFiles" );
146         
147         if( dic != null )
148         {
149             retval = new PDEmbeddedFilesNameTreeNode( dic );
150         }
151         
152         return retval;
153     }
154     
155     /**
156      * Set the named embedded files that are associated with this document.
157      *
158      * @param ef The new embedded files
159      */

160     public void setEmbeddedFiles( PDEmbeddedFilesNameTreeNode ef )
161     {
162         nameDictionary.setItem( "EmbeddedFiles", ef );
163     }
164 }
Popular Tags