Hi David,

Am Montag, den 21.01.2008, 08:25 +0100 schrieb David Nuescheler:
> Hi guys,
> 
> I have been trying to access the JCR session from my .esp script
> to create content for an import script that needs to create many
> nodes in the repository.
> 
> I think my initial thought was to get access to the session from
> the node on the resource via the .getSession() method on Node, but
> since the actual node was hidden by ScriptableNode I didn't find a quick
> way to do that.
> 
> Then I thought that we might even want to expose the session in a more
> direct way. With my "JCR framework"-hat on I would obviously expect
> something on a per request basis that let's me access the jcr session
> that is associated with a specific request, given the authentication
> information etc. on the http requests.
> 
> Maybe we should also get the JCR session from the resource though,
> which I think would fit the current (more abstract) design of Sling better.
> 
> Is there a current solution that I missed?
> What would be a possible future way of doing that?

There are two ways: The better way is to do:

   Session session =
request.getResourceResolver().adaptTo(Session.class);

the second best way is to get the javax.jcr.Session request attribute:

   Session session = (Session)
request.getAttribute(Session.class.getName());

Hope, this helps.

Regards
Felix

> 
> regards,
> david

Reply via email to