You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Grizz Lee <gr...@hotmail.com> on 2007/03/01 17:42:37 UTC

Get versioned file data



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

Re: Get versioned file data

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 3/1/07, Julian Reschke <ju...@gmx.de> wrote:
> Grizz Lee schrieb:
>  > ...
> > Property property = jcrVersion.getProperty("jcr:data"); // throws javax.jcr.PathNotFoundException
> > ...
>
> Property property =
> jcrVersion.getNode("jcr:frozenNode").getProperty("jcr:data");

Or even:

Property property = jcrVersion.getProperty("jcr:frozenNode/jcr:data");

BR,

Jukka Zitting

Re: Get versioned file data

Posted by Julian Reschke <ju...@gmx.de>.
Grizz Lee schrieb:
 > ...
> Property property = jcrVersion.getProperty("jcr:data"); // throws javax.jcr.PathNotFoundException
> ...

Property property = 
jcrVersion.getNode("jcr:frozenNode").getProperty("jcr:data");

Best regards, Julian

Re: Get versioned file data

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 3/1/07, Grizz Lee <gr...@hotmail.com> wrote:
> I'm having trouble to get the file data of a specific version of a versioned file
> from the repository.
> [...]
> - 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

The frozen contents of the node at checkin time are stored as the
jcr:frozenNode child of the version node. Thus you can access the
versioned contents of the file as jcr:frozenNode/jcr:data.

BR,

Jukka Zitting

Re: Get versioned file data

Posted by Alexander Klimetschek <ak...@day.com>.
Hi,

You are mentioning the frozen node, but in the code below you don't access it.

Property property = jcrVersion.getProperty("jcr:data");

should be

Property property =
jcrVersion.getNode("jcr:frozenNode").getProperty("jcr:data");

And if you already do that, you might actually use an older version of
jackrabbit core with a bug related to that. Someone else had exactly
the same problem recently:
http://markmail.org/message/b3ux3gruvtf4wq76 (look at the last
messages of the thread for the "solution").

Regards,
Alex

On Wed, Oct 8, 2008 at 4:28 PM, nicholas_dipiazza <ni...@xerceo.com> wrote:
>
> 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.
>
>



-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: Get versioned file data

Posted by nicholas_dipiazza <ni...@xerceo.com>.
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.