r9627 - helma/helma/trunk/src/helma/framework/core
[email protected] Fri, 17 Apr 2009 22:41:00 +0200 (CEST)
| Newsgroups | gmane.comp.java.helma.cvs |
|---|---|
| Message-ID | <20090417204100.B8B723D0D6@mia> |
Author: hannes
Date: 2009-04-17 22:41:00 +0200 (Fri, 17 Apr 2009)
New Revision: 9627
Modified:
helma/helma/trunk/src/helma/framework/core/Prototype.java
helma/helma/trunk/src/helma/framework/core/SkinManager.java
Log:
Remove weird feature to allow overriding subskins via mainskin, making skin lookup code much simpler. Fix bug to find base skin in skinpath from extended skin in prototype repository.
Details at http://dev.helma.org/trac/helma/changeset/9627
Modified: helma/helma/trunk/src/helma/framework/core/Prototype.java
===================================================================
--- helma/helma/trunk/src/helma/framework/core/Prototype.java 2009-04-17 14:49:26 UTC (rev 9626)
+++ helma/helma/trunk/src/helma/framework/core/Prototype.java 2009-04-17 20:41:00 UTC (rev 9627)
@@ -333,39 +333,25 @@
* other locations or database stored skins. If parentName and
* subName are defined, the skin may be a subskin of another skin.
*/
- public Skin getSkin(String skinName, String parentName, String subName)
+ public Skin getSkin(Prototype proto, String skinname, String subskin, Object[] skinpath)
throws IOException {
- Skin skin = null;
- Resource res = skinMap.getResource(skinName);
+ Resource res = skinMap.getResource(skinname);
while (res != null) {
- skin = Skin.getSkin(res, app);
- if (skin.hasMainskin())
- break;
- String extendz = skin.getExtends();
- if (extendz != null && extendz != skinName)
- return getSkin(extendz, null, null);
- res = res.getOverloadedResource();
- }
- if (parentName != null) {
- Skin parentSkin = null;
- Resource parentResource = skinMap.getResource(parentName);
- while (parentResource != null) {
- parentSkin = Skin.getSkin(parentResource, app);
- if (parentSkin.hasSubskin(subName))
- break;
- String extendz = parentSkin.getExtends();
- if (extendz != null && extendz != parentName)
- return getSkin(extendz, extendz, subName);
- parentResource = parentResource.getOverloadedResource();
+ Skin skin = Skin.getSkin(res, app);
+ if (subskin == null && skin.hasMainskin()) {
+ return skin;
+ } else if (subskin != null && skin.hasSubskin(subskin)) {
+ return skin.getSubskin(subskin);
}
- if (parentResource != null) {
- if (res != null && app.getResourceComparator().compare(res, parentResource) > 0)
- return skin;
- else
- return parentSkin.getSubskin(subName);
+ String baseskin = skin.getExtends();
+ if (baseskin != null && !baseskin.equalsIgnoreCase(skinname)) {
+ // we need to call SkinManager.getSkin() to fetch overwritten
+ // base skins from skinpath
+ return app.skinmgr.getSkin(proto, baseskin, subskin, skinpath);
}
+ res = res.getOverloadedResource();
}
- return skin;
+ return null;
}
/**
Modified: helma/helma/trunk/src/helma/framework/core/SkinManager.java
===================================================================
--- helma/helma/trunk/src/helma/framework/core/SkinManager.java 2009-04-17 14:49:26 UTC (rev 9626)
+++ helma/helma/trunk/src/helma/framework/core/SkinManager.java 2009-04-17 20:41:00 UTC (rev 9627)
@@ -42,66 +42,58 @@
skinExtension = ".skin";
}
- protected Skin getSkin(Prototype prototype, String skinname, Object[] skinpath)
+ public Skin getSkin(Prototype prototype, String skinname, Object[] skinpath)
throws IOException {
if (prototype == null) {
return null;
}
- Skin skin;
- Prototype proto = prototype;
-
- // if name contains #, this may be a subskin of some other skin
- String parentName = null, subskinName = null;
+ // if name contains '#' split name into mainskin and subskin
+ String subskin = null;
int hash = skinname.indexOf('#');
if (hash > -1) {
- parentName = skinname.substring(0, hash);
- subskinName = skinname.substring(hash + 1);
+ subskin = skinname.substring(hash + 1);
+ skinname = skinname.substring(0, hash);
}
+ return getSkin(prototype, skinname, subskin, skinpath);
+ }
- // First check if the skin has been already used within the execution of this request
- // check for skinsets set via res.skinpath property
- do {
+ public Skin getSkin(Prototype prototype, String skinname,
+ String subskin, Object[] skinpath)
+ throws IOException {
+ Prototype proto = prototype;
+
+ // Loop over prototype chain and check skinpath and prototype skin resources
+ while (proto != null) {
+ Skin skin;
if (skinpath != null) {
for (int i = 0; i < skinpath.length; i++) {
skin = getSkinInPath(skinpath[i], proto.getName(), skinname);
if (skin != null) {
// check if skin skin contains main skin
- if (skin.hasMainskin()) {
+ if (subskin == null && skin.hasMainskin()) {
return skin;
+ } else if (subskin != null && skin.hasSubskin(subskin)) {
+ return skin.getSubskin(subskin);
}
- String extendz = skin.getExtends();
- if (extendz != null && !extendz.equals(skinname)) {
- return getSkin(prototype, extendz, skinpath);
+ String baseskin = skin.getExtends();
+ if (baseskin != null && !baseskin.equals(skinname)) {
+ return getSkin(prototype, baseskin, subskin, skinpath);
}
- } else if (parentName != null) {
- // get parent skin
- skin = getSkinInPath(skinpath[i], proto.getName(), parentName);
- // check if it contains subskin
- if (skin != null) {
- if (skin.hasSubskin(subskinName)) {
- return skin.getSubskin(subskinName);
- }
- String extendz = skin.getExtends();
- if (extendz != null && !extendz.equals(skinname)) {
- return getSkin(prototype, extendz + "#" + subskinName, skinpath);
- }
- }
}
}
}
// skin for this prototype wasn't found in the skinsets.
// the next step is to look if it is defined as skin file in the application directory
- skin = proto.getSkin(skinname, parentName, subskinName);
-
+ skin = proto.getSkin(prototype, skinname, subskin, skinpath);
if (skin != null) {
return skin;
}
// still not found. See if there is a parent prototype which might define the skin.
proto = proto.getParentPrototype();
- } while (proto != null);
+ }
// looked every where, nothing to be found
return null;