01: /*
02: * Copyright 2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package examples;
17:
18: import javax.servlet.jsp.*;
19: import javax.servlet.jsp.tagext.*;
20:
21: import java.io.IOException;
22:
23: /**
24: * Log the contents of the body. Could be used to handle errors etc.
25: */
26: public class LogTag extends ExampleTagBase {
27: boolean toBrowser = false;
28:
29: public void setToBrowser(String value) {
30: if (value == null)
31: toBrowser = false;
32: else if (value.equalsIgnoreCase("true"))
33: toBrowser = true;
34: else
35: toBrowser = false;
36: }
37:
38: public int doStartTag() throws JspException {
39: return EVAL_BODY_TAG;
40: }
41:
42: public int doAfterBody() throws JspException {
43: try {
44: String s = bodyOut.getString();
45: System.err.println(s);
46: if (toBrowser)
47: bodyOut.writeOut(bodyOut.getEnclosingWriter());
48: return SKIP_BODY;
49: } catch (IOException ex) {
50: throw new JspTagException(ex.toString());
51: }
52: }
53: }
|