jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fabián Mandelbaum <fmandelb...@gmail.com>
Subject Changing the content/properties of mix:versionable nodes without creating a new version
Date Tue, 06 Jul 2010 17:23:19 GMT
Hello there,

I have an nt:file node with the mix:versionable mixin. There are times
when I'd like to NOT create a new revision/version of the file when
storing the file. That is, the jcr:content node contents of the
nt:file change, but I don't want a new revision in the revision
history for that nt:file node.

The code I'm using now is something this:

    public String store(File file, String folder, boolean newVersion)
throws RepositoryException, FileNotFoundException {
        folder = folderName(folder);
        String nname = file.getName();
        String path = String.format("%s%s/%s", PATH, folder, nname); // NOI18N
        String fpath = path;
        Node rnode = null;
        if (session.itemExists(path)) { // Update
            Node fnode = ((Node)session.getItem(path));
            rnode = fnode.getNode("jcr:content"); // NOI18N
            if (newVersion) { // Create new version
        } else { // Add
            path = String.format("%s%s", PATH, folder);
            Node fnode = ((Node)session.getItem(path)).addNode(nname,
"nt:file"); // NOI18N
            rnode = fnode.addNode("jcr:content", "nt:resource"); // NOI18N
            rnode.addMixin("mix:versionable"); // NOI18N
            fnode.addMixin("mix:lockable"); // NOI18N
MimeUtils.getInstance().getMimeType(file)); // NOI18N
        Calendar lastModified = Calendar.getInstance();
        rnode.setProperty("jcr:lastModified", lastModified); // NOI18N
        rnode.setProperty("jcr:data", new AutoCloseInputStream(new
FileInputStream(file))); // NOI18N
        path = String.format("%s%s/%s", PPATH, folder, nname); // NOI18N
        Node pnode = null;
        if (session.itemExists(path)) {
            pnode = (Node)session.getItem(path);
        } else {
            path = String.format("%s%s", PPATH, folder); // NOI18N
            pnode = ((Node)session.getItem(path)).addNode(nname);
            pnode.addMixin("mix:lockable"); // NOI18N
        pnode.setProperty("cco_size", file.length()); // NOI18N
        if (newVersion) {
        return fpath;

PATH and PPATH are constants with base path for content and custom
properties, respectively, folderName is a name-normalizing function to
handle spaces and other 'strange' chars. The rest is fairly standard
or self-explained

If I first call this function with newVersion = true, a revision 1.0
is created, so far, so good. When I call it again, for the same file,
with newVersion = false (because now I just want to update the file's
content node without creating a new version), I get the following

javax.jcr.version.VersionException: Unable to perform operation. Node
is checked-in.
	at org.apache.jackrabbit.core.ItemValidator.checkCondition(ItemValidator.java:308)
	at org.apache.jackrabbit.core.ItemValidator.checkModify(ItemValidator.java:274)
	at org.apache.jackrabbit.core.NodeImpl.checkSetProperty(NodeImpl.java:1381)
	at org.apache.jackrabbit.core.NodeImpl.setProperty(NodeImpl.java:2410)
	at com.calenco.repository.ContentDAO.store(ContentDAO.java:189)

So. Can I modify the code above in any way to be able to create
versions of files as I wish, or do mix:versionable nodes must always
have a new version created when one of its properties change?

Thanks in advance for your answers.

Fabián Mandelbaum
IS Engineer

View raw message