jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Grizz Lee <grizz_...@hotmail.com>
Subject Get versioned file data
Date Thu, 01 Mar 2007 16:42:37 GMT

I'm having trouble to get the file data of a specific version of a versioned file from the
What I do is the following:
- Create a jcr:content node of type nt:resource.
- Upload version 1.0 of the file to jcr:content
- Make the jcr:content versionable 
- Save and checkin
- Upload version 1.1 of the file to jcr:content
- Save and checkin
- Get the version history of jcr:content
- Get the version with the correct version name from the history
- Get the property jcr:data of the version throws a javax.jcr.PathNotFoundException
Getting the latest version works ok.
Listing the version history works ok.
I expect that the onParentVersion attribute of the common jcr:data property is COPY so that
should be ok.
Can anybody help me get the jcr:data property from a version?
Kind regards,
// Code to create the versions:
File file = new File(...);
MimeTable mt = MimeTable.getDefaultTable();
String mimeType = mt.getContentTypeFor(file.getName());
if (mimeType==null) mimeType="application/octet-stream";
Node version1Node = masterNode.addNode("jcr:content", "nt:resource");
version1Node.setProperty("jcr:mimeType", mimeType);
version1Node.setProperty("jcr:encoding", "");
version1Node.setProperty("jcr:data", new FileInputStream(file));
version1Node.setProperty("jcr:lastModified", Calendar.getInstance());
file = new File(...);
mimeType = mt.getContentTypeFor(file.getName());
if (mimeType==null) mimeType="application/octet-stream";
Node version2Node = masterNode.getNode("jcr:content");
version2Node.setProperty("jcr:mimeType", mimeType);
version2Node.setProperty("jcr:encoding", "");
version2Node.setProperty("jcr:data", new FileInputStream(file));
version2Node.setProperty("jcr:lastModified", Calendar.getInstance());
// Code to retrieve the latest version
Node contentNode = masterNode.getNode("jcr:content");
Property property = jcrVersion.getProperty("jcr:data"); // OK
InputStream stream = property.getStream();
// Code to retrieve the version with versionName
Node contentNode = masterNode.getNode("jcr:content");
VersionHistory history = contentNode.getVersionHistory();
Version jcrVersion = history.getVersion(versionName);
Property property = jcrVersion.getProperty("jcr:data"); // throws javax.jcr.PathNotFoundException
InputStream stream = property.getStream();
Search from any Web page with powerful protection. Get the FREE Windows Live Toolbar Today!
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message