001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Portions Copyright Apache Software Foundation.
007: *
008: * The contents of this file are subject to the terms of either the GNU
009: * General Public License Version 2 only ("GPL") or the Common Development
010: * and Distribution License("CDDL") (collectively, the "License"). You
011: * may not use this file except in compliance with the License. You can obtain
012: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
013: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
014: * language governing permissions and limitations under the License.
015: *
016: * When distributing the software, include this License Header Notice in each
017: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
018: * Sun designates this particular file as subject to the "Classpath" exception
019: * as provided by Sun in the GPL Version 2 section of the License file that
020: * accompanied this code. If applicable, add the following below the License
021: * Header, with the fields enclosed by brackets [] replaced by your own
022: * identifying information: "Portions Copyrighted [year]
023: * [name of copyright owner]"
024: *
025: * Contributor(s):
026: *
027: * If you wish your version of this file to be governed by only the CDDL or
028: * only the GPL Version 2, indicate your decision by adding "[Contributor]
029: * elects to include this software in this distribution under the [CDDL or GPL
030: * Version 2] license." If you don't indicate a single choice of license, a
031: * recipient has the option to distribute your version of this file under
032: * either the CDDL, the GPL Version 2 or to extend the choice of license to
033: * its licensees as provided above. However, if you add GPL Version 2 code
034: * and therefore, elected the GPL Version 2 license, then the option applies
035: * only if the new code is made subject to such option by the copyright
036: * holder.
037: */
038:
039: package org.apache.taglibs.standard.lang.jstl;
040:
041: import java.io.PrintStream;
042: import java.text.MessageFormat;
043:
044: /**
045: *
046: * <p>The evaluator may pass an instance of this class to operators
047: * and expressions during evaluation. They should use this to log any
048: * warning or error messages that might come up. This allows all of
049: * our logging policies to be concentrated in one class.
050: *
051: * <p>Errors are conditions that are severe enough to abort operation.
052: * Warnings are conditions through which the operation may continue,
053: * but which should be reported to the developer.
054: *
055: * @author Nathan Abramson - Art Technology Group
056: * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: tcfujii $
057: **/
058:
059: public class Logger {
060: //-------------------------------------
061: // Member variables
062: //-------------------------------------
063:
064: PrintStream mOut;
065:
066: //-------------------------------------
067: /**
068: *
069: * Constructor
070: *
071: * @param pOut the PrintStream to which warnings should be printed
072: **/
073: public Logger(PrintStream pOut) {
074: mOut = pOut;
075: }
076:
077: //-------------------------------------
078: /**
079: *
080: * Returns true if the application should even bother to try logging
081: * a warning.
082: **/
083: public boolean isLoggingWarning() {
084: return false;
085: }
086:
087: //-------------------------------------
088: /**
089: *
090: * Logs a warning
091: **/
092: public void logWarning(String pMessage, Throwable pRootCause)
093: throws ELException {
094: if (isLoggingWarning()) {
095: if (pMessage == null) {
096: System.out.println(pRootCause);
097: } else if (pRootCause == null) {
098: System.out.println(pMessage);
099: } else {
100: System.out.println(pMessage + ": " + pRootCause);
101: }
102: }
103: }
104:
105: //-------------------------------------
106: /**
107: *
108: * Logs a warning
109: **/
110: public void logWarning(String pTemplate) throws ELException {
111: if (isLoggingWarning()) {
112: logWarning(pTemplate, null);
113: }
114: }
115:
116: //-------------------------------------
117: /**
118: *
119: * Logs a warning
120: **/
121: public void logWarning(Throwable pRootCause) throws ELException {
122: if (isLoggingWarning()) {
123: logWarning(null, pRootCause);
124: }
125: }
126:
127: //-------------------------------------
128: /**
129: *
130: * Logs a warning
131: **/
132: public void logWarning(String pTemplate, Object pArg0)
133: throws ELException {
134: if (isLoggingWarning()) {
135: logWarning(MessageFormat.format(pTemplate,
136: new Object[] { "" + pArg0, }));
137: }
138: }
139:
140: //-------------------------------------
141: /**
142: *
143: * Logs a warning
144: **/
145: public void logWarning(String pTemplate, Throwable pRootCause,
146: Object pArg0) throws ELException {
147: if (isLoggingWarning()) {
148: logWarning(MessageFormat.format(pTemplate,
149: new Object[] { "" + pArg0, }), pRootCause);
150: }
151: }
152:
153: //-------------------------------------
154: /**
155: *
156: * Logs a warning
157: **/
158: public void logWarning(String pTemplate, Object pArg0, Object pArg1)
159: throws ELException {
160: if (isLoggingWarning()) {
161: logWarning(MessageFormat.format(pTemplate, new Object[] {
162: "" + pArg0, "" + pArg1, }));
163: }
164: }
165:
166: //-------------------------------------
167: /**
168: *
169: * Logs a warning
170: **/
171: public void logWarning(String pTemplate, Throwable pRootCause,
172: Object pArg0, Object pArg1) throws ELException {
173: if (isLoggingWarning()) {
174: logWarning(MessageFormat.format(pTemplate, new Object[] {
175: "" + pArg0, "" + pArg1, }), pRootCause);
176: }
177: }
178:
179: //-------------------------------------
180: /**
181: *
182: * Logs a warning
183: **/
184: public void logWarning(String pTemplate, Object pArg0,
185: Object pArg1, Object pArg2) throws ELException {
186: if (isLoggingWarning()) {
187: logWarning(MessageFormat.format(pTemplate, new Object[] {
188: "" + pArg0, "" + pArg1, "" + pArg2, }));
189: }
190: }
191:
192: //-------------------------------------
193: /**
194: *
195: * Logs a warning
196: **/
197: public void logWarning(String pTemplate, Throwable pRootCause,
198: Object pArg0, Object pArg1, Object pArg2)
199: throws ELException {
200: if (isLoggingWarning()) {
201: logWarning(MessageFormat.format(pTemplate, new Object[] {
202: "" + pArg0, "" + pArg1, "" + pArg2, }), pRootCause);
203: }
204: }
205:
206: //-------------------------------------
207: /**
208: *
209: * Logs a warning
210: **/
211: public void logWarning(String pTemplate, Object pArg0,
212: Object pArg1, Object pArg2, Object pArg3)
213: throws ELException {
214: if (isLoggingWarning()) {
215: logWarning(MessageFormat.format(pTemplate, new Object[] {
216: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3, }));
217: }
218: }
219:
220: //-------------------------------------
221: /**
222: *
223: * Logs a warning
224: **/
225: public void logWarning(String pTemplate, Throwable pRootCause,
226: Object pArg0, Object pArg1, Object pArg2, Object pArg3)
227: throws ELException {
228: if (isLoggingWarning()) {
229: logWarning(MessageFormat.format(pTemplate, new Object[] {
230: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3, }),
231: pRootCause);
232: }
233: }
234:
235: //-------------------------------------
236: /**
237: *
238: * Logs a warning
239: **/
240: public void logWarning(String pTemplate, Object pArg0,
241: Object pArg1, Object pArg2, Object pArg3, Object pArg4)
242: throws ELException {
243: if (isLoggingWarning()) {
244: logWarning(MessageFormat.format(pTemplate, new Object[] {
245: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
246: "" + pArg4, }));
247: }
248: }
249:
250: //-------------------------------------
251: /**
252: *
253: * Logs a warning
254: **/
255: public void logWarning(String pTemplate, Throwable pRootCause,
256: Object pArg0, Object pArg1, Object pArg2, Object pArg3,
257: Object pArg4) throws ELException {
258: if (isLoggingWarning()) {
259: logWarning(MessageFormat.format(pTemplate, new Object[] {
260: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
261: "" + pArg4, }), pRootCause);
262: }
263: }
264:
265: //-------------------------------------
266: /**
267: *
268: * Logs a warning
269: **/
270: public void logWarning(String pTemplate, Object pArg0,
271: Object pArg1, Object pArg2, Object pArg3, Object pArg4,
272: Object pArg5) throws ELException {
273: if (isLoggingWarning()) {
274: logWarning(MessageFormat.format(pTemplate, new Object[] {
275: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
276: "" + pArg4, "" + pArg5, }));
277: }
278: }
279:
280: //-------------------------------------
281: /**
282: *
283: * Logs a warning
284: **/
285: public void logWarning(String pTemplate, Throwable pRootCause,
286: Object pArg0, Object pArg1, Object pArg2, Object pArg3,
287: Object pArg4, Object pArg5) throws ELException {
288: if (isLoggingWarning()) {
289: logWarning(MessageFormat.format(pTemplate, new Object[] {
290: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
291: "" + pArg4, "" + pArg5, }), pRootCause);
292: }
293: }
294:
295: //-------------------------------------
296: /**
297: *
298: * Returns true if the application should even bother to try logging
299: * an error.
300: **/
301: public boolean isLoggingError() {
302: return true;
303: }
304:
305: //-------------------------------------
306: /**
307: *
308: * Logs an error
309: **/
310: public void logError(String pMessage, Throwable pRootCause)
311: throws ELException {
312: if (isLoggingError()) {
313: if (pMessage == null) {
314: throw new ELException(pRootCause);
315: } else if (pRootCause == null) {
316: throw new ELException(pMessage);
317: } else {
318: throw new ELException(pMessage, pRootCause);
319: }
320: }
321: }
322:
323: //-------------------------------------
324: /**
325: *
326: * Logs an error
327: **/
328: public void logError(String pTemplate) throws ELException {
329: if (isLoggingError()) {
330: logError(pTemplate, null);
331: }
332: }
333:
334: //-------------------------------------
335: /**
336: *
337: * Logs an error
338: **/
339: public void logError(Throwable pRootCause) throws ELException {
340: if (isLoggingError()) {
341: logError(null, pRootCause);
342: }
343: }
344:
345: //-------------------------------------
346: /**
347: *
348: * Logs an error
349: **/
350: public void logError(String pTemplate, Object pArg0)
351: throws ELException {
352: if (isLoggingError()) {
353: logError(MessageFormat.format(pTemplate, new Object[] { ""
354: + pArg0, }));
355: }
356: }
357:
358: //-------------------------------------
359: /**
360: *
361: * Logs an error
362: **/
363: public void logError(String pTemplate, Throwable pRootCause,
364: Object pArg0) throws ELException {
365: if (isLoggingError()) {
366: logError(MessageFormat.format(pTemplate, new Object[] { ""
367: + pArg0, }), pRootCause);
368: }
369: }
370:
371: //-------------------------------------
372: /**
373: *
374: * Logs an error
375: **/
376: public void logError(String pTemplate, Object pArg0, Object pArg1)
377: throws ELException {
378: if (isLoggingError()) {
379: logError(MessageFormat.format(pTemplate, new Object[] {
380: "" + pArg0, "" + pArg1, }));
381: }
382: }
383:
384: //-------------------------------------
385: /**
386: *
387: * Logs an error
388: **/
389: public void logError(String pTemplate, Throwable pRootCause,
390: Object pArg0, Object pArg1) throws ELException {
391: if (isLoggingError()) {
392: logError(MessageFormat.format(pTemplate, new Object[] {
393: "" + pArg0, "" + pArg1, }), pRootCause);
394: }
395: }
396:
397: //-------------------------------------
398: /**
399: *
400: * Logs an error
401: **/
402: public void logError(String pTemplate, Object pArg0, Object pArg1,
403: Object pArg2) throws ELException {
404: if (isLoggingError()) {
405: logError(MessageFormat.format(pTemplate, new Object[] {
406: "" + pArg0, "" + pArg1, "" + pArg2, }));
407: }
408: }
409:
410: //-------------------------------------
411: /**
412: *
413: * Logs an error
414: **/
415: public void logError(String pTemplate, Throwable pRootCause,
416: Object pArg0, Object pArg1, Object pArg2)
417: throws ELException {
418: if (isLoggingError()) {
419: logError(MessageFormat.format(pTemplate, new Object[] {
420: "" + pArg0, "" + pArg1, "" + pArg2, }), pRootCause);
421: }
422: }
423:
424: //-------------------------------------
425: /**
426: *
427: * Logs an error
428: **/
429: public void logError(String pTemplate, Object pArg0, Object pArg1,
430: Object pArg2, Object pArg3) throws ELException {
431: if (isLoggingError()) {
432: logError(MessageFormat.format(pTemplate, new Object[] {
433: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3, }));
434: }
435: }
436:
437: //-------------------------------------
438: /**
439: *
440: * Logs an error
441: **/
442: public void logError(String pTemplate, Throwable pRootCause,
443: Object pArg0, Object pArg1, Object pArg2, Object pArg3)
444: throws ELException {
445: if (isLoggingError()) {
446: logError(MessageFormat.format(pTemplate, new Object[] {
447: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3, }),
448: pRootCause);
449: }
450: }
451:
452: //-------------------------------------
453: /**
454: *
455: * Logs an error
456: **/
457: public void logError(String pTemplate, Object pArg0, Object pArg1,
458: Object pArg2, Object pArg3, Object pArg4)
459: throws ELException {
460: if (isLoggingError()) {
461: logError(MessageFormat.format(pTemplate, new Object[] {
462: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
463: "" + pArg4, }));
464: }
465: }
466:
467: //-------------------------------------
468: /**
469: *
470: * Logs an error
471: **/
472: public void logError(String pTemplate, Throwable pRootCause,
473: Object pArg0, Object pArg1, Object pArg2, Object pArg3,
474: Object pArg4) throws ELException {
475: if (isLoggingError()) {
476: logError(MessageFormat.format(pTemplate, new Object[] {
477: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
478: "" + pArg4, }), pRootCause);
479: }
480: }
481:
482: //-------------------------------------
483: /**
484: *
485: * Logs an error
486: **/
487: public void logError(String pTemplate, Object pArg0, Object pArg1,
488: Object pArg2, Object pArg3, Object pArg4, Object pArg5)
489: throws ELException {
490: if (isLoggingError()) {
491: logError(MessageFormat.format(pTemplate, new Object[] {
492: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
493: "" + pArg4, "" + pArg5, }));
494: }
495: }
496:
497: //-------------------------------------
498: /**
499: *
500: * Logs an error
501: **/
502: public void logError(String pTemplate, Throwable pRootCause,
503: Object pArg0, Object pArg1, Object pArg2, Object pArg3,
504: Object pArg4, Object pArg5) throws ELException {
505: if (isLoggingError()) {
506: logError(MessageFormat.format(pTemplate, new Object[] {
507: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
508: "" + pArg4, "" + pArg5, }), pRootCause);
509: }
510: }
511:
512: //-------------------------------------
513: }
|