Examples of IResourceStream


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

      String path = Packages.absolutePath(scope, fileName);

      Application app = Application.get();

      // first try default class loading locator to find the resource
      IResourceStream stream = app.getResourceSettings()
        .getResourceStreamLocator()
        .locate(scope, path, getStyle(), getVariation(), getLocale(), null, false);

      if (stream == null)
      {
        // if the default locator didn't find the resource then fallback
        stream = new ResourceStreamLocator().locate(scope, path, getStyle(), getVariation(), getLocale(), null, false);
      }

      if (stream == null)
      {
        throw new IllegalArgumentException("resource " + fileName + " not found for scope " +
          scope + " (path = " + path + ")");
      }

      setLastModified(stream.lastModifiedTime());

      try
      {
        if (encoding != null)
        {
          buffer.append(Streams.readString(stream.getInputStream(), encoding));
        }
        else
        {
          buffer.append(Streams.readString(stream.getInputStream()));
        }
      }
      catch (IOException e)
      {
        throw new RuntimeException(e);
      }
      catch (ResourceStreamNotFoundException e)
      {
        throw new RuntimeException(e);
      }
      finally
      {
        try
        {
          stream.close();
        }
        catch (IOException e)
        {
          log.error(e.getMessage(), e);
        }
View Full Code Here

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

  private List<IResourceStream> collectResourceStreams()
  {
    List<IResourceStream> ret = new ArrayList<IResourceStream>(providedResources.size());
    for (IReferenceHeaderItem curItem : providedResources)
    {
      IResourceStream stream = ((PackageResource)curItem.getReference().getResource()).getResourceStream();
      if (stream == null)
        return null;

      ret.add(stream);
    }
View Full Code Here

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

    return style != null ? style : Session.get().getStyle();
  }

  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

    final ResourceResponse resourceResponse = new ResourceResponse();

    if (resourceResponse.dataNeedsToBeWritten(attributes))
    {
      // get resource stream
      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");

      String contentType = resourceStream.getContentType();

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

      // set Content-Type (may be null)
      resourceResponse.setContentType(contentType);

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

      if (lastModified != null)
        resourceResponse.setLastModified(lastModified);

      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 UrlAttributes(null, null, null);

    return new 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

      if (null != propertiesFolder)
      {
        WebApplicationPath webPath = new WebApplicationPath(servletContext);
        webPath.add(propertiesFolder);
        IResourceStream stream = webPath.find(Initializer.class, velocityPropertiesFile);
        InputStream is = null;
        try
        {
          is = stream.getInputStream();
          Properties props = new Properties();
          props.load(is);
          return props;
        }
        catch (IOException e)
View Full Code Here

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

      fileName = file.getName();
    }

    fileName = UrlEncoder.QUERY_INSTANCE.encode(fileName, getRequest().getCharset());

    IResourceStream resourceStream = new FileResourceStream(
      new org.apache.wicket.util.file.File(file));
    getRequestCycle().scheduleRequestHandlerAfterCurrent(
      new ResourceStreamRequestHandler(resourceStream)
      {
        @Override
View Full Code Here

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

  public IResourceStream locate(Class<?> clazz, String path)
  {
    Key key = new Key(clazz.getName(), path, null, null, null);
    IResourceStreamReference resourceStreamReference = cache.get(key);

    final IResourceStream result;
    if (resourceStreamReference == null)
    {
      result = delegate.locate(clazz, path);

      updateCache(key, result);
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.