You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by jb...@apache.org on 2010/11/20 18:57:49 UTC
svn commit: r1037279 [4/10] - in /tomcat/taglibs/standard/trunk/impl: ./
src/main/java/org/apache/taglibs/standard/
src/main/java/org/apache/taglibs/standard/functions/
src/main/java/org/apache/taglibs/standard/tag/common/core/
src/main/java/org/apache...
Modified: tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/fmt/TimeZoneSupport.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/fmt/TimeZoneSupport.java?rev=1037279&r1=1037278&r2=1037279&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/fmt/TimeZoneSupport.java (original)
+++ tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/fmt/TimeZoneSupport.java Sat Nov 20 17:57:45 2010
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.tag.common.fmt;
@@ -41,7 +41,7 @@ public abstract class TimeZoneSupport ex
// Protected state
protected Object value; // 'value' attribute
-
+
//*********************************************************************
// Private state
@@ -53,12 +53,12 @@ public abstract class TimeZoneSupport ex
// Constructor and initialization
public TimeZoneSupport() {
- super();
- init();
+ super();
+ init();
}
private void init() {
- value = null;
+ value = null;
}
@@ -66,7 +66,7 @@ public abstract class TimeZoneSupport ex
// Collaboration with subtags
public TimeZone getTimeZone() {
- return timeZone;
+ return timeZone;
}
@@ -76,36 +76,37 @@ public abstract class TimeZoneSupport ex
@Override
public int doStartTag() throws JspException {
- if (value == null) {
- timeZone = TimeZone.getTimeZone("GMT");
- } else if (value instanceof String) {
- if (((String) value).trim().equals("")) {
- timeZone = TimeZone.getTimeZone("GMT");
- } else {
- timeZone = TimeZone.getTimeZone((String) value);
- }
- } else {
- timeZone = (TimeZone) value;
- }
+ if (value == null) {
+ timeZone = TimeZone.getTimeZone("GMT");
+ } else if (value instanceof String) {
+ if (((String) value).trim().equals("")) {
+ timeZone = TimeZone.getTimeZone("GMT");
+ } else {
+ timeZone = TimeZone.getTimeZone((String) value);
+ }
+ } else {
+ timeZone = (TimeZone) value;
+ }
- return EVAL_BODY_BUFFERED;
+ return EVAL_BODY_BUFFERED;
}
@Override
public int doEndTag() throws JspException {
- try {
- pageContext.getOut().print(bodyContent.getString());
- } catch (IOException ioe) {
- throw new JspTagException(ioe.toString(), ioe);
- }
+ try {
+ pageContext.getOut().print(bodyContent.getString());
+ } catch (IOException ioe) {
+ throw new JspTagException(ioe.toString(), ioe);
+ }
- return EVAL_PAGE;
+ return EVAL_PAGE;
}
// Releases any resources we may have (or inherit)
+
@Override
public void release() {
- init();
+ init();
}
@@ -131,26 +132,27 @@ public abstract class TimeZoneSupport ex
* nested inside a <timeZone> action and no time zone configuration
* setting exists
*/
+
static TimeZone getTimeZone(PageContext pc, Tag fromTag) {
- TimeZone tz = null;
+ TimeZone tz = null;
- Tag t = findAncestorWithClass(fromTag, TimeZoneSupport.class);
- if (t != null) {
- // use time zone from parent <timeZone> tag
- TimeZoneSupport parent = (TimeZoneSupport) t;
- tz = parent.getTimeZone();
- } else {
- // get time zone from configuration setting
- Object obj = Config.find(pc, Config.FMT_TIME_ZONE);
- if (obj != null) {
- if (obj instanceof TimeZone) {
- tz = (TimeZone) obj;
- } else {
- tz = TimeZone.getTimeZone((String) obj);
- }
- }
- }
+ Tag t = findAncestorWithClass(fromTag, TimeZoneSupport.class);
+ if (t != null) {
+ // use time zone from parent <timeZone> tag
+ TimeZoneSupport parent = (TimeZoneSupport) t;
+ tz = parent.getTimeZone();
+ } else {
+ // get time zone from configuration setting
+ Object obj = Config.find(pc, Config.FMT_TIME_ZONE);
+ if (obj != null) {
+ if (obj instanceof TimeZone) {
+ tz = (TimeZone) obj;
+ } else {
+ tz = TimeZone.getTimeZone((String) obj);
+ }
+ }
+ }
- return tz;
+ return tz;
}
}
Modified: tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/DataSourceUtil.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/DataSourceUtil.java?rev=1037279&r1=1037278&r2=1037279&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/DataSourceUtil.java (original)
+++ tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/DataSourceUtil.java Sat Nov 20 17:57:45 2010
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.tag.common.sql;
@@ -32,9 +32,9 @@ import org.apache.taglibs.standard.resou
/**
* <p>A simple <code>DataSource</code> utility for the standard
* <code>DriverManager</code> class.
- *
+ * <p/>
* TO DO: need to cache DataSource
- *
+ *
* @author Justyna Horwat
*/
public class DataSourceUtil {
@@ -49,23 +49,22 @@ public class DataSourceUtil {
* is
*/
static DataSource getDataSource(Object rawDataSource, PageContext pc)
- throws JspException
- {
- DataSource dataSource = null;
+ throws JspException {
+ DataSource dataSource = null;
if (rawDataSource == null) {
rawDataSource = Config.find(pc, Config.SQL_DATA_SOURCE);
}
- if (rawDataSource == null) {
- return null;
- }
+ if (rawDataSource == null) {
+ return null;
+ }
/*
- * If the 'dataSource' attribute's value resolves to a String
- * after rtexpr/EL evaluation, use the string as JNDI path to
- * a DataSource
- */
+ * If the 'dataSource' attribute's value resolves to a String
+ * after rtexpr/EL evaluation, use the string as JNDI path to
+ * a DataSource
+ */
if (rawDataSource instanceof String) {
try {
Context ctx = new InitialContext();
@@ -78,66 +77,64 @@ public class DataSourceUtil {
} else if (rawDataSource instanceof DataSource) {
dataSource = (DataSource) rawDataSource;
} else {
- throw new JspException(
- Resources.getMessage("SQL_DATASOURCE_INVALID_TYPE"));
- }
+ throw new JspException(
+ Resources.getMessage("SQL_DATASOURCE_INVALID_TYPE"));
+ }
- return dataSource;
+ return dataSource;
}
/**
* Parse JDBC parameters and setup dataSource appropriately
*/
private static DataSource getDataSource(String params)
- throws JspException
- {
+ throws JspException {
DataSourceWrapper dataSource = new DataSourceWrapper();
String[] paramString = new String[4];
- int escCount = 0;
- int aryCount = 0;
+ int escCount = 0;
+ int aryCount = 0;
int begin = 0;
- for(int index=0; index < params.length(); index++) {
+ for (int index = 0; index < params.length(); index++) {
char nextChar = params.charAt(index);
if (TOKEN.indexOf(nextChar) != -1) {
if (escCount == 0) {
- paramString[aryCount] = params.substring(begin,index).trim();
+ paramString[aryCount] = params.substring(begin, index).trim();
begin = index + 1;
if (++aryCount > 4) {
throw new JspTagException(
- Resources.getMessage("JDBC_PARAM_COUNT"));
+ Resources.getMessage("JDBC_PARAM_COUNT"));
}
}
}
if (ESCAPE.indexOf(nextChar) != -1) {
escCount++;
- }
- else {
+ } else {
escCount = 0;
}
}
paramString[aryCount] = params.substring(begin).trim();
- // use the JDBC URL from the parameter string
+ // use the JDBC URL from the parameter string
dataSource.setJdbcURL(paramString[0]);
- // try to load a driver if it's present
+ // try to load a driver if it's present
if (paramString[1] != null) {
try {
dataSource.setDriverClassName(paramString[1]);
} catch (Exception ex) {
throw new JspTagException(
- Resources.getMessage("DRIVER_INVALID_CLASS",
- ex.toString()), ex);
+ Resources.getMessage("DRIVER_INVALID_CLASS",
+ ex.toString()), ex);
}
- }
+ }
- // set the username and password
+ // set the username and password
dataSource.setUserName(paramString[2]);
dataSource.setPassword(paramString[3]);
- return dataSource;
+ return dataSource;
}
}
Modified: tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/DataSourceWrapper.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/DataSourceWrapper.java?rev=1037279&r1=1037278&r2=1037279&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/DataSourceWrapper.java (original)
+++ tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/DataSourceWrapper.java Sat Nov 20 17:57:45 2010
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.tag.common.sql;
@@ -32,7 +32,7 @@ import org.apache.taglibs.standard.resou
/**
* <p>A simple <code>DataSource</code> wrapper for the standard
* <code>DriverManager</code> class.
- *
+ *
* @author Hans Bergsten
*/
public class DataSourceWrapper implements DataSource {
@@ -41,8 +41,8 @@ public class DataSourceWrapper implement
private String userName;
private String password;
- public void setDriverClassName(String driverClassName)
- throws ClassNotFoundException, InstantiationException,
+ public void setDriverClassName(String driverClassName)
+ throws ClassNotFoundException, InstantiationException,
IllegalAccessException {
//get the classloader
@@ -52,11 +52,14 @@ public class DataSourceWrapper implement
cl = Thread.currentThread().getContextClassLoader();
} else {
cl = java.security.AccessController.doPrivileged(
- new java.security.PrivilegedAction<ClassLoader>()
- {public ClassLoader run() {return Thread.currentThread().getContextClassLoader();}});
+ new java.security.PrivilegedAction<ClassLoader>() {
+ public ClassLoader run() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
}
//done getting classloader
-
+
Object instance = Class.forName(driverClassName, true, cl).newInstance();
if (instance instanceof Driver) {
driver = (Driver) instance;
@@ -64,15 +67,15 @@ public class DataSourceWrapper implement
}
public void setJdbcURL(String jdbcURL) {
- this.jdbcURL = jdbcURL;
+ this.jdbcURL = jdbcURL;
}
public void setUserName(String userName) {
- this.userName = userName;
+ this.userName = userName;
}
public void setPassword(String password) {
- this.password = password;
+ this.password = password;
}
/**
@@ -100,44 +103,44 @@ public class DataSourceWrapper implement
}
return conn;
}
-
+
/**
* Always throws a SQLException. Username and password are set
* in the constructor and can not be changed.
*/
- public Connection getConnection(String username, String password)
+ public Connection getConnection(String username, String password)
throws SQLException {
throw new SQLException(Resources.getMessage("NOT_SUPPORTED"));
}
-
+
/**
* Always throws a SQLException. Not supported.
*/
public int getLoginTimeout() throws SQLException {
throw new SQLException(Resources.getMessage("NOT_SUPPORTED"));
}
-
+
/**
* Always throws a SQLException. Not supported.
*/
public PrintWriter getLogWriter() throws SQLException {
throw new SQLException(Resources.getMessage("NOT_SUPPORTED"));
}
-
+
/**
* Always throws a SQLException. Not supported.
*/
public void setLoginTimeout(int seconds) throws SQLException {
throw new SQLException(Resources.getMessage("NOT_SUPPORTED"));
}
-
+
/**
* Always throws a SQLException. Not supported.
*/
public synchronized void setLogWriter(PrintWriter out) throws SQLException {
throw new SQLException(Resources.getMessage("NOT_SUPPORTED"));
}
-
+
public synchronized boolean isWrapperFor(Class c) throws SQLException {
throw new SQLException(Resources.getMessage("NOT_SUPPORTED"));
}
Modified: tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/DateParamTagSupport.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/DateParamTagSupport.java?rev=1037279&r1=1037278&r2=1037279&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/DateParamTagSupport.java (original)
+++ tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/DateParamTagSupport.java Sat Nov 20 17:57:45 2010
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.tag.common.sql;
import javax.servlet.jsp.JspException;
@@ -27,7 +27,7 @@ import org.apache.taglibs.standard.resou
/**
* <p>Tag handler for <Param> in JSTL, used to set
* parameter values for a SQL statement.</p>
- *
+ *
* @author Justyna Horwat
*/
@@ -35,11 +35,11 @@ public abstract class DateParamTagSuppor
//*********************************************************************
// Private constants
-
+
private static final String TIMESTAMP_TYPE = "timestamp";
private static final String TIME_TYPE = "time";
private static final String DATE_TYPE = "date";
-
+
//*********************************************************************
// Protected state
@@ -67,19 +67,19 @@ public abstract class DateParamTagSuppor
@Override
public int doEndTag() throws JspException {
- SQLExecutionTag parent = (SQLExecutionTag)
- findAncestorWithClass(this, SQLExecutionTag.class);
- if (parent == null) {
- throw new JspTagException(
- Resources.getMessage("SQL_PARAM_OUTSIDE_PARENT"));
- }
+ SQLExecutionTag parent = (SQLExecutionTag)
+ findAncestorWithClass(this, SQLExecutionTag.class);
+ if (parent == null) {
+ throw new JspTagException(
+ Resources.getMessage("SQL_PARAM_OUTSIDE_PARENT"));
+ }
if (value != null) {
convertValue();
}
- parent.addSQLParameter(value);
- return EVAL_PAGE;
+ parent.addSQLParameter(value);
+ return EVAL_PAGE;
}
@@ -88,21 +88,21 @@ public abstract class DateParamTagSuppor
private void convertValue() throws JspException {
- if ((type == null) || (type.equalsIgnoreCase(TIMESTAMP_TYPE))) {
- if (!(value instanceof java.sql.Timestamp)) {
- value = new java.sql.Timestamp(value.getTime());
- }
- } else if (type.equalsIgnoreCase(TIME_TYPE)) {
- if (!(value instanceof java.sql.Time)) {
- value = new java.sql.Time(value.getTime());
- }
- } else if (type.equalsIgnoreCase(DATE_TYPE)) {
- if (!(value instanceof java.sql.Date)) {
- value = new java.sql.Date(value.getTime());
- }
- } else {
- throw new JspException(
- Resources.getMessage("SQL_DATE_PARAM_INVALID_TYPE", type));
- }
+ if ((type == null) || (type.equalsIgnoreCase(TIMESTAMP_TYPE))) {
+ if (!(value instanceof java.sql.Timestamp)) {
+ value = new java.sql.Timestamp(value.getTime());
+ }
+ } else if (type.equalsIgnoreCase(TIME_TYPE)) {
+ if (!(value instanceof java.sql.Time)) {
+ value = new java.sql.Time(value.getTime());
+ }
+ } else if (type.equalsIgnoreCase(DATE_TYPE)) {
+ if (!(value instanceof java.sql.Date)) {
+ value = new java.sql.Date(value.getTime());
+ }
+ } else {
+ throw new JspException(
+ Resources.getMessage("SQL_DATE_PARAM_INVALID_TYPE", type));
+ }
}
}
Modified: tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/ParamTagSupport.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/ParamTagSupport.java?rev=1037279&r1=1037278&r2=1037279&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/ParamTagSupport.java (original)
+++ tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/ParamTagSupport.java Sat Nov 20 17:57:45 2010
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.tag.common.sql;
import javax.servlet.jsp.JspException;
@@ -27,7 +27,7 @@ import org.apache.taglibs.standard.resou
/**
* <p>Tag handler for <Param> in JSTL, used to set
* parameter values for a SQL statement.</p>
- *
+ *
* @author Hans Bergsten
*/
@@ -39,25 +39,24 @@ public abstract class ParamTagSupport ex
@Override
public int doEndTag() throws JspException {
- SQLExecutionTag parent = (SQLExecutionTag)
- findAncestorWithClass(this, SQLExecutionTag.class);
- if (parent == null) {
- throw new JspTagException(
- Resources.getMessage("SQL_PARAM_OUTSIDE_PARENT"));
- }
-
- Object paramValue = null;
- if (value != null) {
- paramValue = value;
- }
- else if (bodyContent != null) {
- paramValue = bodyContent.getString().trim();
- if (((String) paramValue).trim().length() == 0) {
- paramValue = null;
- }
- }
+ SQLExecutionTag parent = (SQLExecutionTag)
+ findAncestorWithClass(this, SQLExecutionTag.class);
+ if (parent == null) {
+ throw new JspTagException(
+ Resources.getMessage("SQL_PARAM_OUTSIDE_PARENT"));
+ }
+
+ Object paramValue = null;
+ if (value != null) {
+ paramValue = value;
+ } else if (bodyContent != null) {
+ paramValue = bodyContent.getString().trim();
+ if (((String) paramValue).trim().length() == 0) {
+ paramValue = null;
+ }
+ }
- parent.addSQLParameter(paramValue);
- return EVAL_PAGE;
+ parent.addSQLParameter(paramValue);
+ return EVAL_PAGE;
}
}
Modified: tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/QueryTagSupport.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/QueryTagSupport.java?rev=1037279&r1=1037278&r2=1037279&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/QueryTagSupport.java (original)
+++ tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/QueryTagSupport.java Sat Nov 20 17:57:45 2010
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.tag.common.sql;
@@ -21,37 +21,31 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
-
import java.util.ArrayList;
import java.util.List;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.PageContext;
-
import javax.servlet.jsp.jstl.core.Config;
-
import javax.servlet.jsp.jstl.sql.Result;
import javax.servlet.jsp.jstl.sql.SQLExecutionTag;
-
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.TryCatchFinally;
-
import javax.sql.DataSource;
import org.apache.taglibs.standard.resources.Resources;
-
import org.apache.taglibs.standard.tag.common.core.Util;
/**
- * <p>Tag handler for <Query> in JSTL.
- *
+ * <p>Tag handler for <Query> in JSTL.
+ *
* @author Hans Bergsten
* @author Justyna Horwat
*/
-public abstract class QueryTagSupport extends BodyTagSupport
- implements TryCatchFinally, SQLExecutionTag {
+public abstract class QueryTagSupport extends BodyTagSupport
+ implements TryCatchFinally, SQLExecutionTag {
private String var;
private int scope;
@@ -151,8 +145,8 @@ public abstract class QueryTagSupport ex
maxRows = Integer.parseInt((String) obj);
} catch (NumberFormatException nfe) {
throw new JspException(Resources.getMessage("SQL_MAXROWS_PARSE_ERROR",
- (String) obj),
- nfe);
+ (String) obj),
+ nfe);
}
} else {
throw new JspException(Resources.getMessage("SQL_MAXROWS_INVALID"));
@@ -175,7 +169,7 @@ public abstract class QueryTagSupport ex
* named by the <code>var</code> attribute in the scope specified
* by the <code>scope</code> attribute, as an object that implements
* the Result interface.
- *
+ * <p/>
* <p>The connection used to execute the statement comes either
* from the <code>DataSource</code> specified by the
* <code>dataSource</code> attribute, provided by a parent action
@@ -191,8 +185,7 @@ public abstract class QueryTagSupport ex
String sqlStatement = null;
if (sql != null) {
sqlStatement = sql;
- }
- else if (bodyContent != null) {
+ } else if (bodyContent != null) {
sqlStatement = bodyContent.getString();
}
if (sqlStatement == null || sqlStatement.trim().length() == 0) {
@@ -277,7 +270,8 @@ public abstract class QueryTagSupport ex
if (conn != null && !isPartOfTransaction) {
try {
conn.close();
- } catch (SQLException e) {} // Not much we can do
+ } catch (SQLException e) {
+ } // Not much we can do
}
conn = null;
@@ -293,7 +287,7 @@ public abstract class QueryTagSupport ex
Connection conn = null;
isPartOfTransaction = false;
- TransactionTagSupport parent = (TransactionTagSupport)findAncestorWithClass(this, TransactionTagSupport.class);
+ TransactionTagSupport parent = (TransactionTagSupport) findAncestorWithClass(this, TransactionTagSupport.class);
if (parent != null) {
if (dataSourceSpecified) {
throw new JspTagException(Resources.getMessage("ERROR_NESTED_DATASOURCE"));
@@ -305,21 +299,20 @@ public abstract class QueryTagSupport ex
throw new JspException(Resources.getMessage("SQL_DATASOURCE_NULL"));
}
DataSource dataSource = DataSourceUtil.getDataSource(rawDataSource,
- pageContext);
+ pageContext);
try {
conn = dataSource.getConnection();
} catch (Exception ex) {
- throw new JspException(Resources.getMessage("DATASOURCE_INVALID",
- ex.toString()));
+ throw new JspException(Resources.getMessage("DATASOURCE_INVALID",
+ ex.toString()));
}
}
return conn;
}
- private void setParameters(PreparedStatement ps, List parameters)
- throws SQLException
- {
+ private void setParameters(PreparedStatement ps, List parameters)
+ throws SQLException {
if (parameters != null) {
for (int i = 0; i < parameters.size(); i++) {
/* The first parameter has index 1. If a null
Modified: tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/ResultImpl.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/ResultImpl.java?rev=1037279&r1=1037278&r2=1037279&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/ResultImpl.java (original)
+++ tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/ResultImpl.java Sat Nov 20 17:57:45 2010
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.tag.common.sql;
@@ -29,10 +29,10 @@ import javax.servlet.jsp.jstl.sql.Result
/**
* <p>This class creates a cached version of a <tt>ResultSet</tt>.
- * It's represented as a <tt>Result</tt> implementation, capable of
- * returing an array of <tt>Row</tt> objects containing a <tt>Column</tt>
+ * It's represented as a <tt>Result</tt> implementation, capable of
+ * returing an array of <tt>Row</tt> objects containing a <tt>Column</tt>
* instance for each column in the row.</p>
- *
+ * <p/>
* <p>Note -- this is a private copy for the RI to avoid making the
* corresponding class in javax.servlet.* public.</p>
*
@@ -50,7 +50,7 @@ public class ResultImpl implements Resul
* Build a <code>Result</code> object from a <code>ResultSet</code> object.
*
* @param rs an open <tt>ResultSet</tt>, positioned before the first row
- * @exception SQLException if a database error occurs
+ * @throws SQLException if a database error occurs
*/
public ResultImpl(ResultSet rs) throws SQLException {
this(rs, -1, -1);
@@ -59,9 +59,9 @@ public class ResultImpl implements Resul
/**
* Build a <code>Result</code> object from a <code>ResultSet</code> object.
*
- * @param rs an open <tt>ResultSet</tt>, positioned before the first row
+ * @param rs an open <tt>ResultSet</tt>, positioned before the first row
* @param maxRows query maximum rows limit
- * @exception SQLException if a database error occurs
+ * @throws SQLException if a database error occurs
*/
public ResultImpl(ResultSet rs, int maxRows) throws SQLException {
// Matching API in ResultSupport - apologies for the bad
@@ -73,15 +73,14 @@ public class ResultImpl implements Resul
* This constructor reads the ResultSet and saves a cached
* copy.
*
- * @param rs an open <tt>ResultSet</tt>, positioned before the first
- * row
+ * @param rs an open <tt>ResultSet</tt>, positioned before the first
+ * row
* @param startRow beginning row to be cached
* @param maxRows query maximum rows limit
- * @exception SQLException if a database error occurs
+ * @throws SQLException if a database error occurs
*/
public ResultImpl(ResultSet rs, int startRow, int maxRows)
- throws SQLException
- {
+ throws SQLException {
rowMap = new ArrayList();
rowByIndex = new ArrayList();
@@ -91,7 +90,7 @@ public class ResultImpl implements Resul
// Create the column name array
columnNames = new String[noOfColumns];
for (int i = 1; i <= noOfColumns; i++) {
- columnNames[i-1] = rsmd.getColumnName(i);
+ columnNames[i - 1] = rsmd.getColumnName(i);
}
// Throw away all rows upto startRow
@@ -103,21 +102,21 @@ public class ResultImpl implements Resul
int processedRows = 0;
while (rs.next()) {
if ((maxRows != -1) && (processedRows == maxRows)) {
- isLimited = true;
+ isLimited = true;
break;
}
Object[] columns = new Object[noOfColumns];
- SortedMap columnMap =
- new TreeMap(String.CASE_INSENSITIVE_ORDER);
+ SortedMap columnMap =
+ new TreeMap(String.CASE_INSENSITIVE_ORDER);
// JDBC uses 1 as the lowest index!
for (int i = 1; i <= noOfColumns; i++) {
- Object value = rs.getObject(i);
+ Object value = rs.getObject(i);
if (rs.wasNull()) {
value = null;
}
- columns[i-1] = value;
- columnMap.put(columnNames[i-1], value);
+ columns[i - 1] = value;
+ columnMap.put(columnNames[i - 1], value);
}
rowMap.add(columnMap);
rowByIndex.add(columns);
@@ -140,7 +139,7 @@ public class ResultImpl implements Resul
}
//should just be able to return SortedMap[] object
- return (SortedMap []) rowMap.toArray(new SortedMap[0]);
+ return (SortedMap[]) rowMap.toArray(new SortedMap[0]);
}
@@ -157,7 +156,7 @@ public class ResultImpl implements Resul
}
//should just be able to return Object[][] object
- return (Object [][])rowByIndex.toArray(new Object[0][0]);
+ return (Object[][]) rowByIndex.toArray(new Object[0][0]);
}
/**
@@ -175,7 +174,7 @@ public class ResultImpl implements Resul
* Returns the number of rows in the cached ResultSet
*
* @return the number of cached rows, or -1 if the Result could
- * not be initialized due to SQLExceptions
+ * not be initialized due to SQLExceptions
*/
public int getRowCount() {
if (rowMap == null) {
Modified: tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/SetDataSourceTagSupport.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/SetDataSourceTagSupport.java?rev=1037279&r1=1037278&r2=1037279&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/SetDataSourceTagSupport.java (original)
+++ tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/SetDataSourceTagSupport.java Sat Nov 20 17:57:45 2010
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.tag.common.sql;
@@ -31,7 +31,7 @@ import org.apache.taglibs.standard.tag.c
/**
* <p>Tag handler for <SetDataSource> in JSTL, used to create
* a simple DataSource for prototyping.</p>
- *
+ *
* @author Hans Bergsten
* @author Justyna Horwat
*/
@@ -52,16 +52,16 @@ public class SetDataSourceTagSupport ext
// Constructor and initialization
public SetDataSourceTagSupport() {
- super();
- init();
+ super();
+ init();
}
private void init() {
- dataSource = null;
- dataSourceSpecified = false;
- jdbcURL = driverClassName = userName = password = null;
- var = null;
- scope = PageContext.PAGE_SCOPE;
+ dataSource = null;
+ dataSourceSpecified = false;
+ jdbcURL = driverClassName = userName = password = null;
+ var = null;
+ scope = PageContext.PAGE_SCOPE;
}
@@ -71,14 +71,13 @@ public class SetDataSourceTagSupport ext
/**
* Setter method for the scope of the variable to hold the
* result.
- *
*/
public void setScope(String scope) {
this.scope = Util.getScope(scope);
}
public void setVar(String var) {
- this.var = var;
+ this.var = var;
}
@@ -92,10 +91,10 @@ public class SetDataSourceTagSupport ext
if (dataSource != null) {
ds = DataSourceUtil.getDataSource(dataSource, pageContext);
} else {
- if (dataSourceSpecified) {
- throw new JspException(
- Resources.getMessage("SQL_DATASOURCE_NULL"));
- }
+ if (dataSourceSpecified) {
+ throw new JspException(
+ Resources.getMessage("SQL_DATASOURCE_NULL"));
+ }
DataSourceWrapper dsw = new DataSourceWrapper();
try {
@@ -106,27 +105,28 @@ public class SetDataSourceTagSupport ext
}
catch (Exception e) {
throw new JspTagException(
- Resources.getMessage("DRIVER_INVALID_CLASS",
- e.toString()), e);
+ Resources.getMessage("DRIVER_INVALID_CLASS",
+ e.toString()), e);
}
dsw.setJdbcURL(jdbcURL);
dsw.setUserName(userName);
dsw.setPassword(password);
- ds = (DataSource) dsw;
+ ds = (DataSource) dsw;
}
if (var != null) {
- pageContext.setAttribute(var, ds, scope);
+ pageContext.setAttribute(var, ds, scope);
} else {
Config.set(pageContext, Config.SQL_DATA_SOURCE, ds, scope);
}
- return SKIP_BODY;
+ return SKIP_BODY;
}
// Releases any resources we may have (or inherit)
+
@Override
public void release() {
- init();
+ init();
}
}
Modified: tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/TransactionTagSupport.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/TransactionTagSupport.java?rev=1037279&r1=1037278&r2=1037279&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/TransactionTagSupport.java (original)
+++ tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/TransactionTagSupport.java Sat Nov 20 17:57:45 2010
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.tag.common.sql;
@@ -30,25 +30,25 @@ import org.apache.taglibs.standard.resou
/**
- * <p>Tag handler for <Transaction> in JSTL.
- *
+ * <p>Tag handler for <Transaction> in JSTL.
+ *
* @author Hans Bergsten
*/
-public abstract class TransactionTagSupport extends TagSupport
- implements TryCatchFinally {
+public abstract class TransactionTagSupport extends TagSupport
+ implements TryCatchFinally {
//*********************************************************************
// Private constants
private static final String TRANSACTION_READ_COMMITTED
- = "read_committed";
+ = "read_committed";
private static final String TRANSACTION_READ_UNCOMMITTED
- = "read_uncommitted";
+ = "read_uncommitted";
private static final String TRANSACTION_REPEATABLE_READ
- = "repeatable_read";
+ = "repeatable_read";
private static final String TRANSACTION_SERIALIZABLE
- = "serializable";
+ = "serializable";
//*********************************************************************
@@ -70,15 +70,14 @@ public abstract class TransactionTagSupp
// Constructor and initialization
public TransactionTagSupport() {
- super();
- conn = null;
- dataSourceSpecified = false;
- rawDataSource = null;
- isolation = Connection.TRANSACTION_NONE;
+ super();
+ conn = null;
+ dataSourceSpecified = false;
+ rawDataSource = null;
+ isolation = Connection.TRANSACTION_NONE;
}
-
//*********************************************************************
// Tag logic
@@ -90,33 +89,33 @@ public abstract class TransactionTagSupp
@Override
public int doStartTag() throws JspException {
- if ((rawDataSource == null) && dataSourceSpecified) {
- throw new JspException(
- Resources.getMessage("SQL_DATASOURCE_NULL"));
- }
+ if ((rawDataSource == null) && dataSourceSpecified) {
+ throw new JspException(
+ Resources.getMessage("SQL_DATASOURCE_NULL"));
+ }
DataSource dataSource = DataSourceUtil.getDataSource(rawDataSource,
- pageContext);
+ pageContext);
- try {
- conn = dataSource.getConnection();
- origIsolation = conn.getTransactionIsolation();
- if (origIsolation == Connection.TRANSACTION_NONE) {
- throw new JspTagException(
- Resources.getMessage("TRANSACTION_NO_SUPPORT"));
- }
- if ((isolation != Connection.TRANSACTION_NONE)
- && (isolation != origIsolation)) {
- conn.setTransactionIsolation(isolation);
- }
- conn.setAutoCommit(false);
- } catch (SQLException e) {
- throw new JspTagException(
- Resources.getMessage("ERROR_GET_CONNECTION",
- e.toString()), e);
- }
+ try {
+ conn = dataSource.getConnection();
+ origIsolation = conn.getTransactionIsolation();
+ if (origIsolation == Connection.TRANSACTION_NONE) {
+ throw new JspTagException(
+ Resources.getMessage("TRANSACTION_NO_SUPPORT"));
+ }
+ if ((isolation != Connection.TRANSACTION_NONE)
+ && (isolation != origIsolation)) {
+ conn.setTransactionIsolation(isolation);
+ }
+ conn.setAutoCommit(false);
+ } catch (SQLException e) {
+ throw new JspTagException(
+ Resources.getMessage("ERROR_GET_CONNECTION",
+ e.toString()), e);
+ }
- return EVAL_BODY_INCLUDE;
+ return EVAL_BODY_INCLUDE;
}
/**
@@ -124,28 +123,28 @@ public abstract class TransactionTagSupp
*/
@Override
public int doEndTag() throws JspException {
- try {
- conn.commit();
- } catch (SQLException e) {
- throw new JspTagException(
- Resources.getMessage("TRANSACTION_COMMIT_ERROR",
- e.toString()), e);
- }
- return EVAL_PAGE;
+ try {
+ conn.commit();
+ } catch (SQLException e) {
+ throw new JspTagException(
+ Resources.getMessage("TRANSACTION_COMMIT_ERROR",
+ e.toString()), e);
+ }
+ return EVAL_PAGE;
}
/**
* Rollbacks the transaction and rethrows the Throwable.
*/
public void doCatch(Throwable t) throws Throwable {
- if (conn != null) {
- try {
- conn.rollback();
- } catch (SQLException e) {
- // Ignore to not hide orignal exception
- }
- }
- throw t;
+ if (conn != null) {
+ try {
+ conn.rollback();
+ } catch (SQLException e) {
+ // Ignore to not hide orignal exception
+ }
+ }
+ throw t;
}
/**
@@ -153,27 +152,28 @@ public abstract class TransactionTagSupp
* closes it.
*/
public void doFinally() {
- if (conn != null) {
- try {
- if ((isolation != Connection.TRANSACTION_NONE)
- && (isolation != origIsolation)) {
- conn.setTransactionIsolation(origIsolation);
- }
- conn.setAutoCommit(true);
- conn.close();
- } catch (SQLException e) {
- // Not much we can do
- }
- }
- conn = null;
- isolation = Connection.TRANSACTION_NONE;
+ if (conn != null) {
+ try {
+ if ((isolation != Connection.TRANSACTION_NONE)
+ && (isolation != origIsolation)) {
+ conn.setTransactionIsolation(origIsolation);
+ }
+ conn.setAutoCommit(true);
+ conn.close();
+ } catch (SQLException e) {
+ // Not much we can do
+ }
+ }
+ conn = null;
+ isolation = Connection.TRANSACTION_NONE;
}
// Releases any resources we may have (or inherit)
+
@Override
public void release() {
- dataSourceSpecified = false;
- rawDataSource = null;
+ dataSourceSpecified = false;
+ rawDataSource = null;
}
@@ -185,18 +185,18 @@ public abstract class TransactionTagSupp
*/
public void setIsolation(String iso) throws JspTagException {
- if (TRANSACTION_READ_COMMITTED.equals(iso)) {
- isolation = Connection.TRANSACTION_READ_COMMITTED;
- } else if (TRANSACTION_READ_UNCOMMITTED.equals(iso)) {
- isolation = Connection.TRANSACTION_READ_UNCOMMITTED;
- } else if (TRANSACTION_REPEATABLE_READ.equals(iso)) {
- isolation = Connection.TRANSACTION_REPEATABLE_READ;
- } else if (TRANSACTION_SERIALIZABLE.equals(iso)) {
- isolation = Connection.TRANSACTION_SERIALIZABLE;
- } else {
- throw new JspTagException(
- Resources.getMessage("TRANSACTION_INVALID_ISOLATION"));
- }
+ if (TRANSACTION_READ_COMMITTED.equals(iso)) {
+ isolation = Connection.TRANSACTION_READ_COMMITTED;
+ } else if (TRANSACTION_READ_UNCOMMITTED.equals(iso)) {
+ isolation = Connection.TRANSACTION_READ_UNCOMMITTED;
+ } else if (TRANSACTION_REPEATABLE_READ.equals(iso)) {
+ isolation = Connection.TRANSACTION_REPEATABLE_READ;
+ } else if (TRANSACTION_SERIALIZABLE.equals(iso)) {
+ isolation = Connection.TRANSACTION_SERIALIZABLE;
+ } else {
+ throw new JspTagException(
+ Resources.getMessage("TRANSACTION_INVALID_ISOLATION"));
+ }
}
/**
@@ -204,6 +204,6 @@ public abstract class TransactionTagSupp
* the Connection.
*/
public Connection getSharedConnection() {
- return conn;
+ return conn;
}
}
Modified: tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/UpdateTagSupport.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/UpdateTagSupport.java?rev=1037279&r1=1037278&r2=1037279&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/UpdateTagSupport.java (original)
+++ tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/UpdateTagSupport.java Sat Nov 20 17:57:45 2010
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.tag.common.sql;
@@ -35,14 +35,14 @@ import org.apache.taglibs.standard.resou
import org.apache.taglibs.standard.tag.common.core.Util;
/**
- * <p>Tag handler for <Update> in JSTL.
- *
+ * <p>Tag handler for <Update> in JSTL.
+ *
* @author Hans Bergsten
* @author Justyna Horwat
*/
-public abstract class UpdateTagSupport extends BodyTagSupport
- implements TryCatchFinally, SQLExecutionTag {
+public abstract class UpdateTagSupport extends BodyTagSupport
+ implements TryCatchFinally, SQLExecutionTag {
private String var;
private int scope;
@@ -68,18 +68,18 @@ public abstract class UpdateTagSupport e
// Constructor and initialization
public UpdateTagSupport() {
- super();
- init();
+ super();
+ init();
}
private void init() {
- rawDataSource = null;
- sql = null;
- conn = null;
- parameters = null;
- isPartOfTransaction = dataSourceSpecified = false;
+ rawDataSource = null;
+ sql = null;
+ conn = null;
+ parameters = null;
+ isPartOfTransaction = dataSourceSpecified = false;
scope = PageContext.PAGE_SCOPE;
- var = null;
+ var = null;
}
@@ -91,7 +91,7 @@ public abstract class UpdateTagSupport e
* result.
*/
public void setVar(String var) {
- this.var = var;
+ this.var = var;
}
/**
@@ -113,13 +113,13 @@ public abstract class UpdateTagSupport e
@Override
public int doStartTag() throws JspException {
- try {
- conn = getConnection();
- } catch (SQLException e) {
- throw new JspException(sql + ": " + e.getMessage(), e);
- }
+ try {
+ conn = getConnection();
+ } catch (SQLException e) {
+ throw new JspException(sql + ": " + e.getMessage(), e);
+ }
- return EVAL_BODY_BUFFERED;
+ return EVAL_BODY_BUFFERED;
}
/**
@@ -128,7 +128,7 @@ public abstract class UpdateTagSupport e
* named by the <code>var</code> attribute in the scope specified
* by the <code>scope</code> attribute, as an object that implements
* the Result interface.
- *
+ * <p/>
* <p>The connection used to execute the statement comes either
* from the <code>DataSource</code> specified by the
* <code>dataSource</code> attribute, provided by a parent action
@@ -137,50 +137,50 @@ public abstract class UpdateTagSupport e
*/
@Override
public int doEndTag() throws JspException {
- /*
- * Use the SQL statement specified by the sql attribute, if any,
- * otherwise use the body as the statement.
- */
- String sqlStatement = null;
- if (sql != null) {
- sqlStatement = sql;
- }
- else if (bodyContent != null) {
- sqlStatement = bodyContent.getString();
- }
- if (sqlStatement == null || sqlStatement.trim().length() == 0) {
- throw new JspTagException(
- Resources.getMessage("SQL_NO_STATEMENT"));
- }
-
- int result = 0;
- PreparedStatement ps = null;
- try {
- ps = conn.prepareStatement(sqlStatement);
- setParameters(ps, parameters);
- result = ps.executeUpdate();
- }
- catch (Throwable e) {
- throw new JspException(sqlStatement + ": " + e.getMessage(), e);
- } finally {
- if (ps != null) {
- try {
- ps.close();
- } catch (SQLException sqe) {
- throw new JspException(sqe.getMessage(), sqe);
- }
- }
- }
- if (var != null)
- pageContext.setAttribute(var, new Integer(result), scope);
- return EVAL_PAGE;
+ /*
+ * Use the SQL statement specified by the sql attribute, if any,
+ * otherwise use the body as the statement.
+ */
+ String sqlStatement = null;
+ if (sql != null) {
+ sqlStatement = sql;
+ } else if (bodyContent != null) {
+ sqlStatement = bodyContent.getString();
+ }
+ if (sqlStatement == null || sqlStatement.trim().length() == 0) {
+ throw new JspTagException(
+ Resources.getMessage("SQL_NO_STATEMENT"));
+ }
+
+ int result = 0;
+ PreparedStatement ps = null;
+ try {
+ ps = conn.prepareStatement(sqlStatement);
+ setParameters(ps, parameters);
+ result = ps.executeUpdate();
+ }
+ catch (Throwable e) {
+ throw new JspException(sqlStatement + ": " + e.getMessage(), e);
+ } finally {
+ if (ps != null) {
+ try {
+ ps.close();
+ } catch (SQLException sqe) {
+ throw new JspException(sqe.getMessage(), sqe);
+ }
+ }
+ }
+ if (var != null) {
+ pageContext.setAttribute(var, new Integer(result), scope);
+ }
+ return EVAL_PAGE;
}
/**
* Just rethrows the Throwable.
*/
public void doCatch(Throwable t) throws Throwable {
- throw t;
+ throw t;
}
/**
@@ -188,16 +188,16 @@ public abstract class UpdateTagSupport e
* as part of a transaction.
*/
public void doFinally() {
- if (conn != null && !isPartOfTransaction) {
- try {
- conn.close();
- } catch (SQLException e) {
- // Not much we can do
- }
- }
+ if (conn != null && !isPartOfTransaction) {
+ try {
+ conn.close();
+ } catch (SQLException e) {
+ // Not much we can do
+ }
+ }
- parameters = null;
- conn = null;
+ parameters = null;
+ conn = null;
}
@@ -209,10 +209,10 @@ public abstract class UpdateTagSupport e
* parameter values.
*/
public void addSQLParameter(Object o) {
- if (parameters == null) {
- parameters = new ArrayList();
- }
- parameters.add(o);
+ if (parameters == null) {
+ parameters = new ArrayList();
+ }
+ parameters.add(o);
}
@@ -220,50 +220,49 @@ public abstract class UpdateTagSupport e
// Private utility methods
private Connection getConnection() throws JspException, SQLException {
- // Fix: Add all other mechanisms
- Connection conn = null;
- isPartOfTransaction = false;
-
- TransactionTagSupport parent = (TransactionTagSupport)
- findAncestorWithClass(this, TransactionTagSupport.class);
- if (parent != null) {
+ // Fix: Add all other mechanisms
+ Connection conn = null;
+ isPartOfTransaction = false;
+
+ TransactionTagSupport parent = (TransactionTagSupport)
+ findAncestorWithClass(this, TransactionTagSupport.class);
+ if (parent != null) {
if (dataSourceSpecified) {
throw new JspTagException(
- Resources.getMessage("ERROR_NESTED_DATASOURCE"));
+ Resources.getMessage("ERROR_NESTED_DATASOURCE"));
}
- conn = parent.getSharedConnection();
+ conn = parent.getSharedConnection();
isPartOfTransaction = true;
- } else {
- if ((rawDataSource == null) && dataSourceSpecified) {
- throw new JspException(
- Resources.getMessage("SQL_DATASOURCE_NULL"));
- }
- DataSource dataSource = DataSourceUtil.getDataSource(rawDataSource,
- pageContext);
+ } else {
+ if ((rawDataSource == null) && dataSourceSpecified) {
+ throw new JspException(
+ Resources.getMessage("SQL_DATASOURCE_NULL"));
+ }
+ DataSource dataSource = DataSourceUtil.getDataSource(rawDataSource,
+ pageContext);
try {
conn = dataSource.getConnection();
} catch (Exception ex) {
throw new JspException(
- Resources.getMessage("DATASOURCE_INVALID",
- ex.toString()));
+ Resources.getMessage("DATASOURCE_INVALID",
+ ex.toString()));
}
- }
+ }
- return conn;
+ return conn;
}
- private void setParameters(PreparedStatement ps, List parameters)
- throws SQLException
- {
- if (parameters != null) {
- for (int i = 0; i < parameters.size(); i++) {
+ private void setParameters(PreparedStatement ps, List parameters)
+ throws SQLException {
+ if (parameters != null) {
+ for (int i = 0; i < parameters.size(); i++) {
/* The first parameter has index 1. If a null
* is passed to setObject the parameter will be
* set to JDBC null so an explicit call to
* ps.setNull is not required.
*/
ps.setObject(i + 1, parameters.get(i));
- }
- }
+ }
+ }
}
}
Modified: tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/ExprSupport.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/ExprSupport.java?rev=1037279&r1=1037278&r2=1037279&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/ExprSupport.java (original)
+++ tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/ExprSupport.java Sat Nov 20 17:57:45 2010
@@ -13,19 +13,19 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.tag.common.xml;
-import org.apache.taglibs.standard.util.EscapeXML;
-
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;
+import org.apache.taglibs.standard.util.EscapeXML;
+
/**
* <p>Tag handler for <out> in JSTL's XML library.</p>
- *
+ * <p/>
* TODO: should we rename this to OutSupport to match the tag name?
*
* @author Shawn Bayern
@@ -37,7 +37,7 @@ public abstract class ExprSupport extend
// Internal state
private String select; // tag attribute
- protected boolean escapeXml; // tag attribute
+ protected boolean escapeXml; // tag attribute
//*********************************************************************
// Construction and initialization
@@ -53,8 +53,9 @@ public abstract class ExprSupport extend
}
// resets local state
+
private void init() {
- select = null;
+ select = null;
escapeXml = true;
}
@@ -63,19 +64,21 @@ public abstract class ExprSupport extend
// Tag logic
// applies XPath expression from 'select' and prints the result
+
@Override
public int doStartTag() throws JspException {
try {
XPathUtil xu = new XPathUtil(pageContext);
String result = xu.valueOf(XPathUtil.getContext(this), select);
EscapeXML.emit(result, escapeXml, pageContext.getOut());
- return SKIP_BODY;
+ return SKIP_BODY;
} catch (java.io.IOException ex) {
throw new JspTagException(ex.toString(), ex);
}
}
// Releases any resources we may have (or inherit)
+
@Override
public void release() {
super.release();
@@ -87,6 +90,6 @@ public abstract class ExprSupport extend
// Attribute accessors
public void setSelect(String select) {
- this.select = select;
+ this.select = select;
}
}
Modified: tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/ForEachTag.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/ForEachTag.java?rev=1037279&r1=1037278&r2=1037279&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/ForEachTag.java (original)
+++ tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/ForEachTag.java Sat Nov 20 17:57:45 2010
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.tag.common.xml;
@@ -27,18 +27,18 @@ import org.apache.taglibs.standard.resou
/**
* <p>Support for the XML library's <forEach> tag.</p>
*
- * @see javax.servlet.jsp.jstl.core.LoopTagSupport
* @author Shawn Bayern
+ * @see javax.servlet.jsp.jstl.core.LoopTagSupport
*/
public class ForEachTag extends LoopTagSupport {
//*********************************************************************
// Private state
- private String select; // tag attribute
- private List nodes; // XPath result
- private int nodesIndex; // current index
- private org.w3c.dom.Node current; // current node
+ private String select; // tag attribute
+ private List nodes; // XPath result
+ private int nodesIndex; // current index
+ private org.w3c.dom.Node current; // current node
//*********************************************************************
// Iteration control methods
@@ -59,11 +59,12 @@ public class ForEachTag extends LoopTagS
@Override
protected Object next() throws JspTagException {
- Object o = nodes.get(nodesIndex++);
- if (!(o instanceof org.w3c.dom.Node))
- throw new JspTagException(
- Resources.getMessage("FOREACH_NOT_NODESET"));
- current = (org.w3c.dom.Node) o;
+ Object o = nodes.get(nodesIndex++);
+ if (!(o instanceof org.w3c.dom.Node)) {
+ throw new JspTagException(
+ Resources.getMessage("FOREACH_NOT_NODESET"));
+ }
+ current = (org.w3c.dom.Node) o;
return current;
}
@@ -72,9 +73,10 @@ public class ForEachTag extends LoopTagS
// Tag logic and lifecycle management
// Releases any resources we may have (or inherit)
+
@Override
public void release() {
- init();
+ init();
super.release();
}
@@ -83,7 +85,7 @@ public class ForEachTag extends LoopTagS
// Attribute accessors
public void setSelect(String select) {
- this.select = select;
+ this.select = select;
}
public void setBegin(int begin) throws JspTagException {
@@ -103,13 +105,14 @@ public class ForEachTag extends LoopTagS
this.step = step;
validateStep();
}
-
+
//*********************************************************************
// Public methods for subtags
/* Retrieves the current context. */
+
public org.w3c.dom.Node getContext() throws JspTagException {
- // expose the current node as the context
+ // expose the current node as the context
return current;
}
@@ -118,10 +121,10 @@ public class ForEachTag extends LoopTagS
// Private utility methods
private void init() {
- select = null;
- nodes = null;
- nodesIndex = 0;
- current = null;
- }
+ select = null;
+ nodes = null;
+ nodesIndex = 0;
+ current = null;
+ }
}
Modified: tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/IfTag.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/IfTag.java?rev=1037279&r1=1037278&r2=1037279&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/IfTag.java (original)
+++ tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/IfTag.java Sat Nov 20 17:57:45 2010
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.taglibs.standard.tag.common.xml;
@@ -32,12 +32,14 @@ public class IfTag extends ConditionalTa
// Constructor and lifecycle management
// initialize inherited and local state
+
public IfTag() {
super();
init();
}
// Releases any resources we may have (or inherit)
+
@Override
public void release() {
super.release();
@@ -73,6 +75,7 @@ public class IfTag extends ConditionalTa
// Private utility methods
// resets internal state
+
private void init() {
select = null;
}
Modified: tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/JSTLPrefixResolver.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/JSTLPrefixResolver.java?rev=1037279&r1=1037278&r2=1037279&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/JSTLPrefixResolver.java (original)
+++ tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/JSTLPrefixResolver.java Sat Nov 20 17:57:45 2010
@@ -28,127 +28,118 @@ import org.w3c.dom.Node;
* can be used to perform prefix-to-namespace lookup
* for the XPath object.
*/
-public class JSTLPrefixResolver implements PrefixResolver
-{
+public class JSTLPrefixResolver implements PrefixResolver {
- /**
- * The context to resolve the prefix from, if the context
- * is not given. */
+ /**
+ * The context to resolve the prefix from, if the context
+ * is not given.
+ */
HashMap namespaces;
- /**
- * The URI for the XML namespace.
- * (Duplicate of that found in org.apache.xpath.XPathContext). */
-
- public static final String S_XMLNAMESPACEURI =
- "http://www.w3.org/XML/1998/namespace";
-
- /**
- * No-arg constructor which would create empty HashMap of namespaces
- */
- public JSTLPrefixResolver()
- {
- namespaces = new HashMap();
- }
-
- public JSTLPrefixResolver( HashMap nses )
- {
- namespaces = nses;
- }
-
- /**
- * Given a namespace, get the corresponding prefix. This assumes that
- * the PrevixResolver hold's it's own namespace context, or is a namespace
- * context itself.
- * @param prefix Prefix to resolve.
- * @return Namespace that prefix resolves to, or null if prefix
- * is not bound.
- */
- public String getNamespaceForPrefix(String prefix)
- {
- return (String)namespaces.get(prefix);
- }
-
- /**
- * Given a prefix and a Context Node, get the corresponding namespace.
- * Warning: This will not work correctly if namespaceContext
- * is an attribute node.
- * @param prefix Prefix to resolve.
- * @param namespaceContext Node from which to start searching for a
- * xmlns attribute that binds a prefix to a namespace.
- * @return Namespace that prefix resolves to, or null if prefix
- * is not bound.
- */
- public String getNamespaceForPrefix(String prefix,
- org.w3c.dom.Node namespaceContext)
- {
-
- Node parent = namespaceContext;
- String namespace = null;
-
- if (prefix.equals("xml"))
- {
- namespace = S_XMLNAMESPACEURI;
- }
- else
- {
- int type;
-
- while ((null != parent) && (null == namespace)
- && (((type = parent.getNodeType()) == Node.ELEMENT_NODE)
- || (type == Node.ENTITY_REFERENCE_NODE)))
- {
- if (type == Node.ELEMENT_NODE)
- {
- NamedNodeMap nnm = parent.getAttributes();
-
- for (int i = 0; i < nnm.getLength(); i++)
- {
- Node attr = nnm.item(i);
- String aname = attr.getNodeName();
- boolean isPrefix = aname.startsWith("xmlns:");
-
- if (isPrefix || aname.equals("xmlns"))
- {
- int index = aname.indexOf(':');
- String p = isPrefix ? aname.substring(index + 1) : "";
-
- if (p.equals(prefix))
- {
- namespace = attr.getNodeValue();
+ /**
+ * The URI for the XML namespace.
+ * (Duplicate of that found in org.apache.xpath.XPathContext).
+ */
+
+ public static final String S_XMLNAMESPACEURI =
+ "http://www.w3.org/XML/1998/namespace";
+
+ /**
+ * No-arg constructor which would create empty HashMap of namespaces
+ */
+ public JSTLPrefixResolver() {
+ namespaces = new HashMap();
+ }
+
+ public JSTLPrefixResolver(HashMap nses) {
+ namespaces = nses;
+ }
+
+ /**
+ * Given a namespace, get the corresponding prefix. This assumes that
+ * the PrevixResolver hold's it's own namespace context, or is a namespace
+ * context itself.
+ *
+ * @param prefix Prefix to resolve.
+ * @return Namespace that prefix resolves to, or null if prefix
+ * is not bound.
+ */
+ public String getNamespaceForPrefix(String prefix) {
+ return (String) namespaces.get(prefix);
+ }
- break;
- }
+ /**
+ * Given a prefix and a Context Node, get the corresponding namespace.
+ * Warning: This will not work correctly if namespaceContext
+ * is an attribute node.
+ *
+ * @param prefix Prefix to resolve.
+ * @param namespaceContext Node from which to start searching for a
+ * xmlns attribute that binds a prefix to a namespace.
+ * @return Namespace that prefix resolves to, or null if prefix
+ * is not bound.
+ */
+ public String getNamespaceForPrefix(String prefix,
+ org.w3c.dom.Node namespaceContext) {
+
+ Node parent = namespaceContext;
+ String namespace = null;
+
+ if (prefix.equals("xml")) {
+ namespace = S_XMLNAMESPACEURI;
+ } else {
+ int type;
+
+ while ((null != parent) && (null == namespace)
+ && (((type = parent.getNodeType()) == Node.ELEMENT_NODE)
+ || (type == Node.ENTITY_REFERENCE_NODE))) {
+ if (type == Node.ELEMENT_NODE) {
+ NamedNodeMap nnm = parent.getAttributes();
+
+ for (int i = 0; i < nnm.getLength(); i++) {
+ Node attr = nnm.item(i);
+ String aname = attr.getNodeName();
+ boolean isPrefix = aname.startsWith("xmlns:");
+
+ if (isPrefix || aname.equals("xmlns")) {
+ int index = aname.indexOf(':');
+ String p = isPrefix ? aname.substring(index + 1) : "";
+
+ if (p.equals(prefix)) {
+ namespace = attr.getNodeValue();
+
+ break;
+ }
+ }
+ }
+ }
+
+ parent = parent.getParentNode();
}
- }
}
- parent = parent.getParentNode();
- }
+ return namespace;
}
- return namespace;
- }
+ /**
+ * Return the base identifier.
+ *
+ * @return null
+ */
+ public String getBaseIdentifier() {
+ return null;
+ }
- /**
- * Return the base identifier.
- *
- * @return null
- */
- public String getBaseIdentifier()
- {
- return null;
- }
-
- /**
- * @see PrefixResolver#handlesNullPrefixes() */
- public boolean handlesNullPrefixes() {
- return false;
- }
-
- public void addNamespace ( String prefix, String uri ) {
- namespaces.put( prefix, uri );
- }
+ /**
+ * @see PrefixResolver#handlesNullPrefixes()
+ */
+ public boolean handlesNullPrefixes() {
+ return false;
+ }
+
+ public void addNamespace(String prefix, String uri) {
+ namespaces.put(prefix, uri);
+ }
}
Modified: tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/JSTLXPathAPI.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/JSTLXPathAPI.java?rev=1037279&r1=1037278&r2=1037279&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/JSTLXPathAPI.java (original)
+++ tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/xml/JSTLXPathAPI.java Sat Nov 20 17:57:45 2010
@@ -39,7 +39,7 @@ import org.w3c.dom.traversal.NodeIterato
* created for each evaluation. A faster way is to precompile the
* XPaths using the low-level API, and then just use the XPaths
* over and over.
- *
+ * <p/>
* NOTE: In particular, each call to this method will create a new
* XPathContext, a new DTMManager... and thus a new DTM. That's very
* safe, since it guarantees that you're always processing against a
@@ -49,198 +49,191 @@ import org.w3c.dom.traversal.NodeIterato
* methods.
*
* @see <a href="http://www.w3.org/TR/xpath">XPath Specification</a>
- *
*/
-public class JSTLXPathAPI extends XPathAPI {
+public class JSTLXPathAPI extends XPathAPI {
/**
* Use an XPath string to select a single node.
* XPath namespace prefixes are resolved using the prefixResolver.
*
- * @param contextNode The node to start searching from.
- * @param str A valid XPath string.
+ * @param contextNode The node to start searching from.
+ * @param str A valid XPath string.
* @param prefixResolver The PrefixResolver using which prefixes in the XPath will be resolved to namespaces.
* @return The first node found that matches the XPath, or null.
- *
* @throws JspTagException
*/
public static Node selectSingleNode(
- Node contextNode, String str, PrefixResolver prefixResolver)
- throws JspTagException {
-
+ Node contextNode, String str, PrefixResolver prefixResolver)
+ throws JspTagException {
+
// Have the XObject return its result as a NodeSetDTM.
NodeIterator nl = selectNodeIterator(contextNode, str, prefixResolver);
-
+
// Return the first node, or null
return nl.nextNode();
}
-
+
/**
* Use an XPath string to select a single node.
* XPath namespace prefixes are resolved using the prefixResolver.
*
- * @param contextNode The node to start searching from.
- * @param str A valid XPath string.
+ * @param contextNode The node to start searching from.
+ * @param str A valid XPath string.
* @param prefixResolver The PrefixResolver using which prefixes in the XPath will be resolved to namespaces.
* @return The first node found that matches the XPath, or null.
- *
* @throws JspTagException
*/
public static Node selectSingleNode(
- Node contextNode, String str, PrefixResolver prefixResolver,
- XPathContext xpathSupport ) throws JspTagException {
-
+ Node contextNode, String str, PrefixResolver prefixResolver,
+ XPathContext xpathSupport) throws JspTagException {
+
// Have the XObject return its result as a NodeSetDTM.
NodeIterator nl = selectNodeIterator(contextNode, str, prefixResolver, xpathSupport);
-
+
// Return the first node, or null
return nl.nextNode();
}
-
+
/**
- * Use an XPath string to select a nodelist.
- * XPath namespace prefixes are resolved using PrefixResolver.
- *
- * @param contextNode The node to start searching from.
- * @param str A valid XPath string.
- * @param prefixResolver The PrefixResolver using which prefixes in the XPath will be resolved to namespaces.
- * @return A NodeIterator, should never be null.
+ * Use an XPath string to select a nodelist.
+ * XPath namespace prefixes are resolved using PrefixResolver.
*
+ * @param contextNode The node to start searching from.
+ * @param str A valid XPath string.
+ * @param prefixResolver The PrefixResolver using which prefixes in the XPath will be resolved to namespaces.
+ * @return A NodeIterator, should never be null.
* @throws JspTagException
*/
public static NodeIterator selectNodeIterator(
- Node contextNode, String str, PrefixResolver prefixResolver)
- throws JspTagException {
-
+ Node contextNode, String str, PrefixResolver prefixResolver)
+ throws JspTagException {
+
// Execute the XPath, and have it return the result
XObject list = eval(contextNode, str, prefixResolver, null);
-
+
// Have the XObject return its result as a NodeSetDTM.
return getNodeIterator(list);
}
-
+
/**
- * Use an XPath string to select a nodelist.
- * XPath namespace prefixes are resolved using PrefixResolver.
- *
- * @param contextNode The node to start searching from.
- * @param str A valid XPath string.
- * @param prefixResolver The PrefixResolver using which prefixes in the XPath will be resolved to namespaces.
- * @return A NodeIterator, should never be null.
+ * Use an XPath string to select a nodelist.
+ * XPath namespace prefixes are resolved using PrefixResolver.
*
+ * @param contextNode The node to start searching from.
+ * @param str A valid XPath string.
+ * @param prefixResolver The PrefixResolver using which prefixes in the XPath will be resolved to namespaces.
+ * @return A NodeIterator, should never be null.
* @throws JspTagException
*/
public static NodeIterator selectNodeIterator(
- Node contextNode, String str, PrefixResolver prefixResolver,
- XPathContext xpathSupport ) throws JspTagException {
-
+ Node contextNode, String str, PrefixResolver prefixResolver,
+ XPathContext xpathSupport) throws JspTagException {
+
// Execute the XPath, and have it return the result
XObject list = eval(contextNode, str, prefixResolver, xpathSupport);
-
+
// Have the XObject return its result as a NodeSetDTM.
return getNodeIterator(list);
}
-
+
/**
- * Use an XPath string to select a nodelist.
- * XPath namespace prefixes are resolved using the prefixResolver.
- *
- * @param contextNode The node to start searching from.
- * @param str A valid XPath string.
- * @param prefixResolver The PrefixResolver using which prefixes in the XPath will be resolved to namespaces.
- * @return A NodeIterator, should never be null.
+ * Use an XPath string to select a nodelist.
+ * XPath namespace prefixes are resolved using the prefixResolver.
*
+ * @param contextNode The node to start searching from.
+ * @param str A valid XPath string.
+ * @param prefixResolver The PrefixResolver using which prefixes in the XPath will be resolved to namespaces.
+ * @return A NodeIterator, should never be null.
* @throws JspTagException
*/
private static NodeList selectNodeList(
- Node contextNode, String str, PrefixResolver prefixResolver)
- throws JspTagException {
+ Node contextNode, String str, PrefixResolver prefixResolver)
+ throws JspTagException {
// Execute the XPath, and have it return the result
XObject list = eval(contextNode, str, prefixResolver, null);
-
+
// Return a NodeList.
return getNodeList(list);
}
-
+
/**
- * Use an XPath string to select a nodelist.
- * XPath namespace prefixes are resolved using the prefixResolver.
- *
- * @param contextNode The node to start searching from.
- * @param str A valid XPath string.
- * @param prefixResolver The PrefixResolver using which prefixes in the XPath will be resolved to namespaces.
- * @return A NodeIterator, should never be null.
+ * Use an XPath string to select a nodelist.
+ * XPath namespace prefixes are resolved using the prefixResolver.
*
+ * @param contextNode The node to start searching from.
+ * @param str A valid XPath string.
+ * @param prefixResolver The PrefixResolver using which prefixes in the XPath will be resolved to namespaces.
+ * @return A NodeIterator, should never be null.
* @throws JspTagException
*/
public static NodeList selectNodeList(
- Node contextNode, String str, PrefixResolver prefixResolver,
- XPathContext xpathSupport )
- throws JspTagException
- {
+ Node contextNode, String str, PrefixResolver prefixResolver,
+ XPathContext xpathSupport)
+ throws JspTagException {
// Execute the XPath, and have it return the result
XObject list = eval(contextNode, str, prefixResolver, xpathSupport);
-
+
// Return a NodeList.
return getNodeList(list);
}
-
+
/**
* Returns a NodeIterator from an XObject.
- * @param list The XObject from which a NodeIterator is returned.
- * @return A NodeIterator, should never be null.
- * @throws JspTagException
+ *
+ * @param list The XObject from which a NodeIterator is returned.
+ * @return A NodeIterator, should never be null.
+ * @throws JspTagException
*/
- private static NodeIterator getNodeIterator(XObject list)
- throws JspTagException {
+ private static NodeIterator getNodeIterator(XObject list)
+ throws JspTagException {
try {
return list.nodeset();
} catch (TransformerException ex) {
throw new JspTagException(
- Resources.getMessage("XPATH_ERROR_XOBJECT", ex.toString()), ex);
+ Resources.getMessage("XPATH_ERROR_XOBJECT", ex.toString()), ex);
}
- }
+ }
/**
* Returns a NodeList from an XObject.
- * @param list The XObject from which a NodeList is returned.
- * @return A NodeList, should never be null.
- * @throws JspTagException
+ *
+ * @param list The XObject from which a NodeList is returned.
+ * @return A NodeList, should never be null.
+ * @throws JspTagException
*/
- static NodeList getNodeList(XObject list)
- throws JspTagException {
+ static NodeList getNodeList(XObject list)
+ throws JspTagException {
try {
return list.nodelist();
} catch (TransformerException ex) {
throw new JspTagException(
- Resources.getMessage("XPATH_ERROR_XOBJECT", ex.toString()), ex);
+ Resources.getMessage("XPATH_ERROR_XOBJECT", ex.toString()), ex);
}
- }
-
+ }
+
/**
- * Evaluate XPath string to an XObject.
- * XPath namespace prefixes are resolved from the namespaceNode.
- * The implementation of this is a little slow, since it creates
- * a number of objects each time it is called. This could be optimized
- * to keep the same objects around, but then thread-safety issues would arise.
- *
- * @param contextNode The node to start searching from.
- * @param str A valid XPath string.
- * @param xpathSupport The node from which prefixes in the XPath will be resolved to namespaces.
- * @param prefixResolver Will be called if the parser encounters namespace
- * prefixes, to resolve the prefixes to URLs.
- * @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null.
- * @see org.apache.xpath.objects.XObject
- * @see org.apache.xpath.objects.XNull
- * @see org.apache.xpath.objects.XBoolean
- * @see org.apache.xpath.objects.XNumber
- * @see org.apache.xpath.objects.XString
- * @see org.apache.xpath.objects.XRTreeFrag
- *
+ * Evaluate XPath string to an XObject.
+ * XPath namespace prefixes are resolved from the namespaceNode.
+ * The implementation of this is a little slow, since it creates
+ * a number of objects each time it is called. This could be optimized
+ * to keep the same objects around, but then thread-safety issues would arise.
+ *
+ * @param contextNode The node to start searching from.
+ * @param str A valid XPath string.
+ * @param xpathSupport The node from which prefixes in the XPath will be resolved to namespaces.
+ * @param prefixResolver Will be called if the parser encounters namespace
+ * prefixes, to resolve the prefixes to URLs.
+ * @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null.
* @throws JspTagException
+ * @see org.apache.xpath.objects.XObject
+ * @see org.apache.xpath.objects.XNull
+ * @see org.apache.xpath.objects.XBoolean
+ * @see org.apache.xpath.objects.XNumber
+ * @see org.apache.xpath.objects.XString
+ * @see org.apache.xpath.objects.XRTreeFrag
*/
public static XObject eval(
- Node contextNode, String str, PrefixResolver prefixResolver,
- XPathContext xpathSupport) throws JspTagException {
+ Node contextNode, String str, PrefixResolver prefixResolver,
+ XPathContext xpathSupport) throws JspTagException {
//System.out.println("eval of XPathContext params: contextNode:str(xpath)"+
// ":prefixResolver:xpathSupport => " + contextNode + ":" + str + ":" +
// prefixResolver + ":" + xpathSupport );
@@ -248,7 +241,7 @@ public class JSTLXPathAPI extends XPathA
if (xpathSupport == null) {
return eval(contextNode, str, prefixResolver);
}
-
+
// Since we don't have a XML Parser involved here, install some default support
// for things like namespaces, etc.
// (Changed from: XPathContext xpathSupport = new XPathContext();
@@ -256,25 +249,25 @@ public class JSTLXPathAPI extends XPathA
// XPathContext should be done away with.)
// Create the XPath object.
XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
-
+
// Execute the XPath, and have it return the result
int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);
-
+
// System.out.println("Context Node id ( after getDTMHandlerFromNode) => " + ctxtNode );
XObject xobj = xpath.execute(xpathSupport, ctxtNode, prefixResolver);
return xobj;
} catch (TransformerException ex) {
throw new JspTagException(
- Resources.getMessage("XPATH_ERROR_EVALUATING_EXPR", str, ex.toString()), ex);
+ Resources.getMessage("XPATH_ERROR_EVALUATING_EXPR", str, ex.toString()), ex);
} catch (IllegalArgumentException ex) {
throw new JspTagException(
- Resources.getMessage("XPATH_ILLEGAL_ARG_EVALUATING_EXPR", str, ex.toString()), ex);
+ Resources.getMessage("XPATH_ILLEGAL_ARG_EVALUATING_EXPR", str, ex.toString()), ex);
}
}
-
+
public static XObject eval(
- Node contextNode, String str, PrefixResolver prefixResolver,
- XPathContext xpathSupport, Vector varQNames) throws JspTagException {
+ Node contextNode, String str, PrefixResolver prefixResolver,
+ XPathContext xpathSupport, Vector varQNames) throws JspTagException {
//p("***************** eval ");
//p( "contextNode => " + contextNode );
//p( "XPath str => " + str );
@@ -283,22 +276,22 @@ public class JSTLXPathAPI extends XPathA
//p( "Var QNames => " + varQNames );
//p( "Global Var Size => " + varQNames.size() );
try {
- XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
- xpath.fixupVariables( varQNames, varQNames.size());
+ XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
+ xpath.fixupVariables(varQNames, varQNames.size());
// Execute the XPath, and have it return the result
- int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);
+ int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);
// System.out.println("Context Node id ( after getDTMHandlerFromNode) => " + ctxtNode );
return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
} catch (TransformerException ex) {
throw new JspTagException(
- Resources.getMessage("XPATH_ERROR_EVALUATING_EXPR", str, ex.toString()), ex);
+ Resources.getMessage("XPATH_ERROR_EVALUATING_EXPR", str, ex.toString()), ex);
} catch (IllegalArgumentException ex) {
throw new JspTagException(
- Resources.getMessage("XPATH_ILLEGAL_ARG_EVALUATING_EXPR", str, ex.toString()), ex);
+ Resources.getMessage("XPATH_ILLEGAL_ARG_EVALUATING_EXPR", str, ex.toString()), ex);
}
- }
-
+ }
+
private static void p(String s) {
System.out.println("[JSTLXPathAPI] " + s);
- }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org