Accessing JCR

2009-04-22 Thread Carl Hall
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

2009-04-22 Thread Alexander Klimetschek
On Wed, Apr 22, 2009 at 4:26 PM, Carl Hall carl.h...@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.klimetsc...@day.com


Re: Accessing JCR

2009-04-22 Thread Bertrand Delacretaz
Hi Carl,

On Wed, Apr 22, 2009 at 4:26 PM, Carl Hall carl.h...@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