CLK-306
git-svn-id: https://svn.apache.org/repos/asf/click/trunk/click@1197500 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/.classpath b/.classpath
index 3c77976..956770e 100644
--- a/.classpath
+++ b/.classpath
@@ -10,7 +10,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/commons-codec-1.4.jar"/>
<classpathentry kind="lib" path="lib/junit-3.8.1.jar"/>
- <classpathentry kind="lib" path="lib/ognl-2.6.9.jar"/>
<classpathentry kind="lib" path="lib/log4j-1.2.16.jar"/>
<classpathentry kind="lib" path="lib/commons-fileupload-1.2.1.jar"/>
<classpathentry kind="lib" path="lib/commons-lang-2.5.jar"/>
@@ -28,5 +27,6 @@
<classpathentry kind="lib" path="lib/commons-io-2.0.1.jar"/>
<classpathentry kind="lib" path="lib/velocity-1.7.jar"/>
<classpathentry kind="lib" path="lib/servlet-api-2.4.jar"/>
+ <classpathentry kind="lib" path="lib/mvel2-2.0.19.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/extras/src/org/apache/click/extras/control/FieldColumn.java b/extras/src/org/apache/click/extras/control/FieldColumn.java
index 36365f7..efb873f 100644
--- a/extras/src/org/apache/click/extras/control/FieldColumn.java
+++ b/extras/src/org/apache/click/extras/control/FieldColumn.java
@@ -18,11 +18,8 @@
*/
package org.apache.click.extras.control;
-import java.util.HashMap;
import java.util.Map;
-import ognl.OgnlException;
-
import org.apache.click.Context;
import org.apache.click.control.Column;
import org.apache.click.control.Field;
@@ -68,9 +65,6 @@
/** The columns field to process and render. */
protected Field field;
- /** The ognl context map. */
- private transient Map<?, ?> ognlContext;
-
// ----------------------------------------------------------- Constructors
/**
@@ -181,19 +175,7 @@
}
} else {
- if (ognlContext == null) {
- ognlContext = new HashMap<Object, Object>();
- }
-
- try {
- PropertyUtils.setValueOgnl(row,
- propertyName,
- value,
- ognlContext);
-
- } catch (OgnlException oe) {
- throw new RuntimeException(oe);
- }
+ PropertyUtils.setValue(row, propertyName, value);
}
}
diff --git a/extras/src/org/apache/click/extras/gae/GoogleAppEngineListener.java b/extras/src/org/apache/click/extras/gae/GoogleAppEngineListener.java
index e313b57..db45c5d 100644
--- a/extras/src/org/apache/click/extras/gae/GoogleAppEngineListener.java
+++ b/extras/src/org/apache/click/extras/gae/GoogleAppEngineListener.java
@@ -21,8 +21,6 @@
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
-import ognl.OgnlRuntime;
-
/**
* Provides <a href="http://code.google.com/appengine/docs/java/overview.html" class="external" target="_blank">Google App Engine</a>
* (GAE) support for Click applications. GAE is a free Java hosting service
@@ -230,8 +228,7 @@
/**
* Sets the Ognl Runtime SecurityManager to <tt>null</tt> so as not to
- * interfere with Google App Engine (GAE). GAE provides its own strict
- * SecurityManager which clashes with Ognl security checks.
+ * interfere with Google App Engine (GAE).
*
* <pre class="prettyprint">
* OgnlRuntime.setSecurityManager(null); </pre>
@@ -240,6 +237,5 @@
* changes to the servlet context
*/
public void contextInitialized(ServletContextEvent servletContextEvent) {
- OgnlRuntime.setSecurityManager(null);
}
}
diff --git a/framework/src/org/apache/click/ClickServlet.java b/framework/src/org/apache/click/ClickServlet.java
index bb83d05..fb233ed 100644
--- a/framework/src/org/apache/click/ClickServlet.java
+++ b/framework/src/org/apache/click/ClickServlet.java
@@ -39,24 +39,17 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
-import ognl.DefaultMemberAccess;
-import ognl.MemberAccess;
-import ognl.Ognl;
-import ognl.OgnlException;
-import ognl.TypeConverter;
-
import org.apache.click.service.ConfigService;
+import org.apache.click.service.ConfigService.AutoBinding;
import org.apache.click.service.LogService;
import org.apache.click.service.ResourceService;
import org.apache.click.service.TemplateException;
import org.apache.click.service.XmlConfigService;
-import org.apache.click.service.ConfigService.AutoBinding;
import org.apache.click.util.ClickUtils;
import org.apache.click.util.ErrorPage;
import org.apache.click.util.HtmlStringBuffer;
import org.apache.click.util.PageImports;
import org.apache.click.util.PropertyUtils;
-import org.apache.click.util.RequestTypeConverter;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.lang.ClassUtils;
import org.apache.commons.lang.StringUtils;
@@ -141,12 +134,6 @@
protected final static String CONFIG_SERVICE_CLASS = "config-service-class";
/**
- * The custom TypeConverter classname as an init parameter name:
- * &nbps; "<tt>type-converter-class</tt>".
- */
- protected final static String TYPE_CONVERTER_CLASS = "type-converter-class";
-
- /**
* The forwarded request marker attribute: "<tt>click-forward</tt>".
*/
protected final static String CLICK_FORWARD = "click-forward";
@@ -164,15 +151,9 @@
/** The application log service. */
protected LogService logger;
- /** The OGNL member access handler. */
- protected MemberAccess memberAccess;
-
/** The application resource service. */
protected ResourceService resourceService;
- /** The request parameters OGNL type converter. */
- protected TypeConverter typeConverter;
-
/** The thread local page listeners. */
private static final ThreadLocal<List<PageInterceptor>>
THREAD_LOCAL_INTERCEPTORS = new ThreadLocal<List<PageInterceptor>>();
@@ -1332,19 +1313,13 @@
* returned by the {@link #getTypeConverter()} method.
*
* @param page the page whose fields are to be processed
- * @throws OgnlException if an error occurs
*/
- protected void processPageRequestParams(Page page) throws OgnlException {
+ protected void processPageRequestParams(Page page) {
if (configService.getPageFields(page.getClass()).isEmpty()) {
return;
}
- Map<?, ?> ognlContext = null;
-
- boolean customConverter =
- ! getTypeConverter().getClass().equals(RequestTypeConverter.class);
-
HttpServletRequest request = page.getContext().getRequest();
for (Enumeration<?> e = request.getParameterNames(); e.hasMoreElements();) {
@@ -1358,18 +1333,12 @@
if (field != null) {
Class<?> type = field.getType();
- if (customConverter
- || (type.isPrimitive()
- || String.class.isAssignableFrom(type)
- || Number.class.isAssignableFrom(type)
- || Boolean.class.isAssignableFrom(type))) {
+ if (type.isPrimitive()
+ || String.class.isAssignableFrom(type)
+ || Number.class.isAssignableFrom(type)
+ || Boolean.class.isAssignableFrom(type)) {
- if (ognlContext == null) {
- ognlContext = Ognl.createDefaultContext(
- page, null, getTypeConverter(), getMemberAccess());
- }
-
- PropertyUtils.setValueOgnl(page, name, value, ognlContext);
+ PropertyUtils.setValue(page, name, value);
if (logger.isTraceEnabled()) {
logger.trace(" auto bound variable: " + name + "=" + value);
@@ -1619,37 +1588,6 @@
}
/**
- * Return the request parameters OGNL <tt>TypeConverter</tt>. This method
- * performs a lazy load of the TypeConverter object, using the classname
- * defined in the Servlet init parameter <tt>type-converter-class</tt>,
- * if this parameter is not defined this method will return a
- * {@link RequestTypeConverter} instance.
- *
- * @return the request parameters OGNL <tt>TypeConverter</tt>
- * @throws RuntimeException if the TypeConverter instance could not be created
- */
- @SuppressWarnings("unchecked")
- protected TypeConverter getTypeConverter() throws RuntimeException {
- if (typeConverter == null) {
- Class<? extends TypeConverter> converter = RequestTypeConverter.class;
-
- try {
- String classname = getInitParameter(TYPE_CONVERTER_CLASS);
- if (StringUtils.isNotBlank(classname)) {
- converter = ClickUtils.classForName(classname);
- }
-
- typeConverter = converter.newInstance();
-
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- return typeConverter;
- }
-
- /**
* Creates and returns a new Context instance for this path, class and
* request.
* <p/>
@@ -1998,25 +1936,12 @@
// ------------------------------------------------ Package Private Methods
/**
- * Return the OGNL <tt>MemberAccess</tt>. This method performs a lazy load
- * of the MemberAccess object, using a {@link DefaultMemberAccess} instance.
+ * Create a Click application ConfigService instance.
*
- * @return the OGNL <tt>MemberAccess</tt>
+ * @param servletContext the Servlet Context
+ * @return a new application ConfigService instance
+ * @throws Exception if an initialization error occurs
*/
- MemberAccess getMemberAccess() {
- if (memberAccess == null) {
- memberAccess = new DefaultMemberAccess(true);
- }
- return memberAccess;
- }
-
- /**
- * Create a Click application ConfigService instance.
- *
- * @param servletContext the Servlet Context
- * @return a new application ConfigService instance
- * @throws Exception if an initialization error occurs
- */
@SuppressWarnings("unchecked")
ConfigService createConfigService(ServletContext servletContext)
throws Exception {
diff --git a/framework/src/org/apache/click/service/XmlConfigService.java b/framework/src/org/apache/click/service/XmlConfigService.java
index 1c93598..64d98bc 100644
--- a/framework/src/org/apache/click/service/XmlConfigService.java
+++ b/framework/src/org/apache/click/service/XmlConfigService.java
@@ -39,8 +39,6 @@
import javax.servlet.ServletContext;
-import ognl.Ognl;
-
import org.apache.click.Control;
import org.apache.click.Page;
import org.apache.click.PageInterceptor;
@@ -1543,7 +1541,7 @@
String name = i.next().toString();
String value = propertyMap.get(name).toString();
- Ognl.setValue(name, fileUploadService, value);
+ PropertyUtils.setValue(fileUploadService, name, value);
}
} else {
@@ -1579,7 +1577,7 @@
String name = i.next().toString();
String value = propertyMap.get(name).toString();
- Ognl.setValue(name, logService, value);
+ PropertyUtils.setValue(logService, name, value);
}
} else {
logService = new ConsoleLogService();
@@ -1608,7 +1606,7 @@
String name = i.next().toString();
String value = propertyMap.get(name).toString();
- Ognl.setValue(name, messagesMapService, value);
+ PropertyUtils.setValue(messagesMapService, name, value);
}
}
@@ -1671,7 +1669,7 @@
String name = i.next().toString();
String value = propertyMap.get(name).toString();
- Ognl.setValue(name, resourceService, value);
+ PropertyUtils.setValue(resourceService, name, value);
}
} else {
@@ -1707,7 +1705,7 @@
String name = i.next().toString();
String value = propertyMap.get(name).toString();
- Ognl.setValue(name, templateService, value);
+ PropertyUtils.setValue(templateService, name, value);
}
} else {
@@ -2176,13 +2174,10 @@
try {
listener = interceptorClass.newInstance();
- Map ognlContext = new HashMap();
-
for (Property property : properties) {
- PropertyUtils.setValueOgnl(listener,
- property.getName(),
- property.getValue(),
- ognlContext);
+ PropertyUtils.setValue(listener,
+ property.getName(),
+ property.getValue());
}
} catch (Exception e) {
diff --git a/framework/src/org/apache/click/util/ClickUtils.java b/framework/src/org/apache/click/util/ClickUtils.java
index afe6201..e472a8d 100644
--- a/framework/src/org/apache/click/util/ClickUtils.java
+++ b/framework/src/org/apache/click/util/ClickUtils.java
@@ -171,12 +171,12 @@
HTML_ENTITIES[166] = "¦"; // broken bar = broken vertical bar
HTML_ENTITIES[167] = "§"; // section sign
HTML_ENTITIES[168] = "¨"; // diaeresis = spacing diaeresis
- HTML_ENTITIES[169] = "©"; // © - copyright sign
+ HTML_ENTITIES[169] = "©"; // © - copyright sign
HTML_ENTITIES[170] = "ª"; // feminine ordinal indicator
HTML_ENTITIES[171] = "«"; // left-pointing double angle quotation mark = left pointing guillemet
HTML_ENTITIES[172] = "¬"; //not sign
HTML_ENTITIES[173] = "­"; //soft hyphen = discretionary hyphen
- HTML_ENTITIES[174] = "®"; // ® - registered trademark sign
+ HTML_ENTITIES[174] = "®"; // ® - registered trademark sign
HTML_ENTITIES[175] = "¯"; //macron = spacing macron = overline = APL overbar
HTML_ENTITIES[176] = "°"; //degree sign
HTML_ENTITIES[177] = "±"; //plus-minus sign = plus-or-minus sign
@@ -194,70 +194,70 @@
HTML_ENTITIES[189] = "½"; //vulgar fraction one half = fraction one half
HTML_ENTITIES[190] = "¾"; //vulgar fraction three quarters = fraction three quarters
HTML_ENTITIES[191] = "¿"; //inverted question mark = turned question mark
- HTML_ENTITIES[192] = "À"; // À - uppercase A, grave accent
- HTML_ENTITIES[193] = "Á"; // Á - uppercase A, acute accent
- HTML_ENTITIES[194] = "Â"; // Â - uppercase A, circumflex accent
- HTML_ENTITIES[195] = "Ã"; // Ã - uppercase A, tilde
- HTML_ENTITIES[196] = "Ä"; // Ä - uppercase A, umlaut
- HTML_ENTITIES[197] = "Å"; // Å - uppercase A, ring
- HTML_ENTITIES[198] = "Æ"; // Æ - uppercase AE
- HTML_ENTITIES[199] = "Ç"; // Ç - uppercase C, cedilla
- HTML_ENTITIES[200] = "È"; // È - uppercase E, grave accent
- HTML_ENTITIES[201] = "É"; // É - uppercase E, acute accent
- HTML_ENTITIES[202] = "Ê"; // Ê - uppercase E, circumflex accent
- HTML_ENTITIES[203] = "Ë"; // Ë - uppercase E, umlaut
- HTML_ENTITIES[204] = "Ì"; // Ì - uppercase I, grave accent
- HTML_ENTITIES[205] = "Í"; // Í - uppercase I, acute accent
- HTML_ENTITIES[206] = "Î"; // Î - uppercase I, circumflex accent
- HTML_ENTITIES[207] = "Ï"; // Ï - uppercase I, umlaut
- HTML_ENTITIES[208] = "Ð"; // Ð - uppercase Eth, Icelandic
- HTML_ENTITIES[209] = "Ñ"; // Ñ - uppercase N, tilde
- HTML_ENTITIES[210] = "Ò"; // Ò - uppercase O, grave accent
- HTML_ENTITIES[211] = "Ó"; // Ó - uppercase O, acute accent
- HTML_ENTITIES[212] = "Ô"; // Ô - uppercase O, circumflex accent
- HTML_ENTITIES[213] = "Õ"; // Õ - uppercase O, tilde
- HTML_ENTITIES[214] = "Ö"; // Ö - uppercase O, umlaut
+ HTML_ENTITIES[192] = "À"; // À - uppercase A, grave accent
+ HTML_ENTITIES[193] = "Á"; // Ã� - uppercase A, acute accent
+ HTML_ENTITIES[194] = "Â"; // Â - uppercase A, circumflex accent
+ HTML_ENTITIES[195] = "Ã"; // Ã - uppercase A, tilde
+ HTML_ENTITIES[196] = "Ä"; // Ä - uppercase A, umlaut
+ HTML_ENTITIES[197] = "Å"; // Ã… - uppercase A, ring
+ HTML_ENTITIES[198] = "Æ"; // Æ - uppercase AE
+ HTML_ENTITIES[199] = "Ç"; // Ç - uppercase C, cedilla
+ HTML_ENTITIES[200] = "È"; // È - uppercase E, grave accent
+ HTML_ENTITIES[201] = "É"; // É - uppercase E, acute accent
+ HTML_ENTITIES[202] = "Ê"; // Ê - uppercase E, circumflex accent
+ HTML_ENTITIES[203] = "Ë"; // Ë - uppercase E, umlaut
+ HTML_ENTITIES[204] = "Ì"; // ÃŒ - uppercase I, grave accent
+ HTML_ENTITIES[205] = "Í"; // Ã� - uppercase I, acute accent
+ HTML_ENTITIES[206] = "Î"; // ÃŽ - uppercase I, circumflex accent
+ HTML_ENTITIES[207] = "Ï"; // Ã� - uppercase I, umlaut
+ HTML_ENTITIES[208] = "Ð"; // Ã� - uppercase Eth, Icelandic
+ HTML_ENTITIES[209] = "Ñ"; // Ñ - uppercase N, tilde
+ HTML_ENTITIES[210] = "Ò"; // Ã’ - uppercase O, grave accent
+ HTML_ENTITIES[211] = "Ó"; // Ó - uppercase O, acute accent
+ HTML_ENTITIES[212] = "Ô"; // Ãâ? - uppercase O, circumflex accent
+ HTML_ENTITIES[213] = "Õ"; // Õ - uppercase O, tilde
+ HTML_ENTITIES[214] = "Ö"; // Ö - uppercase O, umlaut
HTML_ENTITIES[215] = "×"; //multiplication sign
- HTML_ENTITIES[216] = "Ø"; // Ø - uppercase O, slash
- HTML_ENTITIES[217] = "Ù"; // Ù - uppercase U, grave accent
- HTML_ENTITIES[218] = "Ú"; // Ú - uppercase U, acute accent
- HTML_ENTITIES[219] = "Û"; // Û - uppercase U, circumflex accent
- HTML_ENTITIES[220] = "Ü"; // Ü - uppercase U, umlaut
- HTML_ENTITIES[221] = "Ý"; // Ý - uppercase Y, acute accent
- HTML_ENTITIES[222] = "Þ"; // Þ - uppercase THORN, Icelandic
- HTML_ENTITIES[223] = "ß"; // ß - lowercase sharps, German
- HTML_ENTITIES[224] = "à"; // à - lowercase a, grave accent
- HTML_ENTITIES[225] = "á"; // á - lowercase a, acute accent
- HTML_ENTITIES[226] = "â"; // â - lowercase a, circumflex accent
- HTML_ENTITIES[227] = "ã"; // ã - lowercase a, tilde
- HTML_ENTITIES[228] = "ä"; // ä - lowercase a, umlaut
- HTML_ENTITIES[229] = "å"; // å - lowercase a, ring
- HTML_ENTITIES[230] = "æ"; // æ - lowercase ae
- HTML_ENTITIES[231] = "ç"; // ç - lowercase c, cedilla
- HTML_ENTITIES[232] = "è"; // è - lowercase e, grave accent
- HTML_ENTITIES[233] = "é"; // é - lowercase e, acute accent
- HTML_ENTITIES[234] = "ê"; // ê - lowercase e, circumflex accent
- HTML_ENTITIES[235] = "ë"; // ë - lowercase e, umlaut
- HTML_ENTITIES[236] = "ì"; // ì - lowercase i, grave accent
- HTML_ENTITIES[237] = "í"; // í - lowercase i, acute accent
- HTML_ENTITIES[238] = "î"; // î - lowercase i, circumflex accent
- HTML_ENTITIES[239] = "ï"; // ï - lowercase i, umlaut
- HTML_ENTITIES[240] = "ð"; // ð - lowercase eth, Icelandic
- HTML_ENTITIES[241] = "ñ"; // ñ - lowercase n, tilde
- HTML_ENTITIES[242] = "ò"; // ò - lowercase o, grave accent
- HTML_ENTITIES[243] = "ó"; // ó - lowercase o, acute accent
- HTML_ENTITIES[244] = "ô"; // ô - lowercase o, circumflex accent
- HTML_ENTITIES[245] = "õ"; // õ - lowercase o, tilde
- HTML_ENTITIES[246] = "ö"; // ö - lowercase o, umlaut
+ HTML_ENTITIES[216] = "Ø"; // Ø - uppercase O, slash
+ HTML_ENTITIES[217] = "Ù"; // Ù - uppercase U, grave accent
+ HTML_ENTITIES[218] = "Ú"; // Ú - uppercase U, acute accent
+ HTML_ENTITIES[219] = "Û"; // Û - uppercase U, circumflex accent
+ HTML_ENTITIES[220] = "Ü"; // Ãœ - uppercase U, umlaut
+ HTML_ENTITIES[221] = "Ý"; // Ã� - uppercase Y, acute accent
+ HTML_ENTITIES[222] = "Þ"; // Þ - uppercase THORN, Icelandic
+ HTML_ENTITIES[223] = "ß"; // ß - lowercase sharps, German
+ HTML_ENTITIES[224] = "à"; // Ã - lowercase a, grave accent
+ HTML_ENTITIES[225] = "á"; // á - lowercase a, acute accent
+ HTML_ENTITIES[226] = "â"; // â - lowercase a, circumflex accent
+ HTML_ENTITIES[227] = "ã"; // ã - lowercase a, tilde
+ HTML_ENTITIES[228] = "ä"; // ä - lowercase a, umlaut
+ HTML_ENTITIES[229] = "å"; // Ã¥ - lowercase a, ring
+ HTML_ENTITIES[230] = "æ"; // æ - lowercase ae
+ HTML_ENTITIES[231] = "ç"; // ç - lowercase c, cedilla
+ HTML_ENTITIES[232] = "è"; // è - lowercase e, grave accent
+ HTML_ENTITIES[233] = "é"; // é - lowercase e, acute accent
+ HTML_ENTITIES[234] = "ê"; // ê - lowercase e, circumflex accent
+ HTML_ENTITIES[235] = "ë"; // ë - lowercase e, umlaut
+ HTML_ENTITIES[236] = "ì"; // ì - lowercase i, grave accent
+ HTML_ENTITIES[237] = "í"; // Ã - lowercase i, acute accent
+ HTML_ENTITIES[238] = "î"; // î - lowercase i, circumflex accent
+ HTML_ENTITIES[239] = "ï"; // ï - lowercase i, umlaut
+ HTML_ENTITIES[240] = "ð"; // ð - lowercase eth, Icelandic
+ HTML_ENTITIES[241] = "ñ"; // ñ - lowercase n, tilde
+ HTML_ENTITIES[242] = "ò"; // ò - lowercase o, grave accent
+ HTML_ENTITIES[243] = "ó"; // ó - lowercase o, acute accent
+ HTML_ENTITIES[244] = "ô"; // ô - lowercase o, circumflex accent
+ HTML_ENTITIES[245] = "õ"; // õ - lowercase o, tilde
+ HTML_ENTITIES[246] = "ö"; // ö - lowercase o, umlaut
HTML_ENTITIES[247] = "÷"; // division sign
- HTML_ENTITIES[248] = "ø"; // ø - lowercase o, slash
- HTML_ENTITIES[249] = "ù"; // ù - lowercase u, grave accent
- HTML_ENTITIES[250] = "ú"; // ú - lowercase u, acute accent
- HTML_ENTITIES[251] = "û"; // û - lowercase u, circumflex accent
- HTML_ENTITIES[252] = "ü"; // ü - lowercase u, umlaut
- HTML_ENTITIES[253] = "ý"; // ý - lowercase y, acute accent
- HTML_ENTITIES[254] = "þ"; // þ - lowercase thorn, Icelandic
- HTML_ENTITIES[255] = "ÿ"; // ÿ - lowercase y, umlaut
+ HTML_ENTITIES[248] = "ø"; // ø - lowercase o, slash
+ HTML_ENTITIES[249] = "ù"; // ù - lowercase u, grave accent
+ HTML_ENTITIES[250] = "ú"; // ú - lowercase u, acute accent
+ HTML_ENTITIES[251] = "û"; // û - lowercase u, circumflex accent
+ HTML_ENTITIES[252] = "ü"; // ü - lowercase u, umlaut
+ HTML_ENTITIES[253] = "ý"; // ý - lowercase y, acute accent
+ HTML_ENTITIES[254] = "þ"; // þ - lowercase thorn, Icelandic
+ HTML_ENTITIES[255] = "ÿ"; // ÿ - lowercase y, umlaut
// http://www.w3.org/TR/REC-html40/sgml/entities.html
// <!-- Latin Extended-B -->
HTML_ENTITIES[402] = "ƒ"; //latin small f with hook = function= florin, U+0192 ISOtech -->
@@ -513,16 +513,30 @@
}
OutputStream os = null;
- GZIPOutputStream gos = null;
try {
response.setContentType("text/html");
- if (compress) {
+ // Only compress if flag set, and HTML value is greater than 2K
+ if (compress && buffer.length() > 2024) {
response.setHeader("Content-Encoding", "gzip");
+ ByteArrayOutputStream bos = null;
+ GZIPOutputStream gos = null;
+ try {
+ bos = new ByteArrayOutputStream();
+ gos = new GZIPOutputStream(bos);
+ gos.write(buffer.toString().getBytes());
+
+ } finally {
+ ClickUtils.close(gos);
+ ClickUtils.close(bos);
+ }
+
+ byte[] byteArray = bos.toByteArray();
+ response.setContentLength(byteArray.length);
+
os = response.getOutputStream();
- gos = new GZIPOutputStream(os);
- gos.write(buffer.toString().getBytes());
+ IOUtils.write(byteArray, os);
} else {
response.setContentLength(buffer.length());
@@ -535,7 +549,6 @@
ClickUtils.getLogService().error(ex.getMessage(), ex);
} finally {
- ClickUtils.close(gos);
ClickUtils.close(os);
}
}
diff --git a/framework/src/org/apache/click/util/ContainerUtils.java b/framework/src/org/apache/click/util/ContainerUtils.java
index b81aa36..e4c9298 100644
--- a/framework/src/org/apache/click/util/ContainerUtils.java
+++ b/framework/src/org/apache/click/util/ContainerUtils.java
@@ -20,8 +20,6 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
-import java.math.BigDecimal;
-import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -29,10 +27,6 @@
import java.util.Set;
import java.util.TreeSet;
-import ognl.DefaultTypeConverter;
-import ognl.Ognl;
-import ognl.OgnlOps;
-
import org.apache.click.Control;
import org.apache.click.Page;
import org.apache.click.control.Button;
@@ -135,8 +129,6 @@
LogService logService = ClickUtils.getLogService();
Set<String> properties = getObjectPropertyNames(object);
- Map<?, ?> ognlContext = Ognl.createDefaultContext(
- object, null, new FixBigDecimalTypeConverter(), null);
for (Field field : fieldList) {
@@ -155,7 +147,7 @@
ensureObjectPathNotNull(object, fieldName);
try {
- PropertyUtils.setValueOgnl(object, fieldName, field.getValueObject(), ognlContext);
+ PropertyUtils.setValue(object, fieldName, field.getValueObject());
if (logService.isDebugEnabled()) {
String containerClassName =
@@ -1382,46 +1374,4 @@
ClickUtils.getLogService().warn(message);
}
- /**
- * This class fix an error in ognl's conversion of double->BigDecimal. The
- * default conversion uses BigDecimal(double), the fix is to use
- * BigDecimal.valueOf(double)
- *
- */
- private static class FixBigDecimalTypeConverter extends DefaultTypeConverter {
- @SuppressWarnings("unchecked")
- @Override
- public Object convertValue(Map context, Object value, Class toType) {
- if (value != null && toType == BigDecimal.class) {
- return bigDecValue(value);
- }
- return OgnlOps.convertValue(value, toType);
- }
-
- /**
- * Convert the given value into a BigDecimal.
- *
- * @param value the object to convert into a BigDecimal
- * @return the converted BigDecimal value
- */
- private BigDecimal bigDecValue(Object value) {
- if (value == null) {
- return BigDecimal.valueOf(0L);
- }
- Class<?> c = value.getClass();
- if (c == BigDecimal.class) {
- return (BigDecimal) value;
- }
- if (c == BigInteger.class) {
- return new BigDecimal((BigInteger) value);
- }
- if (c == Boolean.class) {
- return BigDecimal.valueOf(((Boolean) value).booleanValue() ? 1 : 0);
- }
- if (c == Character.class) {
- return BigDecimal.valueOf(((Character) value).charValue());
- }
- return new BigDecimal(value.toString().trim());
- }
- }
}
diff --git a/framework/src/org/apache/click/util/PropertyUtils.java b/framework/src/org/apache/click/util/PropertyUtils.java
index a4f3382..55277da 100644
--- a/framework/src/org/apache/click/util/PropertyUtils.java
+++ b/framework/src/org/apache/click/util/PropertyUtils.java
@@ -18,12 +18,13 @@
*/
package org.apache.click.util;
+import java.io.Serializable;
import java.lang.reflect.Method;
+import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import ognl.Ognl;
-import ognl.OgnlException;
+import org.mvel2.MVEL;
/**
* Provide property getter and setter utility methods.
@@ -31,11 +32,13 @@
@SuppressWarnings("unchecked")
public class PropertyUtils {
- /** Provides a synchronized cache of OGNL expressions. */
- private static final Map<String, Object> OGNL_EXPRESSION_CACHE = new ConcurrentHashMap<String, Object>();
-
/** Provides a synchronized cache of get value reflection methods. */
- private static final Map<String, Object> GET_METHOD_CACHE = new ConcurrentHashMap<String, Object>();
+ private static final Map<String, Object> GET_METHOD_CACHE
+ = new ConcurrentHashMap<String, Object>();
+
+ /** Provides a synchronized cache of MVEL expressions. */
+ private static final Map<String, Serializable> MVEL_EXPRESSION_CACHE
+ = new ConcurrentHashMap<String, Serializable>();
// -------------------------------------------------------- Public Methods
@@ -121,56 +124,28 @@
}
/**
- * Return the property value for the given object and property name using
- * the OGNL library.
- * <p/>
- * This method is thread-safe, and caches parsed OGNL expressions in an
- * internal synchronized cache.
- *
- * @param source the source object
- * @param name the name of the property
- * @param context the OGNL context, do NOT modify this object
- * @return the property value for the given source object and property name
- * @throws OgnlException if an OGN error occurs
- */
- public static Object getValueOgnl(Object source, String name, Map context)
- throws OgnlException {
-
- Object expression = OGNL_EXPRESSION_CACHE.get(name);
- if (expression == null) {
- expression = Ognl.parseExpression(name);
- OGNL_EXPRESSION_CACHE.put(name, expression);
- }
-
- return Ognl.getValue(expression, context, source);
- }
-
- /**
- * Return the property value for the given object and property name using
- * the OGNL library.
- * <p/>
- * This method is thread-safe, and caches parsed OGNL expressions in an
- * internal synchronized cache.
+ * Return the property value for the given object and property name using the MVEL library.
*
* @param target the target object to set the property of
* @param name the name of the property to set
* @param value the property value to set
- * @param context the OGNL context, do NOT modify this object
- * @throws OgnlException if an OGN error occurs
*/
- public static void setValueOgnl(Object target, String name, Object value, Map context)
- throws OgnlException {
+ public static void setValue(Object target, String name, Object value) {
- Object expression = OGNL_EXPRESSION_CACHE.get(name);
- if (expression == null) {
- expression = Ognl.parseExpression(name);
- OGNL_EXPRESSION_CACHE.put(name, expression);
+ String expression = target.getClass().getSimpleName() + "." + name + " = value";
+
+ Serializable compiledExpression = MVEL_EXPRESSION_CACHE.get(expression);
+
+ if (compiledExpression == null) {
+ compiledExpression = MVEL.compileExpression(expression);
+ MVEL_EXPRESSION_CACHE.put(expression, compiledExpression);
}
- Ognl.setValue(expression,
- context,
- target,
- value);
+ Map vars = new HashMap();
+ vars.put(target.getClass().getSimpleName(), target);
+ vars.put("value", value);
+
+ MVEL.executeExpression(compiledExpression, vars);
}
// -------------------------------------------------------- Private Methods
diff --git a/framework/src/org/apache/click/util/RequestTypeConverter.java b/framework/src/org/apache/click/util/RequestTypeConverter.java
deleted file mode 100644
index 9cbc7ff..0000000
--- a/framework/src/org/apache/click/util/RequestTypeConverter.java
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, 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.click.util;
-
-import java.lang.reflect.Array;
-import java.lang.reflect.Member;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.util.Map;
-
-import org.apache.commons.lang.Validate;
-
-import ognl.OgnlOps;
-import ognl.OgnlRuntime;
-import ognl.TypeConverter;
-
-/**
- * Provides an request parameter OGNL TypeConverter class.
- * <p/>
- * This class is adapted from the OGNL <tt>DefaultTypeConverter</tt>, by
- * Luke Blanshard and Drew Davidson, and provides additional Date conversion
- * capabilities.
- */
-public class RequestTypeConverter implements TypeConverter {
-
- // --------------------------------------------------------- Public Methods
-
- /**
- * Converts the given value to a given type. The OGNL context, target,
- * member and name of property being set are given. This method should be
- * able to handle conversion in general without any context, target, member
- * or property name specified.
- *
- * @param context OGNL context under which the conversion is being done
- * @param target target object in which the property is being set
- * @param member member (Constructor, Method or Field) being set
- * @param propertyName property name being set
- * @param value value to be converted
- * @param toType type to which value is converted
- * @return Converted value of type toType or TypeConverter.NoConversionPossible
- * to indicate that the conversion was not possible.
- */
- @SuppressWarnings("unchecked")
- public Object convertValue(Map context, Object target, Member member,
- String propertyName, Object value, Class toType) {
-
- return convertValue(value, toType);
- }
-
- // ------------------------------------------------------ Protected Methods
-
- /**
- * Return the converted value for the given value object and target type.
- *
- * @param value the value object to convert
- * @param toType the target class type to convert the value to
- * @return a converted value into the specified type
- */
- protected Object convertValue(Object value, Class<?> toType) {
- Object result = null;
-
- if (value != null) {
-
- // If array -> array then convert components of array individually
- if (value.getClass().isArray() && toType.isArray()) {
- Class<?> componentType = toType.getComponentType();
-
- result =
- Array.newInstance(componentType, Array.getLength(value));
-
- for (int i = 0, icount = Array.getLength(value); i < icount; i++) {
- Array.set(result,
- i,
- convertValue(Array.get(value, i),
- componentType));
- }
-
- } else {
- if ((toType == Integer.class) || (toType == Integer.TYPE)) {
- result = Integer.valueOf((int) OgnlOps.longValue(value));
-
- } else if ((toType == Double.class) || (toType == Double.TYPE)) {
- result = new Double(OgnlOps.doubleValue(value));
-
- } else if ((toType == Boolean.class) || (toType == Boolean.TYPE)) {
- result = Boolean.valueOf(value.toString());
-
- } else if ((toType == Byte.class) || (toType == Byte.TYPE)) {
- result = Byte.valueOf((byte) OgnlOps.longValue(value));
-
- } else if ((toType == Character.class) || (toType == Character.TYPE)) {
- result = Character.valueOf((char) OgnlOps.longValue(value));
-
- } else if ((toType == Short.class) || (toType == Short.TYPE)) {
- result = Short.valueOf((short) OgnlOps.longValue(value));
-
- } else if ((toType == Long.class) || (toType == Long.TYPE)) {
- result = Long.valueOf(OgnlOps.longValue(value));
-
- } else if ((toType == Float.class) || (toType == Float.TYPE)) {
- result = new Float(OgnlOps.doubleValue(value));
-
- } else if (toType == BigInteger.class) {
- result = OgnlOps.bigIntValue(value);
-
- } else if (toType == BigDecimal.class) {
- result = bigDecValue(value);
-
- } else if (toType == String.class) {
- result = OgnlOps.stringValue(value);
-
- } else if (toType == java.util.Date.class) {
- long time = getTimeFromDateString(value.toString());
- if (time > Long.MIN_VALUE) {
- result = new java.util.Date(time);
- }
-
- } else if (toType == java.sql.Date.class) {
- long time = getTimeFromDateString(value.toString());
- if (time > Long.MIN_VALUE) {
- result = new java.sql.Date(time);
- }
-
- } else if (toType == java.sql.Time.class) {
- long time = getTimeFromDateString(value.toString());
- if (time > Long.MIN_VALUE) {
- result = new java.sql.Time(time);
- }
-
- } else if (toType == java.sql.Timestamp.class) {
- long time = getTimeFromDateString(value.toString());
- if (time > Long.MIN_VALUE) {
- result = new java.sql.Timestamp(time);
- }
- }
- }
-
- } else {
- if (toType.isPrimitive()) {
- result = OgnlRuntime.getPrimitiveDefaultValue(toType);
- }
- }
- return result;
- }
-
- /**
- * Return the time value in milliseconds of the given date value string,
- * or Long.MIN_VALUE if the date could not be determined.
- *
- * @param value the date value string
- * @return the time value in milliseconds or Long.MIN_VALUE if not determined
- */
- protected long getTimeFromDateString(String value) {
- Validate.notNull(value, "Null value string");
-
- value = value.trim();
-
- if (value.length() == 0) {
- return Long.MIN_VALUE;
- }
-
- if (isTimeValue(value)) {
- return Long.parseLong(value);
- }
-
- java.util.Date date = createDateFromSqlString(value);
- if (date != null) {
- return date.getTime();
- }
-
- try {
- DateFormat format = DateFormat.getDateInstance();
-
- date = format.parse(value);
-
- return date.getTime();
-
- } catch (ParseException pe) {
- return Long.MIN_VALUE;
- }
- }
-
- /**
- * Return true if the given string value is a long time value.
- *
- * @param value the string value to test
- * @return true if the given string value is a long time value.
- */
- protected boolean isTimeValue(String value) {
- for (int i = 0, size = value.length(); i < size; i++) {
- char aChar = value.charAt(i);
- if (i == 0) {
- if (!Character.isDigit(aChar) && aChar != '-') {
- return false;
- }
- } else {
- if (!Character.isDigit(aChar)) {
- return false;
- }
- }
- }
- return true;
- }
-
- /**
- * Return a new date object from the give SQL format date string, or null
- * if the value is invalid.
- *
- * @param value the SQL format date string
- * @return a new date object from the give SQL format date string
- */
- protected java.util.Date createDateFromSqlString(String value) {
- if (value.length() != 10) {
- return null;
- }
-
- for (int i = 0, size = value.length(); i < size; i++) {
- char aChar = value.charAt(i);
- if (!Character.isDigit(aChar) && aChar != '-') {
- return null;
- }
- }
-
- int firstDash = value.indexOf('-');
- int secondDash = value.indexOf('-', firstDash + 1);
-
- if ((firstDash > 0)
- & (secondDash > 0)
- & (secondDash < value.length() - 1)) {
-
- try {
- int year = Integer.parseInt(value.substring(0, firstDash)) - 1900;
-
- int month = Integer.parseInt(value.substring(firstDash + 1, secondDash)) - 1;
-
- int day = Integer.parseInt(value.substring(secondDash + 1));
-
- return new java.util.Date(year, month, day);
-
- } catch (NumberFormatException nfe) {
- return null;
- }
-
- } else {
- return null;
- }
- }
-
- /**
- * Convert the given value into a BigDecimal.
- *
- * @param value the object to convert into a BigDecimal
- * @return the converted BigDecimal value
- */
- private BigDecimal bigDecValue(Object value) {
- if (value == null) {
- return BigDecimal.valueOf(0L);
- }
- Class<?> c = value.getClass();
- if (c == BigDecimal.class) {
- return (BigDecimal) value;
- }
- if (c == BigInteger.class) {
- return new BigDecimal((BigInteger) value);
- }
-
- if (c == Boolean.class) {
- return BigDecimal.valueOf(((Boolean) value).booleanValue() ? 1 : 0);
- }
- if (c == Character.class) {
- return BigDecimal.valueOf(((Character) value).charValue());
- }
-
- return new BigDecimal(value.toString().trim());
- }
-}
diff --git a/framework/test/org/apache/click/util/RequestTypeConverterTest.java b/framework/test/org/apache/click/util/RequestTypeConverterTest.java
deleted file mode 100644
index a3ea59c..0000000
--- a/framework/test/org/apache/click/util/RequestTypeConverterTest.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, 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.click.util;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Locale;
-import junit.framework.TestCase;
-
-/**
- * Tests for RequestTypeConverter.
- */
-public class RequestTypeConverterTest extends TestCase {
-
- /**
- * Sanity checks for RequestTypeConverter.
- */
- public void test() {
- RequestTypeConverter rtc = new RequestTypeConverter();
- assertEquals("true", rtc.convertValue("true", Boolean.class).toString());
- assertEquals("false", rtc.convertValue("false", Boolean.class).toString());
-
- assertNull(rtc.convertValue(null, java.util.Date.class));
- assertNull(rtc.convertValue(null, java.sql.Date.class));
- assertNull(rtc.convertValue(null, java.sql.Time.class));
- assertNull(rtc.convertValue(null, java.sql.Timestamp.class));
-
- assertNull(rtc.convertValue(" ", java.util.Date.class));
- assertNull(rtc.convertValue(" ", java.sql.Date.class));
- assertNull(rtc.convertValue(" ", java.sql.Time.class));
- assertNull(rtc.convertValue(" ", java.sql.Timestamp.class));
-
- assertNull(rtc.convertValue("a", java.util.Date.class));
- assertNull(rtc.convertValue("a", java.sql.Date.class));
- assertNull(rtc.convertValue("a", java.sql.Time.class));
- assertNull(rtc.convertValue("a", java.sql.Timestamp.class));
-
- // TODO: MS test needs to account for daylight savings and other factors
- String timeValue = "1166878800000";
-
- String sqlValue = "2006-12-24";
-
- // Set default Locale to Australia so that formatting date in the
- // format dd/MM/yyyy works
- Locale.setDefault(new Locale("en", "AU"));
- String localValue = "24/12/2006";
-
- java.util.Date date1 = (java.util.Date) rtc.convertValue(timeValue, java.util.Date.class);
- java.util.Date date2 = (java.util.Date) rtc.convertValue(sqlValue, java.util.Date.class);
- java.util.Date date3 = (java.util.Date) rtc.convertValue(localValue, java.util.Date.class);
-
- assertNotNull(date1);
- assertNotNull(date2);
- assertNotNull(date3);
-// assertEquals(date1, date2);
- assertEquals(date2, date3);
-
- java.sql.Date date4 = (java.sql.Date) rtc.convertValue(timeValue, java.sql.Date.class);
- java.sql.Date date5 = (java.sql.Date) rtc.convertValue(sqlValue, java.sql.Date.class);
- java.sql.Date date6 = (java.sql.Date) rtc.convertValue(localValue, java.sql.Date.class);
-
- assertNotNull(date4);
- assertNotNull(date5);
- assertNotNull(date6);
-// assertEquals(date4, date5);
- assertEquals(date5, date6);
-
- java.sql.Time date7 = (java.sql.Time) rtc.convertValue(timeValue, java.sql.Time.class);
- java.sql.Time date8 = (java.sql.Time) rtc.convertValue(sqlValue, java.sql.Time.class);
- java.sql.Time date9 = (java.sql.Time) rtc.convertValue(localValue, java.sql.Time.class);
-
- assertNotNull(date7);
- assertNotNull(date8);
- assertNotNull(date9);
-// assertEquals(date7, date8);
- assertEquals(date8, date9);
-
- java.sql.Timestamp date10 = (java.sql.Timestamp) rtc.convertValue(timeValue, java.sql.Timestamp.class);
- java.sql.Timestamp date11 = (java.sql.Timestamp) rtc.convertValue(sqlValue, java.sql.Timestamp.class);
- java.sql.Timestamp date12 = (java.sql.Timestamp) rtc.convertValue(localValue, java.sql.Timestamp.class);
-
- assertNotNull(date10);
- assertNotNull(date11);
- assertNotNull(date12);
-// assertEquals(date10, date11);
- assertEquals(date11, date12);
- }
-
- /**
- * Check that very large BigDecimal numbers are converted correctly.
- * CLK-694.
- */
- public void testLargeBigDecimalConvertion() {
- RequestTypeConverter rtc = new RequestTypeConverter();
-
- String requestParam = "9999999999999999999999999999999999999999999999999.99";
- BigDecimal bd = (BigDecimal) rtc.convertValue(requestParam, BigDecimal.class);
-
- assertEquals(requestParam, bd.toString());
- }
-
- /**
- * Check that very large BigInteger numbers are converted correctly.
- */
- public void testLargeBigIntegerConvertion() {
- RequestTypeConverter rtc = new RequestTypeConverter();
-
- String requestParam = "99999999999999999999999999999999999999999999999";
- BigInteger bi = (BigInteger) rtc.convertValue(requestParam, BigInteger.class);
- assertEquals(requestParam, bi.toString());
- }
-}