diff --git a/src/helma/framework/core/Prototype.java b/src/helma/framework/core/Prototype.java index 55894002..d16a64eb 100644 --- a/src/helma/framework/core/Prototype.java +++ b/src/helma/framework/core/Prototype.java @@ -353,7 +353,7 @@ public final class Prototype { */ public synchronized void addSkinResource(Resource res) { skins.add(res); - skinMap.put(res.getShortName(), res); + skinMap.put(res.getBaseName(), res); trackers.put(res.getName(), new ResourceTracker(res)); } @@ -504,7 +504,7 @@ public final class Prototype { for (Iterator i = skins.iterator(); i.hasNext();) { Resource res = (Resource) i.next(); - super.put(res.getShortName(), res); + super.put(res.getBaseName(), res); } // if skinpath is not null, overload/add skins from there diff --git a/src/helma/framework/repository/AbstractRepository.java b/src/helma/framework/repository/AbstractRepository.java index 36ee3531..144ad7d2 100644 --- a/src/helma/framework/repository/AbstractRepository.java +++ b/src/helma/framework/repository/AbstractRepository.java @@ -83,7 +83,7 @@ public abstract class AbstractRepository implements Repository { public Resource getResource(String name) { update(); - return (Resource) resources.get(getName() + "/" + name); + return (Resource) resources.get(name); } public Iterator getResources() { diff --git a/src/helma/framework/repository/FileRepository.java b/src/helma/framework/repository/FileRepository.java index 01a1af2a..c7f26440 100644 --- a/src/helma/framework/repository/FileRepository.java +++ b/src/helma/framework/repository/FileRepository.java @@ -72,7 +72,7 @@ public class FileRepository extends AbstractRepository { } else { this.parent = parent; shortName = dir.getName(); - name = parent.getName() + "/" + shortName; + name = dir.getAbsolutePath(); } } @@ -155,7 +155,7 @@ public class FileRepository extends AbstractRepository { } else if (list[i].isFile()) { // a file resource FileResource resource = new FileResource(list[i], this); - newResources.put(resource.getName(), resource); + newResources.put(resource.getShortName(), resource); } } diff --git a/src/helma/framework/repository/FileResource.java b/src/helma/framework/repository/FileResource.java index 08dd055b..01f3c8d0 100644 --- a/src/helma/framework/repository/FileResource.java +++ b/src/helma/framework/repository/FileResource.java @@ -25,6 +25,7 @@ public class FileResource implements Resource { Repository repository; String name; String shortName; + String baseName; public FileResource(File file) { this(file, null); @@ -36,10 +37,9 @@ public class FileResource implements Resource { this.repository = repository; name = file.getAbsolutePath(); shortName = file.getName(); - // cut off extension from short name - if (shortName.lastIndexOf(".") > -1) { - shortName = shortName.substring(0, shortName.lastIndexOf(".")); - } + // base name is short name with extension cut off + int lastDot = shortName.lastIndexOf("."); + baseName = (lastDot == -1) ? shortName : shortName.substring(0, lastDot); } public String getName() { @@ -50,6 +50,10 @@ public class FileResource implements Resource { return shortName; } + public String getBaseName() { + return baseName; + } + public InputStream getInputStream() { try { return new FileInputStream(file); diff --git a/src/helma/framework/repository/Resource.java b/src/helma/framework/repository/Resource.java index a2e15a4a..b9f17ca2 100644 --- a/src/helma/framework/repository/Resource.java +++ b/src/helma/framework/repository/Resource.java @@ -70,6 +70,13 @@ public interface Resource { */ public String getShortName(); + /** + * Returns the short name of the resource with the file extension + * (everything following the last dot character) cut off. + * @return + */ + public String getBaseName(); + /** * Returns an url to the resource if the repository of this resource is * able to provide urls diff --git a/src/helma/framework/repository/ZipRepository.java b/src/helma/framework/repository/ZipRepository.java index 83ecf4a3..5ee44a9c 100644 --- a/src/helma/framework/repository/ZipRepository.java +++ b/src/helma/framework/repository/ZipRepository.java @@ -107,7 +107,7 @@ public final class ZipRepository extends AbstractRepository { newRepositories.add(new ZipRepository(file, this, entry)); } else { ZipResource resource = new ZipResource(file, entry, this); - newResources.put(resource.getName(), resource); + newResources.put(resource.getShortName(), resource); } } } diff --git a/src/helma/framework/repository/ZipResource.java b/src/helma/framework/repository/ZipResource.java index b1b02e1a..615fb0b1 100644 --- a/src/helma/framework/repository/ZipResource.java +++ b/src/helma/framework/repository/ZipResource.java @@ -28,6 +28,7 @@ public final class ZipResource implements Resource { private ZipRepository repository; private String name; private String shortName; + private String baseName; protected ZipResource(File zipfile, ZipEntry zipentry, ZipRepository repository) { this.zipentry = zipentry; @@ -41,10 +42,9 @@ public final class ZipResource implements Resource { name = new StringBuffer(repository.getName()).append('/') .append(shortName).toString(); - // cut off extension from short name - if (shortName.lastIndexOf(".") > -1) { - shortName = shortName.substring(0, shortName.lastIndexOf(".")); - } + // base name is short name with extension cut off + int lastDot = shortName.lastIndexOf("."); + baseName = (lastDot == -1) ? shortName : shortName.substring(0, lastDot); } public long lastModified() { @@ -115,6 +115,10 @@ public final class ZipResource implements Resource { return shortName; } + public String getBaseName() { + return baseName; + } + public URL getUrl() { throw new UnsupportedOperationException("getUrl() not implemented for ZipResource"); } diff --git a/src/helma/scripting/rhino/HacHspConverter.java b/src/helma/scripting/rhino/HacHspConverter.java index 8cb8e8c9..0139d0db 100644 --- a/src/helma/scripting/rhino/HacHspConverter.java +++ b/src/helma/scripting/rhino/HacHspConverter.java @@ -29,12 +29,12 @@ import java.util.StringTokenizer; public class HacHspConverter { public static String convertHac(Resource action) throws IOException { - String functionName = action.getShortName().replace('.', '_') + "_action"; + String functionName = action.getBaseName().replace('.', '_') + "_action"; return composeFunction(functionName, null, action.getContent()); } public static String convertHsp(Resource template) throws IOException { - String functionName = template.getShortName().replace('.', '_'); + String functionName = template.getBaseName().replace('.', '_'); String body = processHspBody(template.getContent()); return composeFunction(functionName, "arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10", @@ -42,7 +42,7 @@ public class HacHspConverter { } public static String convertHspAsString(Resource template) throws IOException { - String functionName = template.getShortName().replace('.', '_') + "_as_string"; + String functionName = template.getBaseName().replace('.', '_') + "_as_string"; String body = processHspBody(template.getContent()); return composeFunction(functionName, "arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10",