taylor 2005/01/19 22:24:37 Modified: applications/demo/src/webapp/WEB-INF/view database-edit.vm database-view.vm applications/demo/src/webapp/WEB-INF web.xml applications/gems/src/java/org/apache/portals/gems/browser BrowserPortlet.java DatabaseBrowserPortlet.java Added: applications/demo/src/webapp/WEB-INF/view status-include.vm applications/gems/src/java/org/apache/portals/gems/util StatusMessage.java Log: DatabaseBrowser new functionality: - JNDI Datasource support (requires setting up a data source for your particular app server) - JNDI Datasource tested - Test Button in Edit Mode - Error Message handling in Edit and View Mode Revision Changes Path 1.2 +4 -0 jakarta-jetspeed-2/applications/demo/src/webapp/WEB-INF/view/database-edit.vm Index: database-edit.vm =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/applications/demo/src/webapp/WEB-INF/view/database-edit.vm,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- database-edit.vm 11 Jan 2005 09:32:25 -0000 1.1 +++ database-edit.vm 20 Jan 2005 06:24:37 -0000 1.2 @@ -11,6 +11,10 @@ #set ($disableSSO = "")
#end +#if ($statusMsg) +#parse ('/WEB-INF/view/status-include.vm') +#end + <h3 class="portlet-section-header">$MESSAGES.getString('label.prefs')</h3> <form name='J2DBEdit' action="$renderResponse.createActionURL()" method="post"> 1.3 +4 -0 jakarta-jetspeed-2/applications/demo/src/webapp/WEB-INF/view/database-view.vm Index: database-view.vm =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/applications/demo/src/webapp/WEB-INF/view/database-view.vm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- database-view.vm 24 Dec 2004 03:34:26 -0000 1.2 +++ database-view.vm 20 Jan 2005 06:24:37 -0000 1.3 @@ -23,6 +23,10 @@ #set ($MESSAGES = $portletConfig.getResourceBundle($renderRequest.Locale)) +#if ($statusMsg) +#parse ('/WEB-INF/view/status-include.vm') +#end + <table cellpadding=0 cellspacing=1 border=0 width="100%"> <tbody> <tr> 1.1 jakarta-jetspeed-2/applications/demo/src/webapp/WEB-INF/view/status-include.vm Index: status-include.vm =================================================================== #* Copyright 2004 The Apache Software Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *# <br/> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <div class="$statusMsg.Type">$statusMsg.Text</div> </tr> </table> 1.12 +8 -0 jakarta-jetspeed-2/applications/demo/src/webapp/WEB-INF/web.xml Index: web.xml =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/applications/demo/src/webapp/WEB-INF/web.xml,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- web.xml 2 Dec 2004 03:13:14 -0000 1.11 +++ web.xml 20 Jan 2005 06:24:37 -0000 1.12 @@ -97,6 +97,14 @@ <taglib-location>/WEB-INF/c.tld</taglib-location> </taglib> + <!-- JNDI Db resource --> + <resource-ref> + <description>DB Connection</description> + <res-ref-name>jdbc/demo</res-ref-name> + <res-type>javax.sql.DataSource</res-type> + <res-auth>Container</res-auth> + </resource-ref> + <security-constraint> <web-resource-collection> <web-resource-name>HTTPBasicDemo</web-resource-name> 1.3 +9 -0 jakarta-jetspeed-2/applications/gems/src/java/org/apache/portals/gems/browser/BrowserPortlet.java Index: BrowserPortlet.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/applications/gems/src/java/org/apache/portals/gems/browser/BrowserPortlet.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- BrowserPortlet.java 11 Jan 2005 09:32:30 -0000 1.2 +++ BrowserPortlet.java 20 Jan 2005 06:24:37 -0000 1.3 @@ -34,6 +34,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.portals.bridges.velocity.GenericVelocityPortlet; +import org.apache.portals.gems.util.StatusMessage; import org.apache.velocity.context.Context; /** @@ -188,6 +189,14 @@ } catch (Exception e) { + String msg = e.toString(); + Throwable cause = e.getCause(); + if (cause != null) + { + msg = msg + ", " + cause.getMessage(); + } + + context.put("statusMsg", new StatusMessage(msg, StatusMessage.ERROR)); // log the error msg log.error("Exception", e); 1.6 +46 -8 jakarta-jetspeed-2/applications/gems/src/java/org/apache/portals/gems/browser/DatabaseBrowserPortlet.java Index: DatabaseBrowserPortlet.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/applications/gems/src/java/org/apache/portals/gems/browser/DatabaseBrowserPortlet.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- DatabaseBrowserPortlet.java 14 Jan 2005 15:27:02 -0000 1.5 +++ DatabaseBrowserPortlet.java 20 Jan 2005 06:24:37 -0000 1.6 @@ -33,11 +33,16 @@ import javax.portlet.PortletException; import javax.portlet.PortletMode; import javax.portlet.PortletPreferences; +import javax.portlet.PortletRequest; import javax.portlet.PortletSession; import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; import javax.sql.DataSource; import org.apache.commons.dbcp.BasicDataSource; +import org.apache.portals.bridges.util.PreferencesHelper; +import org.apache.portals.gems.util.StatusMessage; +import org.apache.portals.messaging.PortletMessaging; /** * DatabaseBrowserPortlet @@ -212,11 +217,11 @@ /* - * Connection Management: TODO: rethink this, current impl is a quick prototype + * Connection Management */ - public Connection getConnection(RenderRequest request) - throws Exception // TODO: switch to Edit Mode on failure + public Connection getConnection(PortletRequest request) + throws Exception { Connection con = null; try @@ -230,8 +235,9 @@ if (dsType.equals("jndi")) { Context ctx = new InitialContext(); - DataSource ds = (DataSource)ctx.lookup(prefs.getValue("JndiDatasource", "")); -// DataSource ds = (DataSource)ctx.lookup("java:/jdbc/jetspeed"); + String dsName = prefs.getValue("JndiDatasource", ""); + Context envContext = (Context)ctx.lookup("java:/comp/env"); + DataSource ds = (DataSource)envContext.lookup(dsName); con = ds.getConnection(); } else if (dsType.equals("dbcp")) @@ -279,6 +285,18 @@ } + public void doEdit(RenderRequest request, RenderResponse response) + throws PortletException, IOException + { + response.setContentType("text/html"); + StatusMessage msg = (StatusMessage)PortletMessaging.consume(request, "dbConnectTest"); + if (msg != null) + { + this.getContext(request).put("statusMsg", msg); + } + super.doEdit(request, response); + } + public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException @@ -288,8 +306,28 @@ String test = request.getParameter("Test"); if (test != null && test.equals("Test")) { - // test the connection - TODO: write this tomorrow :) - System.out.println("Handle TEST processing"); + try + { + PortletPreferences prefs = request.getPreferences(); + PreferencesHelper.requestParamsToPreferences(request); + prefs.store(); + getConnection(request); + StatusMessage msg = new StatusMessage("Connection made successfully.", StatusMessage.SUCCESS); + PortletMessaging.publish(request, "dbConnectTest", msg); + } + catch (Exception e) + { + String msg = e.toString(); + Throwable cause = e.getCause(); + if (cause != null) + { + msg = msg + ", " + cause.getMessage(); + } + StatusMessage sm = new StatusMessage(msg, StatusMessage.ERROR); + PortletMessaging.publish(request, "dbConnectTest", sm); + } + response.setPortletMode(PortletMode.EDIT); + return; } } super.processAction(request, response); 1.1 jakarta-jetspeed-2/applications/gems/src/java/org/apache/portals/gems/util/StatusMessage.java Index: StatusMessage.java =================================================================== /* * Copyright 2000-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.portals.gems.util; import java.io.Serializable; /** * StatusMessage * * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor </a> * @version $Id: StatusMessage.java,v 1.1 2005/01/20 06:24:37 taylor Exp $ */ public class StatusMessage implements Serializable { private static final long serialVersionUID = 1; private String text; private String type; public static final String INFO = "portlet-msg-info"; public static final String ERROR = "portlet-msg-error"; public static final String ALERT = "portlet-msg-alert"; public static final String SUCCESS = "portlet-msg-success"; public StatusMessage(String text, String type) { this.text = new String(text); this.type = type; } public StatusMessage(String text) { this.text = new String(text); this.type = INFO; } /** * @return Returns the text. */ public String getText() { return text; } /** * @param text The text to set. */ public void setText(String text) { this.text = text; } /** * @return Returns the type. */ public String getType() { return type; } /** * @param type The type to set. */ public void setType(String type) { this.type = type; } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]