View Javadoc
1 /* 2 * PROJECT : DAR Runtime and Tools 3 * COPYRIGHT : Copyright (C) 1999-2004 tim.stephenson@enableit.org 4 * LICENSE : GNU LESSER GENERAL PUBLIC LICENSE 5 * Version 2.1, February 1999 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21 package org.enableit.db.darrt.web; 22 23 import java.util.ArrayList; 24 import java.util.List; 25 26 import javax.naming.Binding; 27 import javax.naming.Context; 28 import javax.naming.InitialContext; 29 import javax.naming.NamingEnumeration; 30 31 import org.apache.log4j.Logger; 32 import org.apache.struts.action.ActionServlet; 33 import org.apache.struts.config.ApplicationConfig; 34 import org.enableit.db.DBFilter; 35 import org.enableit.db.darrt.Globals; 36 37 38 /*** 39 * Sepcialisation of the Struts <code>ActionServlet</code> to prepare 40 * the application context for Darrt specific <code>Actions</code>. 41 * 42 * <p>All of the standard Struts behaviour is preserved intact, so that 43 * non-darrt Actions need never know the difference from the normal 44 * Struts ActionServlet.</p> 45 * 46 * @author Tim Stephenson 47 * @web:servlet name="action" load-on-startup="10" 48 * description="Specialisation of Struts Action Servlet" 49 * @web:servlet-init-param name="config" value="/WEB-INF/struts-config.xml" 50 * @web:servlet-init-param name="application" 51 * value="org.enableit.db.darrt.ApplicationResources" 52 * @web:servlet-init-param name="debug" value="0" 53 * @web:servlet-init-param name="detail" value="0" 54 * @web:servlet-init-param name="validate" value="true" 55 * @web:servlet-mapping url-pattern="*.do" 56 */ 57 public class DarrtActionServlet extends ActionServlet { 58 /* 59 * Properties 60 */ 61 62 /*** 63 * The Log4J <code>Logger</code> doing the logging. 64 */ 65 private static Logger logger = Logger.getLogger(DarrtActionServlet.class); 66 67 /*** 68 * CVS info ABOUT this class and its current version 69 */ 70 public static final String ABOUT = "$Revision: 1.8 $"; 71 72 /* 73 * Constructors 74 */ 75 76 /*** 77 * Default Constructor 78 */ 79 public DarrtActionServlet() { 80 super(); 81 } 82 83 /* 84 * Methods 85 */ 86 87 /*** 88 * Initialisation of the Struts and Darrt code. 89 * <p>Most of the processing has been factored into support methods so 90 * that you can override particular functionality at a fairly 91 * granular level.</p> 92 * @throws javax.servlet.ServletException 93 * - if we cannot configure ourselves correctly 94 */ 95 public void init() 96 throws javax.servlet.ServletException { 97 super.init(); 98 initDataSourceList(); 99 initOperatorList(); 100 } 101 102 /*** 103 * Interrogate the JNDI context for data sources and make their names 104 * available as a <code>List</code> in Application scope. 105 * @throws javax.servlet.ServletException 106 * - if we cannot configure ourselves correctly 107 */ 108 private void initDataSourceList() 109 throws javax.servlet.ServletException { 110 logger.info("METHOD_ENTRY: initDataSourceList"); 111 112 try { 113 Context ctx = new InitialContext(); 114 NamingEnumeration enum = ctx.listBindings("java:comp/env/jdbc"); 115 List dsNames = new ArrayList(); 116 117 while (enum.hasMore()) { 118 Binding binding = (Binding) enum.nextElement(); 119 120 dsNames.add("jdbc/" + binding.getName()); 121 logger.warn("Found data source: [" + binding.getName() + "]"); 122 } 123 124 getServletContext().setAttribute(Globals.DATA_SOURCE_NAMES, dsNames); 125 } catch (Exception e) { 126 String msg = "Exception reading JDBC data sources: " 127 + e.getMessage(); 128 129 logger.error(msg, e); 130 throw new javax.servlet.ServletException(msg, e); 131 } 132 133 logger.info("METHOD_EXIT: initDataSourceList"); 134 } 135 136 /*** 137 * Places a list of operators recognised by the darrt library into the 138 * application context under the key 'org.enableit.db.darrt.OPERATOR_LIST'. 139 */ 140 private void initOperatorList() { 141 logger.info("METHOD_ENTRY: initOperatorList"); 142 143 if (getServletContext().getAttribute(Globals.OPERATOR_LIST) == null) { 144 getServletContext().setAttribute(Globals.OPERATOR_LIST, 145 DBFilter.getOperators()); 146 } 147 148 logger.info("METHOD_EXIT: initOperatorList"); 149 } 150 151 protected void initApplicationMessageResources( 152 ApplicationConfig applicationConfig) 153 throws javax.servlet.ServletException { 154 super.initApplicationMessageResources(applicationConfig); 155 156 /* TODO: Merge all properties into a single set, this would allow an 157 application to overload defaults in the extended application 158 159 See the header.jsp for how this is done at the moment 160 MessageResourcesConfig extConfig = applicationConfig 161 .findMessageResourcesConfig("org.enableit.darrt.extensions.MESSAGE"); 162 163 if (extConfig != null) { 164 Object temp = getServletContext().getAttribute(Action.MESSAGES_KEY) ; 165 if (temp instanceof StandardPropertyMessageResources) { 166 StandardPropertyMessageResources baseBundle = 167 (StandardPropertyMessageResources) temp ; 168 Map messages = baseBundle.getMessages(); 169 170 StandardPropertyMessageResources extMsgBundle = 171 (StandardPropertyMessageResources) getServletContext() 172 .getAttribute("org.enableit.darrt.extensions.MESSAGE") ; 173 if (extMsgBundle != null) { 174 messages.putAll(extMsgBundle.getMessages()); 175 } 176 177 getServletContext().setAttribute(Action.MESSAGES_KEY, messages) ; 178 } 179 180 } */ 181 } 182 }

This page was automatically generated by Maven