Introduced Resource.getBaseName() to return name with extension cut off.

Fixed Resource lookup failure on Windows.
This commit is contained in:
hns 2005-03-23 19:28:04 +00:00
parent 908424d18a
commit 73e377dde1
8 changed files with 32 additions and 17 deletions

View file

@ -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

View file

@ -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() {

View file

@ -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);
}
}

View file

@ -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);

View file

@ -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

View file

@ -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);
}
}
}

View file

@ -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");
}

View file

@ -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",