Bug 21775
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/branches/REL_2_BRANCH@353254 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6e37d3327e
commit
71060cc5c7
@ -62,7 +62,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.poi.hpsf;
|
package org.apache.poi.hpsf;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,6 +84,7 @@ public class TypeReader
|
|||||||
* starts
|
* starts
|
||||||
* @param length The length of the variant including the variant
|
* @param length The length of the variant including the variant
|
||||||
* type field
|
* type field
|
||||||
|
* @param type The variant type to read
|
||||||
* @return A Java object that corresponds best to the variant
|
* @return A Java object that corresponds best to the variant
|
||||||
* field. For example, a VT_I4 is returned as a {@link Long}, a
|
* field. For example, a VT_I4 is returned as a {@link Long}, a
|
||||||
* VT_LPSTR as a {@link String}.
|
* VT_LPSTR as a {@link String}.
|
||||||
@ -92,15 +92,25 @@ public class TypeReader
|
|||||||
* @see Variant
|
* @see Variant
|
||||||
*/
|
*/
|
||||||
public static Object read(final byte[] src, int offset, int length,
|
public static Object read(final byte[] src, int offset, int length,
|
||||||
final int type)
|
final int type)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* FIXME: Support reading more types and clean up this code!
|
* FIXME: Support reading more types and clean up this code!
|
||||||
*/
|
*/
|
||||||
Object value;
|
Object value;
|
||||||
length = length - LittleEndian.INT_SIZE;
|
length = length - LittleEndian.INT_SIZE;
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
|
case Variant.VT_EMPTY:
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* FIXME: The value returned by this case relies on the
|
||||||
|
* assumption that the value VT_EMPTY denotes consists of zero
|
||||||
|
* bytes. I'd be glad if some could confirm or correct this.
|
||||||
|
*/
|
||||||
|
value = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case Variant.VT_I2:
|
case Variant.VT_I2:
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -137,11 +147,11 @@ public class TypeReader
|
|||||||
* Read a byte string. In Java it is represented as a
|
* Read a byte string. In Java it is represented as a
|
||||||
* String object. The 0x00 bytes at the end must be
|
* String object. The 0x00 bytes at the end must be
|
||||||
* stripped.
|
* stripped.
|
||||||
*
|
*
|
||||||
* FIXME: Reading an 8-bit string should pay attention
|
* FIXME: Reading an 8-bit string should pay attention
|
||||||
* to the codepage. Currently the byte making out the
|
* to the codepage. Currently the byte making out the
|
||||||
* property's value are interpreted according to the
|
* property's value are interpreted according to the
|
||||||
* platform's default character set.
|
* platform's default character set.
|
||||||
*/
|
*/
|
||||||
final int first = offset + LittleEndian.INT_SIZE;
|
final int first = offset + LittleEndian.INT_SIZE;
|
||||||
long last = first + LittleEndian.getUInt(src, offset) - 1;
|
long last = first + LittleEndian.getUInt(src, offset) - 1;
|
||||||
@ -149,7 +159,7 @@ public class TypeReader
|
|||||||
while (src[(int) last] == 0 && first <= last)
|
while (src[(int) last] == 0 && first <= last)
|
||||||
last--;
|
last--;
|
||||||
value = new String(src, (int) first, (int) (last - first + 1));
|
value = new String(src, (int) first, (int) (last - first + 1));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Variant.VT_LPWSTR:
|
case Variant.VT_LPWSTR:
|
||||||
{
|
{
|
||||||
@ -160,27 +170,27 @@ public class TypeReader
|
|||||||
*/
|
*/
|
||||||
final int first = offset + LittleEndian.INT_SIZE;
|
final int first = offset + LittleEndian.INT_SIZE;
|
||||||
long last = first + LittleEndian.getUInt(src, offset) - 1;
|
long last = first + LittleEndian.getUInt(src, offset) - 1;
|
||||||
long l = last - first;
|
long l = last - first;
|
||||||
offset += LittleEndian.INT_SIZE;
|
offset += LittleEndian.INT_SIZE;
|
||||||
StringBuffer b = new StringBuffer((int) (last - first));
|
StringBuffer b = new StringBuffer((int) (last - first));
|
||||||
for (int i = 0; i <= l; i++)
|
for (int i = 0; i <= l; i++)
|
||||||
{
|
{
|
||||||
final int i1 = offset + (i * 2);
|
final int i1 = offset + (i * 2);
|
||||||
final int i2 = i1 + 1;
|
final int i2 = i1 + 1;
|
||||||
b.append((char) ((src[i2] << 8) + src[i1]));
|
b.append((char) ((src[i2] << 8) + src[i1]));
|
||||||
}
|
}
|
||||||
/* Strip 0x00 characters from the end of the string: */
|
/* Strip 0x00 characters from the end of the string: */
|
||||||
while (b.charAt(b.length() - 1) == 0x00)
|
while (b.charAt(b.length() - 1) == 0x00)
|
||||||
b.setLength(b.length() - 1);
|
b.setLength(b.length() - 1);
|
||||||
value = b.toString();
|
value = b.toString();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Variant.VT_CF:
|
case Variant.VT_CF:
|
||||||
{
|
{
|
||||||
final byte[] v = new byte[length];
|
final byte[] v = new byte[length];
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++)
|
||||||
v[i] = src[(int) (offset + i)];
|
v[i] = src[(int) (offset + i)];
|
||||||
value = v;
|
value = v;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Variant.VT_BOOL:
|
case Variant.VT_BOOL:
|
||||||
@ -190,24 +200,24 @@ public class TypeReader
|
|||||||
* src[offset + 3] contain the DWord for VT_BOOL, so
|
* src[offset + 3] contain the DWord for VT_BOOL, so
|
||||||
* skip it, we don't need it.
|
* skip it, we don't need it.
|
||||||
*/
|
*/
|
||||||
final int first = offset + LittleEndian.INT_SIZE;
|
// final int first = offset + LittleEndian.INT_SIZE;
|
||||||
long bool = LittleEndian.getUInt(src, offset);
|
long bool = LittleEndian.getUInt(src, offset);
|
||||||
if (bool != 0)
|
if (bool != 0)
|
||||||
value = new Boolean(true);
|
value = new Boolean(true);
|
||||||
else
|
else
|
||||||
value = new Boolean(false);
|
value = new Boolean(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
final byte[] v = new byte[length];
|
final byte[] v = new byte[length];
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++)
|
||||||
v[i] = src[(int) (offset + i)];
|
v[i] = src[(int) (offset + i)];
|
||||||
value = v;
|
value = v;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -76,178 +76,178 @@ public class Variant
|
|||||||
/**
|
/**
|
||||||
* <p>[V][P] Nothing.</p>
|
* <p>[V][P] Nothing.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_EMPTY = 0;
|
public static final int VT_EMPTY = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[V][P] SQL style Null.</p>
|
* <p>[V][P] SQL style Null.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_NULL = 1;
|
public static final int VT_NULL = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[V][T][P][S] 2 byte signed int.</p>
|
* <p>[V][T][P][S] 2 byte signed int.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_I2 = 2;
|
public static final int VT_I2 = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[V][T][P][S] 4 byte signed int.</p>
|
* <p>[V][T][P][S] 4 byte signed int.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_I4 = 3;
|
public static final int VT_I4 = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[V][T][P][S] 4 byte real.</p>
|
* <p>[V][T][P][S] 4 byte real.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_R4 = 4;
|
public static final int VT_R4 = 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[V][T][P][S] 8 byte real.</p>
|
* <p>[V][T][P][S] 8 byte real.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_R8 = 5;
|
public static final int VT_R8 = 5;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[V][T][P][S] currency. <span style="background-color:
|
* <p>[V][T][P][S] currency. <span style="background-color:
|
||||||
* #ffff00">How long is this? How is it to be
|
* #ffff00">How long is this? How is it to be
|
||||||
* interpreted?</span></p>
|
* interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_CY = 6;
|
public static final int VT_CY = 6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[V][T][P][S] date. <span style="background-color:
|
* <p>[V][T][P][S] date. <span style="background-color:
|
||||||
* #ffff00">How long is this? How is it to be
|
* #ffff00">How long is this? How is it to be
|
||||||
* interpreted?</span></p>
|
* interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_DATE = 7;
|
public static final int VT_DATE = 7;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[V][T][P][S] OLE Automation string. <span
|
* <p>[V][T][P][S] OLE Automation string. <span
|
||||||
* style="background-color: #ffff00">How long is this? How is it
|
* style="background-color: #ffff00">How long is this? How is it
|
||||||
* to be interpreted?</span></p>
|
* to be interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_BSTR = 8;
|
public static final int VT_BSTR = 8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[V][T][P][S] IDispatch *. <span style="background-color:
|
* <p>[V][T][P][S] IDispatch *. <span style="background-color:
|
||||||
* #ffff00">How long is this? How is it to be
|
* #ffff00">How long is this? How is it to be
|
||||||
* interpreted?</span></p>
|
* interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_DISPATCH = 9;
|
public static final int VT_DISPATCH = 9;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[V][T][S] SCODE. <span style="background-color: #ffff00">How
|
* <p>[V][T][S] SCODE. <span style="background-color: #ffff00">How
|
||||||
* long is this? How is it to be interpreted?</span></p>
|
* long is this? How is it to be interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_ERROR = 10;
|
public static final int VT_ERROR = 10;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[V][T][P][S] True=-1, False=0.</p>
|
* <p>[V][T][P][S] True=-1, False=0.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_BOOL = 11;
|
public static final int VT_BOOL = 11;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[V][T][P][S] VARIANT *. <span style="background-color:
|
* <p>[V][T][P][S] VARIANT *. <span style="background-color:
|
||||||
* #ffff00">How long is this? How is it to be
|
* #ffff00">How long is this? How is it to be
|
||||||
* interpreted?</span></p>
|
* interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_VARIANT = 12;
|
public static final int VT_VARIANT = 12;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[V][T][S] IUnknown *. <span style="background-color:
|
* <p>[V][T][S] IUnknown *. <span style="background-color:
|
||||||
* #ffff00">How long is this? How is it to be
|
* #ffff00">How long is this? How is it to be
|
||||||
* interpreted?</span></p>
|
* interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_UNKNOWN = 13;
|
public static final int VT_UNKNOWN = 13;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[V][T][S] 16 byte fixed point.</p>
|
* <p>[V][T][S] 16 byte fixed point.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_DECIMAL = 14;
|
public static final int VT_DECIMAL = 14;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[T] signed char.</p>
|
* <p>[T] signed char.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_I1 = 16;
|
public static final int VT_I1 = 16;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[V][T][P][S] unsigned char.</p>
|
* <p>[V][T][P][S] unsigned char.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_UI1 = 17;
|
public static final int VT_UI1 = 17;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[T][P] unsigned short.</p>
|
* <p>[T][P] unsigned short.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_UI2 = 18;
|
public static final int VT_UI2 = 18;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[T][P] unsigned int.</p>
|
* <p>[T][P] unsigned int.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_UI4 = 19;
|
public static final int VT_UI4 = 19;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[T][P] signed 64-bit int.</p>
|
* <p>[T][P] signed 64-bit int.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_I8 = 20;
|
public static final int VT_I8 = 20;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[T][P] unsigned 64-bit int.</p>
|
* <p>[T][P] unsigned 64-bit int.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_UI8 = 21;
|
public static final int VT_UI8 = 21;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[T] signed machine int.</p>
|
* <p>[T] signed machine int.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_INT = 22;
|
public static final int VT_INT = 22;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[T] unsigned machine int.</p>
|
* <p>[T] unsigned machine int.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_UINT = 23;
|
public static final int VT_UINT = 23;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[T] C style void.</p>
|
* <p>[T] C style void.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_VOID = 24;
|
public static final int VT_VOID = 24;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[T] Standard return type. <span style="background-color:
|
* <p>[T] Standard return type. <span style="background-color:
|
||||||
* #ffff00">How long is this? How is it to be
|
* #ffff00">How long is this? How is it to be
|
||||||
* interpreted?</span></p>
|
* interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_HRESULT = 25;
|
public static final int VT_HRESULT = 25;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[T] pointer type. <span style="background-color:
|
* <p>[T] pointer type. <span style="background-color:
|
||||||
* #ffff00">How long is this? How is it to be
|
* #ffff00">How long is this? How is it to be
|
||||||
* interpreted?</span></p>
|
* interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_PTR = 26;
|
public static final int VT_PTR = 26;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[T] (use VT_ARRAY in VARIANT).</p>
|
* <p>[T] (use VT_ARRAY in VARIANT).</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_SAFEARRAY = 27;
|
public static final int VT_SAFEARRAY = 27;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[T] C style array. <span style="background-color:
|
* <p>[T] C style array. <span style="background-color:
|
||||||
* #ffff00">How long is this? How is it to be
|
* #ffff00">How long is this? How is it to be
|
||||||
* interpreted?</span></p>
|
* interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_CARRAY = 28;
|
public static final int VT_CARRAY = 28;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[T] user defined type. <span style="background-color:
|
* <p>[T] user defined type. <span style="background-color:
|
||||||
* #ffff00">How long is this? How is it to be
|
* #ffff00">How long is this? How is it to be
|
||||||
* interpreted?</span></p>
|
* interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_USERDEFINED = 29;
|
public static final int VT_USERDEFINED = 29;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[T][P] null terminated string.</p>
|
* <p>[T][P] null terminated string.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_LPSTR = 30;
|
public static final int VT_LPSTR = 30;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[T][P] wide (Unicode) null terminated string.</p>
|
* <p>[T][P] wide (Unicode) null terminated string.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_LPWSTR = 31;
|
public static final int VT_LPWSTR = 31;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[P] FILETIME. The FILETIME structure holds a date and time
|
* <p>[P] FILETIME. The FILETIME structure holds a date and time
|
||||||
@ -256,50 +256,50 @@ public class Variant
|
|||||||
* have passed since January 1, 1601. This 64-bit value is split
|
* have passed since January 1, 1601. This 64-bit value is split
|
||||||
* into the two dwords stored in the structure.</p>
|
* into the two dwords stored in the structure.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_FILETIME = 64;
|
public static final int VT_FILETIME = 64;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[P] Length prefixed bytes.</p>
|
* <p>[P] Length prefixed bytes.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_BLOB = 65;
|
public static final int VT_BLOB = 65;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[P] Name of the stream follows.</p>
|
* <p>[P] Name of the stream follows.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_STREAM = 66;
|
public static final int VT_STREAM = 66;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[P] Name of the storage follows.</p>
|
* <p>[P] Name of the storage follows.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_STORAGE = 67;
|
public static final int VT_STORAGE = 67;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[P] Stream contains an object. <span
|
* <p>[P] Stream contains an object. <span
|
||||||
* style="background-color: #ffff00"> How long is this? How is it
|
* style="background-color: #ffff00"> How long is this? How is it
|
||||||
* to be interpreted?</span></p>
|
* to be interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_STREAMED_OBJECT = 68;
|
public static final int VT_STREAMED_OBJECT = 68;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[P] Storage contains an object. <span
|
* <p>[P] Storage contains an object. <span
|
||||||
* style="background-color: #ffff00"> How long is this? How is it
|
* style="background-color: #ffff00"> How long is this? How is it
|
||||||
* to be interpreted?</span></p>
|
* to be interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_STORED_OBJECT = 69;
|
public static final int VT_STORED_OBJECT = 69;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[P] Blob contains an object. <span style="background-color:
|
* <p>[P] Blob contains an object. <span style="background-color:
|
||||||
* #ffff00">How long is this? How is it to be
|
* #ffff00">How long is this? How is it to be
|
||||||
* interpreted?</span></p>
|
* interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_BLOB_OBJECT = 70;
|
public static final int VT_BLOB_OBJECT = 70;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[P] Clipboard format. <span style="background-color:
|
* <p>[P] Clipboard format. <span style="background-color:
|
||||||
* #ffff00">How long is this? How is it to be
|
* #ffff00">How long is this? How is it to be
|
||||||
* interpreted?</span></p>
|
* interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_CF = 71;
|
public static final int VT_CF = 71;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[P] A Class ID.</p>
|
* <p>[P] A Class ID.</p>
|
||||||
@ -331,34 +331,46 @@ public class Variant
|
|||||||
* target="_blank">
|
* target="_blank">
|
||||||
* msdn.microsoft.com/library/en-us/com/stgrstrc_0uwk.asp</a>.</p>
|
* msdn.microsoft.com/library/en-us/com/stgrstrc_0uwk.asp</a>.</p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_CLSID = 72;
|
public static final int VT_CLSID = 72;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[P] simple counted array. <span style="background-color:
|
* <p>[P] simple counted array. <span style="background-color:
|
||||||
* #ffff00">How long is this? How is it to be
|
* #ffff00">How long is this? How is it to be
|
||||||
* interpreted?</span></p>
|
* interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_VECTOR = 0x1000;
|
public static final int VT_VECTOR = 0x1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[V] SAFEARRAY*. <span style="background-color: #ffff00">How
|
* <p>[V] SAFEARRAY*. <span style="background-color: #ffff00">How
|
||||||
* long is this? How is it to be interpreted?</span></p>
|
* long is this? How is it to be interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_ARRAY = 0x2000;
|
public static final int VT_ARRAY = 0x2000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>[V] void* for local use. <span style="background-color:
|
* <p>[V] void* for local use. <span style="background-color:
|
||||||
* #ffff00">How long is this? How is it to be
|
* #ffff00">How long is this? How is it to be
|
||||||
* interpreted?</span></p>
|
* interpreted?</span></p>
|
||||||
*/
|
*/
|
||||||
public final static int VT_BYREF = 0x4000;
|
public static final int VT_BYREF = 0x4000;
|
||||||
|
|
||||||
public final static int VT_RESERVED = 0x8000;
|
/**
|
||||||
|
* <p>FIXME: Document this!</p>
|
||||||
|
*/
|
||||||
|
public static final int VT_RESERVED = 0x8000;
|
||||||
|
|
||||||
public final static int VT_ILLEGAL = 0xFFFF;
|
/**
|
||||||
|
* <p>FIXME: Document this!</p>
|
||||||
|
*/
|
||||||
|
public static final int VT_ILLEGAL = 0xFFFF;
|
||||||
|
|
||||||
public final static int VT_ILLEGALMASKED = 0xFFF;
|
/**
|
||||||
|
* <p>FIXME: Document this!</p>
|
||||||
|
*/
|
||||||
|
public static final int VT_ILLEGALMASKED = 0xFFF;
|
||||||
|
|
||||||
public final static int VT_TYPEMASK = 0xFFF;
|
/**
|
||||||
|
* <p>FIXME: Document this!</p>
|
||||||
|
*/
|
||||||
|
public static final int VT_TYPEMASK = 0xFFF;
|
||||||
|
|
||||||
}
|
}
|
@ -53,7 +53,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.poi.hpsf.basic;
|
package org.apache.poi.hpsf.basic;
|
||||||
import org.apache.poi.poifs.filesystem.*;
|
|
||||||
|
import org.apache.poi.poifs.filesystem.POIFSDocumentPath;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -73,32 +74,32 @@ public class POIFile
|
|||||||
|
|
||||||
public void setName(final String name)
|
public void setName(final String name)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
public String getName()
|
||||||
{
|
{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPath(final POIFSDocumentPath path)
|
public void setPath(final POIFSDocumentPath path)
|
||||||
{
|
{
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public POIFSDocumentPath getPath()
|
public POIFSDocumentPath getPath()
|
||||||
{
|
{
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBytes(final byte[] bytes)
|
public void setBytes(final byte[] bytes)
|
||||||
{
|
{
|
||||||
this.bytes = bytes;
|
this.bytes = bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getBytes()
|
public byte[] getBytes()
|
||||||
{
|
{
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -54,10 +54,23 @@
|
|||||||
|
|
||||||
package org.apache.poi.hpsf.basic;
|
package org.apache.poi.hpsf.basic;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.util.*;
|
import java.io.File;
|
||||||
import junit.framework.*;
|
import java.io.FileNotFoundException;
|
||||||
import org.apache.poi.hpsf.*;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.poi.hpsf.DocumentSummaryInformation;
|
||||||
|
import org.apache.poi.hpsf.HPSFException;
|
||||||
|
import org.apache.poi.hpsf.MarkUnsupportedException;
|
||||||
|
import org.apache.poi.hpsf.NoPropertySetStreamException;
|
||||||
|
import org.apache.poi.hpsf.PropertySet;
|
||||||
|
import org.apache.poi.hpsf.PropertySetFactory;
|
||||||
|
import org.apache.poi.hpsf.SummaryInformation;
|
||||||
|
import org.apache.poi.hpsf.UnexpectedPropertySetTypeException;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -71,37 +84,37 @@ import org.apache.poi.hpsf.*;
|
|||||||
public class TestBasic extends TestCase
|
public class TestBasic extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
final static String POI_FS = "TestGermanWord90.doc";
|
static final String POI_FS = "TestGermanWord90.doc";
|
||||||
final static String[] POI_FILES = new String[]
|
static final String[] POI_FILES = new String[]
|
||||||
{
|
{
|
||||||
"\005SummaryInformation",
|
"\005SummaryInformation",
|
||||||
"\005DocumentSummaryInformation",
|
"\005DocumentSummaryInformation",
|
||||||
"WordDocument",
|
"WordDocument",
|
||||||
"\001CompObj",
|
"\001CompObj",
|
||||||
"1Table"
|
"1Table"
|
||||||
};
|
};
|
||||||
final static int BYTE_ORDER = 0xfffe;
|
static final int BYTE_ORDER = 0xfffe;
|
||||||
final static int FORMAT = 0x0000;
|
static final int FORMAT = 0x0000;
|
||||||
final static int OS_VERSION = 0x00020A04;
|
static final int OS_VERSION = 0x00020A04;
|
||||||
final static byte[] CLASS_ID =
|
static final byte[] CLASS_ID =
|
||||||
{
|
{
|
||||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
|
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
|
||||||
};
|
};
|
||||||
final static int[] SECTION_COUNT =
|
static final int[] SECTION_COUNT =
|
||||||
{1, 2};
|
{1, 2};
|
||||||
final static boolean[] IS_SUMMARY_INFORMATION =
|
static final boolean[] IS_SUMMARY_INFORMATION =
|
||||||
{true, false};
|
{true, false};
|
||||||
final static boolean[] IS_DOCUMENT_SUMMARY_INFORMATION =
|
static final boolean[] IS_DOCUMENT_SUMMARY_INFORMATION =
|
||||||
{false, true};
|
{false, true};
|
||||||
|
|
||||||
POIFile[] poiFiles;
|
POIFile[] poiFiles;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public TestBasic(String name)
|
public TestBasic(final String name)
|
||||||
{
|
{
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
@ -113,11 +126,11 @@ public class TestBasic extends TestCase
|
|||||||
*/
|
*/
|
||||||
public void setUp() throws FileNotFoundException, IOException
|
public void setUp() throws FileNotFoundException, IOException
|
||||||
{
|
{
|
||||||
final File dataDir =
|
final File dataDir =
|
||||||
new File(System.getProperty("HPSF.testdata.path"));
|
new File(System.getProperty("HPSF.testdata.path"));
|
||||||
final File data = new File(dataDir, POI_FS);
|
final File data = new File(dataDir, POI_FS);
|
||||||
|
|
||||||
poiFiles = Util.readPOIFiles(data);
|
poiFiles = Util.readPOIFiles(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -128,9 +141,9 @@ public class TestBasic extends TestCase
|
|||||||
*/
|
*/
|
||||||
public void testReadFiles() throws IOException
|
public void testReadFiles() throws IOException
|
||||||
{
|
{
|
||||||
String[] expected = POI_FILES;
|
String[] expected = POI_FILES;
|
||||||
for (int i = 0; i < expected.length; i++)
|
for (int i = 0; i < expected.length; i++)
|
||||||
Assert.assertEquals(poiFiles[i].getName(), expected[i]);
|
Assert.assertEquals(poiFiles[i].getName(), expected[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -146,37 +159,37 @@ public class TestBasic extends TestCase
|
|||||||
*/
|
*/
|
||||||
public void testCreatePropertySets() throws IOException
|
public void testCreatePropertySets() throws IOException
|
||||||
{
|
{
|
||||||
Class[] expected = new Class[]
|
Class[] expected = new Class[]
|
||||||
{
|
{
|
||||||
SummaryInformation.class,
|
SummaryInformation.class,
|
||||||
DocumentSummaryInformation.class,
|
DocumentSummaryInformation.class,
|
||||||
NoPropertySetStreamException.class,
|
NoPropertySetStreamException.class,
|
||||||
NoPropertySetStreamException.class,
|
NoPropertySetStreamException.class,
|
||||||
NoPropertySetStreamException.class
|
NoPropertySetStreamException.class
|
||||||
};
|
};
|
||||||
for (int i = 0; i < expected.length; i++)
|
for (int i = 0; i < expected.length; i++)
|
||||||
{
|
{
|
||||||
InputStream in = new ByteArrayInputStream(poiFiles[i].getBytes());
|
InputStream in = new ByteArrayInputStream(poiFiles[i].getBytes());
|
||||||
Object o;
|
Object o;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
o = PropertySetFactory.create(in);
|
o = PropertySetFactory.create(in);
|
||||||
}
|
}
|
||||||
catch (NoPropertySetStreamException ex)
|
catch (NoPropertySetStreamException ex)
|
||||||
{
|
{
|
||||||
o = ex;
|
o = ex;
|
||||||
}
|
}
|
||||||
catch (UnexpectedPropertySetTypeException ex)
|
catch (UnexpectedPropertySetTypeException ex)
|
||||||
{
|
{
|
||||||
o = ex;
|
o = ex;
|
||||||
}
|
}
|
||||||
catch (MarkUnsupportedException ex)
|
catch (MarkUnsupportedException ex)
|
||||||
{
|
{
|
||||||
o = ex;
|
o = ex;
|
||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
Assert.assertEquals(o.getClass(), expected[i]);
|
Assert.assertEquals(o.getClass(), expected[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -188,25 +201,24 @@ public class TestBasic extends TestCase
|
|||||||
*/
|
*/
|
||||||
public void testPropertySetMethods() throws IOException, HPSFException
|
public void testPropertySetMethods() throws IOException, HPSFException
|
||||||
{
|
{
|
||||||
String[] expected = POI_FILES;
|
|
||||||
|
|
||||||
/* Loop over the two property sets. */
|
/* Loop over the two property sets. */
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
byte[] b = poiFiles[i].getBytes();
|
byte[] b = poiFiles[i].getBytes();
|
||||||
PropertySet ps =
|
PropertySet ps =
|
||||||
PropertySetFactory.create(new ByteArrayInputStream(b));
|
PropertySetFactory.create(new ByteArrayInputStream(b));
|
||||||
Assert.assertEquals(ps.getByteOrder(), BYTE_ORDER);
|
Assert.assertEquals(ps.getByteOrder(), BYTE_ORDER);
|
||||||
Assert.assertEquals(ps.getFormat(), FORMAT);
|
Assert.assertEquals(ps.getFormat(), FORMAT);
|
||||||
Assert.assertEquals(ps.getOSVersion(), OS_VERSION);
|
Assert.assertEquals(ps.getOSVersion(), OS_VERSION);
|
||||||
Assert.assertEquals(new String(ps.getClassID().getBytes()),
|
Assert.assertEquals(new String(ps.getClassID().getBytes()),
|
||||||
new String(CLASS_ID));
|
new String(CLASS_ID));
|
||||||
Assert.assertEquals(ps.getSectionCount(), SECTION_COUNT[i]);
|
Assert.assertEquals(ps.getSectionCount(), SECTION_COUNT[i]);
|
||||||
Assert.assertEquals(ps.isSummaryInformation(),
|
Assert.assertEquals(ps.isSummaryInformation(),
|
||||||
IS_SUMMARY_INFORMATION[i]);
|
IS_SUMMARY_INFORMATION[i]);
|
||||||
Assert.assertEquals(ps.isDocumentSummaryInformation(),
|
Assert.assertEquals(ps.isDocumentSummaryInformation(),
|
||||||
IS_DOCUMENT_SUMMARY_INFORMATION[i]);
|
IS_DOCUMENT_SUMMARY_INFORMATION[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -214,11 +226,11 @@ public class TestBasic extends TestCase
|
|||||||
/**
|
/**
|
||||||
* <p>Runs the test cases stand-alone.</p>
|
* <p>Runs the test cases stand-alone.</p>
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws Throwable
|
public static void main(final String[] args) throws Throwable
|
||||||
{
|
{
|
||||||
System.setProperty("HPSF.testdata.path",
|
System.setProperty("HPSF.testdata.path",
|
||||||
"./src/testcases/org/apache/poi/hpsf/data");
|
"./src/testcases/org/apache/poi/hpsf/data");
|
||||||
junit.textui.TestRunner.run(TestBasic.class);
|
junit.textui.TestRunner.run(TestBasic.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,20 +37,13 @@ public class TestEmptyProperties extends TestCase
|
|||||||
|
|
||||||
static final String[] POI_FILES = new String[]
|
static final String[] POI_FILES = new String[]
|
||||||
{
|
{
|
||||||
"PerfectOffice_MAIN",
|
"SlideShow",
|
||||||
"\005SummaryInformation",
|
"\005SummaryInformation",
|
||||||
"Main"
|
"PerfectOffice_MAIN"
|
||||||
};
|
};
|
||||||
|
|
||||||
POIFile[] poiFiles;
|
POIFile[] poiFiles;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Constructor</p>
|
|
||||||
*
|
|
||||||
* @param name The name of the test case
|
|
||||||
*/
|
|
||||||
public TestEmptyProperties(final String name)
|
public TestEmptyProperties(final String name)
|
||||||
{
|
{
|
||||||
super(name);
|
super(name);
|
||||||
@ -60,10 +53,6 @@ public class TestEmptyProperties extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Read a the test file from the "data" directory.</p>
|
* <p>Read a the test file from the "data" directory.</p>
|
||||||
*
|
|
||||||
* @exception FileNotFoundException if the file containing the test data
|
|
||||||
* does not exist
|
|
||||||
* @exception IOException if an I/O exception occurs
|
|
||||||
*/
|
*/
|
||||||
public void setUp() throws FileNotFoundException, IOException
|
public void setUp() throws FileNotFoundException, IOException
|
||||||
{
|
{
|
||||||
@ -79,8 +68,6 @@ public class TestEmptyProperties extends TestCase
|
|||||||
/**
|
/**
|
||||||
* <p>Checks the names of the files in the POI filesystem. They
|
* <p>Checks the names of the files in the POI filesystem. They
|
||||||
* are expected to be in a certain order.</p>
|
* are expected to be in a certain order.</p>
|
||||||
*
|
|
||||||
* @exception IOException if an I/O exception occurs
|
|
||||||
*/
|
*/
|
||||||
public void testReadFiles() throws IOException
|
public void testReadFiles() throws IOException
|
||||||
{
|
{
|
||||||
@ -99,11 +86,9 @@ public class TestEmptyProperties extends TestCase
|
|||||||
* property sets. In the latter cases a {@link
|
* property sets. In the latter cases a {@link
|
||||||
* NoPropertySetStreamException} will be thrown when trying to
|
* NoPropertySetStreamException} will be thrown when trying to
|
||||||
* create a {@link PropertySet}.</p>
|
* create a {@link PropertySet}.</p>
|
||||||
*
|
|
||||||
* @exception IOException if an I/O exception occurs
|
|
||||||
*/
|
*/
|
||||||
public void testCreatePropertySets() throws IOException
|
public void testCreatePropertySets() throws IOException
|
||||||
{
|
{
|
||||||
Class[] expected = new Class[]
|
Class[] expected = new Class[]
|
||||||
{
|
{
|
||||||
NoPropertySetStreamException.class,
|
NoPropertySetStreamException.class,
|
||||||
@ -141,13 +126,10 @@ public class TestEmptyProperties extends TestCase
|
|||||||
* <p>Tests the {@link PropertySet} methods. The test file has two
|
* <p>Tests the {@link PropertySet} methods. The test file has two
|
||||||
* property sets: the first one is a {@link SummaryInformation},
|
* property sets: the first one is a {@link SummaryInformation},
|
||||||
* the second one is a {@link DocumentSummaryInformation}.</p>
|
* the second one is a {@link DocumentSummaryInformation}.</p>
|
||||||
*
|
|
||||||
* @exception IOException if an I/O exception occurs
|
|
||||||
* @exception HPSFException if an HPSF operation fails
|
|
||||||
*/
|
*/
|
||||||
public void testPropertySetMethods() throws IOException, HPSFException
|
public void testPropertySetMethods() throws IOException, HPSFException
|
||||||
{
|
{
|
||||||
byte[] b = poiFiles[1].getBytes();
|
byte[] b = poiFiles[2].getBytes();
|
||||||
PropertySet ps =
|
PropertySet ps =
|
||||||
PropertySetFactory.create(new ByteArrayInputStream(b));
|
PropertySetFactory.create(new ByteArrayInputStream(b));
|
||||||
SummaryInformation s = (SummaryInformation) ps;
|
SummaryInformation s = (SummaryInformation) ps;
|
||||||
@ -163,9 +145,9 @@ public class TestEmptyProperties extends TestCase
|
|||||||
assertNull(s.getLastPrinted());
|
assertNull(s.getLastPrinted());
|
||||||
assertNull(s.getCreateDateTime());
|
assertNull(s.getCreateDateTime());
|
||||||
assertNull(s.getLastSaveDateTime());
|
assertNull(s.getLastSaveDateTime());
|
||||||
assertEquals(s.getPageCount(), 0);
|
assertEquals(s.getPageCount());
|
||||||
assertEquals(s.getWordCount(), 0);
|
assertNull(s.getWordCount());
|
||||||
assertEquals(s.getCharCount(), 0);
|
assertNull(s.getCharCount());
|
||||||
assertNull(s.getThumbnail());
|
assertNull(s.getThumbnail());
|
||||||
assertNull(s.getApplicationName());
|
assertNull(s.getApplicationName());
|
||||||
}
|
}
|
||||||
@ -174,10 +156,6 @@ public class TestEmptyProperties extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Runs the test cases stand-alone.</p>
|
* <p>Runs the test cases stand-alone.</p>
|
||||||
*
|
|
||||||
* @param args the command-line arguments (unused)
|
|
||||||
*
|
|
||||||
* @exception Throwable if any exception or error occurs
|
|
||||||
*/
|
*/
|
||||||
public static void main(final String[] args) throws Throwable
|
public static void main(final String[] args) throws Throwable
|
||||||
{
|
{
|
||||||
|
@ -54,10 +54,18 @@
|
|||||||
|
|
||||||
package org.apache.poi.hpsf.basic;
|
package org.apache.poi.hpsf.basic;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.util.*;
|
import java.io.File;
|
||||||
import junit.framework.*;
|
import java.io.FileNotFoundException;
|
||||||
import org.apache.poi.hpsf.*;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.poi.hpsf.HPSFException;
|
||||||
|
import org.apache.poi.hpsf.PropertySet;
|
||||||
|
import org.apache.poi.hpsf.PropertySetFactory;
|
||||||
|
import org.apache.poi.hpsf.Section;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -72,17 +80,22 @@ import org.apache.poi.hpsf.*;
|
|||||||
public class TestUnicode extends TestCase
|
public class TestUnicode extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
final static String POI_FS = "TestUnicode.xls";
|
static final String POI_FS = "TestUnicode.xls";
|
||||||
final static String[] POI_FILES = new String[]
|
static final String[] POI_FILES = new String[]
|
||||||
{
|
{
|
||||||
"\005DocumentSummaryInformation",
|
"\005DocumentSummaryInformation",
|
||||||
};
|
};
|
||||||
File data;
|
File data;
|
||||||
POIFile[] poiFiles;
|
POIFile[] poiFiles;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public TestUnicode(String name)
|
/**
|
||||||
|
* <p>Constructor</p>
|
||||||
|
*
|
||||||
|
* @param name the test case's name
|
||||||
|
*/
|
||||||
|
public TestUnicode(final String name)
|
||||||
{
|
{
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
@ -92,11 +105,11 @@ public class TestUnicode extends TestCase
|
|||||||
/**
|
/**
|
||||||
* <p>Read a the test file from the "data" directory.</p>
|
* <p>Read a the test file from the "data" directory.</p>
|
||||||
*/
|
*/
|
||||||
public void setUp() throws FileNotFoundException, IOException
|
protected void setUp() throws FileNotFoundException, IOException
|
||||||
{
|
{
|
||||||
final File dataDir =
|
final File dataDir =
|
||||||
new File(System.getProperty("HPSF.testdata.path"));
|
new File(System.getProperty("HPSF.testdata.path"));
|
||||||
data = new File(dataDir, POI_FS);
|
data = new File(dataDir, POI_FS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -108,23 +121,23 @@ public class TestUnicode extends TestCase
|
|||||||
*/
|
*/
|
||||||
public void testPropertySetMethods() throws IOException, HPSFException
|
public void testPropertySetMethods() throws IOException, HPSFException
|
||||||
{
|
{
|
||||||
POIFile poiFile = Util.readPOIFiles(data, POI_FILES)[0];
|
POIFile poiFile = Util.readPOIFiles(data, POI_FILES)[0];
|
||||||
byte[] b = poiFile.getBytes();
|
byte[] b = poiFile.getBytes();
|
||||||
PropertySet ps =
|
PropertySet ps =
|
||||||
PropertySetFactory.create(new ByteArrayInputStream(b));
|
PropertySetFactory.create(new ByteArrayInputStream(b));
|
||||||
Assert.assertTrue(ps.isDocumentSummaryInformation());
|
Assert.assertTrue(ps.isDocumentSummaryInformation());
|
||||||
Assert.assertEquals(ps.getSectionCount(), 2);
|
Assert.assertEquals(ps.getSectionCount(), 2);
|
||||||
Section s = (Section) ps.getSections().get(1);
|
Section s = (Section) ps.getSections().get(1);
|
||||||
Assert.assertEquals(s.getProperty(1),
|
Assert.assertEquals(s.getProperty(1),
|
||||||
new Integer(1200));
|
new Integer(1200));
|
||||||
Assert.assertEquals(s.getProperty(2),
|
Assert.assertEquals(s.getProperty(2),
|
||||||
new Long(4198897018l));
|
new Long(4198897018L));
|
||||||
Assert.assertEquals(s.getProperty(3),
|
Assert.assertEquals(s.getProperty(3),
|
||||||
"MCon_Info zu Office bei Schreiner");
|
"MCon_Info zu Office bei Schreiner");
|
||||||
Assert.assertEquals(s.getProperty(4),
|
Assert.assertEquals(s.getProperty(4),
|
||||||
"petrovitsch@schreiner-online.de");
|
"petrovitsch@schreiner-online.de");
|
||||||
Assert.assertEquals(s.getProperty(5),
|
Assert.assertEquals(s.getProperty(5),
|
||||||
"Petrovitsch, Wilhelm");
|
"Petrovitsch, Wilhelm");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -132,10 +145,10 @@ public class TestUnicode extends TestCase
|
|||||||
/**
|
/**
|
||||||
* <p>Runs the test cases stand-alone.</p>
|
* <p>Runs the test cases stand-alone.</p>
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args)
|
public static void main(final String[] args)
|
||||||
{
|
{
|
||||||
System.setProperty("HPSF.testdata.path",
|
System.setProperty("HPSF.testdata.path",
|
||||||
"./src/testcases/org/apache/poi/hpsf/data");
|
"./src/testcases/org/apache/poi/hpsf/data");
|
||||||
junit.textui.TestRunner.run(TestUnicode.class);
|
junit.textui.TestRunner.run(TestUnicode.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,9 +54,24 @@
|
|||||||
|
|
||||||
package org.apache.poi.hpsf.basic;
|
package org.apache.poi.hpsf.basic;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.util.*;
|
import java.io.EOFException;
|
||||||
import org.apache.poi.poifs.eventfilesystem.*;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.apache.poi.poifs.eventfilesystem.POIFSReader;
|
||||||
|
import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent;
|
||||||
|
import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -73,6 +88,9 @@ public class Util
|
|||||||
/**
|
/**
|
||||||
* <p>Reads bytes from an input stream and writes them to an
|
* <p>Reads bytes from an input stream and writes them to an
|
||||||
* output stream until end of file is encountered.</p>
|
* output stream until end of file is encountered.</p>
|
||||||
|
*
|
||||||
|
* @param in the input stream to read from
|
||||||
|
* @param out the output stream to write to
|
||||||
*/
|
*/
|
||||||
public static void copy(final InputStream in, final OutputStream out)
|
public static void copy(final InputStream in, final OutputStream out)
|
||||||
throws IOException
|
throws IOException
|
||||||
@ -88,8 +106,8 @@ public class Util
|
|||||||
read = in.read(b, 0, BUF_SIZE);
|
read = in.read(b, 0, BUF_SIZE);
|
||||||
if (read > 0)
|
if (read > 0)
|
||||||
out.write(b, 0, read);
|
out.write(b, 0, read);
|
||||||
else
|
else
|
||||||
eof = true;
|
eof = true;
|
||||||
}
|
}
|
||||||
catch (EOFException ex)
|
catch (EOFException ex)
|
||||||
{
|
{
|
||||||
@ -106,16 +124,16 @@ public class Util
|
|||||||
* into memory and thus does not cope well with large POI
|
* into memory and thus does not cope well with large POI
|
||||||
* filessystems.</p>
|
* filessystems.</p>
|
||||||
*
|
*
|
||||||
* @param file The name of the POI filesystem as seen by the
|
* @param poiFs The name of the POI filesystem as seen by the
|
||||||
* operating system. (This is the "filename".)
|
* operating system. (This is the "filename".)
|
||||||
*
|
*
|
||||||
* @return The POI files. The elements are ordered in the same way
|
* @return The POI files. The elements are ordered in the same way
|
||||||
* as the files in the POI filesystem.
|
* as the files in the POI filesystem.
|
||||||
*/
|
*/
|
||||||
public static POIFile[] readPOIFiles(final File poiFs)
|
public static POIFile[] readPOIFiles(final File poiFs)
|
||||||
throws FileNotFoundException, IOException
|
throws FileNotFoundException, IOException
|
||||||
{
|
{
|
||||||
return readPOIFiles(poiFs, null);
|
return readPOIFiles(poiFs, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -126,7 +144,7 @@ public class Util
|
|||||||
* files into memory and thus does not cope well with large POI
|
* files into memory and thus does not cope well with large POI
|
||||||
* filessystems.</p>
|
* filessystems.</p>
|
||||||
*
|
*
|
||||||
* @param file The name of the POI filesystem as seen by the
|
* @param poiFs The name of the POI filesystem as seen by the
|
||||||
* operating system. (This is the "filename".)
|
* operating system. (This is the "filename".)
|
||||||
*
|
*
|
||||||
* @param poiFiles The names of the POI files to be read.
|
* @param poiFiles The names of the POI files to be read.
|
||||||
@ -135,50 +153,49 @@ public class Util
|
|||||||
* as the files in the POI filesystem.
|
* as the files in the POI filesystem.
|
||||||
*/
|
*/
|
||||||
public static POIFile[] readPOIFiles(final File poiFs,
|
public static POIFile[] readPOIFiles(final File poiFs,
|
||||||
final String[] poiFiles)
|
final String[] poiFiles)
|
||||||
throws FileNotFoundException, IOException
|
throws FileNotFoundException, IOException
|
||||||
{
|
{
|
||||||
final List files = new ArrayList();
|
final List files = new ArrayList();
|
||||||
POIFSReader r = new POIFSReader();
|
POIFSReader r = new POIFSReader();
|
||||||
POIFSReaderListener pfl = new POIFSReaderListener()
|
POIFSReaderListener pfl = new POIFSReaderListener()
|
||||||
{
|
{
|
||||||
public void processPOIFSReaderEvent(POIFSReaderEvent event)
|
public void processPOIFSReaderEvent(final POIFSReaderEvent event)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
POIFile f = new POIFile();
|
POIFile f = new POIFile();
|
||||||
f.setName(event.getName());
|
f.setName(event.getName());
|
||||||
f.setPath(event.getPath());
|
f.setPath(event.getPath());
|
||||||
InputStream in = event.getStream();
|
InputStream in = event.getStream();
|
||||||
ByteArrayOutputStream out =
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
new ByteArrayOutputStream();
|
Util.copy(in, out);
|
||||||
Util.copy(in, out);
|
out.close();
|
||||||
out.close();
|
f.setBytes(out.toByteArray());
|
||||||
f.setBytes(out.toByteArray());
|
files.add(f);
|
||||||
files.add(f);
|
}
|
||||||
}
|
catch (IOException ex)
|
||||||
catch (IOException ex)
|
{
|
||||||
{
|
ex.printStackTrace();
|
||||||
ex.printStackTrace();
|
throw new RuntimeException(ex.getMessage());
|
||||||
throw new RuntimeException(ex.getMessage());
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
if (poiFiles == null)
|
||||||
if (poiFiles == null)
|
/* Register the listener for all POI files. */
|
||||||
/* Register the listener for all POI files. */
|
r.registerListener(pfl);
|
||||||
r.registerListener(pfl);
|
else
|
||||||
else
|
/* Register the listener for the specified POI files
|
||||||
/* Register the listener for the specified POI files
|
* only. */
|
||||||
* only. */
|
for (int i = 0; i < poiFiles.length; i++)
|
||||||
for (int i = 0; i < poiFiles.length; i++)
|
r.registerListener(pfl, poiFiles[i]);
|
||||||
r.registerListener(pfl, poiFiles[i]);
|
|
||||||
|
|
||||||
/* Read the POI filesystem. */
|
/* Read the POI filesystem. */
|
||||||
r.read(new FileInputStream(poiFs));
|
r.read(new FileInputStream(poiFs));
|
||||||
POIFile[] result = new POIFile[files.size()];
|
POIFile[] result = new POIFile[files.size()];
|
||||||
for (int i = 0; i < result.length; i++)
|
for (int i = 0; i < result.length; i++)
|
||||||
result[i] = (POIFile) files.get(i);
|
result[i] = (POIFile) files.get(i);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -188,19 +205,19 @@ public class Util
|
|||||||
*/
|
*/
|
||||||
public static void printSystemProperties()
|
public static void printSystemProperties()
|
||||||
{
|
{
|
||||||
Properties p = System.getProperties();
|
final Properties p = System.getProperties();
|
||||||
List names = new LinkedList();
|
final List names = new LinkedList();
|
||||||
for (Iterator i = p.keySet().iterator(); i.hasNext();)
|
for (Iterator i = p.keySet().iterator(); i.hasNext();)
|
||||||
names.add(i.next());
|
names.add(i.next());
|
||||||
Collections.sort(names);
|
Collections.sort(names);
|
||||||
for (Iterator i = names.iterator(); i.hasNext();)
|
for (final Iterator i = names.iterator(); i.hasNext();)
|
||||||
{
|
{
|
||||||
String name = (String) i.next();
|
String name = (String) i.next();
|
||||||
String value = (String) p.get(name);
|
String value = (String) p.get(name);
|
||||||
System.out.println(name + ": " + value);
|
System.out.println(name + ": " + value);
|
||||||
}
|
}
|
||||||
System.out.println("Current directory: " +
|
System.out.println("Current directory: " +
|
||||||
System.getProperty("user.dir"));
|
System.getProperty("user.dir"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user