env.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 3,016 行 · 第 1/5 页
JAVA
3,016 行
public TimeZone getDefaultTimeZone() { return _defaultTimeZone; } public void setDefaultTimeZone(String id) { _defaultTimeZone = TimeZone.getTimeZone(id); } public void setDefaultTimeZone(TimeZone zone) { _defaultTimeZone = zone; } /* * Returns the ServletContext. */ public ServletContext getServletContext() { return _quercus.getServletContext(); } /* * Sets the ScriptContext. */ public void setScriptContext(ScriptContext context) { _scriptContext = context; } /* * Returns the input (POST, PUT) data. */ public StringValue getInputData() { return _inputData; } /* * Sets the post data. */ public void setInputData(StringValue data) { _inputData = data; } /** * Returns true for strict mode. */ public final boolean isStrict() { return _isStrict; } /* * Returns true if allowed to include urls. */ public boolean isAllowUrlInclude() { return _isAllowUrlInclude; } /* * Returns true if allowed to fopen urls. */ public boolean isAllowUrlFopen() { return _isAllowUrlFopen; } /** * Returns the connection status */ public int getConnectionStatus() { // always returns a valid value for now return 0; } public void start() { _oldThreadEnv = _threadEnv.get(); _startTime = Alarm.getCurrentTime(); _timeLimit = getIniLong("max_execution_time") * 1000; _threadEnv.set(this); // quercus/1b06 String encoding = getOutputEncoding(); String type = getIniString("default_mimetype"); if ("".equals(type) || _response == null) { } else if (encoding != null) _response.setContentType(type + "; charset=" + encoding); else _response.setContentType(type); if (_out != null && encoding != null) { try { _out.setEncoding(encoding); } catch (Exception e) { log.log(Level.WARNING, e.toString(), e); } } HashSet<ModuleStartupListener> listeners = _quercus.getModuleStartupListeners(); for (ModuleStartupListener listener : listeners) listener.startup(this); } /** * add resource to the list of refrences that are * cleaned up when finished with this environment. */ public void addCleanup(EnvCleanup envCleanup) { _cleanupList.add(envCleanup); } /** * remove resource from the list of refrences that are * cleaned up when finished with this environment. * * @param resource */ public void removeCleanup(EnvCleanup envCleanup) { for (int i = _cleanupList.size() - 1; i >= 0; i--) { EnvCleanup res = _cleanupList.get(i); if (envCleanup.equals(res)) { _cleanupList.remove(i); break; } } } /** * Returns the owning PHP engine. */ public Quercus getQuercus() { return _quercus; } /** * Returns the owning PHP engine. */ public ModuleContext getModuleContext() { return _quercus.getModuleContext(); } /** * Returns the configured database. */ public DataSource getDatabase() { return _quercus.getDatabase(); } protected final DataSource findDatabase(String driver, String url) throws Exception { return _quercus.findDatabase(driver, url); } /** * Returns a connection to the given database. If there is * already a connection to this specific database, then * return the connection from the pool. Otherwise, create * a new connection and add it to the pool. */ public Connection getConnection(String driver, String url, String userName, String password) throws Exception { DataSource database = _quercus.getDatabase(); if (database != null) { ConnectionEntry entry = new ConnectionEntry(); entry.init(database, null, null); ConnectionEntry oldEntry = _connMap.get(entry); Connection conn; if (oldEntry != null && (conn = oldEntry.getConnection()) != null && ! conn.isClosed()) return conn; entry.setConnection(database.getConnection()); _connMap.put(entry, entry); conn = entry.getConnection(); return conn; } database = findDatabase(driver, url); ConnectionEntry entry = new ConnectionEntry(); entry.init(database, userName, password); ConnectionEntry oldEntry = _connMap.get(entry); Connection conn; if (oldEntry == null || (conn = oldEntry.getConnection()) == null || conn.isClosed()) { if (userName == null || userName.equals("")) conn = database.getConnection(); else conn = database.getConnection(userName, password); entry.setConnection(conn); _connMap.put(entry, entry); } return conn; } /** * Returns the configured database. */ public DataSource getDataSource(String driver, String url) throws Exception { DataSource database = _quercus.getDatabase(); if (database != null) return database; else return findDatabase(driver, url); } /** * Sets the time limit. */ public void setTimeLimit(long ms) { if (ms <= 0) ms = Long.MAX_VALUE / 2; _timeLimit = ms; } /** * Checks for the program timeout. */ public final void checkTimeout() { long now = Alarm.getCurrentTime(); if (_timeLimit > 0 && _startTime + _timeLimit < now) throw new QuercusRuntimeException(L.l("script timed out")); } public void resetTimeout() { _startTime = Alarm.getCurrentTime(); } /** * Returns the writer. */ public WriteStream getOut() { return _out; } /** * Returns the writer. */ public WriteStream getOriginalOut() { return _originalOut; } /** * Flushes the output buffer. */ public final void flush() { try { getOut().flush(); } catch (IOException e) { throw new QuercusModuleException(e); } } /** * Prints a string */ public final void print(String v) { try { getOut().print(v); } catch (IOException e) { throw new QuercusModuleException(e); } } /** * Prints a character buffer. */ public final void print(char []buffer, int offset, int length) { try { getOut().print(buffer, offset, length); } catch (IOException e) { throw new QuercusModuleException(e); } } /** * Prints a char */ public final void print(char v) { try { getOut().print(v); } catch (IOException e) { throw new QuercusModuleException(e); } } /** * Prints a long */ public final void print(long v) { try { getOut().print(v); } catch (IOException e) { throw new QuercusModuleException(e); } } /** * Prints a double */ public final void print(double v) { try { long longV = (long) v; if (v == longV) getOut().print(longV); else getOut().print(v); } catch (IOException e) { throw new QuercusModuleException(e); } } /** * Prints an object */ public final void print(Object v) { try { getOut().print(v); } catch (IOException e) { throw new QuercusModuleException(e); } } /** * Prints a value */ public final void print(Value v) { v.print(this); } /** * Prints a string */ public final void println() { try { getOut().println(); } catch (IOException e) { throw new QuercusModuleException(e); } } /** * Prints a string */ public final void println(String v) { try { getOut().println(v); } catch (IOException e) { throw new QuercusModuleException(e); } } /** * Prints a string */ public final void println(Value v) { try { v.print(this); getOut().println(); } catch (IOException e) { throw new QuercusModuleException(e); } } /** * Prints and object. */ public final void println(Object v) { try { getOut().println(v); } catch (IOException e) { throw new QuercusModuleException(e); } } /** * Prints a byte buffer. */ public final void write(byte []buffer, int offset, int length) { try { getOut().write(buffer, offset, length); } catch (IOException e) { throw new QuercusModuleException(e); } } /** * Returns the current output buffer. */ public OutputBuffer getOutputBuffer() { return _outputBuffer; } /** * Returns the writer. */ public void pushOutputBuffer(Callback callback, int chunkSize, boolean erase) { if (_outputBuffer == null) { _outputBuffer = new OutputBuffer(_outputBuffer, this, callback, chunkSize, erase); } else _outputBuffer = new OutputBuffer(_outputBuffer, this, callback, chunkSize, erase); _out = _outputBuffer.getOut(); } /** * Pops the output buffer */ public boolean popOutputBuffer() { OutputBuffer outputBuffer = _outputBuffer; if (outputBuffer == null) return false; outputBuffer.close(); _outputBuffer = outputBuffer.getNext(); if (_outputBuffer != null) _out = _outputBuffer.getOut(); else { _out = _originalOut; } return true; } /** * Returns the current directory. */ public Path getPwd() { return _pwd; } /** * Returns the current directory. */ public Path getWorkDir() { return _quercus.getWorkDir(); } /** * Sets the current directory. */ public void setPwd(Path path) { _pwd = path; _lookupCache.clear(); } /** * Returns the initial directory. */ public Path getSelfPath() { return _selfPath; } /** * Returns the initial directory. */ public Path getSelfDirectory() { return _selfDirectory; } /** * Sets the initial directory. */ public void setSelfPath(Path path) { _selfPath = path; _selfDirectory = _selfPath.getParent(); } /** * Returns the upload directory. */ public Path getUploadDirectory() { if (_uploadPath == null) { String realPath = getIniString("upload_tmp_dir"); if (realPath == null) realPath = getRequest().getRealPath("/WEB-INF/upload"); _uploadPath = _quercus.getPwd().lookup(realPath); try { if (! _uploadPath.isDirectory()) _uploadPath.mkdirs(); } catch (IOException e) { log.log(Level.FINE, e.toString(), e); } _uploadPath = _uploadPath.createRoot(); } return _uploadPath; } /* * Returns the temp directory (used by tmpfile()). */ public Path getTempDirectory() { String realPath; if (_tmpPath == null) { if (getRequest() != null) realPath = getRequest().getRealPath("/WEB-INF/tmp"); else realPath = "file:/tmp"; _tmpPath = getPwd().lookup(realPath); try { if (! _tmpPath.isDirectory()) _tmpPath.mkdirs(); } catch (IOException e) { log.log(Level.FINE, e.toString(), e); } } return _tmpPath; } /** * Adds an auto-remove path. */ public void addRemovePath(Path path) { if (_removePaths == null) _removePaths = new ArrayList<Path>();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?