01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. The ASF licenses this file to You
04: * under the Apache License, Version 2.0 (the "License"); you may not
05: * 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. 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;
30: import java.io.StringWriter;
31:
32: import javax.servlet.jsp.JspException;
33: import javax.servlet.jsp.tagext.TagSupport;
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 {
41: private static Log mLogger = LogFactory.getFactory().getInstance(
42: HybridTag.class);
43:
44: public HybridTag() {
45: }
46:
47: public String toString() {
48: String ret = null;
49: try {
50: StringWriter sw = new StringWriter();
51: doStartTag(new PrintWriter(sw, true));
52: // See, design precludes contents
53: doEndTag(new PrintWriter(sw, true));
54: ret = sw.toString();
55: } catch (Exception e) {
56: ret = "Exception in tag";
57: mLogger.error(ret, e);
58: }
59: return ret;
60: }
61:
62: public String emit() {
63: return toString();
64: }
65:
66: public int doStartTag() throws JspException {
67: return doStartTag(new PrintWriter(pageContext.getOut(), true));
68: }
69:
70: public int doEndTag() throws JspException {
71: return doEndTag(new PrintWriter(pageContext.getOut(), true));
72: }
73:
74: /** Default processing of the end tag returning SKIP_BODY. */
75: public int doStartTag(PrintWriter pw) throws JspException {
76: return SKIP_BODY;
77: }
78:
79: /** Default processing of the end tag returning EVAL_PAGE. */
80: public int doEndTag(PrintWriter pw) throws JspException {
81: return EVAL_PAGE;
82: }
83:
84: }
|