Package org.apache.wicket

Examples of org.apache.wicket.Resource


  }

  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


  {
    final String pathInfo = getRelativePath(servletRequest);

    if (pathInfo.startsWith(WebRequestCodingStrategy.RESOURCES_PATH_PREFIX))
    {
      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);
        }

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


        // 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

    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

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.