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.HashMap;
021:
022: /**
023: * <p>Maps section format IDs to {@link PropertyIDMap}s. It is
024: * initialized with two well-known section format IDs: those of the
025: * <tt>\005SummaryInformation</tt> stream and the
026: * <tt>\005DocumentSummaryInformation</tt> stream.</p>
027: *
028: * <p>If you have a section format ID you can use it as a key to query
029: * this map. If you get a {@link PropertyIDMap} returned your section
030: * is well-known and you can query the {@link PropertyIDMap} for PID
031: * strings. If you get back <code>null</code> you are on your own.</p>
032: *
033: * <p>This {@link java.util.Map} expects the byte arrays of section format IDs
034: * as keys. A key maps to a {@link PropertyIDMap} describing the
035: * property IDs in sections with the specified section format ID.</p>
036: *
037: * @author Rainer Klute (klute@rainer-klute.de)
038: * @version $Id: SectionIDMap.java 489730 2006-12-22 19:18:16Z bayard $
039: * @since 2002-02-09
040: */
041: public class SectionIDMap extends HashMap {
042:
043: /**
044: * <p>The SummaryInformation's section's format ID.</p>
045: */
046: public static final byte[] SUMMARY_INFORMATION_ID = new byte[] {
047: (byte) 0xF2, (byte) 0x9F, (byte) 0x85, (byte) 0xE0,
048: (byte) 0x4F, (byte) 0xF9, (byte) 0x10, (byte) 0x68,
049: (byte) 0xAB, (byte) 0x91, (byte) 0x08, (byte) 0x00,
050: (byte) 0x2B, (byte) 0x27, (byte) 0xB3, (byte) 0xD9 };
051:
052: /**
053: * <p>The DocumentSummaryInformation's first and second sections' format
054: * ID.</p>
055: */
056: public static final byte[][] DOCUMENT_SUMMARY_INFORMATION_ID = new byte[][] {
057: { (byte) 0xD5, (byte) 0xCD, (byte) 0xD5, (byte) 0x02,
058: (byte) 0x2E, (byte) 0x9C, (byte) 0x10, (byte) 0x1B,
059: (byte) 0x93, (byte) 0x97, (byte) 0x08, (byte) 0x00,
060: (byte) 0x2B, (byte) 0x2C, (byte) 0xF9, (byte) 0xAE },
061: { (byte) 0xD5, (byte) 0xCD, (byte) 0xD5, (byte) 0x05,
062: (byte) 0x2E, (byte) 0x9C, (byte) 0x10, (byte) 0x1B,
063: (byte) 0x93, (byte) 0x97, (byte) 0x08, (byte) 0x00,
064: (byte) 0x2B, (byte) 0x2C, (byte) 0xF9, (byte) 0xAE } };
065:
066: /**
067: * <p>A property without a known name is described by this string.</p>
068: */
069: public static final String UNDEFINED = "[undefined]";
070:
071: /**
072: * <p>The default section ID map. It maps section format IDs to
073: * {@link PropertyIDMap}s.</p>
074: */
075: private static SectionIDMap defaultMap;
076:
077: /**
078: * <p>Returns the singleton instance of the default {@link
079: * SectionIDMap}.</p>
080: *
081: * @return The instance value
082: */
083: public static SectionIDMap getInstance() {
084: if (defaultMap == null) {
085: final SectionIDMap m = new SectionIDMap();
086: m.put(SUMMARY_INFORMATION_ID, PropertyIDMap
087: .getSummaryInformationProperties());
088: m.put(DOCUMENT_SUMMARY_INFORMATION_ID[0], PropertyIDMap
089: .getDocumentSummaryInformationProperties());
090: defaultMap = m;
091: }
092: return defaultMap;
093: }
094:
095: /**
096: * <p>Returns the property ID string that is associated with a
097: * given property ID in a section format ID's namespace.</p>
098: *
099: * @param sectionFormatID Each section format ID has its own name
100: * space of property ID strings and thus must be specified.
101: * @param pid The property ID
102: * @return The well-known property ID string associated with the
103: * property ID <var>pid</var> in the name space spanned by <var>
104: * sectionFormatID</var> . If the <var>pid</var>
105: * /<var>sectionFormatID </var> combination is not well-known, the
106: * string "[undefined]" is returned.
107: */
108: public static String getPIDString(final byte[] sectionFormatID,
109: final long pid) {
110: final PropertyIDMap m = getInstance().get(sectionFormatID);
111: if (m == null)
112: return UNDEFINED;
113: else {
114: final String s = (String) m.get(pid);
115: if (s == null)
116: return UNDEFINED;
117: return s;
118: }
119: }
120:
121: /**
122: * <p>Returns the {@link PropertyIDMap} for a given section format
123: * ID.</p>
124: *
125: * @param sectionFormatID the section format ID
126: * @return the property ID map
127: */
128: public PropertyIDMap get(final byte[] sectionFormatID) {
129: return (PropertyIDMap) super .get(new String(sectionFormatID));
130: }
131:
132: /**
133: * <p>Returns the {@link PropertyIDMap} for a given section format
134: * ID.</p>
135: *
136: * @param sectionFormatID A section format ID as a <tt>byte[]</tt> .
137: * @deprecated Use {@link #get(byte[])} instead!
138: * @return the property ID map
139: */
140: public Object get(final Object sectionFormatID) {
141: return get((byte[]) sectionFormatID);
142: }
143:
144: /**
145: * <p>Associates a section format ID with a {@link
146: * PropertyIDMap}.</p>
147: *
148: * @param sectionFormatID the section format ID
149: * @param propertyIDMap the property ID map
150: * @return as defined by {@link java.util.Map#put}
151: */
152: public Object put(final byte[] sectionFormatID,
153: final PropertyIDMap propertyIDMap) {
154: return super .put(new String(sectionFormatID), propertyIDMap);
155: }
156:
157: /**
158: * @deprecated Use {@link #put(byte[], PropertyIDMap)} instead!
159: *
160: * @see #put(byte[], PropertyIDMap)
161: *
162: * @param key This parameter remains undocumented since the method is
163: * deprecated.
164: * @param value This parameter remains undocumented since the method is
165: * deprecated.
166: * @return The return value remains undocumented since the method is
167: * deprecated.
168: */
169: public Object put(final Object key, final Object value) {
170: return put((byte[]) key, (PropertyIDMap) value);
171: }
172:
173: }
|