You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Carl Hall <ca...@gmail.com> on 2009/04/22 16:26:44 UTC

Accessing JCR

I've searched through docs but have yet to discover this though I'm
probably just overlooking something.  What's the suggested way to
access data in a jcr repository when not coming from a user related
request (ie. when in an event listener)?  Also, how do I get hold of
the observation manager to register my listener?

Re: Accessing JCR

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Carl,

On Wed, Apr 22, 2009 at 4:26 PM, Carl Hall <ca...@gmail.com> wrote:
> I've searched through docs but have yet to discover this though I'm
> probably just overlooking something.  What's the suggested way to
> access data in a jcr repository when not coming from a user related
> request (ie. when in an event listener)?  Also, how do I get hold of
> the observation manager to register my listener?

In addition to Alex's explanations, you might want to have a look at
the espblog sample [1], where the ThumbnailGeneratorServiceImpl uses a
JCR listener to detect added images, generates thumbnails and stores
those in the repository.

-Bertrand

[1]  http://svn.apache.org/repos/asf/incubator/sling/trunk/samples/espblog

Re: Accessing JCR

Posted by Alexander Klimetschek <ak...@day.com>.
On Wed, Apr 22, 2009 at 4:26 PM, Carl Hall <ca...@gmail.com> wrote:
> I've searched through docs but have yet to discover this though I'm
> probably just overlooking something.  What's the suggested way to
> access data in a jcr repository when not coming from a user related
> request (ie. when in an event listener)?  Also, how do I get hold of
> the observation manager to register my listener?

The o.a.s.jcr.api.SlingRepository interface [1] can be used for that
(it is simply an extension of the Repository interface). It is
directly available as OSGi service. With scr and annotations through
the maven scr plugin, this typically looks like this:

/** @scr.reference */
private SlingRepository repository;

To use it, simply work with standard JCR API calls:

Session session = repository.login(new SimpleCredentials("user", "password"));

or for handy admin-sessions (password is globally configured in the
SlingRepository service config):

Session adminSession = repository.loginAdministrative(null);

[1] https://svn.apache.org/repos/asf/incubator/sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/SlingRepository.java


Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com