ladies and gentlemen
its still not obvious to me how to retrieve the saved file. Can someone
please illuminate the situation?
thanx in advance.
On Tue, Jul 22, 2008 at 3:05 PM, Michael Harris <[EMAIL PROTECTED]>
wrote:
> comments inline below. Thank you for the response.
>
> On Tue, Jul 22, 2008 at 2:20 PM, Julian Reschke <[EMAIL PROTECTED]>
> wrote:
>
>> 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?
>>
>
> I got the code from the wiki. It had the mimetype and the encoding type.
> I modified the code and just put empty strings in for now.
>
>
>
>>
>> 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.
>>
>
> So does it mean anything to say "Can I save the file itself?"
>
>
> so the above code I put into a DAO method saveFile(File, Session). In the
> test for that method, i have
>
> Node root = session.getRootNode();
> // testFile is the file in the Dao
> Node fileNode = root.getNode(testFile.getName());
> Node fileDetails = fileNode.getNode("jcr:content");
>
> Property fileProp = fileDetails.getProperty("jcr:data");
>
> I am trying to get at the file contents, which is just a string "some
> content".
>
> on the property retrieved I dont see the file content (Im in eclipse's
> debugger). How do I retrieve the file. What would a
> loadFile(Session, filename) method look like?
>
>
>
>
>
>
>> 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
>>
>
>
>
> --
> ---------------------
> Michael Harris
>
--
---------------------
Michael Harris