KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > io > AbstractTag


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.io;
18
19 import java.io.BufferedReader JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.io.InputStream JavaDoc;
22 import java.io.InputStreamReader JavaDoc;
23 import java.io.OutputStream JavaDoc;
24 import java.io.OutputStreamWriter JavaDoc;
25 import java.io.Reader JavaDoc;
26 import java.io.Writer JavaDoc;
27 import java.net.HttpURLConnection JavaDoc;
28 import java.net.URL JavaDoc;
29 import java.net.URLConnection JavaDoc;
30
31 import javax.servlet.ServletContext JavaDoc;
32 import javax.servlet.jsp.JspException JavaDoc;
33 import javax.servlet.jsp.JspWriter JavaDoc;
34 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
35 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
36
37 /** A useful base class for Tags
38   *
39   * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan</a>
40   * @version $Revision: 1.2 $
41   */

42 public class AbstractTag extends TagSupport JavaDoc {
43
44     // #### SHOULD MOVE TO LOG4J ASAP
45

46     /** Is tracing enabled? */
47     protected static final boolean TRACE = false;
48     
49     /** Are warnings enabled? */
50     protected static final boolean WARN = true;
51     
52     
53     public AbstractTag() {
54     }
55     
56     /** Handles non-JspExceptions thrown in this instance
57       */

58     protected void handleException( Exception JavaDoc e ) throws JspException JavaDoc {
59         warn( "ERROR: Caught", e );
60         if ( e instanceof JspException JavaDoc ) {
61             throw (JspException JavaDoc) e;
62         }
63         else {
64             pageContext.getServletContext().log( e.getMessage(), e );
65
66             if ( WARN ) {
67                 warn( "Caught Exception: ", e );
68             }
69             throw new JspException JavaDoc( e.getMessage() );
70         }
71     }
72     
73     protected void warn(String JavaDoc text) {
74         System.out.println( "WARNING: " + text );
75         //pageContext.getServletContext().log( text );
76
}
77     
78     protected void warn(String JavaDoc text, Exception JavaDoc e) {
79         System.out.println( "WARNING: " + text + e );
80         //pageContext.getServletContext().log( text + e );
81
e.printStackTrace();
82     }
83     
84     protected void log(String JavaDoc text ) {
85         System.out.println( text );
86         //pageContext.getServletContext().log( text );
87
}
88     
89 }
90
Popular Tags