jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hendrik Beck \(camunda\)" <hendrik.b...@camunda.com>
Subject RE: Displaying images stored in a Jackrabbit repository in a web page
Date Wed, 04 Jul 2007 10:15:09 GMT
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

<img src="/image/path/to/your/node">

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:

<servlet-mapping>
  <servlet-name>ImageViewerServlet</servlet-name> 
  <url-pattern>/image/*</url-pattern> 
</servlet-mapping>


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/<username> [blog:user]
> /blogRoot/<username>/<yyyy> [nt:folder]
> /blogRoot/<username>/<yyyy>/<mm> [nt:folder]
> /blogRoot/<username>/<yyyy>/<mm>/blogEntry [blog:blogEntry]
> /blogRoot/<username>/<yyyy>/<mm>/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
> <img src="/images/uploaded/"+imageFileName/>
> 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

Mime
  • Unnamed multipart/mixed (inline, None, 0 bytes)
View raw message