1 29 30 package com.caucho.quercus.page; 31 32 import com.caucho.quercus.Quercus; 33 import com.caucho.quercus.parser.QuercusParser; 34 import com.caucho.quercus.program.QuercusProgram; 35 import com.caucho.util.LruCache; 36 import com.caucho.vfs.IOExceptionWrapper; 37 import com.caucho.vfs.Path; 38 39 import java.io.IOException ; 40 import java.util.ArrayList ; 41 import java.util.logging.Logger ; 42 43 46 public class PageManager 47 { 48 private static final Logger log 49 = Logger.getLogger(PageManager.class.getName()); 50 51 private final Quercus _quercus; 52 53 private Path _pwd; 54 private boolean _isLazyCompile; 55 private boolean _isCompile; 56 57 protected LruCache<Path,QuercusProgram> _programCache 58 = new LruCache<Path,QuercusProgram>(1024); 59 60 private boolean _isClosed; 61 62 65 public PageManager(Quercus quercus) 66 { 67 _quercus = quercus; 68 } 69 70 public Quercus getQuercus() 71 { 72 return _quercus; 73 } 74 75 78 public Path getPwd() 79 { 80 return _quercus.getPwd(); 81 } 82 83 86 public boolean isCompile() 87 { 88 return _isCompile; 89 } 90 91 94 public void setCompile(boolean isCompile) 95 { 96 _isCompile = isCompile; 97 } 98 99 102 public boolean isLazyCompile() 103 { 104 return _isLazyCompile; 105 } 106 107 110 public void setLazyCompile(boolean isCompile) 111 { 112 _isLazyCompile = isCompile; 113 } 114 115 118 public boolean isActive() 119 { 120 return ! _isClosed; 121 } 122 123 126 145 146 155 public QuercusPage parse(Path path) 156 throws IOException 157 { 158 return parse(path, null, -1); 159 } 160 161 170 public QuercusPage parse(Path path, String fileName, int line) 171 throws IOException 172 { 173 try { 174 QuercusProgram program; 175 176 program = _programCache.get(path); 177 178 if (program == null || program.isModified()) { 179 program = QuercusParser.parse(_quercus, 180 path, 181 _quercus.getScriptEncoding(), 182 fileName, 183 line); 184 _programCache.put(path, program); 185 } 186 187 if (program.getCompiledPage() != null) { 188 return program.getCompiledPage(); 189 } 190 191 return compilePage(program, path); 192 } catch (IOException e) { 193 throw e; 194 } catch (RuntimeException e) { 195 throw e; 196 } catch (Throwable e) { 197 throw new IOExceptionWrapper(e); 198 } 199 } 200 201 protected QuercusPage compilePage(QuercusProgram program, Path path) 202 { 203 return new InterpretedPage(program); 204 } 205 206 public void close() 207 { 208 _isClosed = true; 209 } 210 } 211 212 | Popular Tags |