KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > stefanochizzolini > clown > documents > interchange > metadata > Information


1 /*
2   Copyright 2006 Stefano Chizzolini. http://clown.stefanochizzolini.it
3
4   Contributors:
5     * Stefano Chizzolini (original code developer, info@stefanochizzolini.it):
6       contributed code is Copyright 2006 by Stefano Chizzolini.
7
8   This file should be part of the source code distribution of "PDF Clown library"
9   (the Program): see the accompanying README files for more info.
10
11   This Program is free software; you can redistribute it and/or modify it under
12   the terms of the GNU General Public License as published by the Free Software
13   Foundation; either version 2 of the License, or (at your option) any later version.
14
15   This Program is distributed in the hope that it will be useful, but WITHOUT ANY
16   WARRANTY, either expressed or implied; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
18
19   You should have received a copy of the GNU General Public License along with this
20   Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
21
22   Redistribution and use, with or without modification, are permitted provided that such
23   redistributions retain the above copyright notice, license and disclaimer, along with
24   this list of conditions.
25 */

26
27 package it.stefanochizzolini.clown.documents.interchange.metadata;
28
29 import it.stefanochizzolini.clown.documents.Document;
30 import it.stefanochizzolini.clown.files.File;
31 import it.stefanochizzolini.clown.objects.PdfAtomicObject;
32 import it.stefanochizzolini.clown.objects.PdfDate;
33 import it.stefanochizzolini.clown.objects.PdfDictionary;
34 import it.stefanochizzolini.clown.objects.PdfDirectObject;
35 import it.stefanochizzolini.clown.objects.PdfLiteral;
36 import it.stefanochizzolini.clown.objects.PdfName;
37 import it.stefanochizzolini.clown.objects.PdfObjectWrapper;
38 import it.stefanochizzolini.clown.util.NotImplementedException;
39
40 import java.util.Date JavaDoc;
41
42 /**
43   Document information [PDF:1.6:10.2.1].
44 */

45 public class Information
46   extends PdfObjectWrapper<PdfDictionary>
47 {
48   // <class>
49
// <dynamic>
50
// <constructors>
51
public Information(
52     Document context
53     )
54   {
55     super(
56       context.getFile(),
57       new PdfDictionary()
58       );
59
60     try
61     {
62       Package JavaDoc package_ = getClass().getPackage();
63       setProducer(
64         package_.getSpecificationTitle() + " "
65           + package_.getSpecificationVersion()
66         );
67     }
68     catch(Exception JavaDoc e)
69     {/* Do nothing (noncritical exception). */}
70   }
71
72   /**
73     <h3>Remarks</h3>
74     <p>For internal use only.</p>
75   */

76   public Information(
77     PdfDirectObject baseObject
78     )
79   {
80     super(
81       baseObject,
82       null // NO container (baseObject MUST be an indirect object [PDF:1.6:3.4.4]).
83
);
84   }
85   // </constructors>
86

87   // <interface>
88
// <public>
89
public String JavaDoc getAuthor(
90     )
91   {return this.<String JavaDoc,PdfLiteral>getEntry(PdfName.Author);}
92
93   public Object JavaDoc clone(
94     Document context
95     )
96   {throw new NotImplementedException();}
97
98   public Date getCreationDate(
99     )
100   {return this.<Date,PdfDate>getEntry(PdfName.CreationDate);}
101
102   public String JavaDoc getCreator(
103     )
104   {return this.<String JavaDoc,PdfLiteral>getEntry(PdfName.Creator);}
105
106   public String JavaDoc getKeywords(
107     )
108   {return this.<String JavaDoc,PdfLiteral>getEntry(PdfName.Keywords);}
109
110   public Date getModificationDate(
111     )
112   {return this.<Date,PdfDate>getEntry(PdfName.ModDate);}
113
114   public String JavaDoc getProducer(
115     )
116   {return this.<String JavaDoc,PdfLiteral>getEntry(PdfName.Producer);}
117
118   public String JavaDoc getSubject(
119     )
120   {return this.<String JavaDoc,PdfLiteral>getEntry(PdfName.Subject);}
121
122   public String JavaDoc getTitle(
123     )
124   {return this.<String JavaDoc,PdfLiteral>getEntry(PdfName.Title);}
125
126   public void setAuthor(
127     String JavaDoc value
128     )
129   {this.<String JavaDoc,PdfLiteral>setEntry(PdfName.Author,value,PdfLiteral.class);}
130
131   public void setCreationDate(
132     Date value
133     )
134   {this.<Date,PdfDate>setEntry(PdfName.CreationDate,value,PdfDate.class);}
135
136   public void setCreator(
137     String JavaDoc value
138     )
139   {this.<String JavaDoc,PdfLiteral>setEntry(PdfName.Creator,value,PdfLiteral.class);}
140
141   public void setKeywords(
142     String JavaDoc value
143     )
144   {this.<String JavaDoc,PdfLiteral>setEntry(PdfName.Keywords,value,PdfLiteral.class);}
145
146   public void setModificationDate(
147     Date value
148     )
149   {this.<Date,PdfDate>setEntry(PdfName.ModDate,value,PdfDate.class);}
150
151   public void setProducer(
152     String JavaDoc value
153     )
154   {this.<String JavaDoc,PdfLiteral>setEntry(PdfName.Producer,value,PdfLiteral.class);}
155
156   public void setSubject(
157     String JavaDoc value
158     )
159   {this.<String JavaDoc,PdfLiteral>setEntry(PdfName.Subject,value,PdfLiteral.class);}
160
161   public void setTitle(
162     String JavaDoc value
163     )
164   {this.<String JavaDoc,PdfLiteral>setEntry(PdfName.Title,value,PdfLiteral.class);}
165   // </public>
166

167   // <protected>
168
protected <T,TPdf extends PdfAtomicObject<T>> T getEntry(
169     PdfName key
170     )
171   {
172     TPdf entry = (TPdf)File.resolve(getBaseDataObject().get(key));
173     if(entry == null)
174       return null;
175
176     return (T)entry.getValue();
177   }
178
179   protected <T,TPdf extends PdfAtomicObject<T>> void setEntry(
180     PdfName key,
181     T value,
182     Class JavaDoc<TPdf> entryType // This Class<TPdf> parameter is an ugly workaround to the horrific generics type erasure that precludes full reflection over parameterized types.
183
)
184   {
185     TPdf entry = (TPdf)File.resolve(getBaseDataObject().get(key));
186     if(entry == null)
187     {
188       try
189       {
190         getBaseDataObject().put(
191           key,
192           entry = entryType.newInstance()
193           );
194       }
195       catch(Exception JavaDoc e)
196       {
197         // Propagate the exception!
198
throw new RuntimeException JavaDoc(e);
199       }
200     }
201
202     entry.setValue(value);
203   }
204 /* protected <T,TPdf extends PdfAtomicObject<T>> void setEntry(
205     PdfName key,
206     T value,
207     Class<TPdf> entryType
208     )
209   {
210     TPdf entry = (TPdf)File.resolve(getBaseDataObject().get(key));
211     if(entry == null)
212       getBaseDataObject().put(key,entry = entryType.newInstance());
213
214     entry.setValue(value);
215   }*/

216   // </protected>
217
// </interface>
218
// </class>
219
}
Popular Tags