KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hpsf > wellknown > SectionIDMap


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18 package org.apache.poi.hpsf.wellknown;
19
20 import java.util.HashMap JavaDoc;
21
22 /**
23  * <p>Maps section format IDs to {@link PropertyIDMap}s. It is
24  * initialized with two well-known section format IDs: those of the
25  * <tt>\005SummaryInformation</tt> stream and the
26  * <tt>\005DocumentSummaryInformation</tt> stream.</p>
27  *
28  * <p>If you have a section format ID you can use it as a key to query
29  * this map. If you get a {@link PropertyIDMap} returned your section
30  * is well-known and you can query the {@link PropertyIDMap} for PID
31  * strings. If you get back <code>null</code> you are on your own.</p>
32  *
33  * <p>This {@link java.util.Map} expects the byte arrays of section format IDs
34  * as keys. A key maps to a {@link PropertyIDMap} describing the
35  * property IDs in sections with the specified section format ID.</p>
36  *
37  * @author Rainer Klute (klute@rainer-klute.de)
38  * @version $Id: SectionIDMap.java,v 1.8 2004/04/09 13:05:16 glens Exp $
39  * @since 2002-02-09
40  */

41 public class SectionIDMap extends HashMap JavaDoc
42 {
43
44     /**
45      * <p>The SummaryInformation's section's format ID.</p>
46      */

47     public static final byte[] SUMMARY_INFORMATION_ID = new byte[]
48     {
49         (byte) 0xF2, (byte) 0x9F, (byte) 0x85, (byte) 0xE0,
50         (byte) 0x4F, (byte) 0xF9, (byte) 0x10, (byte) 0x68,
51         (byte) 0xAB, (byte) 0x91, (byte) 0x08, (byte) 0x00,
52         (byte) 0x2B, (byte) 0x27, (byte) 0xB3, (byte) 0xD9
53     };
54
55     /**
56      * <p>The DocumentSummaryInformation's first section's format
57      * ID. The second section has a different format ID which is not
58      * well-known.</p>
59      */

60     public static final byte[] DOCUMENT_SUMMARY_INFORMATION_ID = new byte[]
61     {
62         (byte) 0xD5, (byte) 0xCD, (byte) 0xD5, (byte) 0x02,
63         (byte) 0x2E, (byte) 0x9C, (byte) 0x10, (byte) 0x1B,
64         (byte) 0x93, (byte) 0x97, (byte) 0x08, (byte) 0x00,
65         (byte) 0x2B, (byte) 0x2C, (byte) 0xF9, (byte) 0xAE
66     };
67
68     /**
69      * <p>A property without a known name is described by this string.</p>
70      */

71     public static final String JavaDoc UNDEFINED = "[undefined]";
72
73     /**
74      * <p>The default section ID map. It maps section format IDs to
75      * {@link PropertyIDMap}s.</p>
76      */

77     private static SectionIDMap defaultMap;
78
79
80
81     /**
82      * <p>Returns the singleton instance of the default {@link
83      * SectionIDMap}.</p>
84      *
85      * @return The instance value
86      */

87     public static SectionIDMap getInstance()
88     {
89         if (defaultMap == null)
90         {
91             final SectionIDMap m = new SectionIDMap();
92             m.put(SUMMARY_INFORMATION_ID,
93                   PropertyIDMap.getSummaryInformationProperties());
94             m.put(DOCUMENT_SUMMARY_INFORMATION_ID,
95                   PropertyIDMap.getDocumentSummaryInformationProperties());
96             defaultMap = m;
97         }
98         return defaultMap;
99     }
100
101
102
103     /**
104      * <p>Returns the property ID string that is associated with a
105      * given property ID in a section format ID's namespace.</p>
106      *
107      * @param sectionFormatID Each section format ID has its own name
108      * space of property ID strings and thus must be specified.
109      * @param pid The property ID
110      * @return The well-known property ID string associated with the
111      * property ID <var>pid</var> in the name space spanned by <var>
112      * sectionFormatID</var> . If the <var>pid</var>
113      * /<var>sectionFormatID </var> combination is not well-known, the
114      * string "[undefined]" is returned.
115      */

116     public static String JavaDoc getPIDString(final byte[] sectionFormatID,
117                                       final long pid)
118     {
119         final PropertyIDMap m =
120             (PropertyIDMap) getInstance().get(sectionFormatID);
121         if (m == null)
122             return UNDEFINED;
123         else
124         {
125             final String JavaDoc s = (String JavaDoc) m.get(pid);
126             if (s == null)
127                 return UNDEFINED;
128             return s;
129         }
130     }
131
132
133
134     /**
135      * <p>Returns the {@link PropertyIDMap} for a given section format
136      * ID.</p>
137      *
138      * @param sectionFormatID the section format ID
139      * @return the property ID map
140      */

141     public PropertyIDMap get(final byte[] sectionFormatID)
142     {
143         return (PropertyIDMap) super.get(new String JavaDoc(sectionFormatID));
144     }
145
146
147
148     /**
149      * <p>Returns the {@link PropertyIDMap} for a given section format
150      * ID.</p>
151      *
152      * @param sectionFormatID A section format ID as a <tt>byte[]</tt> .
153      * @deprecated Use {@link #get(byte[])} instead!
154      * @return the property ID map
155      */

156     public Object JavaDoc get(final Object JavaDoc sectionFormatID)
157     {
158         return get((byte[]) sectionFormatID);
159     }
160
161
162
163     /**
164      * <p>Associates a section format ID with a {@link
165      * PropertyIDMap}.</p>
166      *
167      * @param sectionFormatID the section format ID
168      * @param propertyIDMap the property ID map
169      * @return as defined by {@link java.util.Map#put}
170      */

171     public Object JavaDoc put(final byte[] sectionFormatID,
172                       final PropertyIDMap propertyIDMap)
173     {
174         return super.put(new String JavaDoc(sectionFormatID), propertyIDMap);
175     }
176
177
178
179     /**
180      * @deprecated Use {@link #put(byte[], PropertyIDMap)} instead!
181      * @link #put(byte[], PropertyIDMap)
182      *
183      * @param key This parameter remains undocumented since the method is
184      * deprecated.
185      * @param value This parameter remains undocumented since the method is
186      * deprecated.
187      * @return The return value remains undocumented since the method is
188      * deprecated.
189      */

190     public Object JavaDoc put(final Object JavaDoc key, final Object JavaDoc value)
191     {
192         return put((byte[]) key, (PropertyIDMap) value);
193     }
194
195 }
196
Popular Tags