Package org.apache.wicket

Examples of org.apache.wicket.Resource


  protected final void onComponentTag(final ComponentTag tag)
  {
    checkComponentTag(tag, "input");
    checkComponentTagAttribute(tag, "type", "image");

    final Resource resource = getImageResource();
    if (resource != null)
    {
      localizedImageResource.setResource(resource);
    }
    final ResourceReference resourceReference = getImageResourceReference();
View Full Code Here


   */
  protected void onComponentTag(final ComponentTag tag)
  {
    checkComponentTag(tag, "img");
    super.onComponentTag(tag);
    final Resource resource = getImageResource();
    if (resource != null)
    {
      localizedImageResource.setResource(resource);
    }
    final ResourceReference resourceReference = getImageResourceReference();
View Full Code Here

  public void respond(RequestCycle requestCycle)
  {
    Application application = requestCycle.getApplication();
    SharedResources sharedResources = application.getSharedResources();
    final String resourceKey = getRequestParameters().getResourceKey();
    Resource resource = sharedResources.get(resourceKey);

    // try to lazily register
    if (resource == null)
    {
      int ix = resourceKey.indexOf('/');
      if (ix != -1)
      {
        String className = resourceKey.substring(0, ix);
        IClassResolver resolver = application.getApplicationSettings().getClassResolver();
        Class scope = null;
        try
        {
          // First try to match mounted resources.
          scope = Application.get().getSharedResources().getAliasClass(className);

          // If that fails, resolve it as a fully qualified class
          // name.
          if (scope == null)
          {
            scope = resolver.resolveClass(className);
          }
          String path = resourceKey.substring(ix + 1);

          PackageResource packageResource = PackageResource.get(scope, path);
          if (sharedResources.get(resourceKey) == null)
          {
            sharedResources.add(resourceKey, packageResource);
          }
          resource = packageResource;
        }
        catch (Exception e)
        {
          // besides logging, ignore exception; after this an error
          // will be returned that the resource could not be retrieved
          log.error("unable to lazily register shared resource " + resourceKey, e);
        }
      }
    }

    // if resource is still null, it doesn't exist
    if (resource == null)
    {
      Response response = requestCycle.getResponse();
      if (response instanceof WebResponse)
      {
        ((WebResponse)response).getHttpServletResponse().setStatus(
            HttpServletResponse.SC_NOT_FOUND);
        log.error("shared resource " + resourceKey + " not found");
        return;
      }
      else
      {
        throw new WicketRuntimeException("shared resource " + resourceKey + " not found");
      }
    }

    // set request parameters if there are any
    if (requestParameters != null)
    {
      resource.setParameters(requestParameters.getParameters());
    }

    // let the resource handle the request
    resource.onResourceRequested();
  }
View Full Code Here

  }

  public void testInvalidPackageResource() throws Exception
  {
    final SharedResources sharedResources = Application.get().getSharedResources();
    Resource invalidResource = new PackageResource(PackageResourceTest.class, "packaged3.txt",
        Locale.ENGLISH, null);
    assertNotNull(
        "resource packaged3.txt SHOULD be available as a packaged resource even if it doesn't exist",
        invalidResource);

    try
    {
      invalidResource.getResourceStream();
      fail("Should have raised an AbortException");
    }
    catch (AbortException e)
    {
    }
View Full Code Here

  public ResourceReference resourceReference(final Map variables)
  {
    final String uniqueName = sharedResourceName(variables);
    final String templateValue = template.asString(variables);
    final SharedResources sharedResources = Application.get().getSharedResources();
    final Resource resource = sharedResources.get(uniqueName);
    if (resource == null)
    {
      final Resource newResource = new Resource()
      {
        private static final long serialVersionUID = 1L;

        /**
         * @see org.apache.wicket.Resource#getResourceStream()
View Full Code Here

    if (pathInfo.startsWith(WebRequestCodingStrategy.RESOURCES_PATH_PREFIX))
    {

      final String resourceReferenceKey = pathInfo.substring(WebRequestCodingStrategy.RESOURCES_PATH_PREFIX.length());

      Resource resource = null;

      boolean externalCall = !Application.exists();
      try
      {
        // if called externally (i.e. WicketServlet) we need to set the thread local here
        // AND clean it up at the end of the request
        if (externalCall)
        {
          Application.set(webApplication);
        }

        // Try to find shared resource
        resource = webApplication.getSharedResources().get(resourceReferenceKey);

        // If resource found and it is cacheable
        if ((resource != null) && resource.isCacheable())
        {

          final WebRequest request = webApplication.newWebRequest(servletRequest);
          // make the session available.
          Session.findOrCreate(request, new WebResponse());


          // Set parameters from servlet request
          resource.setParameters(request.getParameterMap());

          // Get resource stream
          IResourceStream stream = resource.getResourceStream();

          // Get last modified time from stream
          Time time = stream.lastModifiedTime();

          try
          {
            stream.close();
          }
          catch (IOException e)
          {
            // ignore
          }

          return time != null ? time.getMilliseconds() : -1;
        }
      }
      catch (AbortException e)
      {
        return -1;
      }
      finally
      {
        if (resource != null)
        {
          resource.setParameters(null);
        }
        if (externalCall)
        {
          // Clean up thread local application if this was an external call
          // (if not, doFilter will clean it up)
View Full Code Here

  public void respond(RequestCycle requestCycle)
  {
    Application application = requestCycle.getApplication();
    SharedResources sharedResources = application.getSharedResources();
    final String resourceKey = getRequestParameters().getResourceKey();
    Resource resource = sharedResources.get(resourceKey);

    // try to lazily register
    if (resource == null)
    {
      int ix = resourceKey.indexOf('/');
      if (ix != -1)
      {
        String className = resourceKey.substring(0, ix);
        IClassResolver resolver = application.getApplicationSettings().getClassResolver();
        Class<?> scope = null;
        try
        {
          // First try to match mounted resources.
          scope = Application.get().getSharedResources().getAliasClass(className);

          // If that fails, resolve it as a fully qualified class
          // name.
          if (scope == null)
          {
            scope = resolver.resolveClass(className);
          }

          // get path component of resource key, replace '..' with escape sequence to
          // prevent crippled urls in browser
          final CharSequence escapeString = application.getResourceSettings()
            .getParentFolderPlaceholder();

          String path = resourceKey.substring(ix + 1);
          if (Strings.isEmpty(escapeString) == false)
          {
            path = path.replace(escapeString, "..");
          }

          if (PackageResource.exists(scope, path, null, null, null))
          {
            resource = PackageResource.get(scope, path);
          }
        }
        catch (Exception e)
        {
          // besides logging, ignore exception; after this an error
          // will be returned that the resource could not be retrieved
          log.error("unable to lazily register shared resource " + resourceKey, e);
        }
      }
    }

    // if resource is still null, it doesn't exist
    if (resource == null)
    {
      String msg = "shared resource " + resourceKey + " not found or not allowed access";
      log.info(msg);

      Response response = requestCycle.getResponse();
      if (response instanceof WebResponse)
      {
        ((WebResponse)response).getHttpServletResponse().setStatus(
          HttpServletResponse.SC_NOT_FOUND);
        return;
      }
      else
      {
        throw new WicketRuntimeException(msg);
      }
    }

    // set request parameters if there are any
    if (requestParameters != null)
    {
      resource.setParameters(requestParameters.getParameters());
    }

    // let the resource handle the request
    resource.onResourceRequested();
  }
View Full Code Here

    if (pathInfo.startsWith(WebRequestCodingStrategy.RESOURCES_PATH_PREFIX))
    {

      final String resourceReferenceKey = pathInfo.substring(WebRequestCodingStrategy.RESOURCES_PATH_PREFIX.length());

      Resource resource = null;
      WebRequestCycle requestCycle = null;

      boolean externalCall = !Application.exists();
      try
      {
        // if called externally (i.e. WicketServlet) we need to set the thread local here
        // AND clean it up at the end of the request
        if (externalCall)
        {
          Application.set(webApplication);
        }

        // Try to find shared resource
        resource = webApplication.getSharedResources().get(resourceReferenceKey);

        // If resource found and it is cacheable
        if ((resource != null) && resource.isCacheable())
        {
          // first check the char encoding for getting the parameters
          checkCharacterEncoding(servletRequest);

          final WebRequest request = webApplication.newWebRequest(servletRequest);
          WebResponse response = new WebResponse();
          // create a request cycle if not already there.
          if (RequestCycle.get() == null)
          {
            requestCycle = (WebRequestCycle)webApplication.newRequestCycle(request,
              response);
          }
          // make the session available.
          Session.findOrCreate(request, response);


          // decode the parameters so that shared resource params are also decoded
          // a request cycle is then needed. (see above)
          RequestParameters rp = RequestCycle.get()
            .getProcessor()
            .getRequestCodingStrategy()
            .decode(request);
          // Set parameters from servlet request
          resource.setParameters(rp.getParameters());

          // Get resource stream
          IResourceStream stream = resource.getResourceStream();

          // Get last modified time from stream
          Time time = stream.lastModifiedTime();

          try
          {
            stream.close();
          }
          catch (IOException e)
          {
            // ignore
          }

          return time != null ? time.getMilliseconds() : -1;
        }
      }
      catch (AbortException e)
      {
        return -1;
      }
      finally
      {
        if (resource != null)
        {
          resource.setParameters(null);
        }
        if (externalCall)
        {
          // Clean up thread local application if this was an external call
          // (if not, doFilter will clean it up)
View Full Code Here

  protected final void onComponentTag(final ComponentTag tag)
  {
    checkComponentTag(tag, "input");
    checkComponentTagAttribute(tag, "type", "image");

    final Resource resource = getImageResource();
    if (resource != null)
    {
      localizedImageResource.setResource(resource);
    }
    final ResourceReference resourceReference = getImageResourceReference();
View Full Code Here

  @Override
  protected void onComponentTag(final ComponentTag tag)
  {
    checkComponentTag(tag, "img");
    super.onComponentTag(tag);
    final Resource resource = getImageResource();
    if (resource != null)
    {
      localizedImageResource.setResource(resource);
    }
    final ResourceReference resourceReference = getImageResourceReference();
View Full Code Here

TOP

Related Classes of org.apache.wicket.Resource

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.