[jboss-cvs] jboss-seam/src/main/org/jboss/seam/mock ...
Michael Youngstrom
youngm at gmail.com
Mon May 21 17:25:00 EDT 2007
User: myoungstrom
Date: 07/05/21 17:25:00
Modified: src/main/org/jboss/seam/mock MockServletContext.java
Log:
JBSEAM-1301
Revision Changes Path
1.7 +199 -177 jboss-seam/src/main/org/jboss/seam/mock/MockServletContext.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MockServletContext.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/mock/MockServletContext.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- MockServletContext.java 18 May 2007 18:29:09 -0000 1.6
+++ MockServletContext.java 21 May 2007 21:25:00 -0000 1.7
@@ -1,7 +1,8 @@
-//$Id: MockServletContext.java,v 1.6 2007/05/18 18:29:09 gavin Exp $
+//$Id: MockServletContext.java,v 1.7 2007/05/21 21:25:00 myoungstrom Exp $
package org.jboss.seam.mock;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
@@ -20,6 +21,7 @@
{
private Map<String, String> initParameters = new HashMap<String, String>();
+
private Map<String, Object> attributes = new HashMap<String, Object>();
public Map<String, String> getInitParameters()
@@ -54,24 +56,43 @@
public Set getResourcePaths(String name)
{
- String path = getClass().getResource("/WEB-INF/web.xml").getPath();
- File rootFile = new File(path).getParentFile().getParentFile();
+ Enumeration<URL> enumeration = null;
+ try
+ {
+ enumeration = getClass().getClassLoader().getResources("WEB-INF");
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Error finding webroot.", e);
+ }
Set<String> result = new HashSet<String>();
- File[] files = rootFile.listFiles();
- addPaths( result, files, rootFile.getPath() );
+ while (enumeration.hasMoreElements())
+ {
+ URL url = enumeration.nextElement();
+ File rootFile = new File(url.getPath()).getParentFile();
+ File newFile = new File(rootFile.getPath() + name);
+ File[] files = newFile.listFiles();
+ if (files != null)
+ {
+ addPaths(result, files, rootFile.getPath());
+ }
+ }
return result;
}
private static void addPaths(Set<String> result, File[] files, String rootPath)
{
- for (File file: files)
+ for (File file : files)
+ {
+ String filePath = file.getPath().substring(rootPath.length()).replace('\\', '/');
+ if (file.isDirectory())
{
- //apparently Tomcat does not recurse:
- /*if ( file.isDirectory() )
+ result.add(filePath + "/");
+ }
+ else
{
- addPaths( result, file.listFiles(), rootPath );
- }*/
- result.add( file.getPath().substring( rootPath.length() ) );
+ result.add(filePath);
+ }
}
}
@@ -142,7 +163,7 @@
public Enumeration getInitParameterNames()
{
- return new IteratorEnumeration( initParameters.keySet().iterator() );
+ return new IteratorEnumeration(initParameters.keySet().iterator());
}
public Object getAttribute(String att)
@@ -152,7 +173,7 @@
public Enumeration getAttributeNames()
{
- return new IteratorEnumeration( attributes.keySet().iterator() );
+ return new IteratorEnumeration(attributes.keySet().iterator());
}
public void setAttribute(String att, Object val)
@@ -170,7 +191,8 @@
return "Mock";
}
- public String getContextPath() {
+ public String getContextPath()
+ {
return null;
}
More information about the jboss-cvs-commits
mailing list