Methods Summary |
---|
protected org.apache.poi.poifs.property.Property[] | getVBAProperties(org.apache.poi.poifs.filesystem.POIFSFileSystem fs)
String _VBA_PROJECT_CUR = "_VBA_PROJECT_CUR";
String VBA = "VBA";
DirectoryEntry root = fs.getRoot();
DirectoryEntry vba_project = (DirectoryEntry)root.getEntry(_VBA_PROJECT_CUR);
DirectoryNode vba = (DirectoryNode)vba_project.getEntry(VBA);
DirectoryProperty p = (DirectoryProperty)vba.getProperty();
ArrayList lst = new ArrayList();
for (Iterator it = p.getChildren(); it.hasNext();){
Property ch = (Property)it.next();
lst.add(ch);
}
return (Property [])lst.toArray(new Property[ 0 ]);
|
public void | setUp()
String home = System.getProperty("HSSF.testdata.path");
testFile = new File(home + "/39234.xls");
|
public void | testSerialization()Serialize file system and verify that the order of properties is the same as in the original file.
InputStream is = new FileInputStream(testFile);
POIFSFileSystem fs = new POIFSFileSystem(is);
is.close();
ByteArrayOutputStream out = new ByteArrayOutputStream();
fs.writeFilesystem(out);
out.close();
is = new ByteArrayInputStream(out.toByteArray());
fs = new POIFSFileSystem(is);
is.close();
Property[] props = getVBAProperties(fs);
Arrays.sort(props, new DirectoryProperty.PropertyComparator());
assertEquals(_entries.length, props.length);
for (int i = 0; i < props.length; i++) {
assertEquals(_entries[i], props[i].getName());
}
|
public void | testSortProperties()Test sorting of properties in DirectoryProperty
InputStream is = new FileInputStream(testFile);
POIFSFileSystem fs = new POIFSFileSystem(is);
is.close();
Property[] props = getVBAProperties(fs);
assertEquals(_entries.length, props.length);
// (1). See that there is a problem with the old case-sensitive property comparartor
Arrays.sort(props, new CaseSensitivePropertyComparator());
try {
for (int i = 0; i < props.length; i++) {
assertEquals(_entries[i], props[i].getName());
}
fail("case-sensitive property comparator returns properties in wrong order");
} catch (ComparisonFailure e){
; // as expected
}
// (2) Verify that the fixed proeprty comparator works right
Arrays.sort(props, new DirectoryProperty.PropertyComparator());
for (int i = 0; i < props.length; i++) {
assertEquals(_entries[i], props[i].getName());
}
|