Fix bug #55191 - Avoid a ClassCastException if a HPSF string property isn't directly stored as a string
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1499326 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5a0887c9e4
commit
fb8d0c1076
@ -28,15 +28,10 @@ import org.apache.poi.util.CodePageUtil;
|
||||
* <p>Convenience class representing a DocumentSummary Information stream in a
|
||||
* Microsoft Office document.</p>
|
||||
*
|
||||
* @author Rainer Klute <a
|
||||
* href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
|
||||
* @author Drew Varner (Drew.Varner closeTo sc.edu)
|
||||
* @author robert_flaherty@hyperion.com
|
||||
* @see SummaryInformation
|
||||
*/
|
||||
public class DocumentSummaryInformation extends SpecialPropertySet
|
||||
{
|
||||
|
||||
/**
|
||||
* <p>The document name a document summary information stream
|
||||
* usually has in a POIFS filesystem.</p>
|
||||
@ -68,7 +63,6 @@ public class DocumentSummaryInformation extends SpecialPropertySet
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>Returns the category (or <code>null</code>).</p>
|
||||
*
|
||||
@ -76,7 +70,7 @@ public class DocumentSummaryInformation extends SpecialPropertySet
|
||||
*/
|
||||
public String getCategory()
|
||||
{
|
||||
return (String) getProperty(PropertyIDMap.PID_CATEGORY);
|
||||
return getPropertyStringValue(PropertyIDMap.PID_CATEGORY);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,7 +103,7 @@ public class DocumentSummaryInformation extends SpecialPropertySet
|
||||
*/
|
||||
public String getPresentationFormat()
|
||||
{
|
||||
return (String) getProperty(PropertyIDMap.PID_PRESFORMAT);
|
||||
return getPropertyStringValue(PropertyIDMap.PID_PRESFORMAT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -477,7 +471,7 @@ public class DocumentSummaryInformation extends SpecialPropertySet
|
||||
*/
|
||||
public String getManager()
|
||||
{
|
||||
return (String) getProperty(PropertyIDMap.PID_MANAGER);
|
||||
return getPropertyStringValue(PropertyIDMap.PID_MANAGER);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -509,7 +503,7 @@ public class DocumentSummaryInformation extends SpecialPropertySet
|
||||
*/
|
||||
public String getCompany()
|
||||
{
|
||||
return (String) getProperty(PropertyIDMap.PID_COMPANY);
|
||||
return getPropertyStringValue(PropertyIDMap.PID_COMPANY);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -533,7 +527,6 @@ public class DocumentSummaryInformation extends SpecialPropertySet
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>Returns <code>true</code> if the custom links are dirty.</p> <p>
|
||||
*
|
||||
@ -565,7 +558,6 @@ public class DocumentSummaryInformation extends SpecialPropertySet
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>Gets the custom properties.</p>
|
||||
*
|
||||
@ -629,8 +621,6 @@ public class DocumentSummaryInformation extends SpecialPropertySet
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>Creates section 2 if it is not already present.</p>
|
||||
*
|
||||
@ -645,8 +635,6 @@ public class DocumentSummaryInformation extends SpecialPropertySet
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>Removes the custom properties.</p>
|
||||
*/
|
||||
@ -659,7 +647,6 @@ public class DocumentSummaryInformation extends SpecialPropertySet
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>Throws an {@link UnsupportedOperationException} with a message text
|
||||
* telling which functionality is not yet implemented.</p>
|
||||
|
@ -24,6 +24,7 @@ import java.util.List;
|
||||
|
||||
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
|
||||
import org.apache.poi.poifs.filesystem.DirectoryEntry;
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
|
||||
/**
|
||||
* <p>Abstract superclass for the convenience classes {@link
|
||||
@ -149,7 +150,7 @@ public abstract class SpecialPropertySet extends MutablePropertySet
|
||||
/**
|
||||
* @see PropertySet#getSections
|
||||
*/
|
||||
public List getSections()
|
||||
public List<Section> getSections()
|
||||
{
|
||||
return delegate.getSections();
|
||||
}
|
||||
@ -325,6 +326,40 @@ public abstract class SpecialPropertySet extends MutablePropertySet
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetches the property with the given ID, then does its
|
||||
* best to return it as a String
|
||||
* @return The property as a String, or null if unavailable
|
||||
*/
|
||||
protected String getPropertyStringValue(final int propertyId) {
|
||||
Object o = getProperty(propertyId);
|
||||
|
||||
// Normal cases
|
||||
if (o == null) return null;
|
||||
if (o instanceof String) return (String)o;
|
||||
|
||||
// Do our best with some edge cases
|
||||
if (o instanceof byte[]) {
|
||||
byte[] b = (byte[])o;
|
||||
if (b.length == 0) {
|
||||
return "";
|
||||
}
|
||||
if (b.length == 1) {
|
||||
return Byte.toString(b[0]);
|
||||
}
|
||||
if (b.length == 2) {
|
||||
return Integer.toString( LittleEndian.getUShort(b) );
|
||||
}
|
||||
if (b.length == 4) {
|
||||
return Long.toString( LittleEndian.getUInt(b) );
|
||||
}
|
||||
// Maybe it's a string? who knows!
|
||||
return new String(b);
|
||||
}
|
||||
return o.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.apache.poi.hpsf.PropertySet#hashCode()
|
||||
*/
|
||||
|
@ -25,8 +25,6 @@ import org.apache.poi.hpsf.wellknown.PropertyIDMap;
|
||||
* <p>Convenience class representing a Summary Information stream in a
|
||||
* Microsoft Office document.</p>
|
||||
*
|
||||
* @author Rainer Klute <a
|
||||
* href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
|
||||
* @see DocumentSummaryInformation
|
||||
*/
|
||||
public final class SummaryInformation extends SpecialPropertySet {
|
||||
@ -69,7 +67,7 @@ public final class SummaryInformation extends SpecialPropertySet {
|
||||
*/
|
||||
public String getTitle()
|
||||
{
|
||||
return (String) getProperty(PropertyIDMap.PID_TITLE);
|
||||
return getPropertyStringValue(PropertyIDMap.PID_TITLE);
|
||||
}
|
||||
|
||||
|
||||
@ -105,7 +103,7 @@ public final class SummaryInformation extends SpecialPropertySet {
|
||||
*/
|
||||
public String getSubject()
|
||||
{
|
||||
return (String) getProperty(PropertyIDMap.PID_SUBJECT);
|
||||
return getPropertyStringValue(PropertyIDMap.PID_SUBJECT);
|
||||
}
|
||||
|
||||
|
||||
@ -141,7 +139,7 @@ public final class SummaryInformation extends SpecialPropertySet {
|
||||
*/
|
||||
public String getAuthor()
|
||||
{
|
||||
return (String) getProperty(PropertyIDMap.PID_AUTHOR);
|
||||
return getPropertyStringValue(PropertyIDMap.PID_AUTHOR);
|
||||
}
|
||||
|
||||
|
||||
@ -177,7 +175,7 @@ public final class SummaryInformation extends SpecialPropertySet {
|
||||
*/
|
||||
public String getKeywords()
|
||||
{
|
||||
return (String) getProperty(PropertyIDMap.PID_KEYWORDS);
|
||||
return getPropertyStringValue(PropertyIDMap.PID_KEYWORDS);
|
||||
}
|
||||
|
||||
|
||||
@ -213,7 +211,7 @@ public final class SummaryInformation extends SpecialPropertySet {
|
||||
*/
|
||||
public String getComments()
|
||||
{
|
||||
return (String) getProperty(PropertyIDMap.PID_COMMENTS);
|
||||
return getPropertyStringValue(PropertyIDMap.PID_COMMENTS);
|
||||
}
|
||||
|
||||
|
||||
@ -249,7 +247,7 @@ public final class SummaryInformation extends SpecialPropertySet {
|
||||
*/
|
||||
public String getTemplate()
|
||||
{
|
||||
return (String) getProperty(PropertyIDMap.PID_TEMPLATE);
|
||||
return getPropertyStringValue(PropertyIDMap.PID_TEMPLATE);
|
||||
}
|
||||
|
||||
|
||||
@ -285,7 +283,7 @@ public final class SummaryInformation extends SpecialPropertySet {
|
||||
*/
|
||||
public String getLastAuthor()
|
||||
{
|
||||
return (String) getProperty(PropertyIDMap.PID_LASTAUTHOR);
|
||||
return getPropertyStringValue(PropertyIDMap.PID_LASTAUTHOR);
|
||||
}
|
||||
|
||||
|
||||
@ -321,7 +319,7 @@ public final class SummaryInformation extends SpecialPropertySet {
|
||||
*/
|
||||
public String getRevNumber()
|
||||
{
|
||||
return (String) getProperty(PropertyIDMap.PID_REVNUMBER);
|
||||
return getPropertyStringValue(PropertyIDMap.PID_REVNUMBER);
|
||||
}
|
||||
|
||||
|
||||
@ -668,7 +666,7 @@ public final class SummaryInformation extends SpecialPropertySet {
|
||||
*/
|
||||
public String getApplicationName()
|
||||
{
|
||||
return (String) getProperty(PropertyIDMap.PID_APPNAME);
|
||||
return getPropertyStringValue(PropertyIDMap.PID_APPNAME);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user