001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hpsf;
019:
020: import java.util.Date;
021:
022: import org.apache.poi.hpsf.wellknown.PropertyIDMap;
023:
024: /**
025: * <p>Convenience class representing a Summary Information stream in a
026: * Microsoft Office document.</p>
027: *
028: * @author Rainer Klute <a
029: * href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
030: * @see DocumentSummaryInformation
031: * @version $Id: SummaryInformation.java 496419 2007-01-15 17:56:52Z klute $
032: * @since 2002-02-09
033: */
034: public class SummaryInformation extends SpecialPropertySet {
035:
036: /**
037: * <p>The document name a summary information stream usually has in a POIFS
038: * filesystem.</p>
039: */
040: public static final String DEFAULT_STREAM_NAME = "\005SummaryInformation";
041:
042: /**
043: * <p>Creates a {@link SummaryInformation} from a given {@link
044: * PropertySet}.</p>
045: *
046: * @param ps A property set which should be created from a summary
047: * information stream.
048: * @throws UnexpectedPropertySetTypeException if <var>ps</var> does not
049: * contain a summary information stream.
050: */
051: public SummaryInformation(final PropertySet ps)
052: throws UnexpectedPropertySetTypeException {
053: super (ps);
054: if (!isSummaryInformation())
055: throw new UnexpectedPropertySetTypeException("Not a "
056: + getClass().getName());
057: }
058:
059: /**
060: * <p>Returns the title (or <code>null</code>).</p>
061: *
062: * @return The title or <code>null</code>
063: */
064: public String getTitle() {
065: return (String) getProperty(PropertyIDMap.PID_TITLE);
066: }
067:
068: /**
069: * <p>Sets the title.</p>
070: *
071: * @param title The title to set.
072: */
073: public void setTitle(final String title) {
074: final MutableSection s = (MutableSection) getFirstSection();
075: s.setProperty(PropertyIDMap.PID_TITLE, title);
076: }
077:
078: /**
079: * <p>Removes the title.</p>
080: */
081: public void removeTitle() {
082: final MutableSection s = (MutableSection) getFirstSection();
083: s.removeProperty(PropertyIDMap.PID_TITLE);
084: }
085:
086: /**
087: * <p>Returns the subject (or <code>null</code>).</p>
088: *
089: * @return The subject or <code>null</code>
090: */
091: public String getSubject() {
092: return (String) getProperty(PropertyIDMap.PID_SUBJECT);
093: }
094:
095: /**
096: * <p>Sets the subject.</p>
097: *
098: * @param subject The subject to set.
099: */
100: public void setSubject(final String subject) {
101: final MutableSection s = (MutableSection) getFirstSection();
102: s.setProperty(PropertyIDMap.PID_SUBJECT, subject);
103: }
104:
105: /**
106: * <p>Removes the subject.</p>
107: */
108: public void removeSubject() {
109: final MutableSection s = (MutableSection) getFirstSection();
110: s.removeProperty(PropertyIDMap.PID_SUBJECT);
111: }
112:
113: /**
114: * <p>Returns the author (or <code>null</code>).</p>
115: *
116: * @return The author or <code>null</code>
117: */
118: public String getAuthor() {
119: return (String) getProperty(PropertyIDMap.PID_AUTHOR);
120: }
121:
122: /**
123: * <p>Sets the author.</p>
124: *
125: * @param author The author to set.
126: */
127: public void setAuthor(final String author) {
128: final MutableSection s = (MutableSection) getFirstSection();
129: s.setProperty(PropertyIDMap.PID_AUTHOR, author);
130: }
131:
132: /**
133: * <p>Removes the author.</p>
134: */
135: public void removeAuthor() {
136: final MutableSection s = (MutableSection) getFirstSection();
137: s.removeProperty(PropertyIDMap.PID_AUTHOR);
138: }
139:
140: /**
141: * <p>Returns the keywords (or <code>null</code>).</p>
142: *
143: * @return The keywords or <code>null</code>
144: */
145: public String getKeywords() {
146: return (String) getProperty(PropertyIDMap.PID_KEYWORDS);
147: }
148:
149: /**
150: * <p>Sets the keywords.</p>
151: *
152: * @param keywords The keywords to set.
153: */
154: public void setKeywords(final String keywords) {
155: final MutableSection s = (MutableSection) getFirstSection();
156: s.setProperty(PropertyIDMap.PID_KEYWORDS, keywords);
157: }
158:
159: /**
160: * <p>Removes the keywords.</p>
161: */
162: public void removeKeywords() {
163: final MutableSection s = (MutableSection) getFirstSection();
164: s.removeProperty(PropertyIDMap.PID_KEYWORDS);
165: }
166:
167: /**
168: * <p>Returns the comments (or <code>null</code>).</p>
169: *
170: * @return The comments or <code>null</code>
171: */
172: public String getComments() {
173: return (String) getProperty(PropertyIDMap.PID_COMMENTS);
174: }
175:
176: /**
177: * <p>Sets the comments.</p>
178: *
179: * @param comments The comments to set.
180: */
181: public void setComments(final String comments) {
182: final MutableSection s = (MutableSection) getFirstSection();
183: s.setProperty(PropertyIDMap.PID_COMMENTS, comments);
184: }
185:
186: /**
187: * <p>Removes the comments.</p>
188: */
189: public void removeComments() {
190: final MutableSection s = (MutableSection) getFirstSection();
191: s.removeProperty(PropertyIDMap.PID_COMMENTS);
192: }
193:
194: /**
195: * <p>Returns the template (or <code>null</code>).</p>
196: *
197: * @return The template or <code>null</code>
198: */
199: public String getTemplate() {
200: return (String) getProperty(PropertyIDMap.PID_TEMPLATE);
201: }
202:
203: /**
204: * <p>Sets the template.</p>
205: *
206: * @param template The template to set.
207: */
208: public void setTemplate(final String template) {
209: final MutableSection s = (MutableSection) getFirstSection();
210: s.setProperty(PropertyIDMap.PID_TEMPLATE, template);
211: }
212:
213: /**
214: * <p>Removes the template.</p>
215: */
216: public void removeTemplate() {
217: final MutableSection s = (MutableSection) getFirstSection();
218: s.removeProperty(PropertyIDMap.PID_TEMPLATE);
219: }
220:
221: /**
222: * <p>Returns the last author (or <code>null</code>).</p>
223: *
224: * @return The last author or <code>null</code>
225: */
226: public String getLastAuthor() {
227: return (String) getProperty(PropertyIDMap.PID_LASTAUTHOR);
228: }
229:
230: /**
231: * <p>Sets the last author.</p>
232: *
233: * @param lastAuthor The last author to set.
234: */
235: public void setLastAuthor(final String lastAuthor) {
236: final MutableSection s = (MutableSection) getFirstSection();
237: s.setProperty(PropertyIDMap.PID_LASTAUTHOR, lastAuthor);
238: }
239:
240: /**
241: * <p>Removes the last author.</p>
242: */
243: public void removeLastAuthor() {
244: final MutableSection s = (MutableSection) getFirstSection();
245: s.removeProperty(PropertyIDMap.PID_LASTAUTHOR);
246: }
247:
248: /**
249: * <p>Returns the revision number (or <code>null</code>). </p>
250: *
251: * @return The revision number or <code>null</code>
252: */
253: public String getRevNumber() {
254: return (String) getProperty(PropertyIDMap.PID_REVNUMBER);
255: }
256:
257: /**
258: * <p>Sets the revision number.</p>
259: *
260: * @param revNumber The revision number to set.
261: */
262: public void setRevNumber(final String revNumber) {
263: final MutableSection s = (MutableSection) getFirstSection();
264: s.setProperty(PropertyIDMap.PID_REVNUMBER, revNumber);
265: }
266:
267: /**
268: * <p>Removes the revision number.</p>
269: */
270: public void removeRevNumber() {
271: final MutableSection s = (MutableSection) getFirstSection();
272: s.removeProperty(PropertyIDMap.PID_REVNUMBER);
273: }
274:
275: /**
276: * <p>Returns the total time spent in editing the document (or
277: * <code>0</code>).</p>
278: *
279: * @return The total time spent in editing the document or 0 if the {@link
280: * SummaryInformation} does not contain this information.
281: */
282: public long getEditTime() {
283: final Date d = (Date) getProperty(PropertyIDMap.PID_EDITTIME);
284: if (d == null)
285: return 0;
286: else
287: return Util.dateToFileTime(d);
288: }
289:
290: /**
291: * <p>Sets the total time spent in editing the document.</p>
292: *
293: * @param time The time to set.
294: */
295: public void setEditTime(final long time) {
296: final Date d = Util.filetimeToDate(time);
297: final MutableSection s = (MutableSection) getFirstSection();
298: s.setProperty(PropertyIDMap.PID_EDITTIME, Variant.VT_FILETIME,
299: d);
300: }
301:
302: /**
303: * <p>Remove the total time spent in editing the document.</p>
304: */
305: public void removeEditTime() {
306: final MutableSection s = (MutableSection) getFirstSection();
307: s.removeProperty(PropertyIDMap.PID_EDITTIME);
308: }
309:
310: /**
311: * <p>Returns the last printed time (or <code>null</code>).</p>
312: *
313: * @return The last printed time or <code>null</code>
314: */
315: public Date getLastPrinted() {
316: return (Date) getProperty(PropertyIDMap.PID_LASTPRINTED);
317: }
318:
319: /**
320: * <p>Sets the lastPrinted.</p>
321: *
322: * @param lastPrinted The lastPrinted to set.
323: */
324: public void setLastPrinted(final Date lastPrinted) {
325: final MutableSection s = (MutableSection) getFirstSection();
326: s.setProperty(PropertyIDMap.PID_LASTPRINTED,
327: Variant.VT_FILETIME, lastPrinted);
328: }
329:
330: /**
331: * <p>Removes the lastPrinted.</p>
332: */
333: public void removeLastPrinted() {
334: final MutableSection s = (MutableSection) getFirstSection();
335: s.removeProperty(PropertyIDMap.PID_LASTPRINTED);
336: }
337:
338: /**
339: * <p>Returns the creation time (or <code>null</code>).</p>
340: *
341: * @return The creation time or <code>null</code>
342: */
343: public Date getCreateDateTime() {
344: return (Date) getProperty(PropertyIDMap.PID_CREATE_DTM);
345: }
346:
347: /**
348: * <p>Sets the creation time.</p>
349: *
350: * @param createDateTime The creation time to set.
351: */
352: public void setCreateDateTime(final Date createDateTime) {
353: final MutableSection s = (MutableSection) getFirstSection();
354: s.setProperty(PropertyIDMap.PID_CREATE_DTM,
355: Variant.VT_FILETIME, createDateTime);
356: }
357:
358: /**
359: * <p>Removes the creation time.</p>
360: */
361: public void removeCreateDateTime() {
362: final MutableSection s = (MutableSection) getFirstSection();
363: s.removeProperty(PropertyIDMap.PID_CREATE_DTM);
364: }
365:
366: /**
367: * <p>Returns the last save time (or <code>null</code>).</p>
368: *
369: * @return The last save time or <code>null</code>
370: */
371: public Date getLastSaveDateTime() {
372: return (Date) getProperty(PropertyIDMap.PID_LASTSAVE_DTM);
373: }
374:
375: /**
376: * <p>Sets the total time spent in editing the document.</p>
377: *
378: * @param time The time to set.
379: */
380: public void setLastSaveDateTime(final Date time) {
381: final MutableSection s = (MutableSection) getFirstSection();
382: s.setProperty(PropertyIDMap.PID_LASTSAVE_DTM,
383: Variant.VT_FILETIME, time);
384: }
385:
386: /**
387: * <p>Remove the total time spent in editing the document.</p>
388: */
389: public void removeLastSaveDateTime() {
390: final MutableSection s = (MutableSection) getFirstSection();
391: s.removeProperty(PropertyIDMap.PID_LASTSAVE_DTM);
392: }
393:
394: /**
395: * <p>Returns the page count or 0 if the {@link SummaryInformation} does
396: * not contain a page count.</p>
397: *
398: * @return The page count or 0 if the {@link SummaryInformation} does not
399: * contain a page count.
400: */
401: public int getPageCount() {
402: return getPropertyIntValue(PropertyIDMap.PID_PAGECOUNT);
403: }
404:
405: /**
406: * <p>Sets the page count.</p>
407: *
408: * @param pageCount The page count to set.
409: */
410: public void setPageCount(final int pageCount) {
411: final MutableSection s = (MutableSection) getFirstSection();
412: s.setProperty(PropertyIDMap.PID_PAGECOUNT, pageCount);
413: }
414:
415: /**
416: * <p>Removes the page count.</p>
417: */
418: public void removePageCount() {
419: final MutableSection s = (MutableSection) getFirstSection();
420: s.removeProperty(PropertyIDMap.PID_PAGECOUNT);
421: }
422:
423: /**
424: * <p>Returns the word count or 0 if the {@link SummaryInformation} does
425: * not contain a word count.</p>
426: *
427: * @return The word count or <code>null</code>
428: */
429: public int getWordCount() {
430: return getPropertyIntValue(PropertyIDMap.PID_WORDCOUNT);
431: }
432:
433: /**
434: * <p>Sets the word count.</p>
435: *
436: * @param wordCount The word count to set.
437: */
438: public void setWordCount(final int wordCount) {
439: final MutableSection s = (MutableSection) getFirstSection();
440: s.setProperty(PropertyIDMap.PID_WORDCOUNT, wordCount);
441: }
442:
443: /**
444: * <p>Removes the word count.</p>
445: */
446: public void removeWordCount() {
447: final MutableSection s = (MutableSection) getFirstSection();
448: s.removeProperty(PropertyIDMap.PID_WORDCOUNT);
449: }
450:
451: /**
452: * <p>Returns the character count or 0 if the {@link SummaryInformation}
453: * does not contain a char count.</p>
454: *
455: * @return The character count or <code>null</code>
456: */
457: public int getCharCount() {
458: return getPropertyIntValue(PropertyIDMap.PID_CHARCOUNT);
459: }
460:
461: /**
462: * <p>Sets the character count.</p>
463: *
464: * @param charCount The character count to set.
465: */
466: public void setCharCount(final int charCount) {
467: final MutableSection s = (MutableSection) getFirstSection();
468: s.setProperty(PropertyIDMap.PID_CHARCOUNT, charCount);
469: }
470:
471: /**
472: * <p>Removes the character count.</p>
473: */
474: public void removeCharCount() {
475: final MutableSection s = (MutableSection) getFirstSection();
476: s.removeProperty(PropertyIDMap.PID_CHARCOUNT);
477: }
478:
479: /**
480: * <p>Returns the thumbnail (or <code>null</code>) <strong>when this
481: * method is implemented. Please note that the return type is likely to
482: * change!</strong></p>
483: *
484: * <p><strong>Hint to developers:</strong> Drew Varner <Drew.Varner
485: * -at- sc.edu> said that this is an image in WMF or Clipboard (BMP?)
486: * format. However, we won't do any conversion into any image type but
487: * instead just return a byte array.</p>
488: *
489: * @return The thumbnail or <code>null</code>
490: */
491: public byte[] getThumbnail() {
492: return (byte[]) getProperty(PropertyIDMap.PID_THUMBNAIL);
493: }
494:
495: /**
496: * <p>Sets the thumbnail.</p>
497: *
498: * @param thumbnail The thumbnail to set.
499: */
500: public void setThumbnail(final byte[] thumbnail) {
501: final MutableSection s = (MutableSection) getFirstSection();
502: s.setProperty(PropertyIDMap.PID_THUMBNAIL, /* FIXME: */
503: Variant.VT_LPSTR, thumbnail);
504: }
505:
506: /**
507: * <p>Removes the thumbnail.</p>
508: */
509: public void removeThumbnail() {
510: final MutableSection s = (MutableSection) getFirstSection();
511: s.removeProperty(PropertyIDMap.PID_THUMBNAIL);
512: }
513:
514: /**
515: * <p>Returns the application name (or <code>null</code>).</p>
516: *
517: * @return The application name or <code>null</code>
518: */
519: public String getApplicationName() {
520: return (String) getProperty(PropertyIDMap.PID_APPNAME);
521: }
522:
523: /**
524: * <p>Sets the application name.</p>
525: *
526: * @param applicationName The application name to set.
527: */
528: public void setApplicationName(final String applicationName) {
529: final MutableSection s = (MutableSection) getFirstSection();
530: s.setProperty(PropertyIDMap.PID_APPNAME, applicationName);
531: }
532:
533: /**
534: * <p>Removes the application name.</p>
535: */
536: public void removeApplicationName() {
537: final MutableSection s = (MutableSection) getFirstSection();
538: s.removeProperty(PropertyIDMap.PID_APPNAME);
539: }
540:
541: /**
542: * <p>Returns a security code which is one of the following values:</p>
543: *
544: * <ul>
545: *
546: * <li><p>0 if the {@link SummaryInformation} does not contain a
547: * security field or if there is no security on the document. Use
548: * {@link PropertySet#wasNull()} to distinguish between the two
549: * cases!</p></li>
550: *
551: * <li><p>1 if the document is password protected</p></li>
552: *
553: * <li><p>2 if the document is read-only recommended</p></li>
554: *
555: * <li><p>4 if the document is read-only enforced</p></li>
556: *
557: * <li><p>8 if the document is locked for annotations</p></li>
558: *
559: * </ul>
560: *
561: * @return The security code or <code>null</code>
562: */
563: public int getSecurity() {
564: return getPropertyIntValue(PropertyIDMap.PID_SECURITY);
565: }
566:
567: /**
568: * <p>Sets the security code.</p>
569: *
570: * @param security The security code to set.
571: */
572: public void setSecurity(final int security) {
573: final MutableSection s = (MutableSection) getFirstSection();
574: s.setProperty(PropertyIDMap.PID_SECURITY, security);
575: }
576:
577: /**
578: * <p>Removes the security code.</p>
579: */
580: public void removeSecurity() {
581: final MutableSection s = (MutableSection) getFirstSection();
582: s.removeProperty(PropertyIDMap.PID_SECURITY);
583: }
584:
585: }
|