001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Portions Copyright Apache Software Foundation.
007: *
008: * The contents of this file are subject to the terms of either the GNU
009: * General Public License Version 2 only ("GPL") or the Common Development
010: * and Distribution License("CDDL") (collectively, the "License"). You
011: * may not use this file except in compliance with the License. You can obtain
012: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
013: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
014: * language governing permissions and limitations under the License.
015: *
016: * When distributing the software, include this License Header Notice in each
017: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
018: * Sun designates this particular file as subject to the "Classpath" exception
019: * as provided by Sun in the GPL Version 2 section of the License file that
020: * accompanied this code. If applicable, add the following below the License
021: * Header, with the fields enclosed by brackets [] replaced by your own
022: * identifying information: "Portions Copyrighted [year]
023: * [name of copyright owner]"
024: *
025: * Contributor(s):
026: *
027: * If you wish your version of this file to be governed by only the CDDL or
028: * only the GPL Version 2, indicate your decision by adding "[Contributor]
029: * elects to include this software in this distribution under the [CDDL or GPL
030: * Version 2] license." If you don't indicate a single choice of license, a
031: * recipient has the option to distribute your version of this file under
032: * either the CDDL, the GPL Version 2 or to extend the choice of license to
033: * its licensees as provided above. However, if you add GPL Version 2 code
034: * and therefore, elected the GPL Version 2 license, then the option applies
035: * only if the new code is made subject to such option by the copyright
036: * holder.
037: */
038: package org.apache.taglibs.standard.tag.el.sql;
039:
040: import javax.servlet.jsp.JspException;
041:
042: import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
043: import org.apache.taglibs.standard.tag.common.sql.QueryTagSupport;
044:
045: /**
046: * Subclass for the JSTL library with EL support.
047: *
048: * @author Hans Bergsten
049: * @author Justyna Horwat
050: */
051: public class QueryTag extends QueryTagSupport {
052:
053: private String dataSourceEL;
054: private String sqlEL;
055: private String startRowEL;
056: private String maxRowsEL;
057:
058: //*********************************************************************
059: // Constructor
060:
061: /**
062: * Constructs a new QueryTag. As with TagSupport, subclasses
063: * should not provide other constructors and are expected to call
064: * the superclass constructor
065: */
066: public QueryTag() {
067: super ();
068: }
069:
070: //*********************************************************************
071: // Accessor methods
072:
073: public void setDataSource(String dataSourceEL) {
074: this .dataSourceEL = dataSourceEL;
075: this .dataSourceSpecified = true;
076: }
077:
078: /**
079: * The index of the first row returned can be
080: * specified using startRow.
081: */
082: public void setStartRow(String startRowEL) {
083: this .startRowEL = startRowEL;
084: }
085:
086: /**
087: * Query result can be limited by specifying
088: * the maximum number of rows returned.
089: */
090: public void setMaxRows(String maxRowsEL) {
091: this .maxRowsEL = maxRowsEL;
092: this .maxRowsSpecified = true;
093: }
094:
095: /**
096: * Setter method for the SQL statement to use for the
097: * query. The statement may contain parameter markers
098: * (question marks, ?). If so, the parameter values must
099: * be set using nested value elements.
100: */
101: public void setSql(String sqlEL) {
102: this .sqlEL = sqlEL;
103: }
104:
105: public int doStartTag() throws JspException {
106: evaluateExpressions();
107: return super .doStartTag();
108: }
109:
110: //*********************************************************************
111: // Private utility methods
112:
113: // Evaluates expressions as necessary
114: private void evaluateExpressions() throws JspException {
115: Integer tempInt = null;
116:
117: if (dataSourceEL != null) {
118: rawDataSource = (Object) ExpressionEvaluatorManager
119: .evaluate("dataSource", dataSourceEL, Object.class,
120: this , pageContext);
121: }
122:
123: if (sqlEL != null) {
124: sql = (String) ExpressionEvaluatorManager.evaluate("sql",
125: sqlEL, String.class, this , pageContext);
126: }
127:
128: if (startRowEL != null) {
129: tempInt = (Integer) ExpressionEvaluatorManager.evaluate(
130: "startRow", startRowEL, Integer.class, this ,
131: pageContext);
132: if (tempInt != null)
133: startRow = tempInt.intValue();
134: }
135:
136: if (maxRowsEL != null) {
137: tempInt = (Integer) ExpressionEvaluatorManager.evaluate(
138: "maxRows", maxRowsEL, Integer.class, this,
139: pageContext);
140: if (tempInt != null)
141: maxRows = tempInt.intValue();
142: }
143: }
144: }
|