jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fabián Mandelbaum <fmandelb...@gmail.com>
Subject Re: How do i get a stored file back from the repository?
Date Tue, 11 Dec 2007 14:44:09 GMT
File f = new File("file_retrieved_from_the_repo.txt");
Node contentNode =
instance.session.getRootNode().getNode("/hello/world/test/jcr:content");
InputStream contentStream = contentNode.getProperty("jcr:data").getStream();
IOUtils.copy(contentStream, FileUtils.openOutputStream(f));

Please note the following:

* This example was written QUICKLY, so it may have errors, double check
everything, notably the XPATH for the getNode().

* The example uses IOUtils and FileUtils from Apache's Common IO lib
(http://commons.apache.org/io/), you can copy the stream as you wish.

Good luck!

Christian Cronen escribió:
> hey there, 
> i have saved a simple file called example.txt in my repository with the 
> following code lines. 
>                                 root = instance.session.getRootNode();
>                                 Node hello = root.addNode("hello");
>                                 Node world = hello.addNode("world");
>                                 world.setProperty("message", "Hello, 
> world!");
>                                 Node test = world.addNode("test", 
> "nt:file");
>                                 Node res = test.addNode("jcr:content", 
> "nt:resource");
>  
>                                 File testfile = new 
> File("D:/example.txt");
>  
>                                 world.setProperty("filename", 
> testfile.getName() );
>                                 world.setProperty("size", 
> testfile.length() );
>                                 FileInputStream in = new 
> FileInputStream(testfile);
>                                 res.setProperty("jcr:encoding", "");
>                                 res.setProperty("jcr:mimeType", 
> "text/plain");
>                                 res.setProperty("jcr:data", in );
>  
>                                 Calendar lastModified = 
> Calendar.getInstance();
>                                 lastModified.setTimeInMillis( 
> testfile.lastModified() );
>  
>                                 res.setProperty("jcr:lastModified", 
> lastModified);
>  
>                                 instance.session.save();
> But now i could not get the file back from the repository. So my question 
> is what i have to do to get it back. 
>
> Kind regards
> Christian
>
>
> Christian Cronen
> Diplom-Student 
>
> maxence solutions gmbh 
> phone
> fax
> cell
> internet
> skype 
> +49-(0)-2133-2599-0
> +49-(0)-2133-2599-29
> +49-(0)-160-90532507
> christian.cronen@maxence.de
> christian.cronen
>
>
>
> Am Weissen Stein 1
> Stuerzelbergcenter
> D - 41541 Dormagen
> Sitz der Gesellschaft: Dormagen
> Handelsregister: HRB 12561, Neuss
> Geschäftsführer: Dipl.-Math. Ralf Granderath 
> www.maxence.de
>
>
>   


Mime
View raw message