001: /*
002: * The Apache Software License, Version 1.1
003: *
004: * Copyright (c) 1999 The Apache Software Foundation. All rights
005: * reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The end-user documentation included with the redistribution, if
020: * any, must include the following acknowlegement:
021: * "This product includes software developed by the
022: * Apache Software Foundation (http://www.apache.org/)."
023: * Alternately, this acknowlegement may appear in the software itself,
024: * if and wherever such third-party acknowlegements normally appear.
025: *
026: * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
027: * Foundation" must not be used to endorse or promote products derived
028: * from this software without prior written permission. For written
029: * permission, please contact apache@apache.org.
030: *
031: * 5. Products derived from this software may not be called "Apache"
032: * nor may "Apache" appear in their names without prior written
033: * permission of the Apache Group.
034: *
035: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046: * SUCH DAMAGE.
047: * ====================================================================
048: *
049: * This software consists of voluntary contributions made by many
050: * individuals on behalf of the Apache Software Foundation. For more
051: * information on the Apache Software Foundation, please see
052: * <http://www.apache.org/>.
053: *
054: */
055:
056: package org.apache.commons.el;
057:
058: import java.io.PrintStream;
059: import java.text.MessageFormat;
060: import javax.servlet.jsp.el.ELException;
061:
062: /**
063: *
064: * <p>The evaluator may pass an instance of this class to operators
065: * and expressions during evaluation. They should use this to log any
066: * warning or error messages that might come up. This allows all of
067: * our logging policies to be concentrated in one class.
068: *
069: * <p>Errors are conditions that are severe enough to abort operation.
070: * Warnings are conditions through which the operation may continue,
071: * but which should be reported to the developer.
072: *
073: * @author Nathan Abramson - Art Technology Group
074: * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: luehe $
075: **/
076:
077: public class Logger {
078: //-------------------------------------
079: // Member variables
080: //-------------------------------------
081:
082: PrintStream mOut;
083:
084: //-------------------------------------
085: /**
086: *
087: * Constructor
088: *
089: * @param pOut the PrintStream to which warnings should be printed
090: **/
091: public Logger(PrintStream pOut) {
092: mOut = pOut;
093: }
094:
095: //-------------------------------------
096: /**
097: *
098: * Returns true if the application should even bother to try logging
099: * a warning.
100: **/
101: public boolean isLoggingWarning() {
102: return false;
103: }
104:
105: //-------------------------------------
106: /**
107: *
108: * Logs a warning
109: **/
110: public void logWarning(String pMessage, Throwable pRootCause)
111: throws ELException {
112: if (isLoggingWarning()) {
113: if (pMessage == null) {
114: System.out.println(pRootCause);
115: } else if (pRootCause == null) {
116: System.out.println(pMessage);
117: } else {
118: System.out.println(pMessage + ": " + pRootCause);
119: }
120: }
121: }
122:
123: //-------------------------------------
124: /**
125: *
126: * Logs a warning
127: **/
128: public void logWarning(String pTemplate) throws ELException {
129: if (isLoggingWarning()) {
130: logWarning(pTemplate, null);
131: }
132: }
133:
134: //-------------------------------------
135: /**
136: *
137: * Logs a warning
138: **/
139: public void logWarning(Throwable pRootCause) throws ELException {
140: if (isLoggingWarning()) {
141: logWarning(null, pRootCause);
142: }
143: }
144:
145: //-------------------------------------
146: /**
147: *
148: * Logs a warning
149: **/
150: public void logWarning(String pTemplate, Object pArg0)
151: throws ELException {
152: if (isLoggingWarning()) {
153: logWarning(MessageFormat.format(pTemplate,
154: new Object[] { "" + pArg0, }));
155: }
156: }
157:
158: //-------------------------------------
159: /**
160: *
161: * Logs a warning
162: **/
163: public void logWarning(String pTemplate, Throwable pRootCause,
164: Object pArg0) throws ELException {
165: if (isLoggingWarning()) {
166: logWarning(MessageFormat.format(pTemplate,
167: new Object[] { "" + pArg0, }), pRootCause);
168: }
169: }
170:
171: //-------------------------------------
172: /**
173: *
174: * Logs a warning
175: **/
176: public void logWarning(String pTemplate, Object pArg0, Object pArg1)
177: throws ELException {
178: if (isLoggingWarning()) {
179: logWarning(MessageFormat.format(pTemplate, new Object[] {
180: "" + pArg0, "" + pArg1, }));
181: }
182: }
183:
184: //-------------------------------------
185: /**
186: *
187: * Logs a warning
188: **/
189: public void logWarning(String pTemplate, Throwable pRootCause,
190: Object pArg0, Object pArg1) throws ELException {
191: if (isLoggingWarning()) {
192: logWarning(MessageFormat.format(pTemplate, new Object[] {
193: "" + pArg0, "" + pArg1, }), pRootCause);
194: }
195: }
196:
197: //-------------------------------------
198: /**
199: *
200: * Logs a warning
201: **/
202: public void logWarning(String pTemplate, Object pArg0,
203: Object pArg1, Object pArg2) throws ELException {
204: if (isLoggingWarning()) {
205: logWarning(MessageFormat.format(pTemplate, new Object[] {
206: "" + pArg0, "" + pArg1, "" + pArg2, }));
207: }
208: }
209:
210: //-------------------------------------
211: /**
212: *
213: * Logs a warning
214: **/
215: public void logWarning(String pTemplate, Throwable pRootCause,
216: Object pArg0, Object pArg1, Object pArg2)
217: throws ELException {
218: if (isLoggingWarning()) {
219: logWarning(MessageFormat.format(pTemplate, new Object[] {
220: "" + pArg0, "" + pArg1, "" + pArg2, }), pRootCause);
221: }
222: }
223:
224: //-------------------------------------
225: /**
226: *
227: * Logs a warning
228: **/
229: public void logWarning(String pTemplate, Object pArg0,
230: Object pArg1, Object pArg2, Object pArg3)
231: throws ELException {
232: if (isLoggingWarning()) {
233: logWarning(MessageFormat.format(pTemplate, new Object[] {
234: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3, }));
235: }
236: }
237:
238: //-------------------------------------
239: /**
240: *
241: * Logs a warning
242: **/
243: public void logWarning(String pTemplate, Throwable pRootCause,
244: Object pArg0, Object pArg1, Object pArg2, Object pArg3)
245: throws ELException {
246: if (isLoggingWarning()) {
247: logWarning(MessageFormat.format(pTemplate, new Object[] {
248: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3, }),
249: pRootCause);
250: }
251: }
252:
253: //-------------------------------------
254: /**
255: *
256: * Logs a warning
257: **/
258: public void logWarning(String pTemplate, Object pArg0,
259: Object pArg1, Object pArg2, Object pArg3, Object pArg4)
260: throws ELException {
261: if (isLoggingWarning()) {
262: logWarning(MessageFormat.format(pTemplate, new Object[] {
263: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
264: "" + pArg4, }));
265: }
266: }
267:
268: //-------------------------------------
269: /**
270: *
271: * Logs a warning
272: **/
273: public void logWarning(String pTemplate, Throwable pRootCause,
274: Object pArg0, Object pArg1, Object pArg2, Object pArg3,
275: Object pArg4) throws ELException {
276: if (isLoggingWarning()) {
277: logWarning(MessageFormat.format(pTemplate, new Object[] {
278: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
279: "" + pArg4, }), pRootCause);
280: }
281: }
282:
283: //-------------------------------------
284: /**
285: *
286: * Logs a warning
287: **/
288: public void logWarning(String pTemplate, Object pArg0,
289: Object pArg1, Object pArg2, Object pArg3, Object pArg4,
290: Object pArg5) throws ELException {
291: if (isLoggingWarning()) {
292: logWarning(MessageFormat.format(pTemplate, new Object[] {
293: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
294: "" + pArg4, "" + pArg5, }));
295: }
296: }
297:
298: //-------------------------------------
299: /**
300: *
301: * Logs a warning
302: **/
303: public void logWarning(String pTemplate, Throwable pRootCause,
304: Object pArg0, Object pArg1, Object pArg2, Object pArg3,
305: Object pArg4, Object pArg5) throws ELException {
306: if (isLoggingWarning()) {
307: logWarning(MessageFormat.format(pTemplate, new Object[] {
308: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
309: "" + pArg4, "" + pArg5, }), pRootCause);
310: }
311: }
312:
313: //-------------------------------------
314: /**
315: *
316: * Returns true if the application should even bother to try logging
317: * an error.
318: **/
319: public boolean isLoggingError() {
320: return true;
321: }
322:
323: //-------------------------------------
324: /**
325: *
326: * Logs an error
327: **/
328: public void logError(String pMessage, Throwable pRootCause)
329: throws ELException {
330: if (isLoggingError()) {
331: if (pMessage == null) {
332: throw new ELException(pRootCause);
333: } else if (pRootCause == null) {
334: throw new ELException(pMessage);
335: } else {
336: throw new ELException(pMessage, pRootCause);
337: }
338: }
339: }
340:
341: //-------------------------------------
342: /**
343: *
344: * Logs an error
345: **/
346: public void logError(String pTemplate) throws ELException {
347: if (isLoggingError()) {
348: logError(pTemplate, null);
349: }
350: }
351:
352: //-------------------------------------
353: /**
354: *
355: * Logs an error
356: **/
357: public void logError(Throwable pRootCause) throws ELException {
358: if (isLoggingError()) {
359: logError(null, pRootCause);
360: }
361: }
362:
363: //-------------------------------------
364: /**
365: *
366: * Logs an error
367: **/
368: public void logError(String pTemplate, Object pArg0)
369: throws ELException {
370: if (isLoggingError()) {
371: logError(MessageFormat.format(pTemplate, new Object[] { ""
372: + pArg0, }));
373: }
374: }
375:
376: //-------------------------------------
377: /**
378: *
379: * Logs an error
380: **/
381: public void logError(String pTemplate, Throwable pRootCause,
382: Object pArg0) throws ELException {
383: if (isLoggingError()) {
384: logError(MessageFormat.format(pTemplate, new Object[] { ""
385: + pArg0, }), pRootCause);
386: }
387: }
388:
389: //-------------------------------------
390: /**
391: *
392: * Logs an error
393: **/
394: public void logError(String pTemplate, Object pArg0, Object pArg1)
395: throws ELException {
396: if (isLoggingError()) {
397: logError(MessageFormat.format(pTemplate, new Object[] {
398: "" + pArg0, "" + pArg1, }));
399: }
400: }
401:
402: //-------------------------------------
403: /**
404: *
405: * Logs an error
406: **/
407: public void logError(String pTemplate, Throwable pRootCause,
408: Object pArg0, Object pArg1) throws ELException {
409: if (isLoggingError()) {
410: logError(MessageFormat.format(pTemplate, new Object[] {
411: "" + pArg0, "" + pArg1, }), pRootCause);
412: }
413: }
414:
415: //-------------------------------------
416: /**
417: *
418: * Logs an error
419: **/
420: public void logError(String pTemplate, Object pArg0, Object pArg1,
421: Object pArg2) throws ELException {
422: if (isLoggingError()) {
423: logError(MessageFormat.format(pTemplate, new Object[] {
424: "" + pArg0, "" + pArg1, "" + pArg2, }));
425: }
426: }
427:
428: //-------------------------------------
429: /**
430: *
431: * Logs an error
432: **/
433: public void logError(String pTemplate, Throwable pRootCause,
434: Object pArg0, Object pArg1, Object pArg2)
435: throws ELException {
436: if (isLoggingError()) {
437: logError(MessageFormat.format(pTemplate, new Object[] {
438: "" + pArg0, "" + pArg1, "" + pArg2, }), pRootCause);
439: }
440: }
441:
442: //-------------------------------------
443: /**
444: *
445: * Logs an error
446: **/
447: public void logError(String pTemplate, Object pArg0, Object pArg1,
448: Object pArg2, Object pArg3) throws ELException {
449: if (isLoggingError()) {
450: logError(MessageFormat.format(pTemplate, new Object[] {
451: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3, }));
452: }
453: }
454:
455: //-------------------------------------
456: /**
457: *
458: * Logs an error
459: **/
460: public void logError(String pTemplate, Throwable pRootCause,
461: Object pArg0, Object pArg1, Object pArg2, Object pArg3)
462: throws ELException {
463: if (isLoggingError()) {
464: logError(MessageFormat.format(pTemplate, new Object[] {
465: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3, }),
466: pRootCause);
467: }
468: }
469:
470: //-------------------------------------
471: /**
472: *
473: * Logs an error
474: **/
475: public void logError(String pTemplate, Object pArg0, Object pArg1,
476: Object pArg2, Object pArg3, Object pArg4)
477: throws ELException {
478: if (isLoggingError()) {
479: logError(MessageFormat.format(pTemplate, new Object[] {
480: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
481: "" + pArg4, }));
482: }
483: }
484:
485: //-------------------------------------
486: /**
487: *
488: * Logs an error
489: **/
490: public void logError(String pTemplate, Throwable pRootCause,
491: Object pArg0, Object pArg1, Object pArg2, Object pArg3,
492: Object pArg4) throws ELException {
493: if (isLoggingError()) {
494: logError(MessageFormat.format(pTemplate, new Object[] {
495: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
496: "" + pArg4, }), pRootCause);
497: }
498: }
499:
500: //-------------------------------------
501: /**
502: *
503: * Logs an error
504: **/
505: public void logError(String pTemplate, Object pArg0, Object pArg1,
506: Object pArg2, Object pArg3, Object pArg4, Object pArg5)
507: throws ELException {
508: if (isLoggingError()) {
509: logError(MessageFormat.format(pTemplate, new Object[] {
510: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
511: "" + pArg4, "" + pArg5, }));
512: }
513: }
514:
515: //-------------------------------------
516: /**
517: *
518: * Logs an error
519: **/
520: public void logError(String pTemplate, Throwable pRootCause,
521: Object pArg0, Object pArg1, Object pArg2, Object pArg3,
522: Object pArg4, Object pArg5) throws ELException {
523: if (isLoggingError()) {
524: logError(MessageFormat.format(pTemplate, new Object[] {
525: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
526: "" + pArg4, "" + pArg5, }), pRootCause);
527: }
528: }
529:
530: //-------------------------------------
531: }
|