com.asual.lesscss.loader
Class StreamResourceLoader

java.lang.Object
  extended by com.asual.lesscss.loader.StreamResourceLoader
All Implemented Interfaces:
ResourceLoader
Direct Known Subclasses:
ClasspathResourceLoader, FilesystemResourceLoader, HTTPResourceLoader, JNDIResourceLoader

public abstract class StreamResourceLoader
extends Object
implements ResourceLoader

A base class for loader implementations. Each loader implementation is associated with a URL schema name. When requested resource path starts with the loader's associated schema, schema name is stripped and lookup is retried with plain name instead. Paths starting with other schema names are rejected, plain names are checked using openStream(String) - a non null return value indicates valid resource.

Author:
RafaƂ Krzewski

Constructor Summary
StreamResourceLoader()
           
 
Method Summary
 boolean exists(String path)
          Checks if the given resource exists.
protected abstract  String getSchema()
          Returns the schema name associated with the loader.
 String load(String path, String charset)
          Loads the given resource's contents.
protected abstract  InputStream openStream(String path)
          Returns an InputStream for reading the resource.
protected  String readStream(InputStream is, String charset)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamResourceLoader

public StreamResourceLoader()
Method Detail

getSchema

protected abstract String getSchema()
Returns the schema name associated with the loader.

Returns:
schema name.

openStream

protected abstract InputStream openStream(String path)
                                   throws IOException
Returns an InputStream for reading the resource.

Parameters:
path - the path of the resource.
Returns:
an InputStream or null if the resource does not exist.
Throws:
IOException - when i/o operation fails.

exists

public boolean exists(String path)
               throws IOException
Description copied from interface: ResourceLoader
Checks if the given resource exists.

Specified by:
exists in interface ResourceLoader
Parameters:
path - resource path.
Returns:
true if the resource exists.
Throws:
IOException - when i/o error occurs while checking for resource existence.

load

public String load(String path,
                   String charset)
            throws IOException
Description copied from interface: ResourceLoader
Loads the given resource's contents.

Specified by:
load in interface ResourceLoader
Parameters:
path - resource path.
charset - character set name, valid with respect to Charset.
Returns:
resource contents as a string.
Throws:
IOException - when i/o error occurs while loading the resource, or charset is invalid.

readStream

protected String readStream(InputStream is,
                            String charset)
                     throws IOException
Throws:
IOException


Copyright © 2013 Asual DZZD. All Rights Reserved.