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.7 2003/02/05 19:33:27 klute Exp $ 76 * @since 2002-02-09 77 */ 78 public class PropertyIDMap extends HashMap 79 { 80 81 /* 82 * The following definitions are for property IDs in the first 83 * (and only) section of the Summary Information property set. 84 */ 85 public final static int PID_TITLE = 2; 86 public final static int PID_SUBJECT = 3; 87 public final static int PID_AUTHOR = 4; 88 public final static int PID_KEYWORDS = 5; 89 public final static int PID_COMMENTS = 6; 90 public final static int PID_TEMPLATE = 7; 91 public final static int PID_LASTAUTHOR = 8; 92 public final static int PID_REVNUMBER = 9; 93 public final static int PID_EDITTIME = 10; 94 public final static int PID_LASTPRINTED = 11; 95 public final static int PID_CREATE_DTM = 12; 96 public final static int PID_LASTSAVE_DTM = 13; 97 public final static int PID_PAGECOUNT = 14; 98 public final static int PID_WORDCOUNT = 15; 99 public final static int PID_CHARCOUNT = 16; 100 public final static int PID_THUMBNAIL = 17; 101 public final static int PID_APPNAME = 18; 102 public final static int PID_SECURITY = 19; 103 104 105 106 /* 107 * The following definitions are for property IDs in the first 108 * section of the Document Summary Information property set. 109 */ 110 111 /** 112 * <p>The entry is a dictionary.</p> 113 */ 114 public final static int PID_DICTIONARY = 0; 115 116 /** 117 * <p>The entry denotes a code page.</p> 118 */ 119 public final static int PID_CODEPAGE = 1; 120 121 /** 122 * <p>The entry is a string denoting the category the file belongs 123 * to, e.g. review, memo, etc. This is useful to find documents of 124 * same type.</p> 125 */ 126 public final static int PID_CATEGORY = 2; 127 128 /** 129 * <p>Target format for power point presentation, e.g. 35mm, 130 * printer, video etc.</p> 131 */ 132 public final static int PID_PRESFORMAT = 3; 133 134 /** 135 * <p>Number of bytes.</p> 136 */ 137 public final static int PID_BYTECOUNT = 4; 138 139 /** 140 * <p>Number of lines.</p> 141 */ 142 public final static int PID_LINECOUNT = 5; 143 144 /** 145 * <p>Number of paragraphs.</p> 146 */ 147 public final static int PID_PARCOUNT = 6; 148 149 /** 150 * <p>Number of slides in a power point presentation.</p> 151 */ 152 public final static int PID_SLIDECOUNT = 7; 153 154 /** 155 * <p>Number of slides with notes.</p> 156 */ 157 public final static int PID_NOTECOUNT = 8; 158 159 /** 160 * <p>Number of hidden slides.</p> 161 */ 162 public final static int PID_HIDDENCOUNT = 9; 163 164 /** 165 * <p>Number of multimedia clips, e.g. sound or video.</p> 166 */ 167 public final static int PID_MMCLIPCOUNT = 10; 168 169 /** 170 * <p>This entry is set to -1 when scaling of the thumbnail is 171 * desired. Otherwise the thumbnail should be cropped.</p> 172 */ 173 public final static int PID_SCALE = 11; 174 175 /** 176 * <p>This entry denotes an internally used property. It is a 177 * vector of variants consisting of pairs of a string (VT_LPSTR) 178 * and a number (VT_I4). The string is a heading name, and the 179 * number tells how many document parts are under that 180 * heading.</p> 181 */ 182 public final static int PID_HEADINGPAIR = 12; 183 184 /** 185 * <p>This entry contains the names of document parts (word: names 186 * of the documents in the master document, excel: sheet names, 187 * power point: slide titles, binder: document names).</p> 188 */ 189 public final static int PID_DOCPARTS = 13; 190 191 /** 192 * <p>This entry contains the name of the project manager.</p> 193 */ 194 public final static int PID_MANAGER = 14; 195 196 /** 197 * <p>This entry contains the company name.</p> 198 */ 199 public final static int PID_COMPANY = 15; 200 201 /** 202 * <p>If this entry is -1 the links are dirty and should be 203 * re-evaluated.</p> 204 */ 205 public final static int PID_LINKSDIRTY = 16; 206 207 208 209 /** 210 * <p>Contains the summary information property ID values and 211 * associated strings. See the overall HPSF documentation for 212 * details!</p> 213 */ 214 private static PropertyIDMap summaryInformationProperties; 215 216 /** 217 * <p>Contains the summary information property ID values and 218 * associated strings. See the overall HPSF documentation for 219 * details!</p> 220 */ 221 private static PropertyIDMap documentSummaryInformationProperties; 222 223 224 225 /** 226 * <p>Creates a {@link PropertyIDMap}.</p> 227 */ 228 public PropertyIDMap(int initialCapacity, float loadFactor) 229 { 230 super(initialCapacity, loadFactor); 231 } 232 233 234 235 /** 236 * <p>Puts a ID string for an ID into the {@link 237 * PropertyIDMap}.</p> 238 * 239 * @param id The ID. 240 * @param idString The ID string. 241 * @return As specified by the {@link Map} interface, this method 242 * returns the previous value associated with the specified 243 * <var>id</var>, or <code>null</code> if there was no mapping for 244 * key. 245 */ 246 public Object put(int id, String idString) 247 { 248 return put(new Integer(id), idString); 249 } 250 251 252 253 /** 254 * <p>Gets the ID string for an ID from the {@link 255 * PropertyIDMap}.</p> 256 * 257 * @param id The ID. 258 * @return The ID string associated with <var>id</var>. 259 */ 260 public Object get(int id) 261 { 262 return get(new Integer(id)); 263 } 264 265 266 267 /** 268 * <p>Returns the Summary Information properties singleton.</p> 269 */ 270 public static PropertyIDMap getSummaryInformationProperties() 271 { 272 if (summaryInformationProperties == null) 273 { 274 PropertyIDMap m = new PropertyIDMap(18, (float) 1.0); 275 m.put(PID_TITLE, "PID_TITLE"); 276 m.put(PID_SUBJECT, "PID_SUBJECT"); 277 m.put(PID_AUTHOR, "PID_AUTHOR"); 278 m.put(PID_KEYWORDS, "PID_KEYWORDS"); 279 m.put(PID_COMMENTS, "PID_COMMENTS"); 280 m.put(PID_TEMPLATE, "PID_TEMPLATE"); 281 m.put(PID_LASTAUTHOR, "PID_LASTAUTHOR"); 282 m.put(PID_REVNUMBER, "PID_REVNUMBER"); 283 m.put(PID_EDITTIME, "PID_EDITTIME"); 284 m.put(PID_LASTPRINTED, "PID_LASTPRINTED"); 285 m.put(PID_CREATE_DTM, "PID_CREATE_DTM"); 286 m.put(PID_LASTSAVE_DTM, "PID_LASTSAVE_DTM"); 287 m.put(PID_PAGECOUNT, "PID_PAGECOUNT"); 288 m.put(PID_WORDCOUNT, "PID_WORDCOUNT"); 289 m.put(PID_CHARCOUNT, "PID_CHARCOUNT"); 290 m.put(PID_THUMBNAIL, "PID_THUMBNAIL"); 291 m.put(PID_APPNAME, "PID_APPNAME"); 292 m.put(PID_SECURITY, "PID_SECURITY"); 293 summaryInformationProperties = m; 294 } 295 return summaryInformationProperties; 296 } 297 298 299 300 /** 301 * <p>Returns the Document Summary Information properties 302 * singleton.</p> 303 * 304 * @return The Document Summary Information properties singleton. 305 */ 306 public static PropertyIDMap getDocumentSummaryInformationProperties() 307 { 308 if (documentSummaryInformationProperties == null) 309 { 310 PropertyIDMap m = new PropertyIDMap(17, (float) 1.0); 311 m.put(PID_DICTIONARY, "PID_DICTIONARY"); 312 m.put(PID_CODEPAGE, "PID_CODEPAGE"); 313 m.put(PID_CATEGORY, "PID_CATEGORY"); 314 m.put(PID_PRESFORMAT, "PID_PRESFORMAT"); 315 m.put(PID_BYTECOUNT, "PID_BYTECOUNT"); 316 m.put(PID_LINECOUNT, "PID_LINECOUNT"); 317 m.put(PID_PARCOUNT, "PID_PARCOUNT"); 318 m.put(PID_SLIDECOUNT, "PID_SLIDECOUNT"); 319 m.put(PID_NOTECOUNT, "PID_NOTECOUNT"); 320 m.put(PID_HIDDENCOUNT, "PID_HIDDENCOUNT"); 321 m.put(PID_MMCLIPCOUNT, "PID_MMCLIPCOUNT"); 322 m.put(PID_SCALE, "PID_SCALE"); 323 m.put(PID_HEADINGPAIR, "PID_HEADINGPAIR"); 324 m.put(PID_DOCPARTS, "PID_DOCPARTS"); 325 m.put(PID_MANAGER, "PID_MANAGER"); 326 m.put(PID_COMPANY, "PID_COMPANY"); 327 m.put(PID_LINKSDIRTY, "PID_LINKSDIRTY"); 328 documentSummaryInformationProperties = m; 329 } 330 return documentSummaryInformationProperties; 331 } 332 333 334 335 /** 336 * <p>For the most basic testing.</p> 337 */ 338 public static void main(String args[]) 339 { 340 PropertyIDMap s1 = getSummaryInformationProperties(); 341 PropertyIDMap s2 = getDocumentSummaryInformationProperties(); 342 System.out.println("s1: " + s1); 343 System.out.println("s2: " + s2); 344 } 345 346 } 347