I answered half of my own question. For Office 2003 and prior files, the
following code works fine:
// Open the file
//
InputStream fileStream = new FileInputStream(input);
POIFSFileSystem poifs = new POIFSFileSystem(fileStream);
fileStream.close();
DirectoryEntry dir = poifs.getRoot();
// Retrieve the custom properties from the file
//
DocumentSummaryInformation dsi = null;
DocumentEntry dsiEntry = (DocumentEntry)
dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
DocumentInputStream dis = new DocumentInputStream(dsiEntry);
PropertySet ps = new PropertySet(dis);
dis.close();
dsi = new DocumentSummaryInformation(ps);
CustomProperties properties = dsi.getCustomProperties();
if (properties == null)
properties = new CustomProperties();
// Clear all the custom properties
//
Set names = properties.keySet();
java.util.Iterator it = names.iterator();
while (it.hasNext())
{
String name = (String)it.next();
Object value = properties.get(name);
if (value instanceof String)
{
properties.put(name, " ");
}
else
{
properties.put(name, 0);
}
}
// Save the file with it's updated custom properties
//
dsi.setCustomProperties(properties);
dsi.write(poifs.getRoot(),
DocumentSummaryInformation.DEFAULT_STREAM_NAME);
OutputStream out = new FileOutputStream(input);
poifs.writeFilesystem(out);
out.close();