jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nicholas_dipiazza <nicho...@xerceo.com>
Subject Re: Get versioned file data
Date Wed, 08 Oct 2008 14:28:57 GMT

All of my attempts to get this to work have failed.

My jcr:data is always PropertyNotFoundException from the frozen node. Any
idea why that might happen? 



Grizz Lee wrote:
> 
> 
> 
> 
> Hello,
>  
> I'm having trouble to get the file data of a specific version of a
> versioned file from the repository.
>  
> 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,
>  
> grizz
>  
>  
> // 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());
> version1Node.addMixin("mix:versionable");
> getSession().save();
> version1Node.checkin();
>  
> file = new File(...);
> mimeType = mt.getContentTypeFor(file.getName());
> if (mimeType==null) mimeType="application/octet-stream";
> Node version2Node = masterNode.getNode("jcr:content");
> version2Node.checkout();
> version2Node.setProperty("jcr:mimeType", mimeType);
> version2Node.setProperty("jcr:encoding", "");
> version2Node.setProperty("jcr:data", new FileInputStream(file));
> version2Node.setProperty("jcr:lastModified", Calendar.getInstance());
> getSession().save();
> version2Node.checkin();
>  
>  
> // 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!
> http://get.live.com/toolbar/overview
> 

-- 
View this message in context: http://www.nabble.com/Get-versioned-file-data-tp9253339p19879917.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Mime
View raw message