Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.console.derbylogmanager » [javadoc | source]
    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package org.apache.geronimo.console.derbylogmanager;
   19   
   20   import org.apache.geronimo.console.BasePortlet;
   21   import org.apache.geronimo.console.util.PortletManager;
   22   import org.apache.geronimo.derby.DerbyLog;
   23   
   24   import javax.portlet.ActionRequest;
   25   import javax.portlet.ActionResponse;
   26   import javax.portlet.PortletConfig;
   27   import javax.portlet.PortletContext;
   28   import javax.portlet.PortletException;
   29   import javax.portlet.PortletRequestDispatcher;
   30   import javax.portlet.PortletSession;
   31   import javax.portlet.RenderRequest;
   32   import javax.portlet.RenderResponse;
   33   import javax.portlet.WindowState;
   34   import java.io.IOException;
   35   import java.io.Serializable;
   36   
   37   public class DerbyLogViewerPortlet extends BasePortlet {
   38       private final static String CRITERIA_KEY = "org.apache.geronimo.console.derby.log.CRITERIA";
   39   
   40       protected PortletRequestDispatcher normalView;
   41   
   42       protected PortletRequestDispatcher helpView;
   43   
   44       public void destroy() {
   45           super.destroy();
   46           normalView = null;
   47           helpView = null;
   48       }
   49   
   50       protected void doHelp(RenderRequest renderRequest,
   51                             RenderResponse renderResponse) throws PortletException, IOException {
   52           helpView.include(renderRequest, renderResponse);
   53       }
   54   
   55       protected void doView(RenderRequest renderRequest,
   56                             RenderResponse renderResponse) throws PortletException, IOException {
   57           if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
   58               return;
   59           }
   60           String action = renderRequest.getParameter("action");
   61   
   62           DerbyLog log = (DerbyLog) PortletManager.getManagedBeans(renderRequest, DerbyLog.class)[0];//todo: what if it's not there?
   63           Criteria criteria = (Criteria) renderRequest.getPortletSession(true).getAttribute(CRITERIA_KEY, PortletSession.PORTLET_SCOPE);
   64           
   65           if (criteria == null || (action != null && !"refresh".equals(action))) {
   66               if(criteria == null)
   67                   criteria = new Criteria();
   68               String startPos = renderRequest.getParameter("startPos");
   69               String endPos = renderRequest.getParameter("endPos");
   70               String maxRows = renderRequest.getParameter("maxRows");
   71               String searchString = renderRequest.getParameter("searchString");           
   72               
   73               criteria.max = maxRows == null || maxRows.equals("") ? criteria.max : Integer.parseInt(maxRows);
   74               criteria.start = startPos == null || startPos.equals("") ? null : new Integer(startPos);
   75               criteria.stop = endPos == null || endPos.equals("") ? null : new Integer(endPos);
   76               criteria.text = searchString == null || searchString.equals("") ? null : searchString;
   77               renderRequest.getPortletSession(true).setAttribute(CRITERIA_KEY, criteria, PortletSession.PORTLET_SCOPE);
   78           }
   79   
   80           DerbyLog.SearchResults results = log.searchLog(criteria.start, criteria.stop,
   81                            criteria.max, criteria.text);
   82           renderRequest.setAttribute("searchResults", results.getResults());
   83           renderRequest.setAttribute("lineCount", new Integer(results.getLineCount()));
   84           renderRequest.setAttribute("startPos", criteria.start);
   85           renderRequest.setAttribute("endPos", criteria.stop);
   86           renderRequest.setAttribute("searchString", criteria.text);
   87           renderRequest.setAttribute("maxRows", criteria.max);
   88           if(results.isCapped()) {
   89               renderRequest.setAttribute("capped", Boolean.TRUE);
   90           }
   91   
   92           normalView.include(renderRequest, renderResponse);
   93       }
   94   
   95       @Override
   96       public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException {        
   97           //Add all the parameters to the actionResponse Attributes so we can get the back
   98           actionResponse.setRenderParameters(actionRequest.getParameterMap());    
   99       }
  100       
  101       private static class Criteria implements Serializable {
  102           Integer max = 10;
  103           Integer start;
  104           Integer stop;
  105           String text;
  106       }
  107   
  108       public void init(PortletConfig portletConfig) throws PortletException {
  109           PortletContext pc = portletConfig.getPortletContext();
  110           normalView = pc
  111                   .getRequestDispatcher("/WEB-INF/view/derbylogmanager/view.jsp");
  112           helpView = pc
  113                   .getRequestDispatcher("/WEB-INF/view/derbylogmanager/help.jsp");
  114           super.init(portletConfig);
  115       }
  116   }

Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.console.derbylogmanager » [javadoc | source]