diff options
Diffstat (limited to 'src/java/org/apache/poi')
7 files changed, 74 insertions, 140 deletions
diff --git a/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java b/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java index f10dcc938f..cb945a36ed 100644 --- a/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java +++ b/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java @@ -25,7 +25,6 @@ import java.util.List; import java.util.Map; import org.apache.poi.hpsf.wellknown.PropertyIDMap; -import org.apache.poi.hpsf.wellknown.SectionIDMap; /** * Convenience class representing a DocumentSummary Information stream in a @@ -34,6 +33,7 @@ import org.apache.poi.hpsf.wellknown.SectionIDMap; * @see SummaryInformation */ public class DocumentSummaryInformation extends PropertySet { + /** * The document name a document summary information stream * usually has in a POIFS filesystem. @@ -41,6 +41,18 @@ public class DocumentSummaryInformation extends PropertySet { public static final String DEFAULT_STREAM_NAME = "\005DocumentSummaryInformation"; + /** + * The DocumentSummaryInformation's first and second sections' format ID. + */ + private static final ClassID DOC_SUMMARY_INFORMATION = + new ClassID("{D5CDD502-2E9C-101B-9397-08002B2CF9AE}"); + private static final ClassID USER_DEFINED_PROPERTIES = + new ClassID("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"); + + public static final ClassID[] FORMAT_ID = { + DOC_SUMMARY_INFORMATION, USER_DEFINED_PROPERTIES + }; + @Override public PropertyIDMap getPropertySetIDMap() { return PropertyIDMap.getDocumentSummaryInformationProperties(); @@ -51,7 +63,7 @@ public class DocumentSummaryInformation extends PropertySet { * Creates an empty {@link DocumentSummaryInformation}. */ public DocumentSummaryInformation() { - getFirstSection().setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[0]); + getFirstSection().setFormatID(DOC_SUMMARY_INFORMATION); } @@ -812,7 +824,7 @@ public class DocumentSummaryInformation extends PropertySet { private void ensureSection2() { if (getSectionCount() < 2) { Section s2 = new Section(); - s2.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[1]); + s2.setFormatID(USER_DEFINED_PROPERTIES); addSection(s2); } } diff --git a/src/java/org/apache/poi/hpsf/PropertySet.java b/src/java/org/apache/poi/hpsf/PropertySet.java index a9e8e961ab..77621419ba 100644 --- a/src/java/org/apache/poi/hpsf/PropertySet.java +++ b/src/java/org/apache/poi/hpsf/PropertySet.java @@ -29,7 +29,6 @@ import java.util.List; import org.apache.poi.EmptyFileException; import org.apache.poi.hpsf.wellknown.PropertyIDMap; -import org.apache.poi.hpsf.wellknown.SectionIDMap; import org.apache.poi.poifs.filesystem.DirectoryEntry; import org.apache.poi.poifs.filesystem.Entry; import org.apache.poi.util.CodePageUtil; @@ -659,7 +658,7 @@ public class PropertySet { * represents a Summary Information, else {@code false}. */ public boolean isSummaryInformation() { - return !sections.isEmpty() && matchesSummary(getFirstSection().getFormatID(), SectionIDMap.SUMMARY_INFORMATION_ID); + return !sections.isEmpty() && matchesSummary(getFirstSection().getFormatID(), SummaryInformation.FORMAT_ID); } /** @@ -669,7 +668,7 @@ public class PropertySet { * represents a Document Summary Information, else {@code false}. */ public boolean isDocumentSummaryInformation() { - return !sections.isEmpty() && matchesSummary(getFirstSection().getFormatID(), SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID); + return !sections.isEmpty() && matchesSummary(getFirstSection().getFormatID(), DocumentSummaryInformation.FORMAT_ID); } /* package */ static boolean matchesSummary(ClassID actual, ClassID... expected) { diff --git a/src/java/org/apache/poi/hpsf/PropertySetFactory.java b/src/java/org/apache/poi/hpsf/PropertySetFactory.java index 44436c3b57..06029ab137 100644 --- a/src/java/org/apache/poi/hpsf/PropertySetFactory.java +++ b/src/java/org/apache/poi/hpsf/PropertySetFactory.java @@ -22,7 +22,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; -import org.apache.poi.hpsf.wellknown.SectionIDMap; import org.apache.poi.poifs.filesystem.DirectoryEntry; import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.DocumentInputStream; @@ -110,9 +109,9 @@ public class PropertySetFactory { stream.reset(); ClassID clsId = new ClassID(clsIdBuf, 0); - if (sectionCount > 0 && PropertySet.matchesSummary(clsId, SectionIDMap.SUMMARY_INFORMATION_ID)) { + if (sectionCount > 0 && PropertySet.matchesSummary(clsId, SummaryInformation.FORMAT_ID)) { return new SummaryInformation(stream); - } else if (sectionCount > 0 && PropertySet.matchesSummary(clsId, SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID)) { + } else if (sectionCount > 0 && PropertySet.matchesSummary(clsId, DocumentSummaryInformation.FORMAT_ID)) { return new DocumentSummaryInformation(stream); } else { return new PropertySet(stream); diff --git a/src/java/org/apache/poi/hpsf/Section.java b/src/java/org/apache/poi/hpsf/Section.java index 7202499468..88677801c7 100644 --- a/src/java/org/apache/poi/hpsf/Section.java +++ b/src/java/org/apache/poi/hpsf/Section.java @@ -31,7 +31,6 @@ import java.util.TreeMap; import org.apache.commons.collections4.bidimap.TreeBidiMap; import org.apache.poi.hpsf.wellknown.PropertyIDMap; -import org.apache.poi.hpsf.wellknown.SectionIDMap; import org.apache.poi.util.CodePageUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; @@ -597,29 +596,33 @@ public class Section { /** * Returns the PID string associated with a property ID. The ID - * is first looked up in the {@link Section}'s private - * dictionary. If it is not found there, the method calls {@link - * SectionIDMap#getPIDString}. + * is first looked up in the {@link Section Sections} private dictionary. + * If it is not found there, the property PID string is taken + * from sections format IDs namespace. + * If the PID is also undefined there, i.e. it is not well-known, + * {@code "[undefined]"} is returned. * * @param pid The property ID * - * @return The property ID's string value + * @return The well-known property ID string associated with the + * property ID {@code pid} */ public String getPIDString(final long pid) { - String s = null; Map<Long,String> dic = getDictionary(); - if (dic != null) { - s = dic.get(pid); - } - if (s == null) { - s = SectionIDMap.getPIDString(getFormatID(), pid); + if (dic == null || !dic.containsKey(pid)) { + ClassID fmt = getFormatID(); + if (SummaryInformation.FORMAT_ID.equals(fmt)) { + dic = PropertyIDMap.getSummaryInformationProperties(); + } else if (DocumentSummaryInformation.FORMAT_ID[0].equals(fmt)) { + dic = PropertyIDMap.getDocumentSummaryInformationProperties(); + } } - return s; + + return (dic != null && dic.containsKey(pid)) ? dic.get(pid) : PropertyIDMap.UNDEFINED; } /** - * Removes all properties from the section including 0 (dictionary) and - * 1 (codepage). + * Removes all properties from the section including 0 (dictionary) and 1 (codepage). */ public void clear() { for (Property p : getProperties()) { diff --git a/src/java/org/apache/poi/hpsf/SummaryInformation.java b/src/java/org/apache/poi/hpsf/SummaryInformation.java index 4425abc530..bab1963b1c 100644 --- a/src/java/org/apache/poi/hpsf/SummaryInformation.java +++ b/src/java/org/apache/poi/hpsf/SummaryInformation.java @@ -23,7 +23,6 @@ import java.io.UnsupportedEncodingException; import java.util.Date; import org.apache.poi.hpsf.wellknown.PropertyIDMap; -import org.apache.poi.hpsf.wellknown.SectionIDMap; /** * Convenience class representing a Summary Information stream in a @@ -38,6 +37,13 @@ public final class SummaryInformation extends PropertySet { */ public static final String DEFAULT_STREAM_NAME = "\005SummaryInformation"; + /** + * The SummaryInformation's section's format ID. + */ + public static final ClassID FORMAT_ID = + new ClassID("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"); + + @Override public PropertyIDMap getPropertySetIDMap() { return PropertyIDMap.getSummaryInformationProperties(); } @@ -46,7 +52,7 @@ public final class SummaryInformation extends PropertySet { * Creates an empty {@link SummaryInformation}. */ public SummaryInformation() { - getFirstSection().setFormatID(SectionIDMap.SUMMARY_INFORMATION_ID); + getFirstSection().setFormatID(FORMAT_ID); } /** @@ -594,7 +600,9 @@ public final class SummaryInformation extends PropertySet { */ public Thumbnail getThumbnailThumbnail() { byte[] data = getThumbnail(); - if (data == null) return null; + if (data == null) { + return null; + } return new Thumbnail(data); } diff --git a/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java b/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java index c55d936ae5..130408e7b5 100644 --- a/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java +++ b/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java @@ -317,6 +317,11 @@ public class PropertyIDMap implements Map<Long,String> { public static final int PID_BEHAVIOUR = 0x80000003; /** + * A property without a known name is described by this string. + */ + public static final String UNDEFINED = "[undefined]"; + + /** * Contains the summary information property ID values and * associated strings. See the overall HPSF documentation for * details! diff --git a/src/java/org/apache/poi/hpsf/wellknown/SectionIDMap.java b/src/java/org/apache/poi/hpsf/wellknown/SectionIDMap.java index 07fb6af4ea..620253ae11 100644 --- a/src/java/org/apache/poi/hpsf/wellknown/SectionIDMap.java +++ b/src/java/org/apache/poi/hpsf/wellknown/SectionIDMap.java @@ -17,136 +17,44 @@ package org.apache.poi.hpsf.wellknown; -import java.util.HashMap; -import java.util.Map; - import org.apache.poi.hpsf.ClassID; +import org.apache.poi.hpsf.DocumentSummaryInformation; +import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.util.Internal; +import org.apache.poi.util.Removal; /** - * <p>Maps section format IDs to {@link PropertyIDMap}s. It is - * initialized with two well-known section format IDs: those of the - * <tt>\005SummaryInformation</tt> stream and the - * <tt>\005DocumentSummaryInformation</tt> stream.</p> - * - * <p>If you have a section format ID you can use it as a key to query - * this map. If you get a {@link PropertyIDMap} returned your section - * is well-known and you can query the {@link PropertyIDMap} for PID - * strings. If you get back <code>null</code> you are on your own.</p> - * - * <p>This {@link java.util.Map} expects the byte arrays of section format IDs - * as keys. A key maps to a {@link PropertyIDMap} describing the - * property IDs in sections with the specified section format ID.</p> + * This classed used to map section format IDs to {@link PropertyIDMap PropertyIDMaps}, + * but there's no way to use custom PropertyIDMaps.<p> + * + * It is only kept for its ClassIDs until removal. + * + * @deprecated in 4.0.0, there's no way to create custom PropertyIDMaps, therefore + * this class is obsolete */ @Internal +@Deprecated +@Removal(version="4.2.0") public class SectionIDMap { /** - * The default section ID map. It maps section format IDs to {@link PropertyIDMap PropertyIDMaps} - */ - private static ThreadLocal<Map<ClassID,PropertyIDMap>> defaultMap = - new ThreadLocal<>(); - - /** - * <p>The SummaryInformation's section's format ID.</p> + * The SummaryInformation's section's format ID. + * @deprecated use {@link SummaryInformation#FORMAT_ID} */ - public static final ClassID SUMMARY_INFORMATION_ID = - new ClassID("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"); + @Deprecated + public static final ClassID SUMMARY_INFORMATION_ID = SummaryInformation.FORMAT_ID; /** * The DocumentSummaryInformation's first and second sections' format ID. + * @deprecated use {@link DocumentSummaryInformation#FORMAT_ID} */ - private static final ClassID DOC_SUMMARY_INFORMATION = - new ClassID("{D5CDD502-2E9C-101B-9397-08002B2CF9AE}"); - private static final ClassID USER_DEFINED_PROPERTIES = - new ClassID("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"); - - public static final ClassID[] DOCUMENT_SUMMARY_INFORMATION_ID = { - DOC_SUMMARY_INFORMATION, USER_DEFINED_PROPERTIES - }; + @Deprecated + public static final ClassID[] DOCUMENT_SUMMARY_INFORMATION_ID = DocumentSummaryInformation.FORMAT_ID; /** * A property without a known name is described by this string. + * @deprecated use {@link PropertyIDMap#UNDEFINED} */ - public static final String UNDEFINED = "[undefined]"; - - /** - * <p>Returns the singleton instance of the default {@link - * SectionIDMap}.</p> - * - * @return The instance value - */ - public static SectionIDMap getInstance() { - Map<ClassID,PropertyIDMap> m = defaultMap.get(); - if (m == null) { - m = new HashMap<>(); - m.put(SUMMARY_INFORMATION_ID, PropertyIDMap.getSummaryInformationProperties()); - m.put(DOCUMENT_SUMMARY_INFORMATION_ID[0], PropertyIDMap.getDocumentSummaryInformationProperties()); - defaultMap.set(m); - } - return new SectionIDMap(); - } - - - - /** - * <p>Returns the property ID string that is associated with a - * given property ID in a section format ID's namespace.</p> - * - * @param sectionFormatID Each section format ID has its own name - * space of property ID strings and thus must be specified. - * @param pid The property ID - * @return The well-known property ID string associated with the - * property ID <var>pid</var> in the name space spanned by <var> - * sectionFormatID</var> . If the <var>pid</var> - * /<var>sectionFormatID </var> combination is not well-known, the - * string "[undefined]" is returned. - */ - public static String getPIDString(ClassID sectionFormatID, long pid) { - final PropertyIDMap m = getInstance().get(sectionFormatID); - if (m == null) { - return UNDEFINED; - } - final String s = m.get(pid); - if (s == null) { - return UNDEFINED; - } - return s; - } - - - - /** - * <p>Returns the {@link PropertyIDMap} for a given section format - * ID.</p> - * - * @param sectionFormatID the section format ID - * @return the property ID map - */ - public PropertyIDMap get(final ClassID sectionFormatID) { - return getInstance().get(sectionFormatID); - } - - /** - * Associates a section format ID with a {@link PropertyIDMap}. - * - * @param sectionFormatID the section format ID - * @param propertyIDMap the property ID map - * @return as defined by {@link java.util.Map#put} - */ - public PropertyIDMap put(ClassID sectionFormatID, PropertyIDMap propertyIDMap) { - return getInstance().put(sectionFormatID, propertyIDMap); - } - - /** - * Associates the string representation of a section format ID with a {@link PropertyIDMap} - * - * @param key the key of the PropertyIDMap - * @param value the PropertyIDMap itself - * - * @return the previous PropertyIDMap stored under this key, or {@code null} if there wasn't one - */ - protected PropertyIDMap put(String key, PropertyIDMap value) { - return put(new ClassID(key), value); - } + @Deprecated + public static final String UNDEFINED = PropertyIDMap.UNDEFINED; } |