1 17 18 package org.apache.geronimo.console.internaldb; 19 20 import java.io.IOException ; 21 22 import javax.portlet.ActionRequest; 23 import javax.portlet.ActionResponse; 24 import javax.portlet.PortletConfig; 25 import javax.portlet.PortletException; 26 import javax.portlet.PortletRequestDispatcher; 27 import javax.portlet.RenderRequest; 28 import javax.portlet.RenderResponse; 29 import javax.portlet.WindowState; 30 31 import org.apache.geronimo.console.BasePortlet; 32 import org.apache.commons.logging.Log; 33 import org.apache.commons.logging.LogFactory; 34 35 public class DBViewerPortlet extends BasePortlet { 36 37 private final static Log log = LogFactory.getLog(DBViewerPortlet.class); 38 39 private static final int RDBMS_DERBY = 1; 40 41 private static final int RDBMS_MSSQL = 2; 42 43 private static final String MAXIMIZEDVIEW_JSP = "/WEB-INF/view/internaldb/dbViewerMaximized.jsp"; 44 45 private static final String HELPVIEW_JSP = "/WEB-INF/view/internaldb/dbViewerHelp.jsp"; 46 47 private static final String LISTDATABASES_JSP = "/WEB-INF/view/internaldb/listDatabases.jsp"; 48 49 private static final String LISTTABLES_JSP = "/WEB-INF/view/internaldb/listTables.jsp"; 50 51 private static final String VIEWTABLECONTENTS_JSP = "/WEB-INF/view/internaldb/viewTableContents.jsp"; 52 53 private static final String LISTDB_ACTION = "listDatabases"; 54 55 private static final String LISTTBLS_ACTION = "listTables"; 56 57 private static final String VIEWTBLCONTENTS_ACTION = "viewTableContents"; 58 59 private static final String DERBY_HOME = System.getProperty("derby.system.home"); 60 61 private static DBViewerHelper helper = new DBViewerHelper(); 62 63 private PortletRequestDispatcher maximizedView; 64 65 private PortletRequestDispatcher helpView; 66 67 private PortletRequestDispatcher listDatabasesView; 68 69 private PortletRequestDispatcher listTablesView; 70 71 private PortletRequestDispatcher viewTableContentsView; 72 73 public void processAction(ActionRequest actionRequest, 74 ActionResponse actionResponse) throws PortletException, IOException { 75 String action = actionRequest.getParameter("action"); 77 String db = actionRequest.getParameter("db"); 78 String tbl = actionRequest.getParameter("tbl"); 79 String viewTables = actionRequest.getParameter("viewTables"); 80 String rdbms = actionRequest.getParameter("rdbms"); 81 if (action != null) { 83 actionResponse.setRenderParameter("action", action); 84 } 85 if (db != null) { 86 actionResponse.setRenderParameter("db", db); 87 } 88 if (tbl != null) { 89 actionResponse.setRenderParameter("tbl", tbl); 90 } 91 if (viewTables != null) { 92 actionResponse.setRenderParameter("viewTables", viewTables); 93 } 94 if (rdbms != null) { 95 actionResponse.setRenderParameter("rdbms", rdbms); 96 } 97 } 98 99 protected void doView(RenderRequest renderRequest, 100 RenderResponse renderResponse) throws IOException , PortletException { 101 if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) { 102 return; 103 } 104 String action = renderRequest.getParameter("action"); 105 String db = renderRequest.getParameter("db"); 106 String tbl = renderRequest.getParameter("tbl"); 107 String viewTables = renderRequest.getParameter("viewTables"); 108 String rdbms = renderRequest.getParameter("rdbms"); 109 int rdbmsParam = (rdbms == null ? RDBMS_DERBY : Integer.parseInt(rdbms)); 110 111 if (WindowState.NORMAL.equals(renderRequest.getWindowState())) { 112 if (rdbmsParam == RDBMS_DERBY) { 113 if (LISTTBLS_ACTION.equals(action) 115 || VIEWTBLCONTENTS_ACTION.equals(action)) { 116 if (!helper.isDBValid(DERBY_HOME, db)) { 117 log.error("Database is not valid: " + db); 119 action = ""; 120 } 121 } 122 if (VIEWTBLCONTENTS_ACTION.equals(action)) { 123 if (!helper.isTblValid(db, tbl)) { 124 log.error("Table is not valid: " + tbl); 126 action = ""; 127 } 128 } 129 } 130 131 renderRequest.setAttribute("rdbms", rdbms); 132 if (LISTTBLS_ACTION.equals(action)) { 133 renderRequest.setAttribute("db", db); 134 renderRequest.setAttribute("viewTables", viewTables); 135 renderRequest.setAttribute("ds", DerbyConnectionUtil 136 .getDataSource(db)); 137 listTablesView.include(renderRequest, renderResponse); 138 } else if (VIEWTBLCONTENTS_ACTION.equals(action)) { 139 renderRequest.setAttribute("db", db); 140 renderRequest.setAttribute("tbl", tbl); 141 renderRequest.setAttribute("viewTables", viewTables); 142 renderRequest.setAttribute("ds", DerbyConnectionUtil 143 .getDataSource(db)); 144 viewTableContentsView.include(renderRequest, renderResponse); 145 } else { 146 renderRequest.setAttribute("databases", helper 147 .getDerbyDatabases(DERBY_HOME)); 148 listDatabasesView.include(renderRequest, renderResponse); 149 } 150 } else { 151 maximizedView.include(renderRequest, renderResponse); 152 } 153 } 154 155 protected void doHelp(RenderRequest renderRequest, 156 RenderResponse renderResponse) throws PortletException, IOException { 157 helpView.include(renderRequest, renderResponse); 158 } 159 160 public void init(PortletConfig portletConfig) throws PortletException { 161 super.init(portletConfig); 162 maximizedView = portletConfig.getPortletContext().getRequestDispatcher( 163 MAXIMIZEDVIEW_JSP); 164 helpView = portletConfig.getPortletContext().getRequestDispatcher( 165 HELPVIEW_JSP); 166 listDatabasesView = portletConfig.getPortletContext() 167 .getRequestDispatcher(LISTDATABASES_JSP); 168 listTablesView = portletConfig.getPortletContext() 169 .getRequestDispatcher(LISTTABLES_JSP); 170 viewTableContentsView = portletConfig.getPortletContext() 171 .getRequestDispatcher(VIEWTABLECONTENTS_JSP); 172 } 173 174 public void destroy() { 175 maximizedView = null; 176 helpView = null; 177 listDatabasesView = null; 178 listTablesView = null; 179 viewTableContentsView = null; 180 super.destroy(); 181 } 182 183 } | Popular Tags |