1 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 ; 41 42 45 public class Information 46 extends PdfObjectWrapper<PdfDictionary> 47 { 48 public Information( 52 Document context 53 ) 54 { 55 super( 56 context.getFile(), 57 new PdfDictionary() 58 ); 59 60 try 61 { 62 Package package_ = getClass().getPackage(); 63 setProducer( 64 package_.getSpecificationTitle() + " " 65 + package_.getSpecificationVersion() 66 ); 67 } 68 catch(Exception e) 69 {} 70 } 71 72 76 public Information( 77 PdfDirectObject baseObject 78 ) 79 { 80 super( 81 baseObject, 82 null ); 84 } 85 87 public String getAuthor( 90 ) 91 {return this.<String ,PdfLiteral>getEntry(PdfName.Author);} 92 93 public Object 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 getCreator( 103 ) 104 {return this.<String ,PdfLiteral>getEntry(PdfName.Creator);} 105 106 public String getKeywords( 107 ) 108 {return this.<String ,PdfLiteral>getEntry(PdfName.Keywords);} 109 110 public Date getModificationDate( 111 ) 112 {return this.<Date,PdfDate>getEntry(PdfName.ModDate);} 113 114 public String getProducer( 115 ) 116 {return this.<String ,PdfLiteral>getEntry(PdfName.Producer);} 117 118 public String getSubject( 119 ) 120 {return this.<String ,PdfLiteral>getEntry(PdfName.Subject);} 121 122 public String getTitle( 123 ) 124 {return this.<String ,PdfLiteral>getEntry(PdfName.Title);} 125 126 public void setAuthor( 127 String value 128 ) 129 {this.<String ,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 value 138 ) 139 {this.<String ,PdfLiteral>setEntry(PdfName.Creator,value,PdfLiteral.class);} 140 141 public void setKeywords( 142 String value 143 ) 144 {this.<String ,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 value 153 ) 154 {this.<String ,PdfLiteral>setEntry(PdfName.Producer,value,PdfLiteral.class);} 155 156 public void setSubject( 157 String value 158 ) 159 {this.<String ,PdfLiteral>setEntry(PdfName.Subject,value,PdfLiteral.class);} 160 161 public void setTitle( 162 String value 163 ) 164 {this.<String ,PdfLiteral>setEntry(PdfName.Title,value,PdfLiteral.class);} 165 167 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 <TPdf> entryType ) 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 e) 196 { 197 throw new RuntimeException (e); 199 } 200 } 201 202 entry.setValue(value); 203 } 204 216 } | Popular Tags |