Exploring possibilities with Apache POI

Recently my colleagues and I were tasked with figuring out how to 'track' documents that leave the KnowledgeTree system. Our objective was to allow a user to download / check out a document, make their changes in their preferred tool and then upload it back to KnowledgeTree. Obviously, this is already possible, the only difference now would be that we would need to be able to determine the origin of that document (the actual document in KnowledgeTree), programatically without relying on file names or any other potentially ambiguous data.
We focused initially on one of the most popular types of file, being the Microsoft Office format(s). Our research lead us to the Apache POI project which is a Java API to access Microsoft format files. This API allows access to not only document data (text, embedded objects, etc) but for our needs, it allows read and write access to the document meta data and properties. This allowed us to implement some code which can now embed a GUID into documents, without damaging or making any visible changes to the document.
What does it all mean? Well, in future, when documents enter the KnowledgeTree system, a GUID can be added to them, and upon their return either via the KnowledgeTree Tools, Drop Box, Hot Folders and so on, this GUID can be retrieved and we can intelligently put the document back into it's correct place in the repository making a user's life much easier! Keep an eye out for this feature in future.
Code snippet of inserting a GUID into a document (Opened as POIFSFileSystem)
/* We have already opened poifs as a POIFSFileSystem */
DirectoryEntry dir = poifs.getRoot();
DocumentSummaryInformation dsi;
try
{
/* We are now going to get the virtual document out of the POIFS containing metadata */
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);
}
catch (Exception ex)
{
/* There is no document summary information yet. We have to create a
* new one. */
dsi = PropertySetFactory.newDocumentSummaryInformation();
}
/* We are using CustomProperties to save our info */
CustomProperties customProperties = dsi.getCustomProperties();
if(customProperties == null) {
customProperties = new CustomProperties();
}
customProperties.put("myGuid", "3F2504E0-4F89-11D3-9A0C-0305E82C3301");
dsi.setCustomProperties(customProperties);
/* Either save the document here or continue doing other tasks! */
Comments
Post new comment