001: /*
002: Copyright © 2006 Stefano Chizzolini. http://clown.stefanochizzolini.it
003:
004: Contributors:
005: * Stefano Chizzolini (original code developer, http://www.stefanochizzolini.it):
006: contributed code is Copyright © 2006 by Stefano Chizzolini.
007:
008: This file should be part of the source code distribution of "PDF Clown library"
009: (the Program): see the accompanying README files for more info.
010:
011: This Program is free software; you can redistribute it and/or modify it under
012: the terms of the GNU General Public License as published by the Free Software
013: Foundation; either version 2 of the License, or (at your option) any later version.
014:
015: This Program is distributed in the hope that it will be useful, but WITHOUT ANY
016: WARRANTY, either expressed or implied; without even the implied warranty of
017: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
018:
019: You should have received a copy of the GNU General Public License along with this
020: Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
021:
022: Redistribution and use, with or without modification, are permitted provided that such
023: redistributions retain the above copyright notice, license and disclaimer, along with
024: this list of conditions.
025: */
026:
027: package it.stefanochizzolini.clown.documents.interchange.metadata;
028:
029: import it.stefanochizzolini.clown.documents.Document;
030: import it.stefanochizzolini.clown.files.File;
031: import it.stefanochizzolini.clown.objects.PdfAtomicObject;
032: import it.stefanochizzolini.clown.objects.PdfDate;
033: import it.stefanochizzolini.clown.objects.PdfDictionary;
034: import it.stefanochizzolini.clown.objects.PdfDirectObject;
035: import it.stefanochizzolini.clown.objects.PdfLiteral;
036: import it.stefanochizzolini.clown.objects.PdfName;
037: import it.stefanochizzolini.clown.objects.PdfObjectWrapper;
038: import it.stefanochizzolini.clown.util.NotImplementedException;
039:
040: import java.util.Date;
041:
042: /**
043: Document information [PDF:1.6:10.2.1].
044: */
045: public class Information extends PdfObjectWrapper<PdfDictionary> {
046: // <class>
047: // <dynamic>
048: // <constructors>
049: public Information(Document context) {
050: super (context.getFile(), new PdfDictionary());
051:
052: try {
053: Package package_ = getClass().getPackage();
054: setProducer(package_.getSpecificationTitle() + " "
055: + package_.getSpecificationVersion());
056: } catch (Exception e) {/* Do nothing (noncritical exception). */
057: }
058: }
059:
060: /**
061: <h3>Remarks</h3>
062: <p>For internal use only.</p>
063: */
064: public Information(PdfDirectObject baseObject) {
065: super (baseObject, null // NO container (baseObject MUST be an indirect object [PDF:1.6:3.4.4]).
066: );
067: }
068:
069: // </constructors>
070:
071: // <interface>
072: // <public>
073: public String getAuthor() {
074: return this .<String, PdfLiteral> getEntry(PdfName.Author);
075: }
076:
077: @Override
078: public Information clone(Document context) {
079: throw new NotImplementedException();
080: }
081:
082: public Date getCreationDate() {
083: return this .<Date, PdfDate> getEntry(PdfName.CreationDate);
084: }
085:
086: public String getCreator() {
087: return this .<String, PdfLiteral> getEntry(PdfName.Creator);
088: }
089:
090: public String getKeywords() {
091: return this .<String, PdfLiteral> getEntry(PdfName.Keywords);
092: }
093:
094: public Date getModificationDate() {
095: return this .<Date, PdfDate> getEntry(PdfName.ModDate);
096: }
097:
098: public String getProducer() {
099: return this .<String, PdfLiteral> getEntry(PdfName.Producer);
100: }
101:
102: public String getSubject() {
103: return this .<String, PdfLiteral> getEntry(PdfName.Subject);
104: }
105:
106: public String getTitle() {
107: return this .<String, PdfLiteral> getEntry(PdfName.Title);
108: }
109:
110: public void setAuthor(String value) {
111: this .<String, PdfLiteral> setEntry(PdfName.Author, value,
112: PdfLiteral.class);
113: }
114:
115: public void setCreationDate(Date value) {
116: this .<Date, PdfDate> setEntry(PdfName.CreationDate, value,
117: PdfDate.class);
118: }
119:
120: public void setCreator(String value) {
121: this .<String, PdfLiteral> setEntry(PdfName.Creator, value,
122: PdfLiteral.class);
123: }
124:
125: public void setKeywords(String value) {
126: this .<String, PdfLiteral> setEntry(PdfName.Keywords, value,
127: PdfLiteral.class);
128: }
129:
130: public void setModificationDate(Date value) {
131: this .<Date, PdfDate> setEntry(PdfName.ModDate, value,
132: PdfDate.class);
133: }
134:
135: public void setProducer(String value) {
136: this .<String, PdfLiteral> setEntry(PdfName.Producer, value,
137: PdfLiteral.class);
138: }
139:
140: public void setSubject(String value) {
141: this .<String, PdfLiteral> setEntry(PdfName.Subject, value,
142: PdfLiteral.class);
143: }
144:
145: public void setTitle(String value) {
146: this .<String, PdfLiteral> setEntry(PdfName.Title, value,
147: PdfLiteral.class);
148: }
149:
150: // </public>
151:
152: // <protected>
153: protected <T, TPdf extends PdfAtomicObject<T>> T getEntry(
154: PdfName key) {
155: TPdf entry = (TPdf) File.resolve(getBaseDataObject().get(key));
156: if (entry == null)
157: return null;
158:
159: return (T) entry.getValue();
160: }
161:
162: protected <T, TPdf extends PdfAtomicObject<T>> void setEntry(
163: PdfName key, T value, Class<TPdf> entryType // This Class<TPdf> parameter is an ugly workaround to the horrific generics type erasure that precludes full reflection over parameterized types.
164: ) {
165: TPdf entry = (TPdf) File.resolve(getBaseDataObject().get(key));
166: if (entry == null) {
167: try {
168: getBaseDataObject().put(key,
169: entry = entryType.newInstance());
170: } catch (Exception e) {
171: // Propagate the exception!
172: throw new RuntimeException(e);
173: }
174: }
175:
176: entry.setValue(value);
177: }
178: // </protected>
179: // </interface>
180: // </class>
181: }
|