Changeset 9141
- Timestamp:
- 07/02/08 15:09:24 (5 months ago)
- Files:
-
- helma-ng/trunk/src/org/helma/javascript/ModuleScope.java (modified) (3 diffs)
- helma-ng/trunk/src/org/helma/javascript/ReloadableScript.java (modified) (2 diffs)
- helma-ng/trunk/src/org/helma/repository/AbstractRepository.java (modified) (9 diffs)
- helma-ng/trunk/src/org/helma/repository/AbstractResource.java (added)
- helma-ng/trunk/src/org/helma/repository/FileRepository.java (modified) (4 diffs)
- helma-ng/trunk/src/org/helma/repository/FileResource.java (modified) (3 diffs)
- helma-ng/trunk/src/org/helma/repository/Repository.java (modified) (5 diffs)
- helma-ng/trunk/src/org/helma/repository/Resource.java (modified) (4 diffs)
- helma-ng/trunk/src/org/helma/repository/ResourceTracker.java (modified) (2 diffs)
- helma-ng/trunk/src/org/helma/repository/ZipRepository.java (modified) (8 diffs)
- helma-ng/trunk/src/org/helma/repository/ZipResource.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
helma-ng/trunk/src/org/helma/javascript/ModuleScope.java
r9107 r9141 31 31 Resource resource; 32 32 Repository repository; 33 String name; 33 34 long checksum; 34 35 private static final long serialVersionUID = -2409425841990094897L; … … 38 39 this.resource = resource; 39 40 this.repository = repository; 41 this.name = moduleName; 40 42 setParentScope(null); 41 43 setPrototype(prototype); 42 44 defineProperty("__name__", moduleName, DONTENUM); 43 defineProperty("__path__", repository.get Name(), DONTENUM);45 defineProperty("__path__", repository.getPath(), DONTENUM); 44 46 } 45 47 … … 54 56 public void setChecksum(long checksum) { 55 57 this.checksum = checksum; 58 } 59 60 public String getName() { 61 return name; 56 62 } 57 63 helma-ng/trunk/src/org/helma/javascript/ReloadableScript.java
r9107 r9141 88 88 try { 89 89 exception = null; 90 script = cx.compileReader(resource.getReader(), resource.get Name(), 1, null);90 script = cx.compileReader(resource.getReader(), resource.getPath(), 1, null); 91 91 } catch (Exception x) { 92 92 exception = x; … … 124 124 for (Resource res: resources) { 125 125 if (res.getName().endsWith(".js")) { 126 scripts.add(cx.compileReader(res.getReader(), res.get Name(), 1, null));126 scripts.add(cx.compileReader(res.getReader(), res.getPath(), 1, null)); 127 127 } 128 128 } helma-ng/trunk/src/org/helma/repository/AbstractRepository.java
r8986 r9141 20 20 21 21 import java.io.File; 22 import java.io.IOException;23 22 import java.util.*; 24 23 … … 41 40 42 41 /** 43 * Holds mounted repositories44 */45 Map<String,Repository> mounted = new HashMap<String,Repository>();46 47 /**48 42 * Holds direct resources 49 43 */ … … 53 47 * Cached name for faster access 54 48 */ 55 String name;49 String path; 56 50 57 51 /** 58 52 * Cached short name for faster access 59 53 */ 60 String shortName;54 String name; 61 55 62 56 /* … … 85 79 * Get the full name that identifies this repository globally 86 80 */ 87 public String get Name() {88 return name;81 public String getPath() { 82 return path; 89 83 } 90 84 … … 93 87 * parent repository 94 88 */ 95 public String getShortName() { 96 return shortName; 97 } 98 99 /** 100 * Get this repository's logical script root repository. 101 * 102 *@see {isScriptRoot()} 103 */ 104 public Repository getRootRepository() { 105 if (parent == null || isScriptRoot()) { 106 return this; 107 } else { 108 return parent.getRootRepository(); 109 } 110 } 111 112 /** 113 * Mount a child repository under the given path name. 114 * 115 * @param pathname the path name 116 * @param child the child element 117 */ 118 public void mountRepository(Repository child, String pathname) { 119 if (!child.equals(mounted.get(pathname))) 120 mounted.put(pathname, child); 89 public String getName() { 90 return name; 121 91 } 122 92 … … 129 99 String[] subs = StringUtils.split(path, separator); 130 100 if (subs.length == 1) { 131 Resource res = resources.get(subs[0]); 101 Resource resource = resources.get(subs[0]); 102 if (resource != null) { 103 return resource; 104 } 132 105 // if resource does not exist, create it 133 if (res == null) { 134 res = createResource(subs[0]); 135 resources.put(subs[0], res); 136 } 137 return res; 106 return createResource(subs[0]); 138 107 } 139 108 Repository repository = this; … … 160 129 System.err.println("Warning: resource path doesn not exist: " + path); 161 130 } 162 try { 163 return repository.getAllResources(); 164 } catch (IOException iox) { 165 return Collections.EMPTY_LIST; 166 } 131 return repository.getAllResources(); 167 132 } 168 133 … … 194 159 * contained in sub-reposotories. 195 160 */ 196 public synchronized List<Resource> getAllResources() throws IOException{161 public synchronized List<Resource> getAllResources() { 197 162 update(); 198 163 ArrayList<Resource> allResources = new ArrayList<Resource>(); … … 211 176 */ 212 177 public String toString() { 213 return get Name();178 return getPath(); 214 179 } 215 180 helma-ng/trunk/src/org/helma/repository/FileRepository.java
r8960 r9141 72 72 73 73 if (parent == null) { 74 name = shortName = directory.getAbsolutePath();74 path = name = directory.getAbsolutePath(); 75 75 } else { 76 76 this.parent = parent; 77 shortName = directory.getName(); 78 name = directory.getAbsolutePath(); 79 } 80 } 81 77 name = directory.getName(); 78 path = directory.getAbsolutePath(); 79 } 80 } 81 82 /** 83 * Check whether the repository exists. 84 * @return true if the repository exists. 85 */ 82 86 public boolean exists() { 83 87 return directory.exists() && directory.isDirectory(); 84 }85 86 public void create() {87 if (!directory.exists() || !directory.isDirectory()) {88 directory.mkdirs();89 }90 }91 92 /**93 * Checks wether the repository is to be considered a top-level94 * repository from a scripting point of view. For example, a zip95 * file within a file repository is not a root repository from96 * a physical point of view, but from the scripting point of view it is.97 *98 * @return true if the repository is to be considered a top-level script repository99 */100 public boolean isScriptRoot() {101 return parent == null;102 88 } 103 89 … … 109 95 */ 110 96 public Repository getChildRepository(String name) { 111 if (mounted.containsKey(name)) {112 return mounted.get(name);113 }114 97 return new FileRepository(new File(directory, name), this); 115 98 } … … 185 168 // a file resource 186 169 FileResource resource = new FileResource(file, this); 187 newResources.put(resource.get ShortName(), resource);170 newResources.put(resource.getName(), resource); 188 171 } 189 172 } … … 218 201 219 202 public String toString() { 220 return new StringBuffer("FileRepository[").append( name).append("]").toString();203 return new StringBuffer("FileRepository[").append(path).append("]").toString(); 221 204 } 222 205 } helma-ng/trunk/src/org/helma/repository/FileResource.java
r8994 r9141 25 25 File file; 26 26 Repository repository; 27 String path; 27 28 String name; 28 String shortName;29 29 String baseName; 30 30 … … 44 44 this.repository = repository == null ? 45 45 new FileRepository(file.getParentFile()) : repository; 46 name= file.getPath();47 shortName = file.getName();46 path = file.getPath(); 47 name = file.getName(); 48 48 // base name is short name with extension cut off 49 int lastDot = shortName.lastIndexOf("."); 50 baseName = (lastDot == -1) ? shortName : shortName.substring(0, lastDot); 49 int lastDot = name.lastIndexOf("."); 50 baseName = (lastDot == -1) ? name : name.substring(0, lastDot); 51 } 52 53 public String getPath() { 54 return path; 51 55 } 52 56 53 57 public String getName() { 54 58 return name; 55 }56 57 public String getShortName() {58 return shortName;59 59 } 60 60 … … 122 122 123 123 public int hashCode() { 124 return 17 + name.hashCode();124 return 17 + path.hashCode(); 125 125 } 126 126 127 127 public boolean equals(Object obj) { 128 return obj instanceof FileResource && name.equals(((FileResource)obj).name);128 return obj instanceof FileResource && path.equals(((FileResource)obj).path); 129 129 } 130 130 131 131 public String toString() { 132 return get Name();132 return getPath(); 133 133 } 134 134 } helma-ng/trunk/src/org/helma/repository/Repository.java
r8960 r9141 77 77 * @throws IOException an I/O error occurred 78 78 */ 79 public List<Resource> getAllResources() throws IOException;79 public List<Resource> getAllResources(); 80 80 81 81 /** … … 95 95 96 96 /** 97 * Creates the repository if does not exist yet98 *99 * @throws IOException an I/O error occurred100 */101 public void create() throws IOException;102 103 /**104 * Checks wether the repository is to be considered a top-level105 * repository from a scripting point of view. For example, a zip106 * file within a file repository is not a root repository from107 * a physical point of view, but from the scripting point of view it is.108 *109 * @return true if the repository is to be considered a top-level script repository110 */111 public boolean isScriptRoot();112 113 /**114 97 * Returns this repository's parent repository. 115 98 * Returns null if this repository already is the top-level repository … … 127 110 128 111 /** 129 * Get this repository's logical script root repository.130 *131 * @see {isScriptRoot()}132 * @return top-level repository133 */134 public Repository getRootRepository();135 136 /**137 * Mount a child repository under the given path name.138 *139 * @param pathname the path name140 * @param child the child element141 */142 public void mountRepository(Repository child, String pathname);143 144 /**145 112 * Returns the name of the repository; this is a full name including all 146 113 * parent repositories. … … 148 115 * @return full name of the repository 149 116 */ 150 public String get Name();117 public String getPath(); 151 118 152 119 /** … … 155 122 * @return name of the repository 156 123 */ 157 public String get ShortName();124 public String getName(); 158 125 159 126 } helma-ng/trunk/src/org/helma/repository/Resource.java
r8835 r9141 17 17 package org.helma.repository; 18 18 19 import java.io.IOException; 19 20 import java.io.InputStream; 20 import java.io.IOException;21 21 import java.io.Reader; 22 import java.net.MalformedURLException; 22 23 import java.net.URL; 23 24 … … 32 33 * @return last modified date 33 34 */ 34 public long lastModified() ;35 public long lastModified() throws IOException; 35 36 36 37 /** … … 74 75 75 76 /** 76 * Returns the name of the resource; does not include the name of the 77 * repository the resource was fetched from 78 * @return name of the resource 77 * Returns the path of the resource. 78 * @return path of the resource 79 */ 80 public String getPath(); 81 82 /** 83 * Returns the short name of the resource. 84 * @return short name of the resource 79 85 */ 80 86 public String getName(); 81 82 /**83 * Returns the short name of the resource which is its name exclusive file84 * ending if it exists85 * @return short name of the resource86 */87 public String getShortName();88 87 89 88 /** … … 99 98 * @return url to the resource 100 99 */ 101 public URL getUrl() throws UnsupportedOperationException ;100 public URL getUrl() throws UnsupportedOperationException, MalformedURLException; 102 101 103 102 /** helma-ng/trunk/src/org/helma/repository/ResourceTracker.java
r8835 r9141 28 28 long lastModified; 29 29 30 public ResourceTracker(Resource resource) {30 public ResourceTracker(Resource resource) throws IOException { 31 31 this.resource = resource; 32 32 markClean(); … … 37 37 } 38 38 39 public void markClean() {39 public void markClean() throws IOException { 40 40 lastModified = resource.lastModified(); 41 41 } helma-ng/trunk/src/org/helma/repository/ZipRepository.java
r8986 r9141 81 81 82 82 if (zipentry == null) { 83 name = shortName = file.getName();83 path = name = file.getName(); 84 84 depth = 0; 85 85 entryPath = ""; … … 87 87 String[] pathArray = StringUtils.split(zipentry.getName(), separator); 88 88 depth = pathArray.length; 89 shortName = pathArray[depth - 1];89 name = pathArray[depth - 1]; 90 90 entryPath = zipentry.getName(); 91 name = new StringBuffer(parent.getName())92 .append('/').append( shortName).toString();91 path = new StringBuffer(parent.getPath()) 92 .append('/').append(name).toString(); 93 93 } 94 94 } … … 126 126 } 127 127 String[] entrypath = StringUtils.split(eName, separator); 128 if (depth > 0 && ! shortName.equals(entrypath[depth-1])) {128 if (depth > 0 && !name.equals(entrypath[depth-1])) { 129 129 // catch case where our name is Foo and other's is FooBar 130 130 continue; … … 136 136 // create a new child resource 137 137 ZipResource resource = new ZipResource(entry.getName(), this); 138 newResources.put(resource.get ShortName(), resource);138 newResources.put(resource.getName(), resource); 139 139 } else if (entrypath.length > depth) { 140 140 // create a new child repository … … 213 213 } 214 214 215 public void create() {216 // we do not create zip files as it makes no sense217 throw new UnsupportedOperationException("create() not implemented for ZipRepository");218 }219 220 /**221 * Checks wether the repository is to be considered a top-level222 * repository from a scripting point of view. For example, a zip223 * file within a file repository is not a root repository from224 * a physical point of view, but from the scripting point of view it is.225 *226 * @return true if the repository is to be considered a top-level script repository227 */228 public boolean isScriptRoot() {229 return depth == 0;230 }231 232 215 /** 233 216 * Get a child repository with the given name … … 237 220 */ 238 221 public Repository getChildRepository(String name) { 239 if (mounted.containsKey(name)) {240 return mounted.get(name);241 }242 222 return new ZipRepository(file, this, new ZipEntry(entryPath + "/" + name)); 243 223 } … … 248 228 249 229 public int hashCode() { 250 return 17 + (37 * file.hashCode()) + (37 * name.hashCode());230 return 17 + (37 * file.hashCode()) + (37 * path.hashCode()); 251 231 } 252 232 … … 257 237 258 238 ZipRepository rep = (ZipRepository) obj; 259 return (file.equals(rep.file) && name.equals(rep.name));239 return (file.equals(rep.file) && path.equals(rep.path)); 260 240 } 261 241 262 242 public String toString() { 263 return new StringBuffer("ZipRepository[").append( name).append("]").toString();243 return new StringBuffer("ZipRepository[").append(path).append("]").toString(); 264 244 } 265 245 helma-ng/trunk/src/org/helma/repository/ZipResource.java
r8835 r9141 26 26 private String entryName; 27 27 private ZipRepository repository; 28 private String path; 28 29 private String name; 29 private String shortName;30 30 private String baseName; 31 31 … … 36 36 int lastSlash = entryName.lastIndexOf('/'); 37 37 38 shortName = entryName.substring(lastSlash + 1);39 name = new StringBuffer(repository.getName()).append('/')40 .append( shortName).toString();38 name = entryName.substring(lastSlash + 1); 39 path = new StringBuffer(repository.getPath()).append('/') 40 .append(name).toString(); 41 41 42 42 // base name is short name with extension cut off 43 int lastDot = shortName.lastIndexOf(".");44 baseName = (lastDot == -1) ? shortName : shortName.substring(0, lastDot);43 int lastDot = name.lastIndexOf("."); 44 baseName = (lastDot == -1) ? name : name.substring(0, lastDot); 45 45 } 46 46 … … 131 131 } 132 132 133 public String getPath() { 134 return path; 135 } 136 133 137 public String getName() { 134 138 return name; 135 }136 137 public String getShortName() {138 return shortName;139 139 } 140 140 … … 170 170 171 171 public int hashCode() { 172 return 17 + name.hashCode();172 return 17 + path.hashCode(); 173 173 } 174 174 175 175 public boolean equals(Object obj) { 176 return obj instanceof ZipResource && name.equals(((ZipResource) obj).name);176 return obj instanceof ZipResource && path.equals(((ZipResource) obj).path); 177 177 } 178 178 179 179 public String toString() { 180 return get Name();180 return getPath(); 181 181 } 182 182 }