001: package com.etymon.pj.object;
002:
003: import java.io.*;
004: import java.util.*;
005: import com.etymon.pj.*;
006: import com.etymon.pj.exception.*;
007:
008: /**
009: A representation of a PDF Info dictionary.
010: @author Nassib Nassar
011: */
012: public class PjInfo extends PjDictionary {
013:
014: /**
015: Creates a new Info dictionary.
016: */
017: public PjInfo() {
018: super ();
019: addDefaults();
020: }
021:
022: /**
023: Creates an Info dictionary as a wrapper around a Hashtable.
024: @param h the Hashtable to use for this dictionary.
025: */
026: public PjInfo(Hashtable h) {
027: super (h);
028: addDefaults();
029: }
030:
031: public void setAuthor(PjString author) {
032: _h.put(PjName.AUTHOR, author);
033: }
034:
035: public void setAuthor(PjReference author) {
036: _h.put(PjName.AUTHOR, author);
037: }
038:
039: public PjObject getAuthor() throws InvalidPdfObjectException {
040: return hget(PjName.AUTHOR);
041: }
042:
043: public void setCreationDate(PjDate creationDate) {
044: _h.put(PjName.CREATIONDATE, creationDate);
045: }
046:
047: public void setCreationDate(PjReference creationDate) {
048: _h.put(PjName.CREATIONDATE, creationDate);
049: }
050:
051: public PjObject getCreationDate() throws InvalidPdfObjectException {
052: return hget(PjName.CREATIONDATE);
053: }
054:
055: public void setModDate(PjDate modDate) {
056: _h.put(PjName.MODDATE, modDate);
057: }
058:
059: public void setModDate(PjReference modDate) {
060: _h.put(PjName.MODDATE, modDate);
061: }
062:
063: public PjObject getModDate() throws InvalidPdfObjectException {
064: return hget(PjName.MODDATE);
065: }
066:
067: public void setCreator(PjString creator) {
068: _h.put(PjName.CREATOR, creator);
069: }
070:
071: public void setCreator(PjReference creator) {
072: _h.put(PjName.CREATOR, creator);
073: }
074:
075: public PjObject getCreator() throws InvalidPdfObjectException {
076: return hget(PjName.CREATOR);
077: }
078:
079: public void setProducer(PjString producer) {
080: _h.put(PjName.PRODUCER, new PjString(PjConst.COPYRIGHT_IN_INFO
081: .getString()
082: + ". " + producer.getString()));
083: }
084:
085: public PjObject getProducer() throws InvalidPdfObjectException {
086: return hget(PjName.PRODUCER);
087: }
088:
089: public void setTitle(PjString title) {
090: _h.put(PjName.TITLE, title);
091: }
092:
093: public void setTitle(PjReference title) {
094: _h.put(PjName.TITLE, title);
095: }
096:
097: public PjObject getTitle() throws InvalidPdfObjectException {
098: return hget(PjName.TITLE);
099: }
100:
101: public void setSubject(PjString subject) {
102: _h.put(PjName.SUBJECT, subject);
103: }
104:
105: public void setSubject(PjReference subject) {
106: _h.put(PjName.SUBJECT, subject);
107: }
108:
109: public PjObject getSubject() throws InvalidPdfObjectException {
110: return hget(PjName.SUBJECT);
111: }
112:
113: public void setKeywords(PjString keywords) {
114: _h.put(PjName.KEYWORDS, keywords);
115: }
116:
117: public void setKeywords(PjReference keywords) {
118: _h.put(PjName.KEYWORDS, keywords);
119: }
120:
121: public PjObject getKeywords() throws InvalidPdfObjectException {
122: return hget(PjName.KEYWORDS);
123: }
124:
125: /**
126: Examines a dictionary to see if it is a PDF Info
127: dictionary.
128: @param dictionary the dictionary to examine.
129: @return true if the dictionary could be interpreted as a
130: valid PjInfo object.
131: */
132: public static boolean isLike(PjDictionary dictionary) {
133: // run through the keys and see if they are all valid,
134: // and make sure there is at least one valid key
135: boolean atLeastOneValid = false;
136: Hashtable h = dictionary.getHashtable();
137: PjName key;
138: for (Enumeration enum = h.keys(); enum.hasMoreElements();) {
139: key = (PjName)(enum.nextElement());
140: if ( ( ! key.equals(PjName.AUTHOR) ) &&
141: ( ! key.equals(PjName.CREATIONDATE) ) &&
142: ( ! key.equals(PjName.MODDATE) ) &&
143: ( ! key.equals(PjName.CREATOR) ) &&
144: ( ! key.equals(PjName.PRODUCER) ) &&
145: ( ! key.equals(PjName.TITLE) ) &&
146: ( ! key.equals(PjName.SUBJECT) ) &&
147: ( ! key.equals(PjName.KEYWORDS) ) ) {
148: return false;
149: } else {
150: if ( ! atLeastOneValid ) {
151: atLeastOneValid = true;
152: }
153: }
154: }
155: return atLeastOneValid;
156: }
157:
158: /**
159: Returns a deep copy of this object.
160: @return a deep copy of this object.
161: @exception CloneNotSupportedException if the instance can not be cloned.
162: */
163: public Object clone() throws CloneNotSupportedException {
164: return new PjInfo(cloneHt());
165: }
166:
167: private void addDefaults() {
168: // Here we insert the PjConst.COPYRIGHT_IN_INFO
169: // constant, which contains the pj copyright notice.
170: // You may not remove this copyright notice.
171: _h.put(PjName.PRODUCER, PjConst.COPYRIGHT_IN_INFO);
172: // also need to add CreationDate and ModDate
173: }
174:
175: }
|