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.wellknown; 60 61 import java.util.*; 62 63 /** 64 * <p>Maps section format IDs to {@link PropertyIDMap}s. It is 65 * initialized with two well-known section format IDs: those of the 66 * <tt>\005SummaryInformation</tt> stream and the 67 * <tt>\005DocumentSummaryInformation stream.</p> 68 * 69 * <p>If you have a section format ID you can use it as a key to query 70 * this map. If you get a {@link PropertyIDMap} returned your section 71 * is well-known and you can query the {@link PropertyIDMap} for PID 72 * strings. If you get back <code>null</code> you are on your own.</p> 73 * 74 * <p>This {@link Map} expects the byte arrays of section format IDs 75 * as keys. A key maps to a {@link PropertyIDMap} describing the 76 * property IDs in sections with the specified section format ID.</p> 77 * 78 * @author Rainer Klute (klute@rainer-klute.de) 79 * @version $Id: SectionIDMap.java,v 1.1 2002/02/14 04:00:59 mjohnson Exp $ 80 * @since 2002-02-09 81 */ 82 public class SectionIDMap extends HashMap 83 { 84 85 /** 86 * <p>The SummaryInformation's section's format ID.</p> 87 */ 88 public final static byte[] SUMMARY_INFORMATION_ID = 89 new byte[]{(byte) 0xF2, (byte) 0x9F, (byte) 0x85, (byte) 0xE0, 90 (byte) 0x4F, (byte) 0xF9, (byte) 0x10, (byte) 0x68, 91 (byte) 0xAB, (byte) 0x91, (byte) 0x08, (byte) 0x00, 92 (byte) 0x2B, (byte) 0x27, (byte) 0xB3, (byte) 0xD9}; 93 94 /** 95 * <p>The DocumentSummaryInformation's first section's format 96 * ID. The second section has a different format ID which is not 97 * well-known.</p> 98 */ 99 public final static byte[] DOCUMENT_SUMMARY_INFORMATION_ID = 100 new byte[]{(byte) 0xD5, (byte) 0xCD, (byte) 0xD5, (byte) 0x02, 101 (byte) 0x2E, (byte) 0x9C, (byte) 0x10, (byte) 0x1B, 102 (byte) 0x93, (byte) 0x97, (byte) 0x08, (byte) 0x00, 103 (byte) 0x2B, (byte) 0x2C, (byte) 0xF9, (byte) 0xAE}; 104 105 public final static String UNDEFINED = "[undefined]"; 106 107 108 109 private static SectionIDMap defaultMap; 110 111 112 113 /** 114 * <p>Returns the singleton instance of the default {@link 115 * SectionIDMap}.</p> 116 */ 117 public static SectionIDMap getInstance() 118 { 119 if (defaultMap == null) 120 { 121 final SectionIDMap m = new SectionIDMap(); 122 m.put(SUMMARY_INFORMATION_ID, 123 PropertyIDMap.getSummaryInformationProperties()); 124 m.put(DOCUMENT_SUMMARY_INFORMATION_ID, 125 PropertyIDMap.getDocumentSummaryInformationProperties()); 126 defaultMap = m; 127 } 128 return defaultMap; 129 } 130 131 132 133 /** 134 * <p>Returns the property ID string that is associated with a 135 * given property ID in a section format ID's namespace.</p> 136 * 137 * @param sectionFormatID Each section format ID has its own name 138 * space of property ID strings and thus must be specified. 139 * 140 * @param pid The property ID 141 * 142 * @return The well-known property ID string associated with the 143 * property ID <var>pid</var> in the name space spanned by 144 * <var>sectionFormatID</var>. If the 145 * <var>pid</var>/<var>sectionFormatID</var> combination is not 146 * well-known, the string "[undefined]" is returned. 147 */ 148 public static String getPIDString(final byte[] sectionFormatID, 149 final int pid) 150 { 151 final PropertyIDMap m = 152 (PropertyIDMap) getInstance().get(sectionFormatID); 153 if (m == null) 154 return UNDEFINED; 155 else 156 { 157 final String s = (String) m.get(pid); 158 if (s == null) 159 return UNDEFINED; 160 return s; 161 } 162 } 163 164 165 166 /** 167 * <p>Returns the {@link PropertyIDMap} for a given section format 168 * ID.</p> 169 */ 170 public PropertyIDMap get(final byte[] sectionFormatID) 171 { 172 return (PropertyIDMap) super.get(new String(sectionFormatID)); 173 } 174 175 176 177 /** 178 * <p>Returns the {@link PropertyIDMap} for a given section format 179 * ID.</p> 180 * 181 * @param sectionFormatID A section format ID as a 182 * <tt>byte[]</tt>. 183 * 184 * @deprecated Use {@link #get(byte[])} instead! 185 */ 186 public Object get(final Object sectionFormatID) 187 { 188 return get((byte[]) sectionFormatID); 189 } 190 191 192 193 /** 194 * <p>Associates a section format ID with a {@link 195 * PropertyIDMap}.</p> 196 */ 197 public Object put(final byte[] sectionFormatID, 198 final PropertyIDMap propertyIDMap) 199 { 200 return super.put(new String(sectionFormatID), propertyIDMap); 201 } 202 203 204 205 /** 206 * @deprecated Use {@link #put(byte[], PropertyIDMap)} instead! 207 */ 208 public Object put(final Object key, final Object value) 209 { 210 return put((byte[]) key, (PropertyIDMap) value); 211 } 212 213 } 214