Source Code Cross Referenced for LogsViewBean.java in  » Portal » Open-Portal » com » sun » portal » search » admin » 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 » Portal » Open Portal » com.sun.portal.search.admin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         */
005:
006:        package com.sun.portal.search.admin;
007:
008:        import java.net.URL;
009:        import java.util.*;
010:
011:        import java.io.*;
012:        import javax.servlet.*;
013:        import javax.servlet.http.*;
014:
015:        import com.sun.portal.search.admin.CSViewBeanBase;
016:        import com.sun.portal.search.util.SearchConfig;
017:        import javax.servlet.http.HttpServletRequest;
018:        import com.iplanet.jato.RequestContext;
019:        import com.iplanet.jato.view.event.DisplayEvent;
020:        import com.iplanet.jato.view.event.RequestInvocationEvent;
021:
022:        import com.iplanet.jato.view.html.StaticTextField;
023:        import com.iplanet.jato.view.html.TextField;
024:        import com.iplanet.jato.view.html.CheckBox;
025:        import com.iplanet.jato.view.html.Button;
026:        import com.iplanet.jato.view.html.ComboBox;
027:        import com.iplanet.jato.view.html.RadioButtonGroup;
028:        import com.iplanet.jato.util.HtmlUtil;
029:
030:        import com.iplanet.jato.view.html.Option;
031:        import com.iplanet.jato.view.html.OptionList;
032:
033:        import com.iplanet.jato.view.View;
034:        import com.iplanet.jato.view.ViewBean;
035:        import com.iplanet.jato.view.ViewBeanBase;
036:
037:        import com.iplanet.jato.ViewBeanManager;
038:        import com.iplanet.jato.model.ModelControlException;
039:        import com.iplanet.am.console.components.view.html.IPlanetButton;
040:
041:        /**
042:         * iPS admin console view bean: TODO
043:         */
044:        public class LogsViewBean extends CSViewBeanBase {
045:            public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/Logs.jsp";
046:            public static final String PAGE_NAME = "Logs";
047:            //
048:            // Logs
049:            //
050:            public static final String VLOG_COMBO = "VLogCombo";
051:            public static final String NLINES_TEXT = "NLinesText";
052:            public static final String LOG_RESULT = "LogResult";
053:            public static final String LOG_BUTTON = "LOGButton";
054:
055:            private static final int AVG_BYTES_PER_LINE = 256; // initial try average 256 bytes per line
056:            private static String[] logFNs = { null, null, null, null, null,
057:                    null };
058:            private static final String[] logIndex = { "0", "1", "2", "3", "4",
059:                    "5" };
060:
061:            /**
062:             * constructor
063:             *
064:             * @param PageName  of this view bean
065:             * @param displayURL  default display URL
066:             */
067:            public LogsViewBean() {
068:                super (PAGE_NAME);
069:                setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
070:                registerChildren();
071:            }
072:
073:            /**
074:             * register child component
075:             */
076:            protected void registerChildren() {
077:                registerChild(VLOG_COMBO, ComboBox.class);
078:                registerChild(NLINES_TEXT, TextField.class);
079:                registerChild(LOG_RESULT, StaticTextField.class);
080:                registerChild(LOG_BUTTON, IPlanetButton.class);
081:            }
082:
083:            /**
084:             * create child component
085:             *
086:             * @param name of component
087:             * @return child component
088:             */
089:            protected View createChild(String name) {
090:                View Headerchild = super .createChild(name);
091:                if (Headerchild != null)
092:                    return Headerchild;
093:                if (name.equals(VLOG_COMBO)) {
094:                    ComboBox child = new ComboBox(this , VLOG_COMBO, "");
095:                    OptionList VLogOptions = new OptionList(
096:                            getLocalizedStringArray("log.viewer.loglistlabel",
097:                                    ","), logIndex);
098:                    child.setOptions(VLogOptions);
099:                    return child;
100:                }
101:                if (name.equals(NLINES_TEXT)) {
102:                    return new TextField(this , NLINES_TEXT, "25");
103:                }
104:                if (name.equals(LOG_RESULT)) {
105:                    return new StaticTextField(this , LOG_RESULT,
106:                            getLocalizedString("log.viewer.defaultmsg"));
107:                }
108:                if (name.equals(LOG_BUTTON)) {
109:                    return new IPlanetButton(this , LOG_BUTTON, "");
110:                }
111:
112:                throw new IllegalArgumentException("Invalid child name ["
113:                        + name + "]");
114:            }
115:
116:            private void getLogFNs() throws Exception {
117:                String logDir = CSConfig.getServerRoot() + File.separator
118:                        + "logs" + File.separator;
119:                if (logFNs[0] == null) {
120:                    logFNs[0] = logDir + "filter.log";
121:                }
122:                if (logFNs[1] == null) {
123:                    logFNs[1] = SearchConfig.getValue(SearchConfig.RDMGR_LOGFN);
124:                }
125:                if (logFNs[2] == null) {
126:                    logFNs[2] = SearchConfig.getValue(SearchConfig.DEBUG_LOGFN);
127:                }
128:                if (logFNs[3] == null) {
129:                    logFNs[3] = logDir + "robot.log";
130:                }
131:                if (logFNs[4] == null) {
132:                    logFNs[4] = SearchConfig
133:                            .getValue(SearchConfig.SENGINE_LOGFN);
134:                }
135:                if (logFNs[5] == null) {
136:                    logFNs[5] = SearchConfig.getValue(SearchConfig.RDM_LOGFN);
137:                }
138:            }
139:
140:            public void beginDisplay(DisplayEvent event) {
141:                setPageEncoding();
142:                setDisplayFieldValue(LOG_BUTTON,
143:                        getLocalizedString("log.viewer.buttontext"));
144:            }
145:
146:            public String getLastLines(String logFileName, int showLines)
147:                    throws Exception {
148:                if (showLines <= 0) {
149:                    return null;
150:                }
151:                RandomAccessFile raf = new RandomAccessFile(logFileName, "r");
152:                if (raf.length() == 0) {
153:                    return "";
154:                }
155:                int readSize = showLines * AVG_BYTES_PER_LINE;
156:                byte[] buffer;
157:                int startPosition = 0;
158:                while (true) {
159:                    long tryPosition = raf.length() - readSize;
160:                    if (tryPosition < 0) {
161:                        tryPosition = 0;
162:                        readSize = (int) raf.length();
163:                    }
164:                    raf.seek(tryPosition);
165:
166:                    buffer = new byte[readSize];
167:
168:                    raf.readFully(buffer);
169:                    int line = -1;
170:                    int i;
171:                    for (i = readSize - 1; i >= 0 && line < showLines; i--) {
172:                        if (buffer[i] == '\n') {
173:                            /* test for \r\n */
174:                            if (i > 0 && buffer[i - 1] == '\r') {
175:                                i--;
176:                            }
177:                            line++;
178:                        }
179:                    }
180:                    if (line == showLines) {
181:                        startPosition = i + 2;
182:                        break;
183:                    }
184:                    if (tryPosition == 0) {
185:                        startPosition = 0;
186:                        break;
187:                    }
188:                    readSize += 10000; /* add 10 k more */
189:                }
190:
191:                return new String(buffer, startPosition, buffer.length
192:                        - startPosition, "UTF-8");
193:
194:            }
195:
196:            public void handleLOGButtonRequest(RequestInvocationEvent event) {
197:                int logNdx = getDisplayFieldIntValue(VLOG_COMBO);
198:                try {
199:                    getLogFNs();
200:                } catch (Exception e) {
201:                }
202:
203:                String logFileName = logFNs[logNdx];
204:                int showLines = 25;
205:                try {
206:                    showLines = getDisplayFieldIntValue(NLINES_TEXT);
207:                    if (showLines <= 0) {
208:                        this .errorMessage = getLocalizedString("log.viewer.numberformatexception");
209:                        forwardTo();
210:                        return;
211:                    }
212:                } catch (Exception e) {
213:                    this .errorMessage = getLocalizedString("log.viewer.numberformatexception");
214:                    forwardTo();
215:                    return;
216:                }
217:
218:                try {
219:
220:                    String lastLines = getLastLines(logFileName, showLines);
221:
222:                    if (lastLines != null) {
223:                        StringBuffer outBuf = new StringBuffer();
224:                        int lineCount = 0;
225:                        StringTokenizer st = new StringTokenizer(lastLines,
226:                                "\r\n");
227:                        while (st.hasMoreTokens()) {
228:                            String token = st.nextToken();
229:                            if (token.trim().length() > 0) {
230:                                outBuf.append("<Font color=gray>"
231:                                        + (++lineCount) + " : </font>"
232:                                        + HtmlUtil.escape(token) + "<br>\n");
233:                            }
234:                        }
235:                        if (lineCount > 0) {
236:                            setDisplayFieldValue(LOG_RESULT, outBuf);
237:                        } else {
238:                            setDisplayFieldValue(
239:                                    LOG_RESULT,
240:                                    "<font color=red>"
241:                                            + getLocalizedString("log.viewer.emptylogmsg")
242:                                            + "</font>");
243:                        }
244:                    }
245:                } catch (Exception e) {
246:                    String[] args = { logFileName };
247:                    setDisplayFieldValue(LOG_RESULT, "<font color=red>"
248:                            + this .getLocalizedMessageFormat(
249:                                    "log.viewer.noexistlogmsg", args)
250:                            + "</font>");
251:                }
252:
253:                forwardTo();
254:            }
255:
256:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.