Package org.apache.sling.api.resource

Examples of org.apache.sling.api.resource.ResourceResolver


    @SuppressWarnings("unchecked")
    private void callJsp(final Bindings bindings,
                         final SlingScriptHelper scriptHelper,
                         final ScriptContext context) {

        ResourceResolver resolver = (ResourceResolver) context.getAttribute(SlingScriptConstants.ATTR_SCRIPT_RESOURCE_RESOLVER,
                SlingScriptConstants.SLING_SCOPE);
        if ( resolver == null ) {
            resolver = scriptHelper.getScript().getScriptResource().getResourceResolver();
        }
        final SlingIOProvider io = this.ioProvider;
        final JspFactoryHandler jspfh = this.jspFactoryHandler;

        // abort if JSP Support is shut down concurrently (SLING-2704)
        if (io == null || jspfh == null) {
            logger.warn("callJsp: JSP Script Engine seems to be shut down concurrently; not calling {}",
                    scriptHelper.getScript().getScriptResource().getPath());
            return;
        }

        final ResourceResolver oldResolver = io.setRequestResourceResolver(resolver);
        jspfh.incUsage();
        try {
            final SlingBindings slingBindings = new SlingBindings();
            slingBindings.putAll(bindings);
View Full Code Here


    }

    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);

      Resource loadScript = null;
      if (!scriptName.startsWith("/")) {
        String absScriptName = scriptParent + "/" + scriptName;
        loadScript = resolver.resolve(absScriptName);
      }

      // not resolved relative to the current script
      if (loadScript == null) {
        loadScript = resolver.resolve(scriptName);
      }

      if (loadScript == null) {
        throw Context.reportRuntimeError("Script file " + scriptName
            + " not found");
View Full Code Here

    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);
      if (script!=null&&!(script instanceof NonExistingResource)) {
        scriptName = basepath + absolutePath;
        break;
      }
    }
    if (script==null) {
      throw Context.reportRuntimeError("Unable to resolve module " + absolutePath + " in search path");
    }

    InputStream scriptStream = script.adaptTo(InputStream.class);
    if (scriptStream == null) {
      //try once again
       scriptStream = resrev.resolve(scriptName).adaptTo(InputStream.class);
      if (scriptStream==null) {
        throw Context.reportRuntimeError("Script file " + script.getPath()
            + " cannot be read");
      }
    }
View Full Code Here

                tracker.log("Including script {0} for path={1}, type={2}: {3}", script, resource.getPath(),
                        resource.getResourceType(), servletName);
            }

        } else {
            final ResourceResolver resolver = bindings.getRequest().getResourceResolver();
            final String scriptPath;
            if (!script.startsWith("/")) {

                // resolve relative script
                String parentPath = ResourceUtil.getParent(scriptHelper.getScript().getScriptResource().getPath());
                // check if parent resides on search path
                for (String sp : resolver.getSearchPath()) {
                    if (parentPath.startsWith(sp)) {
                        parentPath = parentPath.substring(sp.length());
                        break;
                    }
                }
View Full Code Here

                break;
            }

            try {
                final EventAdmin localEa = this.support.getEventAdmin();
                final ResourceResolver resolver = this.support.getResourceResolver();
                if (localEa != null && resolver != null ) {
                    final String topic = (String) event.remove(EventConstants.EVENT_TOPIC);
                    final String path = (String) event.get(SlingConstants.PROPERTY_PATH);
                    Resource resource = resolver.getResource(path);
                    boolean sendEvent = true;
                    if (!SlingConstants.TOPIC_RESOURCE_REMOVED.equals(topic)) {
                        if (resource != null) {
                            // check if this is a JCR backed resource, otherwise it is not visible!
                            final Node node = resource.adaptTo(Node.class);
View Full Code Here

  @Override
  public int doEndTag() {
    log.trace("doEndTag");

    ResourceResolver resolver = getResourceResolver();
    Resource resource = null;
    if (path.startsWith("/")) {
      log.debug("Retrieving resource at absolute path: {}", path);
      resource = resolver.getResource(path);
    } else {
      if (base != null) {
        log.debug(
            "Retrieving resource at relative path: {} to resource {}",
            path, base.getPath());
        resource = resolver.getResource(base, path);
      } else {
        log.warn(
            "Unable to retrieve resource at relative path {}, no base resource specified",
            path);
      }
View Full Code Here

   */
  protected ResourceResolver getResourceResolver() {
    final SlingBindings bindings = (SlingBindings) pageContext.getRequest()
        .getAttribute(SlingBindings.class.getName());
    final SlingScriptHelper scriptHelper = bindings.getSling();
    final ResourceResolver resolver = scriptHelper.getRequest()
        .getResourceResolver();
    return resolver;
  }
View Full Code Here

     */
    protected void doInit() {

        this.initializing.lock();
        try {
            final ResourceResolver resolver = this.resolver;
            final MapConfigurationProvider factory = this.factory;
            if (resolver == null || factory == null) {
                return;
            }

View Full Code Here

            }

            // immediately set the resolver field to null to indicate
            // that we have been disposed (this also signals to the
            // event handler to stop working
            final ResourceResolver oldResolver = this.resolver;
            this.resolver = null;

            if (oldResolver != null) {
                oldResolver.close();
            } else {
                log.warn("dispose: ResourceResolver has already been cleared before; duplicate call to dispose ?");
            }
        } finally {
            if (initLocked) {
View Full Code Here

        final String rtPath = (resourceType == null ? null : ResourceUtil.resourceTypeToPath(resourceType));
        // get the resource type resource and check its super type
        String resourceSuperType = null;

        if ( rtPath != null ) {
            ResourceResolver adminResolver = this.getResourceTypeResourceResolver(factory, resolver);
            if ( adminResolver != null ) {
                final Resource rtResource = adminResolver.getResource(rtPath);
                if (rtResource != null) {
                    resourceSuperType = rtResource.getResourceSuperType();
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.sling.api.resource.ResourceResolver

Copyright © 2018 www.massapicom. 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.