Commits

Anonymous committed b600e8b

various optimizations for QuickStart

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@2118573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (3)

src/java/com/opensymphony/webwork/quickstart/MultiDirResource.java

     MultiWebApplicationContext ctx;
     File[] files;
     String uri;
+    boolean simple = false;
 
     public MultiDirResource(MultiWebApplicationContext ctx, String uri, List pathPriority, Map paths) {
         this.ctx = ctx;
         }
 
         this.files = (File[]) files.toArray(new File[files.size()]);
+        if (this.files.length == 1) {
+            this.simple = true;
+        }
     }
 
     public void release() {
     public boolean exists() {
         for (int i = 0; i < files.length; i++) {
             File file = files[i];
-            if (file.exists()) {
+            if (simple || file.exists()) {
                 return true;
             }
         }
     public boolean isDirectory() {
         for (int i = 0; i < files.length; i++) {
             File file = files[i];
-            if (file.exists()) {
+            if (simple || file.exists()) {
                 return file.isDirectory();
             }
         }
     public long lastModified() {
         for (int i = 0; i < files.length; i++) {
             File file = files[i];
-            if (file.exists()) {
+            if (simple || file.exists()) {
                 return file.lastModified();
             }
         }
     public long length() {
         for (int i = 0; i < files.length; i++) {
             File file = files[i];
-            if (file.exists()) {
+            if (simple || file.exists()) {
                 return file.length();
             }
         }
     public URL getURL() {
         for (int i = 0; i < files.length; i++) {
             File file = files[i];
-            if (file.exists()) {
+            if (simple || file.exists()) {
                 try {
                     return file.toURL();
                 } catch (MalformedURLException e) {
     public File getFile() throws IOException {
         for (int i = 0; i < files.length; i++) {
             File file = files[i];
-            if (file.exists()) {
+            if (simple || file.exists()) {
                 return file;
             }
         }
     public String getName() {
         for (int i = 0; i < files.length; i++) {
             File file = files[i];
-            if (file.exists()) {
+            if (simple || file.exists()) {
                 return file.getName();
             }
         }
     public InputStream getInputStream() throws IOException {
         for (int i = 0; i < files.length; i++) {
             File file = files[i];
-            if (file.exists()) {
+            if (simple || file.exists()) {
                 return new FileInputStream(file);
             }
         }
     public OutputStream getOutputStream() throws IOException, SecurityException {
         for (int i = 0; i < files.length; i++) {
             File file = files[i];
-            if (file.exists()) {
+            if (simple || file.exists()) {
                 return new FileOutputStream(file);
             }
         }
     public boolean delete() throws SecurityException {
         for (int i = 0; i < files.length; i++) {
             File file = files[i];
-            if (file.exists()) {
+            if (simple || file.exists()) {
                 return file.delete();
             }
         }
         HashSet set = new HashSet();
         for (int i = 0; i < files.length; i++) {
             File file = files[i];
-            if (file.exists()) {
+            if (simple || file.exists()) {
                 String[] files = file.list();
                 for (int j = 0; j < files.length; j++) {
                     String s = files[j];

src/java/com/opensymphony/webwork/quickstart/MultiWebApplicationContext.java

 import org.mortbay.util.FileResource;
 
 import java.io.IOException;
+import java.io.File;
 import java.net.URLClassLoader;
 import java.net.URL;
 import java.lang.reflect.Constructor;
         // still haven't found what we're looking for?
         // Alright, let's just hack this to work in IDEA
         if (uriInContext.equals("/webwork")) {
-            return FileResource.newResource("src/java/META-INF/taglib.tld");
+            // we do this check to support both "quickstart:showcase" and "quickstart" (using quickstart.xml)
+            if (new File("../../src/java/META-INF/taglib.tld").exists()) {
+                return FileResource.newResource("../../src/java/META-INF/taglib.tld");
+            } else {
+                return FileResource.newResource("src/java/META-INF/taglib.tld");
+            }
         }
 
         MultiDirResource resource = newResolver(uriInContext);

src/java/com/opensymphony/webwork/quickstart/QuickStart.java

         System.out.println("********************************************************");
     }
 
-    static class QuickStartWebAppContext extends WebApplicationContext {
-        public QuickStartWebAppContext() {
-        }
-
-        public QuickStartWebAppContext(String string) {
-            super(string);
-        }
-
-        public Resource getResource(String string) throws IOException {
-            if (string.startsWith("/WEB-INF/lib/")) {
-                String jar = string.substring("/WEB-INF/lib/".length());
-                ClassLoader parent = Thread.currentThread().getContextClassLoader();
-                while (parent != null) {
-                    if (parent instanceof URLClassLoader) {
-                        URL[] urls = ((URLClassLoader) parent).getURLs();
-                        for (int i = 0; i < urls.length; i++) {
-                            URL url = urls[i];
-                            if (url.toExternalForm().endsWith(jar)) {
-                                return JarResource.newResource(url);
-                            }
-                        }
-                    }
-
-                    parent = parent.getParent();
-                }
-            }
-
-            // still haven't found what we're looking for?
-            // Alright, let's just hack this to work in IDEA
-            if (string.equals("/webwork")) {
-                return FileResource.newResource("src/java/META-INF/taglib.tld");
-            }
-
-            return super.getResource(string);
-        }
-    }
-
     static class MyURLClassLoader extends URLClassLoader {
         private ClassLoader parent;