001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.console.derbylogmanager;
017:
018: import org.apache.geronimo.console.BasePortlet;
019: import org.apache.geronimo.console.util.PortletManager;
020: import org.apache.geronimo.derby.DerbyLog;
021:
022: import javax.portlet.ActionRequest;
023: import javax.portlet.ActionResponse;
024: import javax.portlet.PortletConfig;
025: import javax.portlet.PortletContext;
026: import javax.portlet.PortletException;
027: import javax.portlet.PortletRequestDispatcher;
028: import javax.portlet.PortletSession;
029: import javax.portlet.RenderRequest;
030: import javax.portlet.RenderResponse;
031: import javax.portlet.WindowState;
032: import java.io.IOException;
033: import java.io.Serializable;
034:
035: public class DerbyLogViewerPortlet extends BasePortlet {
036: private final static String CRITERIA_KEY = "org.apache.geronimo.console.derby.log.CRITERIA";
037:
038: protected PortletRequestDispatcher normalView;
039:
040: protected PortletRequestDispatcher helpView;
041:
042: public void destroy() {
043: super .destroy();
044: normalView = null;
045: helpView = null;
046: }
047:
048: protected void doHelp(RenderRequest renderRequest,
049: RenderResponse renderResponse) throws PortletException,
050: IOException {
051: helpView.include(renderRequest, renderResponse);
052: }
053:
054: protected void doView(RenderRequest renderRequest,
055: RenderResponse renderResponse) throws PortletException,
056: IOException {
057: if (WindowState.MINIMIZED
058: .equals(renderRequest.getWindowState())) {
059: return;
060: }
061: String action = renderRequest.getParameter("action");
062:
063: DerbyLog log = (DerbyLog) PortletManager.getManagedBeans(
064: renderRequest, DerbyLog.class)[0];//todo: what if it's not there?
065: Criteria criteria = (Criteria) renderRequest.getPortletSession(
066: true).getAttribute(CRITERIA_KEY,
067: PortletSession.PORTLET_SCOPE);
068:
069: if (criteria == null
070: || (action != null && !"refresh".equals(action))) {
071: if (criteria == null)
072: criteria = new Criteria();
073: String startPos = renderRequest.getParameter("startPos");
074: String endPos = renderRequest.getParameter("endPos");
075: String maxRows = renderRequest.getParameter("maxRows");
076: String searchString = renderRequest
077: .getParameter("searchString");
078:
079: criteria.max = maxRows == null || maxRows.equals("") ? criteria.max
080: : Integer.parseInt(maxRows);
081: criteria.start = startPos == null || startPos.equals("") ? null
082: : new Integer(startPos);
083: criteria.stop = endPos == null || endPos.equals("") ? null
084: : new Integer(endPos);
085: criteria.text = searchString == null
086: || searchString.equals("") ? null : searchString;
087: renderRequest.getPortletSession(true).setAttribute(
088: CRITERIA_KEY, criteria,
089: PortletSession.PORTLET_SCOPE);
090: }
091:
092: DerbyLog.SearchResults results = log.searchLog(criteria.start,
093: criteria.stop, criteria.max, criteria.text);
094: renderRequest.setAttribute("searchResults", results
095: .getResults());
096: renderRequest.setAttribute("lineCount", new Integer(results
097: .getLineCount()));
098: renderRequest.setAttribute("startPos", criteria.start);
099: renderRequest.setAttribute("endPos", criteria.stop);
100: renderRequest.setAttribute("searchString", criteria.text);
101: renderRequest.setAttribute("maxRows", criteria.max);
102: if (results.isCapped()) {
103: renderRequest.setAttribute("capped", Boolean.TRUE);
104: }
105:
106: normalView.include(renderRequest, renderResponse);
107: }
108:
109: @Override
110: public void processAction(ActionRequest actionRequest,
111: ActionResponse actionResponse) throws PortletException,
112: IOException {
113: //Add all the parameters to the actionResponse Attributes so we can get the back
114: actionResponse.setRenderParameters(actionRequest
115: .getParameterMap());
116: }
117:
118: private static class Criteria implements Serializable {
119: Integer max = 10;
120: Integer start;
121: Integer stop;
122: String text;
123: }
124:
125: public void init(PortletConfig portletConfig)
126: throws PortletException {
127: PortletContext pc = portletConfig.getPortletContext();
128: normalView = pc
129: .getRequestDispatcher("/WEB-INF/view/derbylogmanager/view.jsp");
130: helpView = pc
131: .getRequestDispatcher("/WEB-INF/view/derbylogmanager/help.jsp");
132: super.init(portletConfig);
133: }
134: }
|