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.wellknown;
019:
020: import java.util.Collections;
021: import java.util.HashMap;
022: import java.util.Map;
023:
024: /**
025: * <p>This is a dictionary which maps property ID values to property
026: * ID strings.</p>
027: *
028: * <p>The methods {@link #getSummaryInformationProperties} and {@link
029: * #getDocumentSummaryInformationProperties} return singleton {@link
030: * PropertyIDMap}s. An application that wants to extend these maps
031: * should treat them as unmodifiable, copy them and modifiy the
032: * copies.</p>
033: *
034: * @author Rainer Klute <a
035: * href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
036: * @version $Id: PropertyIDMap.java 489730 2006-12-22 19:18:16Z bayard $
037: * @since 2002-02-09
038: */
039: public class PropertyIDMap extends HashMap {
040:
041: /*
042: * The following definitions are for property IDs in the first
043: * (and only) section of the Summary Information property set.
044: */
045:
046: /** <p>ID of the property that denotes the document's title</p> */
047: public static final int PID_TITLE = 2;
048:
049: /** <p>ID of the property that denotes the document's subject</p> */
050: public static final int PID_SUBJECT = 3;
051:
052: /** <p>ID of the property that denotes the document's author</p> */
053: public static final int PID_AUTHOR = 4;
054:
055: /** <p>ID of the property that denotes the document's keywords</p> */
056: public static final int PID_KEYWORDS = 5;
057:
058: /** <p>ID of the property that denotes the document's comments</p> */
059: public static final int PID_COMMENTS = 6;
060:
061: /** <p>ID of the property that denotes the document's template</p> */
062: public static final int PID_TEMPLATE = 7;
063:
064: /** <p>ID of the property that denotes the document's last author</p> */
065: public static final int PID_LASTAUTHOR = 8;
066:
067: /** <p>ID of the property that denotes the document's revision number</p> */
068: public static final int PID_REVNUMBER = 9;
069:
070: /** <p>ID of the property that denotes the document's edit time</p> */
071: public static final int PID_EDITTIME = 10;
072:
073: /** <p>ID of the property that denotes the date and time the document was
074: * last printed</p> */
075: public static final int PID_LASTPRINTED = 11;
076:
077: /** <p>ID of the property that denotes the date and time the document was
078: * created.</p> */
079: public static final int PID_CREATE_DTM = 12;
080:
081: /** <p>ID of the property that denotes the date and time the document was
082: * saved</p> */
083: public static final int PID_LASTSAVE_DTM = 13;
084:
085: /** <p>ID of the property that denotes the number of pages in the
086: * document</p> */
087: public static final int PID_PAGECOUNT = 14;
088:
089: /** <p>ID of the property that denotes the number of words in the
090: * document</p> */
091: public static final int PID_WORDCOUNT = 15;
092:
093: /** <p>ID of the property that denotes the number of characters in the
094: * document</p> */
095: public static final int PID_CHARCOUNT = 16;
096:
097: /** <p>ID of the property that denotes the document's thumbnail</p> */
098: public static final int PID_THUMBNAIL = 17;
099:
100: /** <p>ID of the property that denotes the application that created the
101: * document</p> */
102: public static final int PID_APPNAME = 18;
103:
104: /** <p>ID of the property that denotes whether read/write access to the
105: * document is allowed or whether is should be opened as read-only. It can
106: * have the following values:</p>
107: *
108: * <table>
109: * <tbody>
110: * <tr>
111: * <th><p>Value</p></th>
112: * <th><p>Description</p></th>
113: * </tr>
114: * <tr>
115: * <th><p>0</p></th>
116: * <th><p>No restriction</p></th>
117: * </tr>
118: * <tr>
119: * <th><p>2</p></th>
120: * <th><p>Read-only recommended</p></th>
121: * </tr>
122: * <tr>
123: * <th><p>4</p></th>
124: * <th><p>Read-only enforced</p></th>
125: * </tr>
126: * </tbody>
127: * </table>
128: */
129: public static final int PID_SECURITY = 19;
130:
131: /*
132: * The following definitions are for property IDs in the first
133: * section of the Document Summary Information property set.
134: */
135:
136: /**
137: * <p>The entry is a dictionary.</p>
138: */
139: public static final int PID_DICTIONARY = 0;
140:
141: /**
142: * <p>The entry denotes a code page.</p>
143: */
144: public static final int PID_CODEPAGE = 1;
145:
146: /**
147: * <p>The entry is a string denoting the category the file belongs
148: * to, e.g. review, memo, etc. This is useful to find documents of
149: * same type.</p>
150: */
151: public static final int PID_CATEGORY = 2;
152:
153: /**
154: * <p>Target format for power point presentation, e.g. 35mm,
155: * printer, video etc.</p>
156: */
157: public static final int PID_PRESFORMAT = 3;
158:
159: /**
160: * <p>Number of bytes.</p>
161: */
162: public static final int PID_BYTECOUNT = 4;
163:
164: /**
165: * <p>Number of lines.</p>
166: */
167: public static final int PID_LINECOUNT = 5;
168:
169: /**
170: * <p>Number of paragraphs.</p>
171: */
172: public static final int PID_PARCOUNT = 6;
173:
174: /**
175: * <p>Number of slides in a power point presentation.</p>
176: */
177: public static final int PID_SLIDECOUNT = 7;
178:
179: /**
180: * <p>Number of slides with notes.</p>
181: */
182: public static final int PID_NOTECOUNT = 8;
183:
184: /**
185: * <p>Number of hidden slides.</p>
186: */
187: public static final int PID_HIDDENCOUNT = 9;
188:
189: /**
190: * <p>Number of multimedia clips, e.g. sound or video.</p>
191: */
192: public static final int PID_MMCLIPCOUNT = 10;
193:
194: /**
195: * <p>This entry is set to -1 when scaling of the thumbnail is
196: * desired. Otherwise the thumbnail should be cropped.</p>
197: */
198: public static final int PID_SCALE = 11;
199:
200: /**
201: * <p>This entry denotes an internally used property. It is a
202: * vector of variants consisting of pairs of a string (VT_LPSTR)
203: * and a number (VT_I4). The string is a heading name, and the
204: * number tells how many document parts are under that
205: * heading.</p>
206: */
207: public static final int PID_HEADINGPAIR = 12;
208:
209: /**
210: * <p>This entry contains the names of document parts (word: names
211: * of the documents in the master document, excel: sheet names,
212: * power point: slide titles, binder: document names).</p>
213: */
214: public static final int PID_DOCPARTS = 13;
215:
216: /**
217: * <p>This entry contains the name of the project manager.</p>
218: */
219: public static final int PID_MANAGER = 14;
220:
221: /**
222: * <p>This entry contains the company name.</p>
223: */
224: public static final int PID_COMPANY = 15;
225:
226: /**
227: * <p>If this entry is -1 the links are dirty and should be
228: * re-evaluated.</p>
229: */
230: public static final int PID_LINKSDIRTY = 16;
231:
232: /**
233: * <p>The highest well-known property ID. Applications are free to use higher values for custom purposes.</p>
234: */
235: public static final int PID_MAX = PID_LINKSDIRTY;
236:
237: /**
238: * <p>Contains the summary information property ID values and
239: * associated strings. See the overall HPSF documentation for
240: * details!</p>
241: */
242: private static PropertyIDMap summaryInformationProperties;
243:
244: /**
245: * <p>Contains the summary information property ID values and
246: * associated strings. See the overall HPSF documentation for
247: * details!</p>
248: */
249: private static PropertyIDMap documentSummaryInformationProperties;
250:
251: /**
252: * <p>Creates a {@link PropertyIDMap}.</p>
253: *
254: * @param initialCapacity The initial capacity as defined for
255: * {@link HashMap}
256: * @param loadFactor The load factor as defined for {@link HashMap}
257: */
258: public PropertyIDMap(final int initialCapacity,
259: final float loadFactor) {
260: super (initialCapacity, loadFactor);
261: }
262:
263: /**
264: * <p>Creates a {@link PropertyIDMap} backed by another map.</p>
265: *
266: * @param map The instance to be created is backed by this map.
267: */
268: public PropertyIDMap(final Map map) {
269: super (map);
270: }
271:
272: /**
273: * <p>Puts a ID string for an ID into the {@link
274: * PropertyIDMap}.</p>
275: *
276: * @param id The ID.
277: * @param idString The ID string.
278: * @return As specified by the {@link java.util.Map} interface, this method
279: * returns the previous value associated with the specified
280: * <var>id</var>, or <code>null</code> if there was no mapping for
281: * key.
282: */
283: public Object put(final long id, final String idString) {
284: return put(new Long(id), idString);
285: }
286:
287: /**
288: * <p>Gets the ID string for an ID from the {@link
289: * PropertyIDMap}.</p>
290: *
291: * @param id The ID.
292: * @return The ID string associated with <var>id</var>.
293: */
294: public Object get(final long id) {
295: return get(new Long(id));
296: }
297:
298: /**
299: * @return the Summary Information properties singleton
300: */
301: public static PropertyIDMap getSummaryInformationProperties() {
302: if (summaryInformationProperties == null) {
303: PropertyIDMap m = new PropertyIDMap(18, (float) 1.0);
304: m.put(PID_TITLE, "PID_TITLE");
305: m.put(PID_SUBJECT, "PID_SUBJECT");
306: m.put(PID_AUTHOR, "PID_AUTHOR");
307: m.put(PID_KEYWORDS, "PID_KEYWORDS");
308: m.put(PID_COMMENTS, "PID_COMMENTS");
309: m.put(PID_TEMPLATE, "PID_TEMPLATE");
310: m.put(PID_LASTAUTHOR, "PID_LASTAUTHOR");
311: m.put(PID_REVNUMBER, "PID_REVNUMBER");
312: m.put(PID_EDITTIME, "PID_EDITTIME");
313: m.put(PID_LASTPRINTED, "PID_LASTPRINTED");
314: m.put(PID_CREATE_DTM, "PID_CREATE_DTM");
315: m.put(PID_LASTSAVE_DTM, "PID_LASTSAVE_DTM");
316: m.put(PID_PAGECOUNT, "PID_PAGECOUNT");
317: m.put(PID_WORDCOUNT, "PID_WORDCOUNT");
318: m.put(PID_CHARCOUNT, "PID_CHARCOUNT");
319: m.put(PID_THUMBNAIL, "PID_THUMBNAIL");
320: m.put(PID_APPNAME, "PID_APPNAME");
321: m.put(PID_SECURITY, "PID_SECURITY");
322: summaryInformationProperties = new PropertyIDMap(
323: Collections.unmodifiableMap(m));
324: }
325: return summaryInformationProperties;
326: }
327:
328: /**
329: * <p>Returns the Document Summary Information properties
330: * singleton.</p>
331: *
332: * @return The Document Summary Information properties singleton.
333: */
334: public static PropertyIDMap getDocumentSummaryInformationProperties() {
335: if (documentSummaryInformationProperties == null) {
336: PropertyIDMap m = new PropertyIDMap(17, (float) 1.0);
337: m.put(PID_DICTIONARY, "PID_DICTIONARY");
338: m.put(PID_CODEPAGE, "PID_CODEPAGE");
339: m.put(PID_CATEGORY, "PID_CATEGORY");
340: m.put(PID_PRESFORMAT, "PID_PRESFORMAT");
341: m.put(PID_BYTECOUNT, "PID_BYTECOUNT");
342: m.put(PID_LINECOUNT, "PID_LINECOUNT");
343: m.put(PID_PARCOUNT, "PID_PARCOUNT");
344: m.put(PID_SLIDECOUNT, "PID_SLIDECOUNT");
345: m.put(PID_NOTECOUNT, "PID_NOTECOUNT");
346: m.put(PID_HIDDENCOUNT, "PID_HIDDENCOUNT");
347: m.put(PID_MMCLIPCOUNT, "PID_MMCLIPCOUNT");
348: m.put(PID_SCALE, "PID_SCALE");
349: m.put(PID_HEADINGPAIR, "PID_HEADINGPAIR");
350: m.put(PID_DOCPARTS, "PID_DOCPARTS");
351: m.put(PID_MANAGER, "PID_MANAGER");
352: m.put(PID_COMPANY, "PID_COMPANY");
353: m.put(PID_LINKSDIRTY, "PID_LINKSDIRTY");
354: documentSummaryInformationProperties = new PropertyIDMap(
355: Collections.unmodifiableMap(m));
356: }
357: return documentSummaryInformationProperties;
358: }
359:
360: /**
361: * <p>For the most basic testing.</p>
362: *
363: * @param args The command-line arguments
364: */
365: public static void main(final String[] args) {
366: PropertyIDMap s1 = getSummaryInformationProperties();
367: PropertyIDMap s2 = getDocumentSummaryInformationProperties();
368: System.out.println("s1: " + s1);
369: System.out.println("s2: " + s2);
370: }
371:
372: }
|