1 29 30 package com.caucho.quercus.page; 31 32 import com.caucho.quercus.Quercus; 33 import com.caucho.quercus.env.Env; 34 import com.caucho.quercus.env.NullValue; 35 import com.caucho.quercus.env.QuercusLanguageException; 36 import com.caucho.quercus.env.Value; 37 import com.caucho.quercus.program.AbstractFunction; 38 import com.caucho.quercus.program.ClassDef; 39 import com.caucho.vfs.Path; 40 41 import java.util.HashMap ; 42 import java.util.Map ; 43 44 47 abstract public class QuercusPage 48 { 49 private HashMap <String ,AbstractFunction> _funMap 50 = new HashMap <String ,AbstractFunction>(); 51 52 private HashMap <String ,AbstractFunction> _funMapLowerCase 53 = new HashMap <String ,AbstractFunction>(); 54 55 private HashMap <String ,ClassDef> _classMap 56 = new HashMap <String ,ClassDef>(); 57 58 61 public boolean isModified() 62 { 63 return false; 64 } 65 66 69 abstract public Path getSelfPath(Env env); 70 71 74 public AbstractFunction findFunction(String name) 75 { 76 AbstractFunction fun = _funMap.get(name); 77 78 if (fun != null) 79 return fun; 80 81 fun = _funMapLowerCase.get(name.toLowerCase()); 82 83 return fun; 84 } 85 86 89 public ClassDef findClass(String name) 90 { 91 return _classMap.get(name); 92 } 93 94 97 public HashMap <String ,ClassDef> getClassMap() 98 { 99 return _classMap; 100 } 101 102 107 public Value executeTop(Env env) 108 { 109 Path oldPwd = env.getPwd(); 110 111 Path pwd = getPwd(env); 112 113 env.setPwd(pwd); 114 try { 115 return execute(env); 116 } catch (QuercusLanguageException e) { 117 if (env.getExceptionHandler() != null) 118 env.getExceptionHandler().call(env, e.getValue()); 119 120 return NullValue.NULL; 121 } finally { 122 env.setPwd(oldPwd); 123 } 124 } 125 126 129 public Path getPwd(Env env) 130 { 131 return getSelfPath(env).getParent(); 132 } 133 134 135 140 abstract public Value execute(Env env); 141 142 147 public void init(Quercus quercus) 148 { 149 } 150 151 156 public void init(Env env) 157 { 158 } 159 160 163 public void importDefinitions(Env env) 164 { 165 for (Map.Entry <String ,AbstractFunction> entry : _funMap.entrySet()) { 166 AbstractFunction fun = entry.getValue(); 167 168 if (fun.isGlobal()) 169 env.addFunction(entry.getKey(), entry.getValue()); 170 } 171 172 for (Map.Entry <String ,ClassDef> entry : _classMap.entrySet()) { 173 env.addClassDef(entry.getKey(), entry.getValue()); 174 } 175 } 176 177 180 protected void addFunction(String name, AbstractFunction fun) 181 { 182 _funMap.put(name, fun); 183 _funMapLowerCase.put(name.toLowerCase(), fun); 184 } 185 186 189 protected void addClass(String name, ClassDef cl) 190 { 191 _classMap.put(name, cl); 192 } 193 194 public String toString() 195 { 196 return "QuercusPage[]"; 197 } 198 } 199 200 | Popular Tags |