store.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 627 行 · 第 1/2 页
JAVA
627 行
/* * Copyright (c) 1998-2003 Caucho Technology -- all rights reserved * * Caucho Technology permits redistribution, modification and use * of this file in source and binary form ("the Software") under the * Caucho Developer Source License ("the License"). The following * conditions must be met: * * 1. Each copy or derived work of the Software must preserve the copyright * notice and this notice unmodified. * * 2. Redistributions of the Software in source or binary form must include * an unmodified copy of the License, normally in a plain ASCII text * * 3. The names "Resin" or "Caucho" are trademarks of Caucho Technology and * may not be used to endorse products derived from this software. * "Resin" or "Caucho" may not appear in the names of products derived * from this software. * * This Software is provided "AS IS," without a warranty of any kind. * ALL EXPRESS OR IMPLIED REPRESENTATIONS AND WARRANTIES, INCLUDING ANY * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. * * CAUCHO TECHNOLOGY AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE OR ANY THIRD PARTY AS A RESULT OF USING OR * DISTRIBUTING SOFTWARE. IN NO EVENT WILL CAUCHO OR ITS LICENSORS BE LIABLE * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR * INABILITY TO USE SOFTWARE, EVEN IF HE HAS BEEN ADVISED OF THE POSSIBILITY * OF SUCH DAMAGES. * * @author Sam */package com.caucho.doc.javadoc;import com.caucho.config.ConfigException;import com.caucho.config.types.Period;import com.caucho.loader.Environment;import com.caucho.log.Log;import com.caucho.server.webapp.WebApp;import com.caucho.server.webapp.PathMapping;import com.caucho.util.CharBuffer;import com.caucho.util.Crc64;import com.caucho.util.L10N;import com.caucho.vfs.Path;import com.caucho.vfs.ReadStream;import com.caucho.vfs.Vfs;import com.caucho.vfs.WriteStream;import java.io.IOException;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.Collection;import java.util.Iterator;import java.util.LinkedHashMap;import java.util.LinkedList;import java.util.logging.Level;import java.util.logging.Logger;import javax.naming.Context;import javax.naming.InitialContext;import javax.naming.NamingException;import javax.sql.DataSource;/** * A store for javadoc information. */public class Store { static protected final Logger log = Log.open(Store.class); static final L10N L = new L10N(Store.class); private final static String STORE_JNDINAME = "resin-javadoc/store"; private String _dataSource; private LinkedHashMap<String,Api> _api = new LinkedHashMap<String,Api>(); private Path _timestampFile; private String _tableNameFile = "javadoc_file"; private String _tableNameItem = "javadoc_item"; private long _httpCachePeriod; private String _startPage = "overview.jsp"; private boolean _showAddHelp; private long _crc64 = 0; private DataSource _pool; private Exception _initError; /** * A convenience method to do the JNDI lookup */ static public Store getInstance() throws NamingException { Context env = (Context) new InitialContext().lookup("java:comp/env"); Store store = (Store) env.lookup(STORE_JNDINAME); if (store == null) throw new NamingException(L.l("`{0}' is an unknown Store",STORE_JNDINAME)); return store; } /** * The data-source indicates the database to use. */ public void setDataSource(String dataSource) { _dataSource = dataSource; } /** * A timestamp file is used to determine if the database needs to be * recreated from the javadoc, default "WEB-INF/timestamp". */ public void setTimestampFile(Path timestampFile) { _timestampFile = timestampFile; } /** * An api is a javadoc generated set of html files. */ public void addApi(Api api) throws ConfigException { if (_api.get(api.getId()) != null) throw new ConfigException(L.l("id `{0}' already used, id must be unique",api.getId())); _api.put(api.getId(),api); } /** * An api is a javadoc generated set of html files. */ public Api getApi(String id) { return _api.get(id); } /** * An api is a javadoc generated set of html files. */ public Collection<Api> getAllApi() { return _api.values(); } /** * The table name for storing information about javadoc items, the default is * "javadoc_item". */ public void setTableNameItem(String tableNameItem) { _tableNameItem = tableNameItem; } /** * The table name for storing information about javadoc items. */ public String getTableNameItem() { return _tableNameItem; } /** * The table name for storing information about javadoc files, the default is * "javadoc_file". */ public void setTableNameFile(String tableNameFile) { _tableNameFile = tableNameFile; } /** * The table name for storing information about javadoc files. */ public String getTableNameFile() { return _tableNameFile; } /** * The time period to indicate to Resin's cache and to browsers * that the responses (including search results) should be cached. * If Resin's http cache is enabled, then the cached * result will be used for subsequent searches for the same thing, even * by a different user. This is an effective way to avoid hitting the * database for every search. * * examples: 10m, 10h, 10D, * -1 disables (not a good idea, but useful during development). */ public void setHttpCachePeriod(Period httpCachePeriod) { _httpCachePeriod = httpCachePeriod.getPeriod(); } /** * The time period for cache expiry, in ms. */ public long getHttpCachePeriod() { return _httpCachePeriod; } /** * The page to show in the class window for the first request, default * "overview.jsp". */ public void setStartPage(String startPage) { _startPage = startPage; } /** * The page to show in the class window for the first request. */ public String getStartPage() { return _startPage; } /** * True/false show a help message about adding more api's. */ public void setShowAddHelp(boolean showAddHelp) { _showAddHelp = showAddHelp; } /** * True/false show a help message about adding more api's. */ public boolean getShowAddHelp() { return _showAddHelp; } public void init() { try { if (_timestampFile == null) _timestampFile = Vfs.lookup("WEB-INF/timestamp"); try { Context env = (Context) new InitialContext().lookup("java:comp/env"); _pool = (DataSource) env.lookup(_dataSource); if (_pool == null) throw new ConfigException(L.l("`{0}' is an unknown DataSource, database has not been configured or is not configured properly.",_dataSource)); } catch (NamingException e) { throw new ConfigException(e); } // update database if needed for (Iterator<Api> i = _api.values().iterator(); i.hasNext(); ) { Api api = i.next(); _crc64 = api.generateCrc64(_crc64); } _crc64 = Crc64.generate(_crc64,_dataSource); _crc64 = Crc64.generate(_crc64,_timestampFile.toString()); _crc64 = Crc64.generate(_crc64,_tableNameFile); _crc64 = Crc64.generate(_crc64,_tableNameItem); try { if (isNeedUpdate()) createFromIndex(); } catch (Exception ex) { throw new ConfigException(ex); } // add path-mappings to map local files with absolute paths WebApp app = WebApp.getLocal(); CharBuffer cb = CharBuffer.allocate(); for (Iterator<Api> i = _api.values().iterator(); i.hasNext(); ) { Api api = i.next(); if (api.isLocalAbsolute()) { cb.clear(); cb.append("/"); cb.append(api.getId()); cb.append("/*"); String urlPattern = cb.toString(); PathMapping pm = new PathMapping(); pm.setUrlPattern(urlPattern); pm.setRealPath(api.getLocation()); try { app.addPathMapping(pm); } catch (Exception ex) { throw new ConfigException(ex); } } } cb.free(); // add dependencies to the Environment so that if a local api // is regenerated the web-app is restarted
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?