KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > core > tags > HybridTag


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * 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. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 /*
19  * HybridTag.java
20  *
21  * Created on February 10, 2002, 11:12 PM
22  */

23
24 package org.apache.roller.ui.core.tags;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import java.io.PrintWriter JavaDoc;
30 import java.io.StringWriter JavaDoc;
31
32 import javax.servlet.jsp.JspException JavaDoc;
33 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
34
35 /**
36  * JSP tag designed to be used from JSP page or from Velocity page.
37  * Tag must be a standalone tag, design precludes contents.
38  * @author David M Johnson
39  */

40 public abstract class HybridTag extends TagSupport JavaDoc
41 {
42     private static Log mLogger =
43         LogFactory.getFactory().getInstance(HybridTag.class);
44
45     public HybridTag()
46     {
47     }
48
49     public String JavaDoc toString()
50     {
51         String JavaDoc ret = null;
52         try
53         {
54             StringWriter JavaDoc sw = new StringWriter JavaDoc();
55             doStartTag( new PrintWriter JavaDoc( sw, true ));
56             // See, design precludes contents
57
doEndTag( new PrintWriter JavaDoc( sw, true ));
58             ret = sw.toString();
59         }
60         catch (Exception JavaDoc e)
61         {
62             ret = "Exception in tag";
63             mLogger.error(ret,e);
64         }
65         return ret;
66     }
67     
68     public String JavaDoc emit()
69     {
70         return toString();
71     }
72
73     public int doStartTag() throws JspException JavaDoc
74     {
75         return doStartTag( new PrintWriter JavaDoc( pageContext.getOut(), true) );
76     }
77
78
79     public int doEndTag() throws JspException JavaDoc
80     {
81         return doEndTag( new PrintWriter JavaDoc( pageContext.getOut(), true) );
82     }
83
84     /** Default processing of the end tag returning SKIP_BODY. */
85     public int doStartTag( PrintWriter JavaDoc pw ) throws JspException JavaDoc
86     {
87         return SKIP_BODY;
88     }
89
90     /** Default processing of the end tag returning EVAL_PAGE. */
91     public int doEndTag( PrintWriter JavaDoc pw ) throws JspException JavaDoc
92     {
93         return EVAL_PAGE;
94     }
95
96 }
97
Popular Tags