1    /*
2     *  ====================================================================
3     *  The Apache Software License, Version 1.1
4     *
5     *  Copyright (c) 2000 The Apache Software Foundation.  All rights
6     *  reserved.
7     *
8     *  Redistribution and use in source and binary forms, with or without
9     *  modification, are permitted provided that the following conditions
10    *  are met:
11    *
12    *  1. Redistributions of source code must retain the above copyright
13    *  notice, this list of conditions and the following disclaimer.
14    *
15    *  2. Redistributions in binary form must reproduce the above copyright
16    *  notice, this list of conditions and the following disclaimer in
17    *  the documentation and/or other materials provided with the
18    *  distribution.
19    *
20    *  3. The end-user documentation included with the redistribution,
21    *  if any, must include the following acknowledgment:
22    *  "This product includes software developed by the
23    *  Apache Software Foundation (http://www.apache.org/)."
24    *  Alternately, this acknowledgment may appear in the software itself,
25    *  if and wherever such third-party acknowledgments normally appear.
26    *
27    *  4. The names "Apache" and "Apache Software Foundation" must
28    *  not be used to endorse or promote products derived from this
29    *  software without prior written permission. For written
30    *  permission, please contact apache@apache.org.
31    *
32    *  5. Products derived from this software may not be called "Apache",
33    *  nor may "Apache" appear in their name, without prior written
34    *  permission of the Apache Software Foundation.
35    *
36    *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37    *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38    *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39    *  DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40    *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41    *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42    *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43    *  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44    *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45    *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46    *  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47    *  SUCH DAMAGE.
48    *  ====================================================================
49    *
50    *  This software consists of voluntary contributions made by many
51    *  individuals on behalf of the Apache Software Foundation.  For more
52    *  information on the Apache Software Foundation, please see
53    *  <http://www.apache.org/>.
54    */
55   package org.apache.poi.hpsf.wellknown;
56   
57   import java.util.*;
58   
59   /**
60    * <p>This is a dictionary which maps property ID values to property
61    * ID strings.</p>
62    *
63    * <p>The methods {@link #getSummaryInformationProperties} and {@link
64    * #getDocumentSummaryInformationProperties} return singleton {@link
65    * PropertyIDMap}s. An application that wants to extend these maps
66    * should treat them as unmodifiable, copy them and modifiy the
67    * copies.</p>
68    *
69    * <p><strong>FIXME:</strong> Make the singletons
70    * unmodifiable. However, since this requires to use a {@link HashMap}
71    * delegate instead of extending {@link HashMap} and thus requires a
72    * lot of stupid typing. I won't do that for the time being.</p>
73    *
74    * @author Rainer Klute (klute@rainer-klute.de)
75    * @version $Id: PropertyIDMap.java,v 1.5 2002/07/30 14:56:02 klute Exp $
76    * @since 2002-02-09
77    */
78   public class PropertyIDMap extends HashMap
79   {
80   
81       /*
82        * The following definitions are for the Summary Information.
83        */
84       public final static int PID_TITLE = 2;
85       public final static int PID_SUBJECT = 3;
86       public final static int PID_AUTHOR = 4;
87       public final static int PID_KEYWORDS = 5;
88       public final static int PID_COMMENTS = 6;
89       public final static int PID_TEMPLATE = 7;
90       public final static int PID_LASTAUTHOR = 8;
91       public final static int PID_REVNUMBER = 9;
92       public final static int PID_EDITTIME = 10;
93       public final static int PID_LASTPRINTED = 11;
94       public final static int PID_CREATE_DTM = 12;
95       public final static int PID_LASTSAVE_DTM = 13;
96       public final static int PID_PAGECOUNT = 14;
97       public final static int PID_WORDCOUNT = 15;
98       public final static int PID_CHARCOUNT = 16;
99       public final static int PID_THUMBNAIL = 17;
100      public final static int PID_APPNAME = 18;
101      public final static int PID_SECURITY = 19;
102  
103      /*
104       * The following definitions are for the Document Summary Information.
105       */
106      public final static int PID_CATEGORY = 2;
107      public final static int PID_PRESFORMAT = 3;
108      public final static int PID_BYTECOUNT = 4;
109      public final static int PID_LINECOUNT = 5;
110      public final static int PID_PARCOUNT = 6;
111      public final static int PID_SLIDECOUNT = 7;
112      public final static int PID_NOTECOUNT = 8;
113      public final static int PID_HIDDENCOUNT = 9;
114      public final static int PID_MMCLIPCOUNT = 10;
115      public final static int PID_SCALE = 11;
116      public final static int PID_HEADINGPAIR = 12;
117      public final static int PID_DOCPARTS = 13;
118      public final static int PID_MANAGER = 14;
119      public final static int PID_COMPANY = 15;
120      public final static int PID_LINKSDIRTY = 16;
121  
122      /**
123       * <p>Contains the summary information property ID values and
124       * associated strings. See the overall HPSF documentation for
125       * details!</p>
126       */
127      private static PropertyIDMap summaryInformationProperties;
128  
129      /**
130       * <p>Contains the summary information property ID values and
131       * associated strings. See the overall HPSF documentation for
132       * details!</p>
133       */
134      private static PropertyIDMap documentSummaryInformationProperties;
135  
136  
137  
138      /**
139       * <p>Creates a {@link PropertyIDMap}.</p>
140       */
141      public PropertyIDMap(int initialCapacity, float loadFactor)
142      {
143          super(initialCapacity, loadFactor);
144      }
145  
146  
147  
148      /**
149       * <p>Puts a ID string for an ID into the {@link
150       * PropertyIDMap}.</p>
151       *
152       * @param id The ID.
153       * @param idString The ID string.
154       * @return As specified by the {@link Map} interface, this method
155       * returns the previous value associated with the specified
156       * <var>id</var>, or <code>null</code> if there was no mapping for
157       * key.
158       */
159      public Object put(int id, String idString)
160      {
161          return put(new Integer(id), idString);
162      }
163  
164  
165  
166      /**
167       * <p>Gets the ID string for an ID from the {@link
168       * PropertyIDMap}.</p>
169       *
170       * @param id The ID.
171       * @return The ID string associated with <var>id</var>.
172       */
173      public Object get(int id)
174      {
175          return get(new Integer(id));
176      }
177  
178  
179  
180      /**
181       * <p>Returns the Summary Information properties singleton.</p>
182       */
183      public static PropertyIDMap getSummaryInformationProperties()
184      {
185          if (summaryInformationProperties == null)
186  	{
187              PropertyIDMap m = new PropertyIDMap(17, (float) 1.0);
188              m.put(PID_TITLE, "PID_TITLE");
189              m.put(PID_SUBJECT, "PID_SUBJECT");
190              m.put(PID_AUTHOR, "PID_AUTHOR");
191              m.put(PID_KEYWORDS, "PID_KEYWORDS");
192              m.put(PID_COMMENTS, "PID_COMMENTS");
193              m.put(PID_TEMPLATE, "PID_TEMPLATE");
194              m.put(PID_LASTAUTHOR, "PID_LASTAUTHOR");
195              m.put(PID_REVNUMBER, "PID_REVNUMBER");
196              m.put(PID_EDITTIME, "PID_EDITTIME");
197              m.put(PID_LASTPRINTED, "PID_LASTPRINTED");
198              m.put(PID_CREATE_DTM, "PID_CREATE_DTM");
199              m.put(PID_LASTSAVE_DTM, "PID_LASTSAVE_DTM");
200              m.put(PID_PAGECOUNT, "PID_PAGECOUNT");
201              m.put(PID_WORDCOUNT, "PID_WORDCOUNT");
202              m.put(PID_CHARCOUNT, "PID_CHARCOUNT");
203              m.put(PID_THUMBNAIL, "PID_THUMBNAIL");
204              m.put(PID_APPNAME, "PID_APPNAME");
205              m.put(PID_SECURITY, "PID_SECURITY");
206              summaryInformationProperties = m;
207          }
208          return summaryInformationProperties;
209      }
210  
211  
212  
213      /**
214       * <p>Returns the Document Summary Information properties
215       * singleton.</p>
216       *
217       * @return The Document Summary Information properties singleton.
218       */
219      public static PropertyIDMap getDocumentSummaryInformationProperties()
220      {
221          if (documentSummaryInformationProperties == null)
222  	{
223              PropertyIDMap m = new PropertyIDMap(17, (float) 1.0);
224              m.put(PID_CATEGORY, "PID_CATEGORY");
225              m.put(PID_PRESFORMAT, "PID_PRESFORMAT");
226              m.put(PID_BYTECOUNT, "PID_BYTECOUNT");
227              m.put(PID_LINECOUNT, "PID_LINECOUNT");
228              m.put(PID_PARCOUNT, "PID_PARCOUNT");
229              m.put(PID_SLIDECOUNT, "PID_SLIDECOUNT");
230              m.put(PID_NOTECOUNT, "PID_NOTECOUNT");
231              m.put(PID_HIDDENCOUNT, "PID_HIDDENCOUNT");
232              m.put(PID_MMCLIPCOUNT, "PID_MMCLIPCOUNT");
233              m.put(PID_SCALE, "PID_SCALE");
234              m.put(PID_HEADINGPAIR, "PID_HEADINGPAIR");
235              m.put(PID_DOCPARTS, "PID_DOCPARTS");
236              m.put(PID_MANAGER, "PID_MANAGER");
237              m.put(PID_COMPANY, "PID_COMPANY");
238              m.put(PID_LINKSDIRTY, "PID_LINKSDIRTY");
239              documentSummaryInformationProperties = m;
240          }
241          return documentSummaryInformationProperties;
242      }
243  
244  
245  
246      /**
247       * <p>For the most basic testing.</p>
248       */
249      public static void main(String args[])
250      {
251          PropertyIDMap s1 = getSummaryInformationProperties();
252          PropertyIDMap s2 = getDocumentSummaryInformationProperties();
253          System.out.println("s1: " + s1);
254          System.out.println("s2: " + s2);
255      }
256  
257  }
258