Return-Path: Delivered-To: apmail-jackrabbit-users-archive@locus.apache.org Received: (qmail 47649 invoked from network); 23 Jul 2008 15:33:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 Jul 2008 15:33:16 -0000 Received: (qmail 11749 invoked by uid 500); 23 Jul 2008 15:33:14 -0000 Delivered-To: apmail-jackrabbit-users-archive@jackrabbit.apache.org Received: (qmail 11729 invoked by uid 500); 23 Jul 2008 15:33:14 -0000 Mailing-List: contact users-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@jackrabbit.apache.org Delivered-To: mailing list users@jackrabbit.apache.org Received: (qmail 11718 invoked by uid 99); 23 Jul 2008 15:33:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Jul 2008 08:33:14 -0700 X-ASF-Spam-Status: No, hits=3.2 required=10.0 tests=HTML_MESSAGE,NORMAL_HTTP_TO_IP,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [209.85.198.229] (HELO rv-out-0506.google.com) (209.85.198.229) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Jul 2008 15:31:22 +0000 Received: by rv-out-0506.google.com with SMTP id k40so2290308rvb.31 for ; Wed, 23 Jul 2008 08:31:47 -0700 (PDT) Received: by 10.141.83.15 with SMTP id k15mr121256rvl.289.1216827107084; Wed, 23 Jul 2008 08:31:47 -0700 (PDT) Received: by 10.141.122.15 with HTTP; Wed, 23 Jul 2008 08:31:46 -0700 (PDT) Message-ID: <272c2bf60807230831jccddfadkf3f178bbdb40660d@mail.gmail.com> Date: Wed, 23 Jul 2008 11:31:46 -0400 From: "Nick Stuart" To: users@jackrabbit.apache.org Subject: Re: saving files In-Reply-To: <82670ba40807230829g45f6948cq4a7abb1637d1f98@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_40796_13910919.1216827107063" References: <82670ba40807221022w7d56f206h2d5ca6e18385b645@mail.gmail.com> <272c2bf60807230722i2243524g143804696c59f613@mail.gmail.com> <82670ba40807230735n3164b1a3qda1eb5b391a7f675@mail.gmail.com> <272c2bf60807230738r3f00d87bic595d0609d66fa03@mail.gmail.com> <82670ba40807230756x2e1757c7vc07266be8a345a8b@mail.gmail.com> <272c2bf60807230801x4f8165f6j53df14ef42aa8494@mail.gmail.com> <82670ba40807230805k3c02bc27x343cdc36bf3e92b1@mail.gmail.com> <272c2bf60807230822o4d6fc73bua521ded7bb9c2b66@mail.gmail.com> <82670ba40807230827h2195c673od788e1b68acc5af3@mail.gmail.com> <82670ba40807230829g45f6948cq4a7abb1637d1f98@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_40796_13910919.1216827107063 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hmm, wouldn't think the parent node type would have any effect on the subnodes at all, but I do put all my files in folder nodes so never had this case. A bit strange, but there might be a valid reason for it. *shrug* On Wed, Jul 23, 2008 at 11:29 AM, Michael Harris wrote: > yep > > On Wed, Jul 23, 2008 at 11:27 AM, Michael Harris < > michael.e.harris@gmail.com> > wrote: > > > Im using a TransientRepository. > > > > I wonder if its because Im putting the nt:file in the root node and not > in > > a node of type folder. > > > > > > On Wed, Jul 23, 2008 at 11:22 AM, Nick Stuart < > nstuart@speranzasystems.com> > > wrote: > > > >> Hm, that is odd. Are you using a file DataStore or is everything being > >> saved > >> in the database? > >> > >> I have a simple DataStore element in my repo config like this: > >> > >> > >> > >> > >> > >> (syntax might be different for 1.4, cant remember) > >> > >> Again, this shouldn't matter as it worked before when saving to > database. > >> The other thing to look at if you do have a file DataStore is the > >> directory > >> itself. It should have some folders and files in there, all with weird > >> names, but you should be able to find what you added to the repo. And > >> changing it to the FileDataStore lets you test this out too, where I'm > not > >> quite sure where to look if things are in the DB. > >> > >> On Wed, Jul 23, 2008 at 11:05 AM, Michael Harris < > >> michael.e.harris@gmail.com> > >> wrote: > >> > >> > yeah tried that and no dice. wierd eh. I confirmed that the testFile > >> has > >> > content in it.... > >> > > >> > On Wed, Jul 23, 2008 at 11:01 AM, Nick Stuart < > >> nstuart@speranzasystems.com > >> > > > >> > wrote: > >> > > >> > > Well the only thats really different between that and my code is > >> setting > >> > > mimeType and encoding to empty. I don't touch the encoding at all, > and > >> > > always set the mimeType to something even if it is just text/plain. > >> Other > >> > > then that it looks about the same. Try hardcoding at least mimeType > to > >> > > 'text/plain' and remove the encoding bit and see if you get better > >> > results. > >> > > That may be screwing up the retrieval bit, not sure why it would > >> though. > >> > > > >> > > -Nick > >> > > > >> > > On Wed, Jul 23, 2008 at 10:56 AM, Michael Harris < > >> > > michael.e.harris@gmail.com> > >> > > wrote: > >> > > > >> > > > yeah man I tried writing the retrieved stream to a file, it is > >> empty. > >> > > The > >> > > > file that I save definitely has content (confirmed by less). > >> > > > > >> > > > Perhaps you can take a look see (the code isn't complicated); > having > >> > more > >> > > > experience than me you could identify obvious problems pretty > >> quickly. > >> > > > > >> > > > here is the save code > >> > > > > >> > > > public void saveFile(File file, Session session) throws > Exception > >> { > >> > > > // create the file node - see section 6.7.22.6 of the spec > >> > > > > >> > > > 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", ""); > >> > > > FileInputStream fileInputStream = new > FileInputStream(file); > >> > > > resNode.setProperty("jcr:data", fileInputStream); > >> > > > Calendar lastModified = Calendar.getInstance(); > >> > > > lastModified.setTimeInMillis(file.lastModified()); > >> > > > resNode.setProperty("jcr:lastModified", lastModified); > >> > > > > >> > > > session.save(); > >> > > > } > >> > > > > >> > > > and here is the test code > >> > > > > >> > > > protected void setUp() throws Exception { > >> > > > super.setUp(); > >> > > > String testFileName = "/tmp/" + getName() + ".txt"; > >> > > > FileWriter fw = new FileWriter(testFileName); > >> > > > fw.write("some content"); > >> > > > fw.flush(); > >> > > > testFile = new File(testFileName); > >> > > > } > >> > > > > >> > > > > >> > > > public void testSaveFile() throws Exception { > >> > > > Session session = getSession(); > >> > > > dao.saveFile(testFile, session); > >> > > > > >> > > > Node root = session.getRootNode(); > >> > > > Node fileNode = root.getNode(testFile.getName()); > >> > > > Node fileDetails = fileNode.getNode("jcr:content"); > >> > > > > >> > > > Property fileProp = fileDetails.getProperty("jcr:data"); > >> > > > InputStream retrievedStream = fileProp.getStream(); > >> > > > > >> > > > FileOutputStream fos = new > >> > > > FileOutputStream("/tmp/retrievedFile.txt"); > >> > > > byte[] buf = new byte[256]; > >> > > > int read = 0; > >> > > > while ((read = retrievedStream.read(buf)) > 0) { > >> > > > fos.write(buf, 0, read); > >> > > > fos.flush(); > >> > > > } > >> > > > > >> > > > > >> > > > } > >> > > > > >> > > > On Wed, Jul 23, 2008 at 10:38 AM, Nick Stuart < > >> > > nstuart@speranzasystems.com > >> > > > > > >> > > > wrote: > >> > > > > >> > > > > I know that works as I've used it extensively. I am on a 1.5 > >> build, > >> > but > >> > > > it > >> > > > > was working with the 1.4.x build I started with. Have you looked > >> at > >> > the > >> > > > > stream going in to make sure something is actually being saved? > >> You > >> > > > > obviously have the node and property there or otherwise you > would > >> be > >> > > > > getting > >> > > > > a RepositoryException. > >> > > > > > >> > > > > I would check to make sure you are saving everything you think > you > >> > are. > >> > > > > Also, try just using the stream and ignore the debugger (it > might > >> be > >> > > > lying > >> > > > > to you, who knows). But it looks like everything is in order. > >> > > > > > >> > > > > On Wed, Jul 23, 2008 at 10:35 AM, Michael Harris < > >> > > > > michael.e.harris@gmail.com> > >> > > > > wrote: > >> > > > > > >> > > > > > Nick > >> > > > > > > >> > > > > > thanx for the reply. when I do that and inspect the returned > >> > stream > >> > > in > >> > > > > the > >> > > > > > eclipse debugger there is nothing in it. > >> > > > > > > >> > > > > > michael. > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > On Wed, Jul 23, 2008 at 10:22 AM, Nick Stuart < > >> > > > > nstuart@speranzasystems.com > >> > > > > > > > >> > > > > > wrote: > >> > > > > > > >> > > > > > > All you can really do is retrieve the InputStream for said > >> file. > >> > > > Which > >> > > > > > > should be enough, and the nodes hold the rest of the info if > >> you > >> > > need > >> > > > > it > >> > > > > > > obviously (file name, type, etc). > >> > > > > > > > >> > > > > > > Something like: > >> > > > > > > > >> > > > > > > Node resNode = fileNode.getNode("jcr:content"); > >> > > > > > > resNode.getProperty("jcr:data").getStream(); > >> > > > > > > > >> > > > > > > Where fileNode is the jcr:file node type. You wont be able > to > >> > > > actually > >> > > > > > get > >> > > > > > > a > >> > > > > > > File object becuase thats part of JCR, that it extracts that > >> > stuff > >> > > > away > >> > > > > > > from > >> > > > > > > you, and you just deal with the contents and info. > >> > > > > > > > >> > > > > > > -Nick > >> > > > > > > > >> > > > > > > On Wed, Jul 23, 2008 at 10:16 AM, Michael Harris < > >> > > > > > > michael.e.harris@gmail.com> > >> > > > > > > wrote: > >> > > > > > > > >> > > > > > > > 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 < > >> > > > > > > > michael.e.harris@gmail.com> > >> > > > > > > > wrote: > >> > > > > > > > > >> > > > > > > > > comments inline below. Thank you for the response. > >> > > > > > > > > > >> > > > > > > > > On Tue, Jul 22, 2008 at 2:20 PM, Julian Reschke < > >> > > > > > julian.reschke@gmx.de > >> > > > > > > > > >> > > > > > > > > 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 > >> > > > > > > > > >> > > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > -- > >> > > > > > --------------------- > >> > > > > > Michael Harris > >> > > > > > > >> > > > > > >> > > > > >> > > > > >> > > > > >> > > > -- > >> > > > --------------------- > >> > > > Michael Harris > >> > > > > >> > > > >> > > >> > > >> > > >> > -- > >> > --------------------- > >> > Michael Harris > >> > > >> > > > > > > > > -- > > --------------------- > > Michael Harris > > > > > > -- > --------------------- > Michael Harris > ------=_Part_40796_13910919.1216827107063--