Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Sunday, 28 August 2016

AEM Code Snippets

// to get list of selectors in an array
String[] selectors = slingRequest.getRequestPathInfo().getSelectors();
// to get a page from a path
Page page = pageManager.getPage(path);
// to get any containing page for a resource
Page page = pageManager.getContainingPage(resourceResolver.getResource(path));
// to get a session in JSP
final SlingRepository repos = sling.getService(SlingRepository.class);
session = repos.loginAdministrative(null);

// to get query object and run a query
//build query using search in crx explorer or crxdelite
String stmt = "select * from cq:Page where jcr:path like '/content/training/%' and contains(*, '" + slingRequest.getParameter("q") + "') order by jcr:score desc";