jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Klimetschek <aklim...@day.com>
Subject Re: Versioning nt:file Types
Date Wed, 18 Mar 2009 14:36:04 GMT
On Wed, Mar 18, 2009 at 3:25 PM, Fernando Cabredo <fcabredoph@yahoo.com> wrote:
> I have a file located at /pics/picture297.jpg and I would like to add my c://download/picture297.jpg
as a new version into the node.
> I have the code below for the above problem.
>             file = new File("c://download//picture297.jpg");
>             Node root = session.getRootNode();
>             Node fileNode = root.getNode("/pics/picture297.jpg");
>             fileNode.checkout();
>             fileNode.addMixin("mix:versionable");
>             Node resNode = fileNode.addNode ("jcr:content", "nt:resource");
>             resNode.setProperty ("jcr:mimeType", mimeType);
>             resNode.setProperty ("jcr:encoding", "");
>             resNode.setProperty ("jcr:data", new FileInputStream (file));
>             Calendar lastModified = Calendar.getInstance ();
>             lastModified.setTimeInMillis (file.lastModified ());
>             resNode.setProperty ("jcr:lastModified", lastModified);
>             session.save();
> However, it is causing  the following errors:
>   javax.jcr.ItemExistsException: /pics/picture297.jpg/jcr:content
>    at org.apache.jackrabbit.rmi.server.ServerObject.getRepositoryException(ServerObject.java:110)
>    at org.apache.jackrabbit.rmi.server.ServerNode.addNode(ServerNode.java:82)
>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

Well, don't do

    Node resNode = fileNode.addNode ("jcr:content", "nt:resource");

if the "jcr:content" subnode already exists. In this case do getNode().

> I would like also to list the file names of the different versions created on the node.

The filename is stored in the nodename of the nt:file node. If it is
versioned, only its properties and the jcr:content subnode will be
stored with each version. The name doesn't change. To solve that, you
can set a property on the node (you'll need a custom mixin for that,
because nt:file doesn't allow unstructured date) and set it different
in each version. But you probably also want to make the node name more
generic, otherwise the node would always be named after file that
created the first version. But that depends on the semantics of your
app and content.


Alexander Klimetschek

View raw message