ro.isdc.wro.model.resource.locator.wildcard
Class JarWildcardStreamLocator

java.lang.Object
  extended by ro.isdc.wro.model.resource.locator.wildcard.DefaultWildcardStreamLocator
      extended by ro.isdc.wro.model.resource.locator.wildcard.JarWildcardStreamLocator
All Implemented Interfaces:
WildcardExpandedHandlerAware, WildcardStreamLocator

public class JarWildcardStreamLocator
extends DefaultWildcardStreamLocator

Resolves classpath resources looking for wildcard patterns in both file system and in JAR files.

The locateStream(String, File) overrides the default strategy defined in DefaultWildcardStreamLocator and it tries to open the provided file as a JAR. If that's successfully opened all entries inside this container will be verified against the wildcard pattern. If the JAR-lookup strategy fails, default strategy is invoked.

For the moment this WildcardStreamLocator only supports a single wildcard.

Since:
1.3.6
Author:
Matias Mirabelli <matias.mirabelli@globant.com>

Field Summary
 
Fields inherited from class ro.isdc.wro.model.resource.locator.wildcard.DefaultWildcardStreamLocator
RECURSIVE_WILDCARD
 
Constructor Summary
JarWildcardStreamLocator()
           
 
Method Summary
protected  boolean accept(JarEntry entry, String wildcard)
          Validates an entry against a wildcard and determines whether the pattern matches or not.
protected  List<String> getSupportedContainerExtensions()
          Returns a list of file extensions of all valid JAR files.
 InputStream locateStream(String uri, File folder)
          Finds the specified URI pattern inside a JAR file.
protected  InputStream locateStreamFromJar(String uri, File jarPath)
          Finds the specified wildcard-URI resource(s) inside a JAR file and returns an InputStream to read a bundle of matching resources.
protected  JarFile open(File jarFile)
          Opens the specified JAR file and returns a valid handle.
 
Methods inherited from class ro.isdc.wro.model.resource.locator.wildcard.DefaultWildcardStreamLocator
handleFoundResources, hasWildcard, setWildcardExpanderHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JarWildcardStreamLocator

public JarWildcardStreamLocator()
Method Detail

locateStream

public InputStream locateStream(String uri,
                                File folder)
                         throws IOException
Finds the specified URI pattern inside a JAR file. If the specified file isn't a valid JAR default strategy will be used instead.

Specified by:
locateStream in interface WildcardStreamLocator
Overrides:
locateStream in class DefaultWildcardStreamLocator
Parameters:
uri - the resource of the uri to locate. This uri should be exactly the same as defined in Resource.
folder - parent from where the search of fileNameWithWildcard should start.
Returns:
InputStream to the resources collection matching the wildcard.
Throws:
IOException - if folder is invalid or when I/O error occurs while locating the stream.

getSupportedContainerExtensions

protected List<String> getSupportedContainerExtensions()
Returns a list of file extensions of all valid JAR files.

Returns:
A List of file extensions including the final dot. Valid examples are: .jar, .war. By default it only supports .jar extension.

accept

protected boolean accept(JarEntry entry,
                         String wildcard)
Validates an entry against a wildcard and determines whether the pattern matches or not. If the entry is accepted this will be included in the result InputStream.

Parameters:
entry - Entry to evaluate. It cannot be null.
wildcard - Wildcard to match. It cannot be null or empty.
Returns:
true if the expression matches, false otherwise.

open

protected JarFile open(File jarFile)
Opens the specified JAR file and returns a valid handle.

Parameters:
jarFile - Location of the valid JAR file to read. It cannot be null.
Returns:
A valid JarFile to read resources.
Throws:
IllegalArgumentException - If the file cannot be opened because an IOException.

locateStreamFromJar

protected final InputStream locateStreamFromJar(String uri,
                                                File jarPath)
                                         throws IOException
Finds the specified wildcard-URI resource(s) inside a JAR file and returns an InputStream to read a bundle of matching resources.

Parameters:
uri - Resource(s) URI to match. It cannot be null or empty.
jarPath - A valid JAR file. It cannot be null.
Returns:
A valid InputStream to read the bundle. Clients are responsible of closing this InputStream .
Throws:
IOException - If there's any error reading the JAR file.


Copyright © 2008-2011. All Rights Reserved.