You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Nandana Mihindukulasooriya <na...@gmail.com> on 2007/07/03 17:21:28 UTC
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
Re: Displaying images stored in a Jackrabbit repository in a web page
Posted by Nandana Mihindukulasooriya <na...@gmail.com>.
Hi,
Thanks for the quick responses. I implemented it using the method used in
the BinaryViewerServlet as Hendrik instructed. I implemented an
ImageViewerServlet using that method and it works fine. But of course I need
to add more image functionalities and I am glad to see most of them are in
the feature list of the "Stitches". So I am going through the source now.
Thank you once again for the quick response and both
jcr-webexplorer<http://sourceforge.net/projects/jcr-webexplorer/>project
and
stitches <http://stitches.authsum.org> project will help me a lot to get in
to speed with this matter.
Regards,
Nandana
On 7/4/07, Phillip Rhodes <sp...@rhoderunner.com> wrote:
>
> Please check out stitches, it's a library written over jackrabbit that
> provides a lot of functionality around images. For example, uploading an
> image will generate thumbnails of various sizes. stitches is in use in a
> lot of my applications that I use for user generated content.
>
> http://stitches.authsum.org
>
> I have to update the documentation but one point i would like to make is
> that it's not tapestry specific any longer. I hope to has JSF components,
> wicket components, etc...
>
> You can always just look at the source code and see how I handle all the
> image functions for your own project.
>
> Apache license of course.
>
>
>
>
>
> ----- Original Message -----
> From: "Hendrik Beck (camunda)" <he...@camunda.com>
> To: users@jackrabbit.apache.org
> Sent: Wednesday, July 4, 2007 6:15:09 AM (GMT-0500) America/New_York
> Subject: RE: Displaying images stored in a Jackrabbit repository in a web
> page
>
> 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
>
>
Re: Displaying images stored in a Jackrabbit repository in a web
page
Posted by Phillip Rhodes <sp...@rhoderunner.com>.
Please check out stitches, it's a library written over jackrabbit that provides a lot of functionality around images. For example, uploading an image will generate thumbnails of various sizes. stitches is in use in a lot of my applications that I use for user generated content.
http://stitches.authsum.org
I have to update the documentation but one point i would like to make is that it's not tapestry specific any longer. I hope to has JSF components, wicket components, etc...
You can always just look at the source code and see how I handle all the image functions for your own project.
Apache license of course.
----- Original Message -----
From: "Hendrik Beck (camunda)" <he...@camunda.com>
To: users@jackrabbit.apache.org
Sent: Wednesday, July 4, 2007 6:15:09 AM (GMT-0500) America/New_York
Subject: RE: Displaying images stored in a Jackrabbit repository in a web page
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
RE: Displaying images stored in a Jackrabbit repository in a web page
Posted by "Hendrik Beck (camunda)" <he...@camunda.com>.
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