Author: dolander
Date: Tue Nov 16 13:29:52 2004
New Revision: 76040
Added:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/IdMapper.java
Modified:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/ProcessPopulate.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/IHtmlIdWriter.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlBaseTag.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlDataSourceTag.java
incubator/beehive/trunk/netui/src/util/schema/netui-config.xsd
Log:
Checkpoint on the Id Transparency. Move the core code into the IdMapper class.
Add support to the form for writing out the Base64 encoded map.
Add support to process populate to look for the map and use it if present
Stub in support for configuration of the feature
This feature is off at the moment
Added:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/IdMapper.java
==============================================================================
--- (empty file)
+++
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/IdMapper.java
Tue Nov 16 13:29:52 2004
@@ -0,0 +1,83 @@
+package org.apache.beehive.netui.pageflow;
+
+import org.apache.xmlbeans.impl.util.Base64;
+
+import javax.servlet.ServletContext;
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+
+public class IdMapper
+{
+ private StringBuilder _idString;
+ private static final String SPLIT = "\0";
+ private static final String CHARSET = "ISO-8859-1";
+
+ /**
+ * Web.xml initialization parameter for attribute transparency
+ */
+ private static final String ID_TRANSPARENCY = "netui.ID_TRANSPARENCY";
+ private static Boolean _transparent = Boolean.FALSE;
+
+
+ public static boolean isIdTransparency(ServletContext ctxt)
+ {
+ if (_transparent != null)
+ return _transparent.booleanValue();
+
+ String s = ctxt.getInitParameter(ID_TRANSPARENCY);
+ System.err.println("Id Transparency:" + s);
+ _transparent = new Boolean(s);
+ return _transparent.booleanValue();
+ }
+
+ public static HashMap getExpressionMap(String expressions) {
+ assert(expressions != null) : "Parameter 'expressions' must not be
null";
+
+ try {
+ String ex = new
String(Base64.decode(expressions.getBytes(CHARSET)),CHARSET);
+ String[] expr = ex.split(SPLIT);
+ assert((expr.length % 2) == 0) : "Verify that there is an even
number of values failed";
+ HashMap map = new HashMap(expr.length * 2 + 3);
+ for (int i=1;i<expr.length;i+=2) {
+ map.put(expr[i-1],expr[i]);
+ }
+ return map;
+ }
+ catch (UnsupportedEncodingException ex) {
+ System.err.println("Unexpected Exception:" + ex);
+ }
+ return null;
+
+ }
+
+ public String writeId(String id, String expression)
+ {
+ if (!_transparent.booleanValue())
+ return expression;
+
+ if (_idString == null)
+ _idString = new StringBuilder(64);
+
+ if (_idString.length() > 0)
+ _idString.append(SPLIT);
+ _idString.append(id);
+ _idString.append(SPLIT);
+ _idString.append(expression);
+ return id;
+ }
+
+ public String getExpressions() {
+ String nameExpressions = _idString.toString();
+ try {
+ byte[] bytes = nameExpressions.getBytes(CHARSET);
+ String encoded = new String(Base64.encode(bytes), CHARSET);
+ return encoded;
+ }
+ catch (UnsupportedEncodingException ex) {
+ System.err.println("Unexpected Exception:" + ex);
+
+ }
+ return null;
+
+ }
+}
Modified:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/ProcessPopulate.java
==============================================================================
---
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/ProcessPopulate.java
(original)
+++
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/ProcessPopulate.java
Tue Nov 16 13:29:52 2004
@@ -18,30 +18,24 @@
package org.apache.beehive.netui.pageflow;
// java imports
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-// internal imports
+import org.apache.beehive.netui.pageflow.internal.InternalUtils;
import org.apache.beehive.netui.script.Expression;
-import org.apache.beehive.netui.script.ExpressionEvaluatorFactory;
import org.apache.beehive.netui.script.ExpressionEvaluator;
+import org.apache.beehive.netui.script.ExpressionEvaluatorFactory;
import org.apache.beehive.netui.script.ExpressionUpdateException;
-import org.apache.beehive.netui.script.common.ImplicitObjectUtil;
import org.apache.beehive.netui.script.common.ImplicitObjectBean;
-
+import org.apache.beehive.netui.script.common.ImplicitObjectUtil;
import org.apache.beehive.netui.util.Bundle;
import org.apache.beehive.netui.util.logging.Logger;
-import org.apache.beehive.netui.pageflow.internal.InternalUtils;
-
-// external imports
-import org.apache.struts.upload.MultipartRequestHandler;
-import org.apache.struts.action.ActionForm;
import org.apache.commons.beanutils.BeanUtils;
+import org.apache.struts.action.ActionForm;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
/**
* Implement the processPopulate stage of the Struts / PageFlow request
@@ -58,6 +52,11 @@
*/
public class ProcessPopulate
{
+ /**
+ * This defines the name of the parameter that will contain the NetUI ID
map..
+ */
+ public static final String IDMAP_PARAMETER_NAME = "netuiIdMap";
+
private static final Logger _logger =
Logger.getInstance(ProcessPopulate.class);
// these must be kept in sync with the context names specified in the
scripting languages
@@ -168,6 +167,7 @@
boolean isMultipart = false;
// if this returns null, it's not a mulitpart request
+ HashMap expressionMap = null;
Map params = MultipartRequestUtils.handleMultipartRequest(request,
form);
// make adjustments
@@ -184,32 +184,50 @@
// only needs to happen once; all of the objects herein are stable
ImplicitObjectBean bean =
ImplicitObjectUtil.getImplicitObjects(request, response, form);
+ String[] idMap = (String[]) params.get(IDMAP_PARAMETER_NAME);
+ if (idMap != null) {
+ expressionMap = IdMapper.getExpressionMap(idMap[0]);
+ }
+
// TODO: are there any ordering issues with using an Iterator vs. an
Enumeration here?
Iterator iterator = params.keySet().iterator();
while (iterator.hasNext())
{
key = (String) iterator.next();
+ String expr = null;
+
+ // if there is an expression map, lookup the real expression from
the name
+ if (expressionMap != null) {
+ expr = (String) expressionMap.get(key);
+ if (expr == null)
+ expr = key;
+ }
+ else {
+ expr = key;
+ }
+ //System.err.println("Expr: '" + expr + "' key: '" + key + "'");
if (_logger.isDebugEnabled())
_logger.debug("key: " + key + " value type: " +
params.get(key).getClass().getName() + " value: " + params.get(key));
try
{
- if (ee.containsExpression(key))
+ Object paramsValue = params.get(key);
+ if (ee.containsExpression(expr))
{
Object updateValue = null;
- if (!isMultipart || params.get(key) instanceof String[])
+ if (!isMultipart || paramsValue instanceof String[])
{
- String[] values = (String[]) params.get(key);
+ String[] values = (String[]) paramsValue;
// the only "contains" case that is accepted
- if (key.startsWith(WLW_TAG_HANDLER_PREFIX))
+ if (expr.startsWith(WLW_TAG_HANDLER_PREFIX))
{
if (_logger.isDebugEnabled()) _logger.debug("Found
an expression requiring a TAG HANDLER");
- ExpressionUpdateNode node = doTagHandler(key,
values, request);
+ ExpressionUpdateNode node = doTagHandler(expr,
values, request);
- key = node.expression;
+ expr = node.expression;
values = node.values;
}
@@ -227,32 +245,32 @@
try
{
// trap any bad expressions here
- if (ee.isExpression(key))
+ if (ee.isExpression(expr))
{
// common case, make this fast
if (!requestHasPopulated)
- ee.update(key, updateValue, bean, true);
+ ee.update(expr, updateValue, bean, true);
// must check the expression to make sure
pageFlow. and globalApp. don't get executed more than once
else
{
- Expression pe = ee.parseExpression(key);
+ Expression pe = ee.parseExpression(expr);
String contextName = pe.getContext();
if (!contextName.equals(PAGE_FLOW_CONTEXT) &&
!contextName.equals(GLOBAL_APP_CONTEXT))
- ee.update(key, updateValue, bean, true);
+ ee.update(expr, updateValue, bean, true);
}
}
}
// catch any errors, particularly expression parse
failures
catch (ExpressionUpdateException e)
{
- String s = Bundle.getString("ExprUpdateError", new
Object[]{key, e});
+ String s = Bundle.getString("ExprUpdateError", new
Object[]{expr, e});
// this is the hairy NetUI Warning that gets printed
to the console
System.err.println(s);
if (_logger.isErrorEnabled()) _logger.error(s);
// add binding errors via PageFlowUtils
- InternalUtils.addBindingUpdateError(request, key, s,
e);
+ InternalUtils.addBindingUpdateError(request, expr, s,
e);
}
}
else
@@ -262,20 +280,20 @@
if (strutsProperties == null)
strutsProperties = new HashMap();
- strutsProperties.put(key, params.get(key));
+ strutsProperties.put(key, paramsValue);
}
}
// catch any unexpected exception
catch (Exception e)
{
- String s = Bundle.getString("ProcessPopulate_exprUpdateError",
new Object[]{key, e});
+ String s = Bundle.getString("ProcessPopulate_exprUpdateError",
new Object[]{expr, e});
System.err.println(s);
if (_logger.isWarnEnabled()) _logger.warn(s, e);
// add binding errors via PageFlowUtils
- InternalUtils.addBindingUpdateError(request, key, s, e);
+ InternalUtils.addBindingUpdateError(request, expr, s, e);
}
}
@@ -287,8 +305,7 @@
*
* @param key the request key that is being processed
* @param request the ServletRequest object representing this request
- * @throws ExpressionUpdateException if the expression update fails
- */
+ */
static final ExpressionUpdateNode doTagHandler(String key, String[]
values, HttpServletRequest request)
{
// not sure if this array will be mutable. don't want to find out at
this point.
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/IHtmlIdWriter.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/IHtmlIdWriter.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/IHtmlIdWriter.java
Tue Nov 16 13:29:52 2004
@@ -19,8 +19,6 @@
public interface IHtmlIdWriter
{
-
- public final String ID_PARAMETER_NAME = "netuiIdMap";
public final String ID_PREFIX = "netui";
public final String ID_REQUEST_ATTRIBUTE = "netuiIdGenerator";
@@ -29,8 +27,9 @@
* written to the form as a set of hidden fields that will contain the id.
* @param id
* @param expression
+ * @return A String value representing the name
*/
- void writeId(String id, String expression);
+ String writeId(String id, String expression);
/**
* Return the next id
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
Tue Nov 16 13:29:52 2004
@@ -17,11 +17,7 @@
*/
package org.apache.beehive.netui.tags.html;
-import org.apache.beehive.netui.pageflow.FlowControllerFactory;
-import org.apache.beehive.netui.pageflow.PageFlowController;
-import org.apache.beehive.netui.pageflow.PageFlowUtils;
-import org.apache.beehive.netui.pageflow.SharedFlowController;
-import org.apache.beehive.netui.pageflow.FlowController;
+import org.apache.beehive.netui.pageflow.*;
import org.apache.beehive.netui.pageflow.internal.ContextCache;
import org.apache.beehive.netui.pageflow.internal.InternalUtils;
import org.apache.beehive.netui.pageflow.util.PageflowTagUtils;
@@ -38,7 +34,7 @@
import org.apache.struts.config.FormBeanConfig;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.taglib.html.Constants;
-import org.apache.struts.util.RequestUtils;
+import org.apache.xmlbeans.impl.util.Base64;
import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
@@ -48,6 +44,7 @@
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import java.util.*;
+import java.io.UnsupportedEncodingException;
/**
* This tag represents an input form, associated with a bean whose
@@ -214,7 +211,6 @@
private ActionMapping _mapping = null; // The ActionMapping
defining where we will be submitting this form
private ActionServlet _servlet = null; // The ActionServlet
instance we are associated with
private HashMap _focusMap;
- private ArrayList _idList = null;
private ModuleConfig _appConfig = null; // The application
configuration for our module.
private FlowController _flowController = null; // The flow controller
(page flow or shared flow).
private boolean _setRealName = false;
@@ -222,6 +218,7 @@
private Map _params;
private int _nextId;
+ private IdMapper _idMapper;
/**
* Return the name of the Tag.
@@ -531,12 +528,12 @@
* @param id
* @param expression
*/
- public void writeId(String id, String expression)
+ public String writeId(String id, String expression)
{
- if (_idList == null) {
- _idList = new ArrayList();
+ if (_idMapper == null) {
+ _idMapper = new IdMapper();
}
- _idList.add(id + "|" + expression);
+ return _idMapper.writeId(id,expression);
}
/**
@@ -782,15 +779,9 @@
ImplicitObjectUtil.unloadActionForm(pageContext);
// output the hidden fields for id transparency if this is turned on
- if (HtmlBaseTag.isIdTransparency(servletContext)) {
- if (_idList != null) {
- int cnt = _idList.size();
- for (int i = 0; i < cnt; i++) {
- writeHiddenParam(ID_PARAMETER_NAME, (String)
_idList.get(i), writer, request);
- }
- if (cnt > 0)
- write("\n");
- }
+ if (IdMapper.isIdTransparency(servletContext)) {
+ String encoded = _idMapper.getExpressions();
+ writeHiddenParam(ProcessPopulate.IDMAP_PARAMETER_NAME, encoded,
writer, request);
}
// Render a tag representing the end of our current form
@@ -866,8 +857,7 @@
_mapping = null;
_servlet = null;
_focusMap = null;
- if (_idList != null)
- _idList.clear();
+ _idMapper = null;
_appConfig = null;
_flowController = null;
_setRealName = false;
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlBaseTag.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlBaseTag.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlBaseTag.java
Tue Nov 16 13:29:52 2004
@@ -51,28 +51,11 @@
public static final String JAVASCRIPT_STATUS = "netui.javascript.status";
/**
- * Web.xml initialization parameter for attribute transparency
- */
- private static final String ID_TRANSPARENCY = "netui.ID_TRANSPARENCY";
- private static Boolean _transparent;
-
- /**
* This method will return the state associated with the tag. This is
used by this
* base class to access the individual state objects created by the tags.
* @return a subclass of the <code>AbstractHtmlState</code> class.
*/
abstract protected AbstractHtmlState getState();
-
- public static boolean isIdTransparency(ServletContext ctxt)
- {
- if (_transparent != null)
- return _transparent.booleanValue();
-
- String s = ctxt.getInitParameter(ID_TRANSPARENCY);
- System.err.println("Id Transparency:" + s);
- _transparent = new Boolean(s);
- return _transparent.booleanValue();
- }
//***************************** The IHtmlCore properties
*********************************/
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlDataSourceTag.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlDataSourceTag.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlDataSourceTag.java
Tue Nov 16 13:29:52 2004
@@ -125,7 +125,7 @@
if (id == null) {
id = idWriter.getNextId();
}
- idWriter.writeId(id, name);
+ name = idWriter.writeId(id, name);
}
return name;
Modified: incubator/beehive/trunk/netui/src/util/schema/netui-config.xsd
==============================================================================
--- incubator/beehive/trunk/netui/src/util/schema/netui-config.xsd
(original)
+++ incubator/beehive/trunk/netui/src/util/schema/netui-config.xsd Tue Nov
16 13:29:52 2004
@@ -79,6 +79,7 @@
<xsd:complexType name="jsp-tag-config">
<xsd:sequence>
<xsd:element name="doctype" type="xsd:string" minOccurs="0"
maxOccurs="1"/>
+ <xsd:element name="id-transparency" type="xsd:boolean"
minOccurs="0" maxOccurs="1" default="false"/>
</xsd:sequence>
</xsd:complexType>