Thanks, that's exactly what I needed. On Thu, Jul 23, 2009 at 09:47:05PM +0200, Alexander Klimetschek wrote: > On Thu, Jul 23, 2009 at 9:34 PM, D. Stuart > Freeman<[email protected]> wrote: > > Is there a way from within an osgi bundle to get a jcr node by path if I > > don't have access to the request object? > > For getting direct access to the repository and the JCR API, use the > SlingRepository service, which is an extension of the > javax.jcr.Repository with admin-login capabilities (if you don't need > that, you can simply use Repository as service reference). Assuming > you are in a component/service and use the SCR annotations, this would > look like: > > /** @scr.reference */ > protected SlingRepository repository; > > public void jcrMethod() { > // uses admin credentials from sling repository component > config, use with care! > Session adminSession = repository.loginAdministrative(null); > ... > // manual login > Session session = repository.login(new > SimpleCredentials("user", "password"); > } > > If you want to use the Sling resource API for JCR nodes, you can > create your own resource resolver from an existing JCR session: > > /** @scr.reference */ > protected JcrResourceResolverFactory jcrResourceResolverFactory; > > public void resourceMethod(Session session) { > ResourceResolver resolver = > jcrResourceResolverFactory.getResourceResolver(session); > Resource res = resolver.getResource("/some/path"); > .... > } > > Regards, > Alex > > -- > Alexander Klimetschek > [email protected]
-- D. Stuart Freeman Georgia Institute of Technology
signature.asc
Description: Digital signature
