001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.jsp;
030:
031: import com.caucho.log.Log;
032:
033: import javax.el.ELContext;
034: import javax.servlet.jsp.JspContext;
035: import javax.servlet.jsp.JspException;
036: import javax.servlet.jsp.JspWriter;
037: import javax.servlet.jsp.tagext.JspFragment;
038: import javax.servlet.jsp.tagext.JspTag;
039: import java.io.Writer;
040: import java.util.logging.Logger;
041:
042: /**
043: * Abstract implementation for the fragment support.
044: */
045: abstract public class JspFragmentSupport extends JspFragment {
046: private static final Logger log = Log
047: .open(JspFragmentSupport.class);
048:
049: // the page context
050: protected PageContextImpl pageContext;
051:
052: // the EL context
053: protected ELContext _jsp_env;
054:
055: // the parent tag
056: protected JspTag _jsp_parent_tag;
057:
058: // the tag body
059: protected JspFragment _jspBody;
060:
061: /**
062: * Returns the context.
063: */
064: public JspContext getJspContext() {
065: return this .pageContext;
066: }
067:
068: public JspFragment getJspBody() {
069: // jsp/102b
070: return _jspBody;
071: }
072:
073: /**
074: * The public JspFragment interface.
075: *
076: * @param out optional location for the output
077: * @param vars optional map to replace the page context
078: */
079: public void invoke(Writer out) throws JspException {
080: JspWriter oldOut = null;
081:
082: if (out != null)
083: oldOut = pageContext.pushBody(out);
084:
085: try {
086: _jsp_invoke(pageContext.getOut());
087: } catch (RuntimeException e) {
088: throw e;
089: } catch (Error e) {
090: throw e;
091: } catch (JspException e) {
092: throw e;
093: } catch (Throwable e) {
094: throw new JspException(e);
095: } finally {
096: if (oldOut != null)
097: pageContext.setWriter(oldOut);
098: }
099: }
100:
101: /**
102: * Implementations will generate code for this.
103: */
104: abstract protected void _jsp_invoke(JspWriter out) throws Throwable;
105:
106: }
|