Examples of IResourceStream


Examples of org.apache.wicket.util.resource.IResourceStream

    return stream;
  }

  private IResourceStream internalGetResourceStream()
  {
    final IResourceStream resourceStream = getResourceStream();
    Checks.notNull(resourceStream, "%s#getResourceStream() should not return null!", ResourceStreamResource.class.getName());
    return resourceStream;
  }
View Full Code Here

Examples of org.apache.wicket.util.resource.IResourceStream

  }

  @Override
  protected ResourceResponse newResourceResponse(Attributes attributes)
  {
    final IResourceStream resourceStream = internalGetResourceStream();
    ResourceResponse data = new ResourceResponse();
    Time lastModifiedTime = resourceStream.lastModifiedTime();
    if (lastModifiedTime != null)
    {
      data.setLastModified(lastModifiedTime);
    }

    if (cacheDuration != null)
    {
      data.setCacheDuration(cacheDuration);
    }

    // performance check; don't bother to do anything if the resource is still cached by client
    if (data.dataNeedsToBeWritten(attributes))
    {
      InputStream inputStream = null;
      if (resourceStream instanceof IResourceStreamWriter == false)
      {
        try
        {
          inputStream = resourceStream.getInputStream();
        }
        catch (ResourceStreamNotFoundException e)
        {
          data.setError(HttpServletResponse.SC_NOT_FOUND);
          close();
        }
      }

      data.setContentDisposition(contentDisposition);
      Bytes length = resourceStream.length();
      if (length != null)
      {
        data.setContentLength(length.bytes());
      }
      data.setFileName(fileName);

      String contentType = resourceStream.getContentType();
      if (contentType == null && fileName != null && Application.exists())
      {
        contentType = Application.get().getMimeType(fileName);
      }
      data.setContentType(contentType);
View Full Code Here

Examples of org.apache.wicket.util.resource.IResourceStream

  }

  @Override
  public Serializable getCacheKey()
  {
    IResourceStream stream = getCacheableResourceStream();

    // if resource stream can not be found do not cache
    if (stream == null)
    {
      return null;
    }

    return new CacheKey(scopeName, absolutePath, stream.getLocale(), stream.getStyle(),
      stream.getVariation());
  }
View Full Code Here

Examples of org.apache.wicket.util.resource.IResourceStream

  @Override
  protected ResourceResponse newResourceResponse(Attributes attributes)
  {
    final ResourceResponse resourceResponse = new ResourceResponse();

    final IResourceStream resourceStream = getResourceStream();

    // bail out if resource stream could not be found
    if (resourceStream == null)
    {
      return sendResourceError(resourceResponse, HttpServletResponse.SC_NOT_FOUND,
          "Unable to find resource");
    }

    // add Last-Modified header (to support HEAD requests and If-Modified-Since)
    final Time lastModified = resourceStream.lastModifiedTime();

    resourceResponse.setLastModified(lastModified);

    if (resourceResponse.dataNeedsToBeWritten(attributes))
    {
      String contentType = resourceStream.getContentType();

      if (contentType == null && Application.exists())
      {
        contentType = Application.get().getMimeType(path);
      }

      // set Content-Type (may be null)
      resourceResponse.setContentType(contentType);
     
      // set content encoding (may be null)
      resourceResponse.setTextEncoding(getTextEncoding());

      try
      {
        // read resource data
        final byte[] bytes;

        bytes = IOUtils.toByteArray(resourceStream.getInputStream());

        final byte[] processed = processResponse(attributes, bytes);

        // send Content-Length header
        resourceResponse.setContentLength(processed.length);

        // send response body with resource data
        resourceResponse.setWriteCallback(new WriteCallback()
        {
          @Override
          public void writeData(Attributes attributes)
          {
            attributes.getResponse().write(processed);
          }
        });
      }
      catch (IOException e)
      {
        log.debug(e.getMessage(), e);
        return sendResourceError(resourceResponse, 500, "Unable to read resource stream");
      }
      catch (ResourceStreamNotFoundException e)
      {
        log.debug(e.getMessage(), e);
        return sendResourceError(resourceResponse, 500, "Unable to open resource stream");
      }
      finally
      {
        try
        {
          resourceStream.close();
        }
        catch (IOException e)
        {
          log.warn("Unable to close the resource stream", e);
        }
View Full Code Here

Examples of org.apache.wicket.util.resource.IResourceStream

  private IResourceStream internalGetResourceStream(final String style, final Locale locale)
  {
    IResourceStreamLocator resourceStreamLocator = Application.get()
        .getResourceSettings()
        .getResourceStreamLocator();
    IResourceStream resourceStream = resourceStreamLocator.locate(getScope(), absolutePath, style, variation, locale, null, false);

    Class<?> realScope = getScope();
    String realPath = absolutePath;
    if (resourceStream instanceof IFixedLocationResourceStream)
    {
View Full Code Here

Examples of org.apache.wicket.util.resource.IResourceStream

      .getResourceSettings()
      .getResourceStreamLocator();

    String absolutePath = Packages.absolutePath(getScope(), getName());

    IResourceStream stream = locator.locate(getScope(), absolutePath, style, variation, locale,
      null, false);

    if (stream == null)
      return new ResourceReference.UrlAttributes(null, null, null);

    return new ResourceReference.UrlAttributes(stream.getLocale(), stream.getStyle(), stream.getVariation());
  }
View Full Code Here

Examples of org.apache.wicket.util.resource.IResourceStream

    String name = getMinifiedName();
    IResourceStreamLocator locator = Application.get()
        .getResourceSettings()
        .getResourceStreamLocator();
    String absolutePath = Packages.absolutePath(getScope(), name);
    IResourceStream stream = locator.locate(getScope(), absolutePath, getStyle(),
        getVariation(), getLocale(), null, true);

    minifiedName = stream != null ? name : NO_MINIFIED_NAME;
    MINIFIED_NAMES_CACHE.put(this, minifiedName);
    if (minifiedName == NO_MINIFIED_NAME && log.isDebugEnabled())
View Full Code Here

Examples of org.apache.wicket.util.resource.IResourceStream

    }

    public void onResourceRequested()
    {      
        onClick();
        IResourceStream resourceStream = new IResourceStream()
        {
            {
                resourceProvider.open();
            }
            /** Transient input stream to resource */
 
View Full Code Here

Examples of org.apache.wicket.util.resource.IResourceStream

  }

  @Override
  public Serializable getCacheKey()
  {
    IResourceStream stream = getCacheableResourceStream();

    // if resource stream can not be found do not cache
    if (stream == null)
    {
      return null;
    }

    return new CacheKey(scopeName, absolutePath, stream.getLocale(), stream.getStyle(),
      stream.getVariation());
  }
View Full Code Here

Examples of org.apache.wicket.util.resource.IResourceStream

  @Override
  protected ResourceResponse newResourceResponse(Attributes attributes)
  {
    final ResourceResponse resourceResponse = new ResourceResponse();

    final IResourceStream resourceStream = getResourceStream();

    // bail out if resource stream could not be found
    if (resourceStream == null)
    {
      return sendResourceError(resourceResponse, HttpServletResponse.SC_NOT_FOUND,
          "Unable to find resource");
    }

    // add Last-Modified header (to support HEAD requests and If-Modified-Since)
    final Time lastModified = resourceStream.lastModifiedTime();

    resourceResponse.setLastModified(lastModified);

    if (resourceResponse.dataNeedsToBeWritten(attributes))
    {
      String contentType = resourceStream.getContentType();

      if (contentType == null && Application.exists())
      {
        contentType = Application.get().getMimeType(path);
      }

      // set Content-Type (may be null)
      resourceResponse.setContentType(contentType);
     
      // set content encoding (may be null)
      resourceResponse.setTextEncoding(getTextEncoding());

      try
      {
        // read resource data
        final byte[] bytes = IOUtils.toByteArray(resourceStream.getInputStream());

        // send Content-Length header
        resourceResponse.setContentLength(bytes.length);

        // send response body with resource data
        resourceResponse.setWriteCallback(new WriteCallback()
        {
          @Override
          public void writeData(Attributes attributes)
          {
            attributes.getResponse().write(bytes);
          }
        });
      }
      catch (IOException e)
      {
        log.debug(e.getMessage(), e);
        return sendResourceError(resourceResponse, 500, "Unable to read resource stream");
      }
      catch (ResourceStreamNotFoundException e)
      {
        log.debug(e.getMessage(), e);
        return sendResourceError(resourceResponse, 500, "Unable to open resource stream");
      }
      finally
      {
        try
        {
          resourceStream.close();
        }
        catch (IOException e)
        {
          log.warn("Unable to close the resource stream", e);
        }
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.