com.icfolson.aem.groovy.console.extension.impl.DefaultBindingExtensionProvider.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aem-groovy-console Show documentation
Show all versions of aem-groovy-console Show documentation
The AEM Groovy Console provides an interface for running Groovy scripts in the AEM container. Scripts can be
created to manipulate content in the JCR, call OSGi services, or execute arbitrary code using the AEM, Sling,
or JCR APIs.
package com.icfolson.aem.groovy.console.extension.impl
import com.day.cq.search.QueryBuilder
import com.day.cq.wcm.api.PageManager
import com.icfolson.aem.groovy.console.api.BindingExtensionProvider
import com.icfolson.aem.groovy.extension.builders.NodeBuilder
import com.icfolson.aem.groovy.extension.builders.PageBuilder
import org.apache.felix.scr.annotations.Activate
import org.apache.felix.scr.annotations.Component
import org.apache.felix.scr.annotations.Reference
import org.apache.felix.scr.annotations.Service
import org.apache.sling.api.SlingHttpServletRequest
import org.osgi.framework.BundleContext
import org.slf4j.LoggerFactory
import javax.jcr.Session
@Service(BindingExtensionProvider)
@Component(immediate = true)
class DefaultBindingExtensionProvider implements BindingExtensionProvider {
@Reference
private QueryBuilder queryBuilder
private BundleContext bundleContext
@Override
Binding getBinding(SlingHttpServletRequest request) {
def resourceResolver = request.resourceResolver
def session = resourceResolver.adaptTo(Session)
new Binding([
log: LoggerFactory.getLogger("groovyconsole"),
session: session,
slingRequest: request,
pageManager: resourceResolver.adaptTo(PageManager),
resourceResolver: resourceResolver,
queryBuilder: queryBuilder,
nodeBuilder: new NodeBuilder(session),
pageBuilder: new PageBuilder(session),
bundleContext: bundleContext
])
}
@Activate
void activate(BundleContext bundleContext) {
this.bundleContext = bundleContext
}
}