Return-Path: Delivered-To: apmail-jackrabbit-users-archive@locus.apache.org Received: (qmail 63608 invoked from network); 4 Jul 2007 10:15:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Jul 2007 10:15:23 -0000 Received: (qmail 89314 invoked by uid 500); 4 Jul 2007 10:15:25 -0000 Delivered-To: apmail-jackrabbit-users-archive@jackrabbit.apache.org Received: (qmail 89298 invoked by uid 500); 4 Jul 2007 10:15:24 -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 89289 invoked by uid 99); 4 Jul 2007 10:15:24 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jul 2007 03:15:24 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [89.149.215.132] (HELO europe.computation.de) (89.149.215.132) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jul 2007 03:15:20 -0700 Received: (qmail 20899 invoked by uid 89); 4 Jul 2007 10:15:02 -0000 Received: from unknown (HELO hendrik) (141.100.40.72) by 0 with SMTP; 4 Jul 2007 10:15:02 -0000 From: "Hendrik Beck \(camunda\)" To: Subject: RE: Displaying images stored in a Jackrabbit repository in a web page Date: Wed, 4 Jul 2007 17:15:09 +0700 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0406_01C7BE5E.E074E930" X-Mailer: Microsoft Office Outlook, Build 11.0.5510 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 In-Reply-To: <9e2fff830707030821k7ad1347i581769a833ec012e@mail.gmail.com> Thread-Index: Ace9heolemMLVTKbRB+NlJlLP8pHVwAmShBg X-Virus-Checked: Checked by ClamAV on apache.org Message-Id: <20070704101521.454E010FB00F@herse.apache.org> ------=_NextPart_000_0406_01C7BE5E.E074E930 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi Nandana! One solution that works well for me would be the following: Store the picture like you did in a nt:file node (of course). Then as the source for your img tag write something like Then write a Servlet that returns the image (i.e. the content of the 'data' property). This Servlet would be mapped to the path /image/* in the web.xml like that: ImageViewerServlet /image/* The Servlet itself just reads the path after '/image' (here: path/to/your/node), looks if it can find a corresponding node in the repository and (if yes) returns the binary data stored in the jcr:data property in that node. I attached a "BinaryViewerServlet" class that I wrote some time ago. It's not exactly what you need I think but it should be pretty close. I that class I expected the full path including the property, so ending up with '.../jcr:data', which is more generic. If you only want to do it for nt:file (or nt:resource), then it would be enough to have the path to the node and let the Servlet read the property. And: the Jackrabbit team did some nice things about how to retrieve sessions in web applications etc.. So ignore the way it is done here and look around, it should be part of the "Jackrabbit Web Application" component... ;-) Hope that helps a bit. Regards Hendrik > -----Original Message----- > From: Nandana Mihindukulasooriya [mailto:nandana.cse@gmail.com] > Sent: Tuesday, July 03, 2007 10:21 PM > To: users@jackrabbit.apache.org > Subject: Displaying images stored in a Jackrabbit repository in a web page > > Hi, > I am developing a blog application on Jackrabbit and my node > structure is as follows. > > /blogRoot [nt:folder] > /blogRoot/ [blog:user] > /blogRoot// [nt:folder] > /blogRoot/// [nt:folder] > /blogRoot////blogEntry [blog:blogEntry] > /blogRoot////blogEntry/comment [blog:Comment] > > At the moment, a blog entry can have an image attachment and it is > stored as a [nt:file] under the [blog:blogEntry] node. blog:blogEntry > node > type is defined as follows > > [blog:blogEntry] > nt:folder, mix:referenceable > - blog:title (string) mandatory primary > - blog:content (string) mandatory > - blog:rate (long) > - blog:created (date) > - blog:published (date) > - blog:updated (date) > > When I used relational databases, my approach was to save the file > name of the image in a table and store the physical file in the File > System. > For example I generate a file name when a file is uploaded and store it's > name in the database in the relavant blog entry table. So whenever I want > to generate the image in a web page in my web application, I can generate > using > > if images are stored in the file system under /images/uploaded directory. > > Is an approach like this possible with Jackrabbit if I store images under > blopgEntry node as described above. What are the other possibilities I > have > ? > > This is the code I used to store the images, > > // creates a blog entry under the current month > blogEntryNode = monthNode.addNode(title, "blog:blogEntry"); > blogEntryNode.setProperty("blog:title", title); > blogEntryNode.setProperty("blog:content", content); > Value date = > ValueFactoryImpl.getInstance().createValue(Calendar.getInstance > ()); > blogEntryNode.setProperty("blog:created",date ); > > // attach the image to the blog entry > Node imageNode = blogEntryNode.addNode(image.getName(),"nt:file"); > Node contentNode = imageNode.addNode("jcr:content","nt:resource"); > contentNode.setProperty("jcr:data",image.getInputStream()); > contentNode.setProperty("jcr:mimeType",image.getContentType()); > contentNode.setProperty("jcr:lastModified",date); > > You expertise advice/comments are highly appreciated.Thank you very much > in > advance. > > Regards, > Nandana ------=_NextPart_000_0406_01C7BE5E.E074E930--