From: <bra...@us...> - 2007-07-20 01:25:28
|
Revision: 1851 http://archive-access.svn.sourceforge.net/archive-access/?rev=1851&view=rev Author: bradtofel Date: 2007-07-19 18:25:30 -0700 (Thu, 19 Jul 2007) Log Message: ----------- REFACTOR: now replaced by Spring and org.archive.wayback.webapp.ServletRequestContext. woot! Removed Paths: ------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackLogic.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackServlet.java Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackLogic.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackLogic.java 2007-07-20 01:24:30 UTC (rev 1850) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackLogic.java 2007-07-20 01:25:30 UTC (rev 1851) @@ -1,242 +0,0 @@ -/* WaybackLogic - * - * Created on 2005/10/18 14:00:00 - * - * Copyright (C) 2005 Internet Archive. - * - * This file is part of the Wayback Machine (crawler.archive.org). - * - * Wayback Machine is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * any later version. - * - * Wayback Machine is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser Public License for more details. - * - * You should have received a copy of the GNU Lesser Public License - * along with Wayback Machine; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -package org.archive.wayback.core; - -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Properties; -import java.util.logging.Logger; - -import org.archive.wayback.PropertyConfigurable; -import org.archive.wayback.ReplayRenderer; -import org.archive.wayback.QueryRenderer; -import org.archive.wayback.ResultURIConverter; -import org.archive.wayback.ResourceIndex; -import org.archive.wayback.ResourceStore; -import org.archive.wayback.exception.ConfigurationException; -import org.archive.wayback.query.OpenSearchQueryParser; - -/** - * Constructor and go-between for the major components in the Wayback Machine. - * - * @author Brad Tofel - * @version $Date$, $Revision$ - */ -public class WaybackLogic implements PropertyConfigurable { - private static final Logger LOGGER = Logger.getLogger(WaybackLogic.class - .getName()); - - private static final String REPLAY_URI_CONVERTER_PROPERTY = - "replayuriconverter"; - - private static final String REPLAY_RENDERER_PROPERTY = "replayrenderer"; - - private static final String QUERY_RENDERER_PROPERTY = "queryrenderer"; - - private static final String RESOURCE_STORE_PROPERTY = "resourcestore"; - - private static final String RESOURCE_INDEX_PROPERTY = "resourceindex"; - - private Properties configuration = null; - - Hashtable<String,PropertyConfigurable> objectCache = - new Hashtable<String, PropertyConfigurable>(); - - private static Hashtable<String, PropertyConfigurable> singletonCache = - new Hashtable<String, PropertyConfigurable>(); - - private OpenSearchQueryParser qp = null; - - /** - * Constructor - */ - public WaybackLogic() { - super(); - } - - /** - * Initialize this WaybackLogic. Pass in the specific configurations via - * Properties. Will ferret away the configuration properties, to be - * used later when constructing and initializing implementations of - * ResourceIndex, ResourceStore, QueryUI, ReplayUI, and - * ResultURIConverter. - * - * @param configuration - * Generic properties bag for configurations - */ - public void init(Properties configuration) { - - this.configuration = configuration; - } - - protected PropertyConfigurable getInstance(final Properties p, - final String classPrefix) throws ConfigurationException { - - LOGGER.info("WaybackLogic constructing " + classPrefix + "..."); - - PropertyConfigurable result = null; - - String classNameKey = classPrefix + ".classname"; - String propertyPrefix = classPrefix + "."; - String className = null; - - // build new class-specific Properties for class initialization: - Properties classProperties = new Properties(); - for (Enumeration e = p.keys(); e.hasMoreElements();) { - String key = (String) e.nextElement(); - - if (key.equals(classNameKey)) { - - // special .classname value: - className = p.getProperty(key); - - } else if (key.startsWith(propertyPrefix)) { - - String finalKey = key.substring(propertyPrefix.length()); - String value = p.getProperty(key); - classProperties.put(finalKey, value); - - } - } - - // did we find the implementation class? - if (className == null) { - throw new ConfigurationException("No configuration for (" - + classNameKey + ")"); - } - - try { - result = (PropertyConfigurable) Class.forName(className) - .newInstance(); - } catch (Exception e) { - e.printStackTrace(); - throw new ConfigurationException(e.getMessage()); - } - LOGGER.info("new " + className + " created."); - result.init(p); - LOGGER.info("initialized " + className); - - return result; - } - - /** - * possibly initializes and returns a singleton instance of class className - * - * @param className - * @return object of PropertyConfigurable class that has been configured - * with a call to init() - * @throws ConfigurationException - */ - public synchronized PropertyConfigurable getCachedSingleton(final String className) - throws ConfigurationException { - if(!singletonCache.containsKey(className)) { - singletonCache.put(className,getInstance(configuration,className)); - } - return singletonCache.get(className); - } - - /** - * possibly initializes and returns an instance of class className - * - * @param className - * @return object of PropertyConfigurable class that has been configured - * with a call to init() - * @throws ConfigurationException - */ - public synchronized PropertyConfigurable getCachedInstance(final String className) - throws ConfigurationException { - if(!objectCache.containsKey(className)) { - objectCache.put(className,getInstance(configuration,className)); - } - return objectCache.get(className); - } - - /** - * possibly initializes and returns the resourceIndex - * - * @return Returns the resourceIndex. - * @throws ConfigurationException - */ - public ResourceIndex getResourceIndex() throws ConfigurationException { - return (ResourceIndex) getCachedSingleton(RESOURCE_INDEX_PROPERTY); - - } - - /** - * possibly initializes and returns the resourceStore - * - * @return Returns the resourceStore. - * @throws ConfigurationException - */ - public ResourceStore getResourceStore() throws ConfigurationException { - return (ResourceStore) getCachedSingleton(RESOURCE_STORE_PROPERTY); - } - - /** - * possibly initializes and returns the uriConverter - * - * @return Returns the uriConverter. - * @throws ConfigurationException - */ - public ResultURIConverter getURIConverter() - throws ConfigurationException { - return (ResultURIConverter) getCachedInstance( - REPLAY_URI_CONVERTER_PROPERTY); - } - - /** - * possibly initializes and returns the replayRenderer - * - * @return Returns the replayRenderer. - * @throws ConfigurationException - */ - public ReplayRenderer getReplayRenderer() throws ConfigurationException { - return (ReplayRenderer) getCachedInstance(REPLAY_RENDERER_PROPERTY); - } - - /** - * possibly initializes and returns the queryRenderer - * - * @return Returns the queryRenderer. - * @throws ConfigurationException - */ - public QueryRenderer getQueryRenderer() throws ConfigurationException { - return (QueryRenderer) getCachedInstance(QUERY_RENDERER_PROPERTY); - } - /** - * possibly initializes and returns the resourceIndex - * - * @return Returns the resourceIndex. - * @throws ConfigurationException - */ - public synchronized OpenSearchQueryParser getQueryParser() - throws ConfigurationException { - if(qp == null) { - qp = new OpenSearchQueryParser(); - qp.init(configuration); - } - return qp; - } - -} Deleted: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackServlet.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackServlet.java 2007-07-20 01:24:30 UTC (rev 1850) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/WaybackServlet.java 2007-07-20 01:25:30 UTC (rev 1851) @@ -1,96 +0,0 @@ -/* WaybackServlet - * - * $Id$ - * - * Created on 4:42:13 PM May 9, 2006. - * - * Copyright (C) 2006 Internet Archive. - * - * This file is part of wayback. - * - * wayback is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * any later version. - * - * wayback is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser Public License for more details. - * - * You should have received a copy of the GNU Lesser Public License - * along with wayback; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -package org.archive.wayback.core; - -import java.text.ParseException; -import java.util.Enumeration; -import java.util.Map; -import java.util.Properties; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; - -/** - * Base clas for HttpServlets that have the "project standard" WaybackLogic - * factory for accessing other components. - * - * @author brad - * @version $Date$, $Revision$ - */ -public class WaybackServlet extends HttpServlet { - - private static final long serialVersionUID = 1L; - protected WaybackLogic wayback = new WaybackLogic(); - - /** - * generic constructor. - */ - public WaybackServlet() { - super(); - } - - public void init(ServletConfig c) throws ServletException { - - Properties p = new Properties(); - ServletContext sc = c.getServletContext(); - for (Enumeration e = sc.getInitParameterNames(); e.hasMoreElements();) { - String key = (String) e.nextElement(); - p.put(key, sc.getInitParameter(key)); - } - for (Enumeration e = c.getInitParameterNames(); e.hasMoreElements();) { - String key = (String) e.nextElement(); - p.put(key, c.getInitParameter(key)); - } - - wayback.init(p); - } - - protected static String getMapParam(Map queryMap, String field) { - String arr[] = (String[]) queryMap.get(field); - if (arr == null || arr.length == 0) { - return null; - } - return arr[0]; - } - - protected static String getRequiredMapParam(Map queryMap, String field) - throws ParseException { - String value = getMapParam(queryMap,field); - if(value == null) { - throw new ParseException("missing field " + field,0); - } - if(value.length() == 0) { - throw new ParseException("empty field " + field,0); - } - return value; - } - - protected static String getMapParamOrEmpty(Map map, String param) { - String val = getMapParam(map,param); - return (val == null) ? "" : val; - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |