Examples of SlingScriptHelper


Examples of org.apache.sling.api.scripting.SlingScriptHelper

        return getValue(adaptable, type, filterString, callbackRegistry);
    }

    private <T> Object getService(Object adaptable, Class<T> type, String filter,
            DisposalCallbackRegistry callbackRegistry) {
        SlingScriptHelper helper = getScriptHelper(adaptable);

        if (helper != null) {
            T[] services = helper.getServices(type, filter);
            if (services == null || services.length == 0) {
                return null;
            } else {
                return services[0];
            }
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

        }
    }

    private <T> Object[] getServices(Object adaptable, Class<T> type, String filter,
            DisposalCallbackRegistry callbackRegistry) {
        SlingScriptHelper helper = getScriptHelper(adaptable);

        if (helper != null) {
            T[] services = helper.getServices(type, filter);
            return services;
        } else {
            try {
                ServiceReference[] refs = bundleContext.getServiceReferences(type.getName(), filter);
                if (refs == null || refs.length == 0) {
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

        }
        return null;
    }

    private SlingHttpServletResponse getSlingHttpServletResponse(final SlingHttpServletRequest request) {
        SlingScriptHelper scriptHelper = getSlingScriptHelper(request);
        if (scriptHelper != null) {
            return scriptHelper.getResponse();
        }
        return null;
    }
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

    }

    @Test
    public void testScriptVariableField() throws InvalidSyntaxException {
        SlingBindings bindings = new SlingBindings();
        SlingScriptHelper helper = mock(SlingScriptHelper.class);
        bindings.setSling(helper);
        when(request.getAttribute(SlingBindings.class.getName())).thenReturn(bindings);

        InjectorSpecificAnnotationModel model = factory.getAdapter(request, InjectorSpecificAnnotationModel.class);
        assertNotNull("Could not instanciate model", model);
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

    }

    @Test
    public void testScriptVariableConstructor() throws InvalidSyntaxException {
        SlingBindings bindings = new SlingBindings();
        SlingScriptHelper helper = mock(SlingScriptHelper.class);
        bindings.setSling(helper);
        when(request.getAttribute(SlingBindings.class.getName())).thenReturn(bindings);

        org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel model
                = factory.getAdapter(request, org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel.class);
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

   * @return the classloader
   */
  protected ClassLoader getClassLoader() {
    final SlingBindings bindings = (SlingBindings) pageContext.getRequest()
        .getAttribute(SlingBindings.class.getName());
    final SlingScriptHelper scriptHelper = bindings.getSling();
    final DynamicClassLoaderManager dynamicClassLoaderManager = scriptHelper
        .getService(DynamicClassLoaderManager.class);
    final ClassLoader classLoader = dynamicClassLoaderManager
        .getDynamicClassLoader();
    return classLoader;
  }
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

    public Object eval(Reader scriptReader, ScriptContext scriptContext)
            throws ScriptException {
        Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
        String scriptName = "NO_SCRIPT_NAME";
        {
            SlingScriptHelper helper = (SlingScriptHelper) bindings.get(SlingBindings.SLING);
            if (helper != null) {
                scriptName = helper.getScript().getScriptResource().getPath();
            }
        }

        // wrap the reader in an EspReader for ESP scripts
        if (scriptName.endsWith(RhinoJavaScriptEngineFactory.ESP_SCRIPT_EXTENSION)) {
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

    getLogger(cx, thisObj).info(message.toString());
  }

  private void load(Context cx, Scriptable thisObj, Object[] args) {

    SlingScriptHelper sling = getProperty(cx, thisObj, SlingBindings.SLING,
        SlingScriptHelper.class);
    if (sling == null) {
      throw new NullPointerException(SlingBindings.SLING);
    }

    Scriptable globalScope = ScriptableObject.getTopLevelScope(thisObj);

    Resource scriptResource = sling.getScript().getScriptResource();
    ResourceResolver resolver = scriptResource.getResourceResolver();

    // the path of the current script to resolve realtive paths
    String currentScript = sling.getScript().getScriptResource().getPath();
    String scriptParent = ResourceUtil.getParent(currentScript);

    for (Object arg : args) {
      String scriptName = ScriptRuntime.toString(arg);
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

            .replaceAll("([^/]*/)?[^/]*/\\.\\./", "");
      }
    }
    absolutePath = absolutePath + ".js";

    SlingScriptHelper sling = getProperty(cx, thisObj, SlingBindings.SLING,
        SlingScriptHelper.class);
    if (sling == null) {
      throw new NullPointerException(SlingBindings.SLING);
    }
    ResourceResolver resrev = sling.getScript().getScriptResource().getResourceResolver();

    Resource script = null;
    String scriptName = null;
    for (String basepath : resrev.getSearchPath()) {
      script = resrev.resolve(basepath + absolutePath);
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

        @Override
        public Object eval(final Reader script, final ScriptContext context)
                throws ScriptException {
            Bindings props = context.getBindings(ScriptContext.ENGINE_SCOPE);
            SlingScriptHelper scriptHelper = (SlingScriptHelper) props.get(SLING);
            if (scriptHelper != null) {

                // set the current class loader as the thread context loader for
                // the compilation and execution of the JSP script
                ClassLoader old = Thread.currentThread().getContextClassLoader();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.