JavaScript access to the versionHistory property?

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2008 09:36 AM
I'm trying in vain to find a means of examining the version history of a document, using the Javascript API. All I need is the number versions, and the size of each version.
The documentation suggests that FreeMarker can access a nodes 'versionHistory' node, but the JavaScript certainly cannot.
I'm in the process of writing a disk-usage tool, and not having visibility over the document history is a teensy bit of a sticking point 🙂
Can anyone tell me where I'm going wrong?
M.
The documentation suggests that FreeMarker can access a nodes 'versionHistory' node, but the JavaScript certainly cannot.
I'm in the process of writing a disk-usage tool, and not having visibility over the document history is a teensy bit of a sticking point 🙂
Can anyone tell me where I'm going wrong?
M.
Labels:
- Labels:
-
Archive
1 REPLY 1

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2008 11:26 AM
Found it! The solution was use the power of the Rhino Javascript engine to access bits of its Java environment.
The ScriptNode object has a protected 'services' field. Once that can be accessed, everything else falls into place …
Once getServices() is called with a ScriptNode object, we can then call getHistory() to get a Java array of Version objects. Given a Version object, getVersionSize() can be called to get the size of its content.
It's a bit ugly, but a worthy demonstration of Rhinos power.
M.
The ScriptNode object has a protected 'services' field. Once that can be accessed, everything else falls into place …
var PROP_CONTENT = Packages.org.alfresco.model.ContentModel.PROP_CONTENT;var versionService = null;var nodeService = null;function getServices( doc ){ // *BEWARE* - HERE BE DRAGONS var servicesField = doc.getClass().getDeclaredField( "services" ); servicesField.setAccessible( true ); // ick - yuck - nasty - but necessary var serviceRegistry = servicesField.get( doc ); versionService = serviceRegistry.getVersionService(); nodeService = serviceRegistry.getNodeService();}function getHistory( doc ){ return versionService.getVersionHistory( doc.nodeRef ).getAllVersions().toArray();}function getVersionSize( version ){ return nodeService.getProperty( version.getFrozenStateNodeRef(), PROP_CONTENT ).getSize();}
Once getServices() is called with a ScriptNode object, we can then call getHistory() to get a Java array of Version objects. Given a Version object, getVersionSize() can be called to get the size of its content.
It's a bit ugly, but a worthy demonstration of Rhinos power.
M.
