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


  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

      boolean hasWidth = imageData.getThumbWidth() > 0;
      boolean hasHeight = imageData.getThumbHeight() > 0;
      String thumbUrl = getRequest()
          .getRelativePathPrefixToContextRoot()
          + imageData.getThumbUrl();
      Resource thumbResource = imageData.getThumbResource();

      if (thumbResource == null) {
        atts.put("src", thumbUrl);
      } else {
        atts.put("src", urlFor(IResourceListener.INTERFACE));
View Full Code Here

          private static final long serialVersionUID = 1L;

          @Override
          protected Resource newResource() {
            Resource r = ref.getResource();
            if (r == null) {
              throw new WicketRuntimeException("ResourceReference wasn't bound to application yet");
            }
            return r;
          }
View Full Code Here

        if (Strings.isEmpty(fileName)) {
            log.warn("There is no file name of image");
            return;
        }
        final String contentType = RequestCycle.get().getRequest().getParameter(ImageUploadHelper.IMAGE_CONTENT_TYPE);
        Resource resource = new Resource() {
            @Override
            public IResourceStream getResourceStream() {
                FileInputStream inputStream = null;
                try {
                    inputStream = new FileInputStream(ImageUploadHelper.getTemporaryDirPath()+File.separatorChar+fileName);
                } catch(FileNotFoundException ex) {
                    log.error("Problem with getting image - " + ex.getMessage(), ex);
                    throw new RuntimeException("Problem with getting image");
                }
                return new FileResourceStream(contentType, inputStream);
            }
        };
        resource.onResourceRequested();
    }
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 = Strings.replaceAll(path, escapeString, "..").toString();
          }

          if (PackageResource.exists(scope, path, 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";
      Response response = requestCycle.getResponse();
      if (response instanceof WebResponse)
      {
        ((WebResponse)response).getHttpServletResponse().setStatus(
          HttpServletResponse.SC_NOT_FOUND);
        log.error(msg);
        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

          private static final long serialVersionUID = 1L;

          @Override
          protected Resource newResource() {
            Resource r = ref.getResource();
            if (r == null) {
              throw new WicketRuntimeException("ResourceReference wasn't bound to application yet");
            }
            return r;
          }
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

        if (application.getSharedResources().get(Application.class, imageReferenceName,
          locale, style, true) == null)
        {
          // Resource not available yet, so create it with factory and
          // share via Application
          final Resource imageResource = getResourceFactory(application, factoryName).newResource(
            specification, locale, style);
          application.getSharedResources().add(Application.class, imageReferenceName,
            locale, style, imageResource);
        }
View Full Code Here

    {

      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

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.