// Path: src/main/java/com/pureperfect/ferret/vfs/WebFileSystem.java
// public class WebFileSystem
// {
// 	private static final WebFileSystem singleton = new WebFileSystem();
// 
// 	private WebFileSystem()
// 	{
// 		// singleton
// 	}
// 
// 	/**
// 	 * Get the appropriate virtual web resource.
// 	 * 
// 	 * @param parent
// 	 *            The parent directory
// 	 * 
// 	 * @param context
// 	 *            the servlet context for the application
// 	 * @param path
// 	 *            the path to the folder or file
// 	 * @return the appropriate virtual resource
// 	 */
// 	public PathElement getVirtualPath(WebDirectory parent,
// 			ServletContext context, String path)
// 	{
// 		// Directories
// 		if (isWebDirectory(context, path))
// 		{
// 			return new ImplWebDirectory(parent, context, path);
// 		}
// 		// Handle Archives as URLs
// 		else if (path.endsWith(".jar"))
// 		{
// 			try
// 			{
// 				final URL jar = context.getResource(path);
// 
// 				return new ImplArchive(parent, jar);
// 			}
// 			catch (Throwable t)
// 			{
// 				throw new ScanException(t);
// 			}
// 		}
// 		// Class files
// 		else if (path.endsWith(".class"))
// 		{
// 			return new ImplWebClassFile(parent, context, path);
// 		}
// 		// Plain files
// 		else
// 		{
// 			return new ImplWebFile(parent, context, path);
// 		}
// 	}
// 
// 	private static boolean isWebDirectory(ServletContext context, String path)
// 	{
// 		/*
// 		 * If it ends with a '/' its definitely a directory. However not ending
// 		 * with a slash is equally valid (e.g. /WEB-INF/lib). The only way to
// 		 * resolve this is to see if the resource actually exists, but does not
// 		 * have a stream since directories cannot be streamed. This is a rather
// 		 * resource intensive approach, but I don't have a quicker solution at
// 		 * the moment for reliably testing whether or not a give path is a
// 		 * directory.
// 		 */
// 		try
// 		{
// 			return path.endsWith("/")
// 					|| (context.getResource(path) != null && context
// 							.getResourceAsStream(path) == null);
// 		}
// 		catch (MalformedURLException e)
// 		{
// 			throw new ScanException(e);
// 		}
// 	}
// 
// 	/**
// 	 * Get an instance of the file system.
// 	 * 
// 	 * @return an instance of the file system
// 	 */
// 	public static WebFileSystem getInstance()
// 	{
// 		return singleton;
// 	}
// }


import java.util.Set;
import javax.servlet.ServletContext;
import com.pureperfect.ferret.vfs.WebFileSystem;
package com.pureperfect.ferret;




/**
 * A Classpath scanner appropriate for scanning in a Java web application.
 * 
 * @author J. Chris Folsom
 * @version 1.0
 * @since 1.0
 */
public class WebScanner extends Scanner
{
	/**
	 * Create a new WebScanner.
	 */
	public WebScanner()
	{
		super();
	}

	/**
	 * Create a new WebScanner with the given pre-filter.
	 * 
	 * @param prefilter
	 *            the pre-filter to use
	 */
	public WebScanner(Prefilter prefilter)
	{
		super(prefilter);
	}

	/**
	 * Add private resources in WEB-INF to the scan path, but skip WEB-INF/lib
	 * and WEB-INF/classes.
	 * 
	 * @param context
	 *            the servlet context
	 */
	public void addPrivateResources(final ServletContext context)
	{
		Set<String> paths = context.getResourcePaths("/WEB-INF/");

		for (String path : paths)
		{
			// Skip /WEB-INF/lib and /WEB-INF/classes
			if (!("/WEB-INF/lib/".equals(path) || "/WEB-INF/classes/"
					.equals(path)))
			{
				this.add(context, path);
			}
		}
	}

	/**
	 * Add all files outside of WEB-INF/ to the scan path.
	 * 
	 * @param context
	 *            the servlet context
	 */
	public void addPublicResources(final ServletContext context)
	{
// Path: src/main/java/com/pureperfect/ferret/vfs/WebFileSystem.java
// public class WebFileSystem
// {
// 	private static final WebFileSystem singleton = new WebFileSystem();
// 
// 	private WebFileSystem()
// 	{
// 		// singleton
// 	}
// 
// 	/**
// 	 * Get the appropriate virtual web resource.
// 	 * 
// 	 * @param parent
// 	 *            The parent directory
// 	 * 
// 	 * @param context
// 	 *            the servlet context for the application
// 	 * @param path
// 	 *            the path to the folder or file
// 	 * @return the appropriate virtual resource
// 	 */
// 	public PathElement getVirtualPath(WebDirectory parent,
// 			ServletContext context, String path)
// 	{
// 		// Directories
// 		if (isWebDirectory(context, path))
// 		{
// 			return new ImplWebDirectory(parent, context, path);
// 		}
// 		// Handle Archives as URLs
// 		else if (path.endsWith(".jar"))
// 		{
// 			try
// 			{
// 				final URL jar = context.getResource(path);
// 
// 				return new ImplArchive(parent, jar);
// 			}
// 			catch (Throwable t)
// 			{
// 				throw new ScanException(t);
// 			}
// 		}
// 		// Class files
// 		else if (path.endsWith(".class"))
// 		{
// 			return new ImplWebClassFile(parent, context, path);
// 		}
// 		// Plain files
// 		else
// 		{
// 			return new ImplWebFile(parent, context, path);
// 		}
// 	}
// 
// 	private static boolean isWebDirectory(ServletContext context, String path)
// 	{
// 		/*
// 		 * If it ends with a '/' its definitely a directory. However not ending
// 		 * with a slash is equally valid (e.g. /WEB-INF/lib). The only way to
// 		 * resolve this is to see if the resource actually exists, but does not
// 		 * have a stream since directories cannot be streamed. This is a rather
// 		 * resource intensive approach, but I don't have a quicker solution at
// 		 * the moment for reliably testing whether or not a give path is a
// 		 * directory.
// 		 */
// 		try
// 		{
// 			return path.endsWith("/")
// 					|| (context.getResource(path) != null && context
// 							.getResourceAsStream(path) == null);
// 		}
// 		catch (MalformedURLException e)
// 		{
// 			throw new ScanException(e);
// 		}
// 	}
// 
// 	/**
// 	 * Get an instance of the file system.
// 	 * 
// 	 * @return an instance of the file system
// 	 */
// 	public static WebFileSystem getInstance()
// 	{
// 		return singleton;
// 	}
// }


// Path: src/main/java/com/pureperfect/ferret/WebScanner.java
import java.util.Set;
import javax.servlet.ServletContext;
import com.pureperfect.ferret.vfs.WebFileSystem;

package com.pureperfect.ferret;




/**
 * A Classpath scanner appropriate for scanning in a Java web application.
 * 
 * @author J. Chris Folsom
 * @version 1.0
 * @since 1.0
 */
public class WebScanner extends Scanner
{
	/**
	 * Create a new WebScanner.
	 */
	public WebScanner()
	{
		super();
	}

	/**
	 * Create a new WebScanner with the given pre-filter.
	 * 
	 * @param prefilter
	 *            the pre-filter to use
	 */
	public WebScanner(Prefilter prefilter)
	{
		super(prefilter);
	}

	/**
	 * Add private resources in WEB-INF to the scan path, but skip WEB-INF/lib
	 * and WEB-INF/classes.
	 * 
	 * @param context
	 *            the servlet context
	 */
	public void addPrivateResources(final ServletContext context)
	{
		Set<String> paths = context.getResourcePaths("/WEB-INF/");

		for (String path : paths)
		{
			// Skip /WEB-INF/lib and /WEB-INF/classes
			if (!("/WEB-INF/lib/".equals(path) || "/WEB-INF/classes/"
					.equals(path)))
			{
				this.add(context, path);
			}
		}
	}

	/**
	 * Add all files outside of WEB-INF/ to the scan path.
	 * 
	 * @param context
	 *            the servlet context
	 */
	public void addPublicResources(final ServletContext context)
	{
		Set<String> paths = context.getResourcePaths("/");