Examples of IResourceStream


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

    Locale locale, String extension, boolean strict)
  {
    Key key = new Key(scope.getName(), path, locale, style, variation);
    IResourceStreamReference resourceStreamReference = cache.get(key);

    final IResourceStream result;
    if (resourceStreamReference == null)
    {
      result = delegate.locate(scope, path, style, variation, locale, extension, strict);

      updateCache(key, result);
View Full Code Here

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

    if (pathname == null)
    {
      return null;
    }

    IResourceStream resourceStream = super.find(clazz, pathname);

    if (resourceStream == null && pathname.startsWith(WEB_INF) == false)
    {
      for (String path : webappPaths)
      {
View Full Code Here

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

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

    Application app = Application.get();

    // first try default class loading locator to find the resource
    IResourceStream stream = app.getResourceSettings()
      .getResourceStreamLocator()
      .locate(clazz, path);

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

    if (stream == null)
    {
      throw new IllegalArgumentException("resource " + fileName + " not found for scope " +
        clazz + " (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

  @Override
  public IResourceStream locate(final Class<?> clazz, final String path)
  {
    // First try with the resource finder registered with the application
    // (allows for markup reloading)
    IResourceStream stream = locateByResourceFinder(clazz, path);
    if (stream != null)
    {
      return stream;
    }
View Full Code Here

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

      extension, strict);
    while (iter.hasNext())
    {
      String newPath = iter.next();

      IResourceStream stream = locate(clazz, newPath);
      if (stream != null)
      {
        stream.setLocale(iter.getLocale());
        stream.setStyle(iter.getStyle());
        stream.setVariation(iter.getVariation());
        return stream;
      }
    }

    return null;
View Full Code Here

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

   * @param path
   * @return resource stream
   */
  protected IResourceStream locateByClassLoader(final Class<?> clazz, final String path)
  {
    IResourceStream resourceStream = null;

    if (clazz != null)
    {
      resourceStream = getResourceStream(clazz.getClassLoader(), path);
      if (resourceStream != null)
View Full Code Here

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

    ServletContext context = Mockito.mock(ServletContext.class);
    Mockito.when(context.getResource(Mockito.any(String.class))).thenReturn(webUrl);

    WebApplicationPath path = new WebApplicationPath(context);
    IResourceStream resourceStream = path.find(String.class, "WEB-INF/web.xml");
    assertNull(resourceStream);

    IResourceStream otherResourceStream = path.find(String.class, "any/other/resource");
    assertNotNull(otherResourceStream);

  }
View Full Code Here

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

    // until <wicket:child/> is found. Convert <wicket:child/>
    // into <wicket:child> and add it as well.
    WicketTag childTag = null;
    int baseIndex = 0;
    MarkupResourceStream markupResourceStream = baseMarkup.getMarkupResourceStream();
    IResourceStream resource = markupResourceStream.getResource();
    Class<? extends Component> markupClass = markupResourceStream.getMarkupClass();

    for (; baseIndex < baseMarkup.size(); baseIndex++)
    {
      MarkupElement element = baseMarkup.get(baseIndex);
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.