Source Code Cross Referenced for LogViewerPortlet.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » console » logmanager » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server geronimo » plugins » org.apache.geronimo.console.logmanager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.logmanager;
017:
018:        import java.io.File;
019:        import java.io.IOException;
020:        import java.io.Serializable;
021:        import java.util.Enumeration;
022:        import java.util.Map;
023:
024:        import javax.portlet.ActionRequest;
025:        import javax.portlet.ActionResponse;
026:        import javax.portlet.PortletConfig;
027:        import javax.portlet.PortletContext;
028:        import javax.portlet.PortletException;
029:        import javax.portlet.PortletRequestDispatcher;
030:        import javax.portlet.PortletSession;
031:        import javax.portlet.RenderRequest;
032:        import javax.portlet.RenderResponse;
033:        import javax.portlet.WindowState;
034:
035:        import org.apache.geronimo.console.BasePortlet;
036:        import org.apache.geronimo.console.util.PortletManager;
037:        import org.apache.geronimo.system.logging.SystemLog;
038:
039:        /**
040:         * @version $Rev: 617213 $ $Date: 2008-01-31 12:20:33 -0800 (Thu, 31 Jan 2008) $
041:         */
042:        public class LogViewerPortlet extends BasePortlet {
043:            private final static String CRITERIA_KEY = "org.apache.geronimo.console.log.CRITERIA";
044:
045:            protected PortletRequestDispatcher searchView;
046:
047:            protected PortletRequestDispatcher helpView;
048:
049:            protected void doHelp(RenderRequest renderRequest,
050:                    RenderResponse renderRespose) throws PortletException,
051:                    IOException {
052:                helpView.include(renderRequest, renderRespose);
053:            }
054:
055:            @Override
056:            public void processAction(ActionRequest actionRequest,
057:                    ActionResponse actionResponse) throws PortletException,
058:                    IOException {
059:
060:                //Add all the parameters to the actionResponse Attributes so we can get the back
061:                actionResponse.setRenderParameters(actionRequest
062:                        .getParameterMap());
063:
064:            }
065:
066:            protected void doView(RenderRequest renderRequest,
067:                    RenderResponse renderRespose) throws PortletException,
068:                    IOException {
069:                if (WindowState.MINIMIZED
070:                        .equals(renderRequest.getWindowState())) {
071:                    return;
072:                }
073:                String action = renderRequest.getParameter("action");
074:
075:                SystemLog log = PortletManager
076:                        .getCurrentSystemLog(renderRequest);
077:                String[] logFiles = log.getLogFileNames();
078:                LogFile[] files = new LogFile[logFiles.length];
079:                for (int i = 0; i < files.length; i++) {
080:                    files[i] = new LogFile(logFiles[i]);
081:                }
082:                Criteria criteria = (Criteria) renderRequest.getPortletSession(
083:                        true).getAttribute(CRITERIA_KEY,
084:                        PortletSession.PORTLET_SCOPE);
085:
086:                if (criteria != null) {
087:                    // Check if criteria.logFile is in the logFileNames of current logging configuration
088:                    boolean found = false;
089:                    for (String logFile : logFiles) {
090:                        if (criteria.logFile.equals(new File(logFile))) {
091:                            found = true;
092:                            break;
093:                        }
094:                    }
095:                    if (!found) {
096:                        // This arises when log4j properties file is changed dynamically using LogManagerPortlet
097:                        // and the earlier log file is no longer in the current logging configuration.
098:                        // Change the log file to any one in the current logging configuration so that LogViewer
099:                        // won't run into errors.
100:                        criteria.logFile = logFiles[0];
101:                    }
102:                }
103:                if (criteria == null
104:                        || (action != null && !"refresh".equals(action))) {
105:                    if (criteria == null)
106:                        criteria = new Criteria();
107:                    String startPos = renderRequest.getParameter("startPos");
108:                    String endPos = renderRequest.getParameter("endPos");
109:                    String maxRows = renderRequest.getParameter("maxRows");
110:                    String logLevel = renderRequest.getParameter("logLevel");
111:                    String searchString = renderRequest
112:                            .getParameter("searchString");
113:                    String stackTraces = renderRequest
114:                            .getParameter("stackTraces");
115:                    String logFile = renderRequest.getParameter("logFile");
116:                    if (logFile == null || logFile.equals("")) {
117:                        logFile = logFiles[0];
118:                    }
119:
120:                    criteria.level = logLevel == null || logLevel.equals("") ? criteria.level
121:                            : logLevel;
122:                    try {
123:                        criteria.max = maxRows == null || maxRows.equals("") ? criteria.max
124:                                : Integer.parseInt(maxRows);
125:                    } catch (NumberFormatException e) {
126:                        //ignore
127:                    }
128:                    try {
129:                        criteria.start = startPos == null
130:                                || startPos.equals("") ? null : new Integer(
131:                                startPos);
132:                    } catch (NumberFormatException e) {
133:                        //ignore
134:                    }
135:                    try {
136:                        criteria.stop = endPos == null || endPos.equals("") ? null
137:                                : new Integer(endPos);
138:                    } catch (NumberFormatException e) {
139:                        //ignore
140:                    }
141:                    criteria.logFile = logFile;
142:                    criteria.stackTraces = stackTraces != null
143:                            && !stackTraces.equals("");
144:
145:                    criteria.text = searchString == null
146:                            || searchString.equals("") ? null : searchString;
147:                    renderRequest.getPortletSession(true).setAttribute(
148:                            CRITERIA_KEY, criteria,
149:                            PortletSession.PORTLET_SCOPE);
150:                }
151:
152:                SystemLog.SearchResults results = log.getMatchingItems(
153:                        criteria.logFile, criteria.start, criteria.stop,
154:                        criteria.level, criteria.text, criteria.max,
155:                        criteria.stackTraces);
156:                renderRequest.setAttribute("searchResults", results
157:                        .getResults());
158:                renderRequest.setAttribute("lineCount", new Integer(results
159:                        .getLineCount()));
160:                renderRequest.setAttribute("startPos", criteria.start);
161:                renderRequest.setAttribute("endPos", criteria.stop);
162:                renderRequest.setAttribute("logLevel", criteria.level);
163:                renderRequest.setAttribute("searchString", criteria.text);
164:                renderRequest.setAttribute("maxRows", Integer
165:                        .toString(criteria.max));
166:                renderRequest.setAttribute("logFile", criteria.logFile);
167:                renderRequest.setAttribute("logFiles", files);
168:                if (criteria.stackTraces) {
169:                    renderRequest.setAttribute("stackTraces", Boolean.TRUE);
170:                }
171:                if (results.isCapped()) {
172:                    renderRequest.setAttribute("capped", Boolean.TRUE);
173:                }
174:
175:                searchView.include(renderRequest, renderRespose);
176:            }
177:
178:            public void init(PortletConfig portletConfig)
179:                    throws PortletException {
180:                PortletContext pc = portletConfig.getPortletContext();
181:                searchView = pc
182:                        .getRequestDispatcher("/WEB-INF/view/logmanager/search.jsp");
183:                helpView = pc
184:                        .getRequestDispatcher("/WEB-INF/view/logmanager/viewhelp.jsp");
185:                super .init(portletConfig);
186:            }
187:
188:            private static class Criteria implements  Serializable {
189:                int max = 10;
190:                Integer start;
191:                Integer stop;
192:                String text;
193:                String level = "WARN";
194:                String logFile;
195:                boolean stackTraces;
196:            }
197:
198:            public static class LogFile {
199:                private String fullName;
200:                private String name;
201:
202:                public LogFile(String fullName) {
203:                    this .fullName = fullName;
204:                    //todo: what if portla JVM has different separator than server JVM?
205:                    int pos = fullName.lastIndexOf(File.separatorChar);
206:                    if (pos > -1) {
207:                        name = fullName.substring(pos + 1);
208:                    } else {
209:                        name = fullName;
210:                    }
211:                }
212:
213:                public String getFullName() {
214:                    return fullName;
215:                }
216:
217:                public String getName() {
218:                    return name;
219:                }
220:            }
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.