jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Julian Reschke <julian.resc...@gmx.de>
Subject Re: saving files
Date Tue, 22 Jul 2008 18:20:10 GMT
Michael Harris wrote:
> hey all,
> more newb questions here.
> Want to save a file in the repository.  found this on the wiki
> Node folderNode = session.getRootNode();
>         Node fileNode = folderNode.addNode(file.getName(), "nt:file");
>         // create the mandatory child node - jcr:content
>         Node resNode = fileNode.addNode("jcr:content", "nt:resource");
>         resNode.setProperty("jcr:mimeType", "");
>         resNode.setProperty("jcr:encoding", "");
 > ...

That is very bad advice. If you don't know mimeType or encoding, do not 
set it.

Where did you find that?

>         resNode.setProperty("jcr:data", new FileInputStream(file));
>         Calendar lastModified = Calendar.getInstance();
>         lastModified.setTimeInMillis(file.lastModified());
>         resNode.setProperty("jcr:lastModified", lastModified);
> Is the file itself being put in the repository (jcr.data) or just the
> content?

The contents.

> Do I even need the resNode?  Can I just save the file into the fileNode?

Not unless you use a different node type.

> Finally, we are going to need to lock the file (which is why we are using
> jcr).  Is it possible to attach info (like who owns the lock) to the locked
> file?

To some extent, that's part of the JCR locking model (it remembers who 
owns the lock, and exposes the information both in the API and on 
properties defined in mix:lockable).

> Thanx.  This community has been quite helpful.

BR, Julian

View raw message