001: /* ====================================================================
002: * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
003: *
004: * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by Jcorporate Ltd.
021: * (http://www.jcorporate.com/)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. "Jcorporate" and product names such as "Expresso" must
026: * not be used to endorse or promote products derived from this
027: * software without prior written permission. For written permission,
028: * please contact info@jcorporate.com.
029: *
030: * 5. Products derived from this software may not be called "Expresso",
031: * or other Jcorporate product names; nor may "Expresso" or other
032: * Jcorporate product names appear in their name, without prior
033: * written permission of Jcorporate Ltd.
034: *
035: * 6. No product derived from this software may compete in the same
036: * market space, i.e. framework, without prior written permission
037: * of Jcorporate Ltd. For written permission, please contact
038: * partners@jcorporate.com.
039: *
040: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
041: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
042: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
043: * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
044: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
045: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
046: * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
047: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
048: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
049: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
050: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
051: * SUCH DAMAGE.
052: * ====================================================================
053: *
054: * This software consists of voluntary contributions made by many
055: * individuals on behalf of the Jcorporate Ltd. Contributions back
056: * to the project(s) are encouraged when you make modifications.
057: * Please send them to support@jcorporate.com. For more information
058: * on Jcorporate Ltd. and its products, please see
059: * <http://www.jcorporate.com/>.
060: *
061: * Portions of this software are based upon other open source
062: * products and are subject to their respective licenses.
063: */
064:
065: /**
066: * DBLog.java
067: *
068: * Copyright 1999, 2000, 2001 Jcorporate Ltd.
069: */package com.jcorporate.expresso.services.controller;
070:
071: import com.jcorporate.expresso.core.controller.Block;
072: import com.jcorporate.expresso.core.controller.ControllerException;
073: import com.jcorporate.expresso.core.controller.ControllerRequest;
074: import com.jcorporate.expresso.core.controller.ControllerResponse;
075: import com.jcorporate.expresso.core.controller.DBController;
076: import com.jcorporate.expresso.core.controller.Output;
077: import com.jcorporate.expresso.core.controller.State;
078: import com.jcorporate.expresso.core.controller.Transition;
079: import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
080: import com.jcorporate.expresso.core.logging.LogException;
081: import com.jcorporate.expresso.core.logging.LogHandler;
082: import com.jcorporate.expresso.services.dbobj.LogEntry;
083:
084: import java.util.Iterator;
085:
086: /**
087: * Controller for administering and viewing the database and text log
088: *
089: * @author Michael Nash
090: * @version $Revision: 1.13 $ $Date: 2004/11/17 20:48:17 $
091: */
092: public class Log extends DBController {
093: private int maxLines = 100;
094:
095: /**
096: * Our constructor "declares" what states we handle
097: */
098: public Log() {
099: super ();
100:
101: State show = new State("show", "Show Text Log");
102: addState(show);
103: setInitialState("show");
104:
105: State showdb = new State("showDb", "Show Database Log");
106: addState(showdb);
107:
108: State clear = new State("clear", "Clear Text Log");
109: addState(clear);
110: setInitialState("clear");
111:
112: State cleardb = new State("clearDb", "Clear Database Log");
113: addState(cleardb);
114: setInitialState("clearDb");
115: this
116: .setSchema(com.jcorporate.expresso.core.ExpressoSchema.class);
117: } /* Status() */
118:
119: /**
120: * Display the contents of the current server log to the user
121: *
122: * @param request Standard request object
123: * @param response Standard reponse object
124: * @throws ControllerException upon error
125: */
126: public void runShowDbState(ControllerRequest request,
127: ControllerResponse response) throws ControllerException {
128: try {
129: LogHandler.flush();
130: } catch (LogException le) {
131: throw new ControllerException(le);
132: }
133:
134: Block logTable = new Block();
135: response.addBlock(logTable);
136: logTable.setAttribute("table", "Y");
137: logTable.setDescription("Current Log");
138: logTable.setAttribute("header-row",
139: "Time|Message|Object|UserId|Job");
140:
141: try {
142: LogEntry logEntryList = new LogEntry(
143: SecuredDBObject.SYSTEM_ACCOUNT);
144: logEntryList.setDataContext(request.getDataContext());
145: logEntryList.setMaxRecords(maxLines + 1);
146:
147: LogEntry oneEntry = null;
148: Iterator e = logEntryList.searchAndRetrieveList(
149: "LogTime DESC").iterator();
150: int lineCount = 0;
151: Block oneRow = null;
152: Output oneCell = null;
153:
154: while (e.hasNext()) {
155: oneEntry = (LogEntry) e.next();
156: oneRow = new Block("log row");
157: oneRow.setAttribute("row", "Y");
158: logTable.add(oneRow);
159: oneCell = new Output(oneEntry.getField("LogTime"));
160: oneRow.add(oneCell);
161: oneCell = new Output(oneEntry.getField("MessageText"));
162: oneRow.add(oneCell);
163: oneCell = new Output(oneEntry.getField("ObjectName"));
164: oneRow.add(oneCell);
165: oneCell = new Output(oneEntry.getField("ExpUid"));
166: oneRow.add(oneCell);
167: oneCell = new Output(oneEntry.getField("JobNumber"));
168: oneRow.add(oneCell);
169: lineCount++;
170:
171: if (lineCount >= maxLines) {
172: break;
173: }
174: } /* while more elements */
175:
176: if (lineCount == 0) {
177: Output none = new Output("none",
178: "No entries in the log");
179: response.add(none);
180: }
181: //out.println("</table></body></html>");
182: if (lineCount >= maxLines) {
183: Output disp = new Output("disp", "Display stopped at "
184: + maxLines + " lines.");
185: response.add(disp);
186: }
187: } catch (Exception ioe) {
188: throw new ControllerException(ioe);
189: }
190:
191: response.addTransition(new Transition("clearDb", this ));
192: response.addTransition(new Transition("show", this ));
193: response.addTransition(new Transition("clear", this ));
194: } /* */
195:
196: /**
197: * @return java.lang.String The Title of the controller
198: */
199: public String getTitle() {
200: return ("Manage System Logs");
201: } /* getTitle() */
202:
203: } /* DBLog */
|