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.java;
030:
031: import com.caucho.jsp.JspParseException;
032: import com.caucho.xml.QName;
033:
034: abstract public class JstlNode extends JspContainerNode {
035: /**
036: * True if this is a jstl node.
037: */
038: public boolean isJstl() {
039: return true;
040: }
041:
042: /**
043: * Adds an attribute.
044: */
045: public void addAttribute(QName name, String value)
046: throws JspParseException {
047: throw error(L.l("`{0}' is an unknown attribute for <{1}>.",
048: name.getName(), getTagName()));
049: }
050:
051: /**
052: * Generates the code to set a non-null value.
053: *
054: * @param out the writer to the *.java file
055: * @param var the EL name
056: * @param scope the scope name
057: * @param value the value
058: */
059: protected void generateSetNotNull(JspJavaWriter out, String var,
060: String scope, String value) throws Exception {
061: if (var == null) {
062: } else if (scope == null || scope.equals("page")) {
063: out.println("pageContext.setAttribute(\"" + var + "\", "
064: + value + ");");
065: } else if (scope.equals("request")) {
066: out.println("pageContext.getRequest().setAttribute(\""
067: + var + "\", " + value + ");");
068: } else if (scope.equals("session")) {
069: out.println("pageContext.getSession().setAttribute(\""
070: + var + "\", " + value + ");");
071: } else if (scope.equals("application")) {
072: out
073: .println("pageContext.getServletContext().setAttribute(\""
074: + var + "\", " + value + ");");
075: } else
076: throw error(L.l("invalid scope `{0}'", scope));
077: }
078:
079: protected void generateSetOrRemove(JspJavaWriter out, String var,
080: String scope, String value) throws Exception {
081: if (var == null) {
082: } else if (scope == null) {
083: out.println("pageContext.defaultSetOrRemove(\"" + var
084: + "\", " + value + ");");
085: } else if (scope.equals("page")) {
086: out.println("pageContext.pageSetOrRemove(\"" + var + "\", "
087: + value + ");");
088: } else if (scope.equals("request")) {
089: out.println("pageContext.requestSetOrRemove(\"" + var
090: + "\", " + value + ");");
091: } else if (scope.equals("session")) {
092: out.println("pageContext.sessionSetOrRemove(\"" + var
093: + "\", " + value + ");");
094: } else if (scope.equals("application")) {
095: out.println("pageContext.applicationSetOrRemove(\"" + var
096: + "\", " + value + ");");
097: } else
098: throw error(L.l("invalid scope `{0}'", scope));
099: }
100: }
|