1 14 package org.wings.resource; 15 16 import org.wings.Resource; 17 import org.wings.StaticResource; 18 import org.wings.externalizer.ExternalizeManager; 19 20 import java.io.InputStream ; 21 22 30 public class ClasspathResource 31 extends StaticResource { 32 35 protected final ClassLoader classLoader; 36 37 40 protected final String resourceFileName; 41 42 45 public ClasspathResource(String resourceFileName) { 46 this(Resource.class.getClassLoader(), resourceFileName, "unkonwn"); 47 } 48 49 52 public ClasspathResource(String resourceFileName, String mimeType) { 53 this(Resource.class.getClassLoader(), resourceFileName, mimeType); 54 } 55 56 62 public ClasspathResource(ClassLoader classLoader, String resourceFileName) { 63 this(classLoader, resourceFileName, "unknown"); 64 } 65 66 72 public ClasspathResource(ClassLoader classLoader, String resourceFileName, String mimeType) { 73 super(null, mimeType); 74 this.classLoader = classLoader; 75 this.resourceFileName = resourceFileName; 76 int dotIndex = resourceFileName.lastIndexOf('.'); 77 if (dotIndex > -1) { 78 extension = resourceFileName.substring(dotIndex + 1); 79 } 80 externalizerFlags = ExternalizeManager.GLOBAL | ExternalizeManager.FINAL; 81 } 82 83 84 public String toString() { 85 return getId() + " " + resourceFileName; 86 } 87 88 protected InputStream getResourceStream() { 89 return classLoader.getResourceAsStream(resourceFileName); 90 } 91 92 96 97 105 public int hashCode() { 106 return classLoader.hashCode() ^ resourceFileName.hashCode(); 107 } 108 109 115 public boolean equals(Object o) { 116 if (o instanceof ClasspathResource) { 117 ClasspathResource other = (ClasspathResource) o; 118 return ((this == other) 119 || (classLoader.equals(other.classLoader) 120 && resourceFileName.equals(other.resourceFileName))); 121 } 122 return false; 123 } 124 } 125 126 127 | Popular Tags |