1    /* ====================================================================
2     * The Apache Software License, Version 1.1
3     *
4     * Copyright (c) 2000 The Apache Software Foundation.  All rights
5     * reserved.
6     *
7     * Redistribution and use in source and binary forms, with or without
8     * modification, are permitted provided that the following conditions
9     * are met:
10    *
11    * 1. Redistributions of source code must retain the above copyright
12    *    notice, this list of conditions and the following disclaimer.
13    *
14    * 2. Redistributions in binary form must reproduce the above copyright
15    *    notice, this list of conditions and the following disclaimer in
16    *    the documentation and/or other materials provided with the
17    *    distribution.
18    *
19    * 3. The end-user documentation included with the redistribution,
20    *    if any, must include the following acknowledgment:
21    *       "This product includes software developed by the
22    *        Apache Software Foundation (http://www.apache.org/)."
23    *    Alternately, this acknowledgment may appear in the software itself,
24    *    if and wherever such third-party acknowledgments normally appear.
25    *
26    * 4. The names "Apache" and "Apache Software Foundation" must
27    *    not be used to endorse or promote products derived from this
28    *    software without prior written permission. For written
29    *    permission, please contact apache@apache.org.
30    *
31    * 5. Products derived from this software may not be called "Apache",
32    *    nor may "Apache" appear in their name, without prior written
33    *    permission of the Apache Software Foundation.
34    *
35    * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36    * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37    * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38    * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39    * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40    * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41    * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42    * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43    * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44    * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45    * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46    * SUCH DAMAGE.
47    * ====================================================================
48    *
49    * This software consists of voluntary contributions made by many
50    * individuals on behalf of the Apache Software Foundation.  For more
51    * information on the Apache Software Foundation, please see
52    * <http://www.apache.org/>.
53    *
54    * Portions of this software are based upon public domain software
55    * originally written at the National Center for Supercomputing Applications,
56    * University of Illinois, Urbana-Champaign.
57    */
58   
59   package org.apache.poi.hpsf;
60   
61   import java.io.*;
62   import java.util.*;
63   import org.apache.poi.hpsf.wellknown.*;
64   
65   /**
66    * <p>Convenience class representing a Summary Information stream in a
67    * Microsoft Office document.</p>
68    *
69    * <p>See <a
70    * href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/stgu_8910.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/stgu_8910.asp</a>
71    * for documentation from That Redmond Company.
72    *
73    * @see DocumentSummaryInformation
74    *
75    * @author Rainer Klute (klute@rainer-klute.de)
76    * @version $Id: SummaryInformation.java,v 1.6 2002/05/01 09:31:52 klute Exp $
77    * @since 2002-02-09
78    */
79   public class SummaryInformation extends SpecialPropertySet
80   {
81   
82       /**
83        * <p>Creates a {@link SummaryInformation} from a given {@link
84        * PropertySet}.</p>
85        *
86        * @param ps A property set which should be created from a summary
87        * information stream.
88        *
89        * @throws UnexpectedPropertySetTypeException if <var>ps</var>
90        * does not contain a summary information stream.
91        */
92       public SummaryInformation(final PropertySet ps)
93           throws UnexpectedPropertySetTypeException
94       {
95           super(ps);
96           if (!isSummaryInformation())
97               throw new UnexpectedPropertySetTypeException
98                   ("Not a " + getClass().getName());
99       }
100  
101  
102  
103      /**
104       * <p>Returns the stream's title (or <code>null</code>).</p>
105       */
106      public String getTitle()
107      {
108          return (String) getProperty(PropertyIDMap.PID_TITLE);
109      }
110  
111  
112  
113      /**
114       * <p>Returns the stream's subject (or <code>null</code>).</p>
115       */
116      public String getSubject()
117      {
118          return (String) getProperty(PropertyIDMap.PID_SUBJECT);
119      }
120  
121  
122  
123      /**
124       * <p>Returns the stream's author (or <code>null</code>).</p>
125       */
126      public String getAuthor()
127      {
128          return (String) getProperty(PropertyIDMap.PID_AUTHOR);
129      }
130  
131  
132  
133      /**
134       * <p>Returns the stream's keywords (or <code>null</code>).</p>
135       */
136      public String getKeywords()
137      {
138          return (String) getProperty(PropertyIDMap.PID_KEYWORDS);
139      }
140  
141  
142  
143      /**
144       * <p>Returns the stream's comments (or <code>null</code>).</p>
145       */
146      public String getComments()
147      {
148          return (String) getProperty(PropertyIDMap.PID_COMMENTS);
149      }
150  
151  
152  
153      /**
154       * <p>Returns the stream's template (or <code>null</code>).</p>
155       */
156      public String getTemplate()
157      {
158          return (String) getProperty(PropertyIDMap.PID_TEMPLATE);
159      }
160  
161  
162  
163      /**
164       * <p>Returns the stream's last author (or <code>null</code>).</p>
165       */
166      public String getLastAuthor()
167      {
168          return (String) getProperty(PropertyIDMap.PID_LASTAUTHOR);
169      }
170  
171  
172  
173      /**
174       * <p>Returns the stream's revision number (or
175       * <code>null</code>).
176       </p> */
177      public String getRevNumber()
178      {
179          return (String) getProperty(PropertyIDMap.PID_REVNUMBER);
180      }
181  
182  
183  
184      /**
185       * <p>Returns the stream's edit time (or <code>null</code>).</p>
186       */
187      public Date getEditTime()
188      {
189          return (Date) getProperty(PropertyIDMap.PID_EDITTIME);
190      }
191  
192  
193  
194      /**
195       * <p>Returns the stream's last printed time (or
196       * <code>null</code>).</p>
197       */
198      public Date getLastPrinted()
199      {
200          return (Date) getProperty(PropertyIDMap.PID_LASTPRINTED);
201      }
202  
203  
204  
205      /**
206       * <p>Returns the stream's creation time (or
207       * <code>null</code>).</p>
208       */
209      public Date getCreateDateTime()
210      {
211          return (Date) getProperty(PropertyIDMap.PID_CREATE_DTM);
212      }
213  
214  
215  
216      /**
217       * <p>Returns the stream's last save time (or
218       * <code>null</code>).</p>
219       */
220      public Date getLastSaveDateTime()
221      {
222          return (Date) getProperty(PropertyIDMap.PID_LASTSAVE_DTM);
223      }
224  
225  
226  
227      /**
228       * <p>Returns the stream's page count or 0 if the {@link
229       * SummaryInformation} does not contain a page count.</p>
230       */
231      public int getPageCount()
232      {
233          return getPropertyIntValue(PropertyIDMap.PID_PAGECOUNT);
234      }
235  
236  
237  
238      /**
239       * <p>Returns the stream's word count or 0 if the {@link
240       * SummaryInformation} does not contain a word count.</p>
241       */
242      public int getWordCount()
243      {
244          return getPropertyIntValue(PropertyIDMap.PID_WORDCOUNT);
245      }
246  
247  
248  
249      /**
250       * <p>Returns the stream's char count or 0 if the {@link
251       * SummaryInformation} does not contain a char count.</p>
252       */
253      public int getCharCount()
254      {
255          return getPropertyIntValue(PropertyIDMap.PID_CHARCOUNT);
256      }
257  
258  
259  
260      /**
261       * <p>Returns the stream's thumbnail (or <code>null</code>)
262       * <strong>when this method is implemented. Please note that the
263       * return type is likely to change!</strong>
264       *
265       * <p><strong>FIXME / Hint to developers:</strong> Drew Varner
266       * <Drew.Varner -at- sc.edu> said that this is an image in WMF
267       * or Clipboard (BMP?) format. He also provided two links that
268       * might be helpful: <a
269       * href="http://www.csn.ul.ie/~caolan/publink/file/OLE2SummaryAgainst_file-3.27.patch"
270       * target="_blank">http://www.csn.ul.ie/~caolan/publink/file/OLE2SummaryAgainst_file-3.27.patch</a>
271       * and <a
272       * href="http://msdn.microsoft.com/library/en-us/dno97ta/html/msdn_docprop.asp"
273       * target="_blank">http://msdn.microsoft.com/library/en-us/dno97ta/html/msdn_docprop.asp</a>.
274       * However, we won't do any conversion into any image type but
275       * instead just return a byte array.</p>
276       */
277      public byte[] getThumbnail()
278      {
279          return (byte[]) getProperty(PropertyIDMap.PID_THUMBNAIL);
280      }
281  
282  
283  
284      /**
285       * <p>Returns the stream's application name (or
286       * <code>null</code>).</p>
287       */
288      public String getApplicationName()
289      {
290          return (String) getProperty(PropertyIDMap.PID_APPNAME);
291      }
292  
293  
294  
295      /**
296       * <p>Returns one of the following values:</p>
297       *
298       * <ul>
299       *
300       * <li><p>0 if the {@link SummaryInformation} does not contain a
301       * security field or if there is no security on the document. Use
302       * {@link #wasNull} to distinguish between the two cases!</p></li>
303       *
304       * <li><p>1 if the document is password protected</p></li>
305       *
306       * <li><p>2 if the document is read-only recommended</p></li>
307       *
308       * <li><p>4 if the document is read-only enforced</p></li>
309       *
310       * <li><p>8 if the document is locked for annotations</p></li>
311       *
312       * </ul>
313       */
314      public int getSecurity()
315      {
316          return getPropertyIntValue(PropertyIDMap.PID_SECURITY);
317      }
318  
319  }
320