Implemented skin caching.

This commit is contained in:
hns 2002-05-15 17:20:44 +00:00
parent 36eee9e151
commit db69f15dc1

View file

@ -3,7 +3,8 @@
package helma.framework.core; package helma.framework.core;
import java.util.HashMap; import java.util.Map;
import java.util.WeakHashMap;
import java.util.Iterator; import java.util.Iterator;
import helma.objectmodel.INode; import helma.objectmodel.INode;
import java.io.*; import java.io.*;
@ -17,35 +18,42 @@ import java.io.*;
public class SkinManager { public class SkinManager {
Application app; Application app;
Map skincache;
public SkinManager (Application app) { public SkinManager (Application app) {
this.app = app; this.app = app;
skincache = new WeakHashMap ();
} }
public Skin getSkin (Object object, String skinname, Object[] skinpath) { public Skin getSkin (Object object, String skinname, Object[] skinpath) {
Prototype proto = app.getPrototype (object); Prototype proto = app.getPrototype (object);
return getSkin (proto, skinname, "skin", skinpath); String key = new StringBuffer(proto.getName()).append ("/").append (skinname)
.append ("#").append (skinpath.hashCode()).toString ();
// System.err.print ("SKINKEY: "+key);
Skin skin = (Skin) skincache.get (key);
if (skin != null) {
// System.err.println (" ... cached");
return skin;
}
// System.err.println (" ... uncached");
skin = getSkin (proto, skinname, "skin", skinpath);
if (skin != null)
skincache.put (key, skin);
return skin;
} }
public Skin getSkin (Prototype proto, String skinname, String extension, Object[] skinpath) { protected Skin getSkin (Prototype proto, String skinname, String extension, Object[] skinpath) {
if (proto == null) if (proto == null)
return null; return null;
Skin skin = null; Skin skin = null;
// First check if the skin has been already used within the execution of this request // First check if the skin has been already used within the execution of this request
/* SkinKey key = new SkinKey (proto.getName(), skinname, extension);
Skin skin = (Skin) skincache.get (key);
if (skin != null) {
return skin;
} */
// check for skinsets set via res.skinpath property // check for skinsets set via res.skinpath property
do { do {
if (skinpath != null) { if (skinpath != null) {
for (int i=0; i<skinpath.length; i++) { for (int i=0; i<skinpath.length; i++) {
skin = getSkinInternal (skinpath[i], proto.getName (), skinname, extension); skin = getSkinInternal (skinpath[i], proto.getName (), skinname, extension);
if (skin != null) { if (skin != null) {
// skincache.put (key, skin);
return skin; return skin;
} }
} }
@ -54,7 +62,6 @@ public class SkinManager {
// the next step is to look if it is defined as skin file in the application directory // the next step is to look if it is defined as skin file in the application directory
skin = proto.getSkin (skinname); skin = proto.getSkin (skinname);
if (skin != null) { if (skin != null) {
// skincache.put (key, skin);
return skin; return skin;
} }
// still not found. See if there is a parent prototype which might define the skin. // still not found. See if there is a parent prototype which might define the skin.