You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by mr...@apache.org on 2005/08/26 07:46:58 UTC
svn commit: r240168 [19/30] - in /struts/sandbox/trunk/ti: ./
core/src/java/org/apache/ti/ core/src/java/org/apache/ti/config/
core/src/java/org/apache/ti/config/mapper/
core/src/java/org/apache/ti/core/ core/src/java/org/apache/ti/core/factory/
core/s...
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/BundleMap.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/BundleMap.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/BundleMap.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/BundleMap.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,375 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.script.common;
+
+import org.apache.ti.script.common.bundle.BundleNode;
+
+/**
+ * Provide a {@link java.util.Map} of {@link org.apache.ti.script.common.BundleMap.BundleNodeMap} objects that can
+ * expose various implementations of {@link BundleNode} to
+ * expression languages. <p/> This {@link java.util.Map} implementation is
+ * optimized for read as the entrySet() is created lazily. In addition, the
+ * entrySet does not contain all possible BundleNodeMap objects as named
+ * "message-resources" bundles are discovered at runtime and requested by name.
+ * <p/>
+ */
+public class BundleMap {
+
+// extends AbstractScriptableMap {
+//
+// public static final String DEFAULT_STRUTS_BUNDLE_NAME = "default";
+//
+// private static final Logger LOGGER = Logger.getInstance(BundleMap.class);
+//
+// private HashMap _registeredBundles = null;
+//
+// private HttpServletRequest _servletRequest = null;
+// private HttpSession _httpSession = null;
+// private ServletContext _servletContext = null;
+//
+// /**
+// * Create a BundleMap object that is used for data binding to resource
+// * bundles.
+// *
+// * @param servletRequest the current {@link javax.servlet.http.HttpServletRequest} object
+// * @param servletContext a {@link javax.servlet.ServletContext} object that facilitates binding to resource bundles
+// * declared in Struts modules
+// */
+// public BundleMap(HttpServletRequest servletRequest, ServletContext servletContext) {
+// assert servletRequest != null;
+// assert servletContext != null;
+//
+// _servletRequest = servletRequest;
+// _httpSession = servletRequest.getSession(false);
+// _servletContext = servletContext;
+//
+// _registeredBundles = new HashMap();
+// }
+//
+// public void registerResourceBundle(String name, String resourcePath, Locale forcedLocale) {
+// if(_registeredBundles == null)
+// _registeredBundles = new HashMap();
+//
+// if(LOGGER.isInfoEnabled() && _registeredBundles.containsKey(name))
+// LOGGER.info("The bundle map already contains a key \"" + name + "\" overwriting the previous value.");
+//
+// Locale locale = forcedLocale != null ? forcedLocale : InternalUtils.lookupLocale(_servletRequest);
+// ResourceBundle resourceBundle = ResourceBundle.getBundle(resourcePath, locale);
+// BundleNode bundle = BundleNodeFactory.getInstance().getResourceBundleNode(name, resourceBundle, locale);
+// _registeredBundles.put(name, bundle);
+// }
+//
+// public Object get(Object key) {
+// if(key == null)
+// throw new NullPointerException("Binding to a resource bundle does not accept a null key");
+//
+// BundleNodeMap map = lookupScriptableBundle(key.toString());
+// if(map == null) {
+// /* handleBundleNotFound will throw an exception when the message key isn't found */
+// handleBundleNotFound(key.toString());
+// return null;
+// }
+// else return map;
+// }
+//
+// /**
+// * Implementation of Map.containsKey for the bundle implicit object.
+// *
+// * This method is required by JSP 2.0 EL and performs the lookups of the
+// * various available bundles which have been registered either explicitly or
+// * implicitly.
+// *
+// * @param key The name of a bundle to lookup
+// * @return <code>true</code> if the bundle is available; <code>false</code> otherwise
+// */
+// public boolean containsKey(Object key) {
+// if(key == null)
+// throw new NullPointerException("Binding to a resource bundle does not accept a null key");
+//
+// BundleNodeMap map = lookupScriptableBundle(key.toString());
+// return map != null;
+// }
+//
+// public Set entrySet() {
+// ArrayList entries = new ArrayList();
+//
+// /* add BundleNode objects that have been accessed */
+// if(_registeredBundles != null) {
+// Iterator iterator = _registeredBundles.keySet().iterator();
+// while(iterator.hasNext()) {
+// Object key = iterator.next();
+// entries.add(new BundleNodeEntry(key));
+// }
+// }
+//
+// MessageResources resources = null;
+//
+// resources = lookupDefaultStrutsBundle();
+// if(resources != null)
+// entries.add(new BundleNodeEntry(DEFAULT_STRUTS_BUNDLE_NAME));
+//
+// ModuleConfig moduleConfig = lookupCurrentModuleConfig();
+// if(moduleConfig != null) {
+// MessageResourcesConfig[] mrs = moduleConfig.findMessageResourcesConfigs();
+// for(int i = 0; i < mrs.length; i++) {
+// String resourceKey = mrs[i].getKey() + moduleConfig.getPrefix();
+// resources = lookupStrutsBundle(resourceKey);
+// entries.add(new BundleNodeEntry(mrs[i].getKey()));
+// }
+// }
+//
+// return new EntrySet((Entry[])entries.toArray(new Entry[] {}));
+// }
+//
+// /*
+// */
+// private BundleNodeMap lookupScriptableBundle(String name) {
+// BundleNodeMap map = null;
+//
+// /* check to see if the bundle was explicitly registered */
+// if(_registeredBundles != null && _registeredBundles.containsKey(name)) {
+// map = new BundleNodeMap(name, (BundleNode)_registeredBundles.get(name));
+// }
+// else if(name.equals(DEFAULT_STRUTS_BUNDLE_NAME)) {
+// MessageResources resources = lookupDefaultStrutsBundle();
+// if(resources != null) {
+// BundleNode bundleNode = BundleNodeFactory.getInstance().getStrutsBundleNode(name, resources, retrieveUserLocale());
+// map = new BundleNodeMap(name, bundleNode);
+// }
+// }
+// else if(_servletContext.getAttribute(name) != null) {
+// MessageResources resources = lookupStrutsBundle(name);
+// if(resources != null) {
+// BundleNode bundleNode = BundleNodeFactory.getInstance().getStrutsBundleNode(name, resources, retrieveUserLocale());
+// map = new BundleNodeMap(name, bundleNode);
+// }
+// }
+// else {
+// ModuleConfig moduleConfig = lookupCurrentModuleConfig();
+// if(moduleConfig != null) {
+// MessageResourcesConfig[] mrs = moduleConfig.findMessageResourcesConfigs();
+// if(mrs != null) {
+// for(int i = 0; i < mrs.length; i++) {
+// /* skip the default bundle */
+// if(mrs[i].getKey().equals(Globals.MESSAGES_KEY))
+// continue;
+// else if(mrs[i].getKey().equals(name)) {
+// String resourceKey = mrs[i].getKey() + moduleConfig.getPrefix();
+// MessageResources resources = lookupStrutsBundle(resourceKey);
+// BundleNode bundleNode = BundleNodeFactory.getInstance().getStrutsBundleNode(name, resources, retrieveUserLocale());
+// map = new BundleNodeMap(name, bundleNode);
+// break;
+// }
+// }
+// }
+// }
+// }
+//
+// return map;
+// }
+//
+// /**
+// * Lookup the "default" resource bundle for the current Struts module.
+// *
+// * @return a MessageResources object if a "default" bundle exists.
+// * <code>null</code> otherwise
+// */
+// private MessageResources lookupDefaultStrutsBundle() {
+// Object value = _servletRequest.getAttribute(Globals.MESSAGES_KEY);
+// if(value instanceof MessageResources)
+// return (MessageResources)value;
+// else {
+// if(value != null)
+// LOGGER.warn("Can not resolve the default module bundle."
+// + " The object resolved from the request is of type "
+// +(value != null ? value.getClass().toString() : "null"));
+// return null;
+// }
+// }
+//
+// /**
+// * Lookup a specific resource bundle for the current Struts module.
+// *
+// * @param name
+// * the name of the resource bundle to lookup
+// * @return a MessageResources object if a bundle matching the given name
+// * exists. <code>null</code> otherwise.
+// */
+// private MessageResources lookupStrutsBundle(String name) {
+// Object value = _servletContext.getAttribute(name);
+// if(value instanceof MessageResources)
+// return (MessageResources)value;
+// else {
+// if(value != null)
+// LOGGER.warn("Can not resolve module bundle with name \"" + name
+// + "\". The object resolved from ServletContext is of type "
+// +(value != null ? value.getClass().toString() : "null"));
+// return null;
+// }
+// }
+//
+// private final ModuleConfig lookupCurrentModuleConfig() {
+// return (ModuleConfig)_servletRequest.getAttribute(Globals.MODULE_KEY);
+// }
+//
+// private void handleBundleNotFound(String name) {
+//
+// /* At this point, no message bundle could be found. Throw an error that contains a
+// descriptive message about the bundles that are available
+// */
+// String registeredBundles = formatBundleNames(createBundleList());
+// String strutsBundles = formatBundleNames(createStrutsBundleList());
+//
+// String msg = "The bundle named \"" + name + "\" was not found in the list of registered bundles with names "
+// + registeredBundles + " or implicit bundle names " + strutsBundles + ".";
+//
+// LOGGER.error(msg);
+// throw new RuntimeException(msg);
+// }
+//
+// private final String formatBundleNames(String[] names) {
+// InternalStringBuilder sb = new InternalStringBuilder(128);
+// sb.append("[");
+// for(int i = 0; i < names.length; i++) {
+// if(i > 0)
+// sb.append(", ");
+// sb.append(names[i]);
+// }
+// sb.append("]");
+//
+// return sb.toString();
+// }
+//
+// private final String[] createBundleList() {
+// String[] names = null;
+// if(_registeredBundles != null) {
+// names = new String[_registeredBundles.size()];
+// Iterator iterator = _registeredBundles.keySet().iterator();
+// for(int i = 0; iterator.hasNext(); i++) {
+// names[i] = iterator.next().toString();
+// }
+// }
+//
+// return names;
+// }
+//
+// private final String[] createStrutsBundleList() {
+// String[] names = null;
+// ModuleConfig config = lookupCurrentModuleConfig();
+// if(config != null) {
+// MessageResourcesConfig[] mrs = config.findMessageResourcesConfigs();
+// names = new String[mrs.length];
+// if(mrs != null) {
+// for(int i = 0; i < mrs.length; i++) {
+// if(mrs[i].getKey().equals(Globals.MESSAGES_KEY))
+// names[i] = DEFAULT_STRUTS_BUNDLE_NAME;
+// else names[i] = mrs[i].getKey() + config.getPrefix();
+// }
+// }
+// }
+// return names;
+// }
+//
+// /**
+// * Utility method that discovers the {@link java.util.Locale} for the
+// * current request.
+// *
+// * @return the {@link java.util.Locale} to use when looking-up strings while data binding to resource bundles
+// */
+// private final Locale retrieveUserLocale() {
+// return InternalUtils.lookupLocale(_servletRequest);
+// }
+//
+// final class BundleNodeEntry
+// extends Entry
+// {
+// BundleNodeEntry(Object key) {
+// super(key, null);
+// }
+//
+// public Object getValue() {
+// assert getKey() instanceof String;
+//
+// String key = (String)getKey();
+// return lookupScriptableBundle(key);
+// }
+// }
+//
+// /**
+// * Provide a {@link java.util.Map} implementation that exposes a
+// * {@link org.apache.ti.script.common.bundle.BundleNode}
+// * object to an expression language as a Map. Access to the values in the
+// * map is by key and depends on the implementation of the BundleNode. <p/>
+// * Access is read optimized and the complete entrySet() is only constructed
+// * when needed.
+// */
+// final class BundleNodeMap
+// extends AbstractScriptableMap {
+//
+// private String _propertiesName = null;
+// private BundleNode _bundle = null;
+// private Set _entrySet = null;
+//
+// BundleNodeMap(String propertiesName, BundleNode bundle) {
+// assert bundle != null;
+// assert propertiesName != null;
+//
+// _bundle = bundle;
+// _propertiesName = propertiesName;
+// }
+//
+// public Set entrySet() {
+// if(_entrySet == null) {
+// ArrayList list = new ArrayList();
+// Enumeration enumeration = _bundle.getKeys();
+// while(enumeration.hasMoreElements()) {
+// String key =(String)enumeration.nextElement();
+// String msg = _bundle.getString(key);
+// list.add(new Entry(key, msg));
+// }
+// _entrySet = new EntrySet((Entry[])list.toArray(new Entry[] {}));
+// }
+//
+// return _entrySet;
+// }
+//
+// public Object get(Object key) {
+// if(key == null)
+// throw new NullPointerException("Bundle data binding does not accept a null key");
+//
+// String result = _bundle.getString(key.toString());
+// if(result == null) {
+// String msg = "The bundle property name \"" + key + "\" could not be found in the properties bundle \"" + _propertiesName + "\".";
+// LOGGER.error(msg);
+// throw new IllegalArgumentException(msg);
+// }
+// else return result;
+// }
+//
+// public boolean containsKey(Object key) {
+// if(key == null)
+// return false;
+// else return _bundle.getString(key.toString()) != null;
+// }
+//
+// public String toString() {
+// return _bundle != null ? _bundle.toString() : "BundleMap contains an empty BundleNode";
+// }
+// }
+}
+
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/DataAccessProviderBean.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/DataAccessProviderBean.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/DataAccessProviderBean.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/DataAccessProviderBean.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.script.common;
+
+import org.apache.ti.util.logging.Logger;
+
+/**
+ *
+ */
+public class DataAccessProviderBean {
+
+ private static final Logger _logger = Logger.getInstance(DataAccessProviderBean.class);
+
+ private IDataAccessProvider _provider = null;
+
+ public DataAccessProviderBean(IDataAccessProvider provider) {
+ _provider = provider;
+ }
+
+ public Object getItem() {
+ return _provider.getCurrentItem();
+ }
+
+ public Object getContainer() {
+ return new DataAccessProviderBean(_provider.getProviderParent());
+ }
+
+ public int getIndex() {
+ return _provider.getCurrentIndex();
+ }
+
+ public Object getMetadata() {
+ return _provider.getCurrentMetadata();
+ }
+}
+
+
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/DataAccessProviderStack.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/DataAccessProviderStack.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/DataAccessProviderStack.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/DataAccessProviderStack.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.script.common;
+
+import javax.servlet.jsp.JspContext;
+import java.util.Stack;
+
+public class DataAccessProviderStack {
+
+ private static final String KEY = "org.apache.ti.script.common.DataAccessProviderStack";
+
+ private Stack _stack = null;
+
+ public static final void addDataAccessProvider(IDataAccessProvider provider, JspContext jspContext) {
+ assert jspContext != null;
+
+ DataAccessProviderBean bean = new DataAccessProviderBean(provider);
+
+ Object val = jspContext.getAttribute(KEY);
+ DataAccessProviderStack curStack = null;
+ if (val == null) {
+ curStack = new DataAccessProviderStack();
+
+ jspContext.setAttribute(KEY, curStack);
+ } else
+ curStack = (DataAccessProviderStack) val;
+
+ curStack.push(bean);
+
+ jspContext.setAttribute("container", bean);
+
+ return;
+ }
+
+ public static final DataAccessProviderBean removeDataAccessProvider(JspContext jspContext) {
+ assert jspContext != null;
+
+ Object val = jspContext.getAttribute(KEY);
+ if (val != null) {
+ DataAccessProviderStack curStack = (DataAccessProviderStack) val;
+ DataAccessProviderBean lastTop = curStack.pop();
+
+ if (!curStack.isEmpty())
+ jspContext.setAttribute("container", curStack.peek());
+ else
+ jspContext.removeAttribute("container");
+
+ return lastTop;
+ }
+
+ // todo: should this thrown an IllegalStateException?
+
+ return null;
+ }
+
+ public DataAccessProviderStack() {
+ _stack = new Stack();
+ }
+
+ public boolean isEmpty() {
+ return _stack.empty();
+ }
+
+ public DataAccessProviderBean peek() {
+ return (DataAccessProviderBean) _stack.peek();
+ }
+
+ public DataAccessProviderBean pop() {
+ return (DataAccessProviderBean) _stack.pop();
+ }
+
+ public void push(DataAccessProviderBean bean) {
+ _stack.push(bean);
+ }
+
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/IDataAccessProvider.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/IDataAccessProvider.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/IDataAccessProvider.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/IDataAccessProvider.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.script.common;
+
+// java imports
+
+// internal imports
+
+// external imports
+
+/**
+ * The IDataAccessProvider interface is implemented by objects
+ * that need to provide their children with data and wish
+ * to make it available to them with the <code>container</code>
+ * binding context. Expression evaluation will process
+ * all <code>container</code> context references against this interface;
+ * several read-only properties are exposed:
+ * <table cellpadding="2" cellspacing="0" border="1">
+ * <tr><th>Method</th><th>NetUI Data Binding Expression</th><th>Required</th></tr>
+ * <tr><td>getCurrentIndex()</td><td><code>container.index</code></td><td>Yes</td></tr>
+ * <tr><td>getCurrentItem()</td><td><code>container.item</code></td><td>Yes</td></tr>
+ * <tr><td>getCurrentMetadata()</td><td><code>container.metadata</code></td><td>No</td></tr>
+ * <tr><td>getDataSource()</td><td><code>container.dataSource</code></td><td>Yes</td></tr>
+ * <tr><td>getProviderParent()</td><td><code>container.container</code></td><td>Yes</td></tr>
+ * </table>
+ * <p/>
+ * In cases where a IDataAccessProvider contains another IDataAccessProvider, the
+ * grandparent IDataAccessProvider may be referenced with the binding expression
+ * <code>container.container</code>. For example, the item, with the property firstName,
+ * may be accessed with the expression <code>container.container.item.firstName</code>.
+ * </p>
+ * <p/>
+ * The general use of the IDataAccessProvider is as an interface that is implemented
+ * by repeating databound tags that iterate over a data set and render each item
+ * in that data set. The item and iteration index are exposed through this
+ * interface and can be bound to by tags inside of the repeating tag
+ * that implements the IDataAccessProvider interface. This binding expression
+ * should start with <code>container</code> and reference one of the properties above.
+ * </p>
+ */
+public interface IDataAccessProvider {
+
+ /**
+ * Get the current index in this iteration. This should be a
+ * zero based integer that increments after each iteration.
+ *
+ * @return the current index of iteration or 0
+ */
+ public int getCurrentIndex();
+
+ /**
+ * Get the current data item in this IDataAccessProvider.
+ *
+ * @return the current data item or <code>null</code>
+ */
+ public Object getCurrentItem();
+
+ /**
+ * Get the expression that references the data item to which the
+ * IDataAccessProvider is bound.
+ *
+ * @return the expression referencing the data source or <code>null</code> if no
+ * dataSource is set
+ */
+ public String getDataSource();
+
+ /**
+ * Get a metadata object for the current item. This interface
+ * is optional, and implementations of this interface are
+ * provided by the IDataAccessProvider interface. See these
+ * implementations for information about their support for
+ * current item metadata.
+ *
+ * @return the current metadata or <code>null</code> if no metadata can be
+ * found or metadata is not supported by a IDataAccessProvider implementation
+ */
+ public Object getCurrentMetadata();
+
+ /**
+ * Get the parent IDataAccessProvider of a DataAccessProvider. A DataAccessProvider
+ * implementation may be able to nest DataAccessProviders. In this case,
+ * it can be useful to be able to also nest access to data from parent
+ * providers. Implementations of this interface are left with having
+ * to discover and export parents. The return value from this call
+ * on an implementing Object can be <code>null</code>.
+ *
+ * @return the parent DataAccessProvider or <code>null</code> if this method
+ * is not supported or the parent can not be found.
+ */
+ public IDataAccessProvider getProviderParent();
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/ImplicitObjectUtil.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/ImplicitObjectUtil.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/ImplicitObjectUtil.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/ImplicitObjectUtil.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.script.common;
+
+import org.apache.ti.pageflow.FacesBackingBean;
+import org.apache.ti.pageflow.PageFlowController;
+import org.apache.ti.pageflow.PageFlowUtils;
+import org.apache.ti.pageflow.internal.InternalUtils;
+import org.apache.ti.pageflow.xwork.PageFlowActionContext;
+import org.apache.ti.script.el.NetUIUpdateVariableResolver;
+import org.apache.ti.util.logging.Logger;
+
+import javax.servlet.jsp.JspContext;
+import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.el.VariableResolver;
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ *
+ */
+public class ImplicitObjectUtil {
+
+ private static final Logger LOGGER = Logger.getInstance(ImplicitObjectUtil.class);
+
+ private static final String PAGE_FLOW_IMPLICIT_OBJECT_KEY = "pageFlow";
+ private static final String SHARED_FLOW_IMPLICIT_OBJECT_KEY = "sharedFlow";
+// private static final String BUNDLE_IMPLICIT_OBJECT_KEY = "bundle";
+ private static final String BACKING_IMPLICIT_OBJECT_KEY = "backing";
+ private static final String PAGE_INPUT_IMPLICIT_OBJECT_KEY = "pageInput";
+ private static final String ACTION_FORM_IMPLICIT_OBJECT_KEY = "actionForm";
+ private static final String OUTPUT_FORM_BEAN_OBJECT_KEY = "outputFormBean";
+
+ /* do not construct */
+ private ImplicitObjectUtil() {
+ }
+
+ public static final void loadActionForm(JspContext jspContext, Object form) {
+ jspContext.setAttribute(ACTION_FORM_IMPLICIT_OBJECT_KEY, form);
+ }
+
+ public static final void unloadActionForm(JspContext jspContext) {
+ jspContext.removeAttribute(ACTION_FORM_IMPLICIT_OBJECT_KEY);
+ }
+
+ public static final void loadPageFlow(PageFlowController pageFlow) {
+ Map requestScope = PageFlowActionContext.get().getRequestScope();
+ if (pageFlow != null)
+ requestScope.put(PAGE_FLOW_IMPLICIT_OBJECT_KEY, pageFlow);
+
+ Map map = InternalUtils.getPageInputMap();
+ requestScope.put(PAGE_INPUT_IMPLICIT_OBJECT_KEY, map != null ? map : Collections.EMPTY_MAP);
+ }
+
+ public static final void loadFacesBackingBean(FacesBackingBean fbb) {
+ if (fbb != null) {
+ Map requestScope = PageFlowActionContext.get().getRequestScope();
+ requestScope.put(BACKING_IMPLICIT_OBJECT_KEY, fbb);
+ }
+ }
+
+ public static final void unloadFacesBackingBean() {
+ Map requestScope = PageFlowActionContext.get().getRequestScope();
+ requestScope.remove(BACKING_IMPLICIT_OBJECT_KEY);
+ }
+
+ public static final void loadSharedFlow(Map/*<String, SharedFlowController>*/ sharedFlows) {
+ if (sharedFlows != null) {
+ Map requestScope = PageFlowActionContext.get().getRequestScope();
+ requestScope.put(SHARED_FLOW_IMPLICIT_OBJECT_KEY, sharedFlows);
+ }
+ }
+
+ /* TODO: re-add bundle support
+ public static final void loadBundleMap(ServletRequest servletRequest, BundleMap bundleMap) {
+ servletRequest.setAttribute(BUNDLE_IMPLICIT_OBJECT_KEY, bundleMap);
+ }
+ */
+
+ public static final Map/*<String, SharedFlowController>*/ getSharedFlow() {
+ Map requestScope = PageFlowActionContext.get().getRequestScope();
+ return (Map /*<String, SharedFlowController>*/) requestScope.get(SHARED_FLOW_IMPLICIT_OBJECT_KEY);
+ }
+
+ public static final PageFlowController getPageFlow() {
+ PageFlowController jpf = PageFlowUtils.getCurrentPageFlow();
+ if (jpf != null)
+ return jpf;
+ else {
+ // @todo: i18n
+ RuntimeException re = new RuntimeException("There is no current PageFlow for the expression.");
+ if (LOGGER.isErrorEnabled()) LOGGER.error("", re);
+ throw re;
+ }
+ }
+
+ public static final VariableResolver getUpdateVariableResolver(Object form, boolean isHandlingPost) {
+
+ /* todo: need to provide get(Read|Update)VariableResolver methods on the ExpressionEngineFactory */
+ return new NetUIUpdateVariableResolver(form, isHandlingPost);
+ }
+
+ public static final VariableResolver getReadVariableResolver(PageContext pageContext) {
+ assert pageContext != null;
+ return pageContext.getVariableResolver();
+ }
+
+ public static final void loadImplicitObjects(PageFlowController curJpf) {
+ // @todo: need to wrap this in checks for JSP 1.2
+ // @todo: feature: need to add support for chaining in user-code to run when setting implicit objects on the request
+ loadPageFlow(curJpf);
+
+ // @todo: need to move bundleMap creation to a BundleMapFactory
+ // TODO: re-add bundle support
+// BundleMap bundleMap = new BundleMap(request, servletContext);
+// loadBundleMap(request, bundleMap);
+ }
+
+ public static final void loadOutputFormBean(Object bean) {
+ if (bean != null) {
+ Map requestScope = PageFlowActionContext.get().getRequestScope();
+ requestScope.put(OUTPUT_FORM_BEAN_OBJECT_KEY, bean);
+ }
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/ScriptablePageInput.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/ScriptablePageInput.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/ScriptablePageInput.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/ScriptablePageInput.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.script.common;
+
+// java imports
+
+import org.apache.ti.pageflow.PageFlowUtils;
+import org.apache.ti.pageflow.internal.InternalUtils;
+import org.apache.ti.util.logging.Logger;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+// external imports
+
+/**
+ * Provide a {@link java.util.Map} object that exposes a set of page inputs to
+ * expression language clients. Access to these page inputs is based on the
+ * name of the page input.
+ * <p/>
+ * Access is optimized for read in that the "get" method is fast. The entrySet()
+ * method is only used if needed, which is generally to toString the Map.
+ */
+public class ScriptablePageInput
+ extends AbstractScriptableMap {
+
+ private static final Logger _logger = Logger.getInstance(ScriptablePageInput.class);
+
+ private Set _entrySet = null;
+
+ public ScriptablePageInput() {
+ }
+
+ public Object get(Object name) {
+ if (_logger.isDebugEnabled()) _logger.debug("page input get: " + name);
+
+ assert name instanceof String;
+
+ return PageFlowUtils.getActionOutput((String) name);
+ }
+
+ /**
+ * Create a {@link java.util.Set} of page input entries. This implementation
+ * assumes that the page input set does not change, which is acceptable for
+ * JSP clients as the page inputs have been specified when the JSP starts
+ * to render.
+ *
+ * @return Set
+ */
+ public Set entrySet() {
+ if (_entrySet == null) {
+ Map piMap = InternalUtils.getPageInputMap();
+ ArrayList list = new ArrayList();
+ if (piMap != null) {
+ Iterator iterator = piMap.keySet().iterator();
+ while (iterator.hasNext()) {
+ Object name = iterator.next();
+ Object value = piMap.get(name);
+ list.add(new Entry(name, value));
+ }
+ }
+
+ _entrySet = new EntrySet((Entry[]) list.toArray(new Entry[]{}));
+ }
+
+ return _entrySet;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj == null || !(obj instanceof ScriptablePageInput))
+ return false;
+ return super.equals(obj);
+ }
+
+ public boolean containsKey(Object key) {
+ Map piMap = InternalUtils.getPageInputMap();
+ return (piMap != null ? piMap.containsKey(key) : false);
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/bundle/BundleNode.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/bundle/BundleNode.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/bundle/BundleNode.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/bundle/BundleNode.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.script.common.bundle;
+
+import java.util.Enumeration;
+
+/**
+ */
+public abstract class BundleNode {
+
+ public abstract boolean containsKey(String key);
+
+ public abstract String getString(String key);
+
+ public abstract Enumeration getKeys();
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/bundle/BundleNodeFactory.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/bundle/BundleNodeFactory.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/bundle/BundleNodeFactory.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/bundle/BundleNodeFactory.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.script.common.bundle;
+
+import org.apache.ti.util.MessageResources;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+/**
+ *
+ */
+public class BundleNodeFactory {
+
+ private static final BundleNodeFactory FACTORY = new BundleNodeFactory();
+
+ public static final BundleNodeFactory getInstance() {
+ return FACTORY;
+ }
+
+ private BundleNodeFactory() {
+ }
+
+ public final BundleNode getStrutsBundleNode(String name, MessageResources messageResources, Locale locale) {
+ return new StrutsBundleNode(locale, messageResources);
+ }
+
+ public final BundleNode getResourceBundleNode(String name, ResourceBundle resourceBundle, Locale locale) {
+ return new ResourceBundleNode(resourceBundle);
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/bundle/ResourceBundleNode.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/bundle/ResourceBundleNode.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/bundle/ResourceBundleNode.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/bundle/ResourceBundleNode.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.script.common.bundle;
+
+import org.apache.ti.util.internal.InternalStringBuilder;
+
+import java.util.Enumeration;
+import java.util.ResourceBundle;
+
+/**
+ */
+class ResourceBundleNode
+ extends BundleNode {
+
+ private ResourceBundle _bundle;
+
+ ResourceBundleNode(ResourceBundle resourceBundle) {
+ _bundle = resourceBundle;
+ }
+
+ public boolean containsKey(String key) {
+ return _bundle != null && _bundle.getString(key) != null;
+ }
+
+ public String getString(String key) {
+ return _bundle != null ? _bundle.getString(key) : null;
+ }
+
+ public Enumeration getKeys() {
+ return _bundle != null ? _bundle.getKeys() : null;
+ }
+
+ public String toString() {
+ InternalStringBuilder sb = new InternalStringBuilder();
+ sb.append("ResourceBundleNode ");
+ Enumeration keys = getKeys();
+ if (keys != null) {
+ boolean first = true;
+ sb.append("{");
+ while (keys.hasMoreElements()) {
+ if (!first)
+ sb.append(",");
+ else
+ first = false;
+
+ String key = (String) keys.nextElement();
+ sb.append(key);
+ sb.append("=");
+ sb.append(getString(key));
+ }
+ sb.append("}");
+ }
+ return sb.toString();
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/bundle/StrutsBundleNode.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/bundle/StrutsBundleNode.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/bundle/StrutsBundleNode.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/common/bundle/StrutsBundleNode.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.script.common.bundle;
+
+import org.apache.ti.util.MessageResources;
+import org.apache.ti.util.internal.InternalStringBuilder;
+
+import java.util.Enumeration;
+import java.util.Locale;
+
+/**
+ */
+class StrutsBundleNode
+ extends BundleNode {
+
+ private Locale _locale;
+ private MessageResources _messageResource;
+
+ StrutsBundleNode(Locale locale, MessageResources messageResource) {
+ _locale = locale;
+ _messageResource = messageResource;
+ }
+
+ public boolean containsKey(String key) {
+ return _messageResource.getMessage(_locale, key) != null;
+ }
+
+ public String getString(String key) {
+ return _messageResource.getMessage(_locale, key);
+ }
+
+ public Enumeration getKeys() {
+ throw new UnsupportedOperationException("The getKeys() method is not supported on the MessageResources type.");
+ }
+
+ public String toString() {
+ InternalStringBuilder sb = new InternalStringBuilder();
+ sb.append("StrutsBundleNode ");
+ sb.append("messageResource: ");
+ sb.append(_messageResource);
+ sb.append(" ");
+ sb.append("locale: ");
+ sb.append(_locale);
+ return sb.toString();
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/ExpressionEvaluatorImpl.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/ExpressionEvaluatorImpl.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/ExpressionEvaluatorImpl.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/ExpressionEvaluatorImpl.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.script.el;
+
+import org.apache.ti.script.Expression;
+import org.apache.ti.script.ExpressionEvaluationException;
+import org.apache.ti.script.ExpressionEvaluator;
+import org.apache.ti.script.ExpressionUpdateException;
+import org.apache.ti.script.IllegalExpressionException;
+import org.apache.ti.script.el.util.ParseUtils;
+import org.apache.ti.util.logging.Logger;
+
+import javax.servlet.jsp.el.VariableResolver;
+
+/**
+ *
+ */
+public class ExpressionEvaluatorImpl
+ implements ExpressionEvaluator {
+
+ private static final Logger LOGGER = Logger.getInstance(ExpressionEvaluatorImpl.class);
+ private static final boolean DEBUG_ENABLED = LOGGER.isDebugEnabled();
+
+ public static class NetUIELEngineFactory
+ extends org.apache.ti.script.ExpressionEngineFactory {
+
+ public ExpressionEvaluator getInstance() {
+ return new ExpressionEvaluatorImpl();
+ }
+ }
+
+ public Object evaluateStrict(String expression, VariableResolver variableResolver)
+ throws ExpressionEvaluationException {
+ NetUIReadVariableResolver vr = null;
+ try {
+ /* todo: is there compelling enough reson to keep this code here? */
+ vr = new NetUIReadVariableResolver(variableResolver);
+
+ return ParseUtils.evaluate(expression, vr);
+ } catch (Exception e) {
+ if (DEBUG_ENABLED)
+ LOGGER.debug("Expression evaluation failed in NetUIEL. Cause: " + e, e);
+
+ Exception act = e;
+
+ String contextStr = ParseUtils.getContextString(vr.getAvailableVariables());
+ String msg = "Caught exception when evaluating expression \"" + expression + "\" with available binding contexts " +
+ contextStr + ". Root cause: " + ParseUtils.getRootCause(act).toString();
+
+ if (LOGGER.isErrorEnabled())
+ LOGGER.error(msg, act);
+
+ throw new ExpressionEvaluationException(msg, expression, act);
+ }
+ }
+
+ public void update(String expression, Object value, VariableResolver variableResolver, boolean requestParameter)
+ throws ExpressionUpdateException {
+ assert variableResolver instanceof NetUIVariableResolver;
+
+ NetUIVariableResolver vr = (NetUIVariableResolver) variableResolver;
+
+ try {
+ if (DEBUG_ENABLED)
+ LOGGER.debug("Update expression \"" + expression + "\"");
+
+ ParseUtils.update(expression, value, vr);
+ } catch (Exception e) {
+ if (DEBUG_ENABLED)
+ LOGGER.debug("Expression update failed in NetUIEL. Cause: " + e, e);
+
+ String contextStr = ParseUtils.getContextString(vr.getAvailableVariables());
+ String msg = "Exception when attempting to update the expression \"" + expression + "\" with available binding contexts " +
+ contextStr + ". Root cause: " + ParseUtils.getRootCause(e).toString();
+
+ if (LOGGER.isErrorEnabled())
+ LOGGER.error(msg, e);
+
+ ExpressionUpdateException eee = new ExpressionUpdateException(msg, expression, e);
+ eee.setLocalizedMessage(msg);
+
+ throw eee;
+ }
+ }
+
+ /* todo: fix the lookup index to be Object */
+ public String changeContext(String expression, String oldContext, String newContext, int lookupIndex)
+ throws ExpressionEvaluationException {
+ try {
+ ParsedExpression pe = ParseUtils.parse(expression);
+ return pe.changeContext(oldContext, newContext, new Integer(lookupIndex));
+ } catch (Exception e) {
+ String msg = "Error when trying to replace old context '" + oldContext + "' with new context '" +
+ newContext + "' and index '" + lookupIndex + "': " + ParseUtils.getRootCause(e).toString();
+
+ if (LOGGER.isErrorEnabled()) LOGGER.error(msg, e);
+
+ throw new ExpressionEvaluationException(msg, e);
+ }
+ }
+
+ public String qualify(String contextName, String expression)
+ throws ExpressionEvaluationException {
+ try {
+ ParsedExpression pe = ParseUtils.parse(expression);
+ return pe.qualify(contextName);
+ } catch (Exception e) {
+ String msg = "Error when trying to create an expression in namespace \"" + contextName + "\" with fragment \"" +
+ expression + "\". Root cause: " + ParseUtils.getRootCause(e).toString();
+
+ throw new ExpressionEvaluationException(msg, e);
+ }
+ }
+
+ public boolean isExpression(String expression) {
+ try {
+ ParsedExpression pe = ParseUtils.parse(expression);
+ return pe.isExpression();
+ } catch (Exception e) {
+ if (LOGGER.isErrorEnabled())
+ LOGGER.error("Exception parsing expression \"" + expression + "\". Cause: " +
+ ParseUtils.getRootCause(e).toString(), e);
+
+ if (e instanceof IllegalExpressionException)
+ throw (IllegalExpressionException) e;
+ else if (e instanceof ExpressionParseException)
+ throw new IllegalExpressionException(e);
+ else
+ return false;
+ }
+ }
+
+ public boolean containsExpression(String expression) {
+ if (expression == null) return false;
+
+ try {
+ ParsedExpression pe = ParseUtils.parse(expression);
+ assert pe != null;
+ return pe.containsExpression();
+ } catch (Exception e) {
+ if (LOGGER.isErrorEnabled())
+ LOGGER.error("Exception checking for expressions in \"" + expression + "\"", e);
+
+ return false;
+ }
+ }
+
+ public Expression parseExpression(String expression) {
+ if (isExpression(expression)) {
+ ParsedExpression pe = ParseUtils.parse(expression);
+ assert pe != null;
+ return pe.getAtomicExpressionTerm();
+ } else
+ throw new IllegalExpressionException("The expression \"" + expression + "\" can not be parsed as it is not an atomic expression.");
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/ExpressionParseException.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/ExpressionParseException.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/ExpressionParseException.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/ExpressionParseException.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.script.el;
+
+/**
+ *
+ */
+public class ExpressionParseException
+ extends RuntimeException {
+
+ /**
+ */
+ public ExpressionParseException() {
+ super();
+ }
+
+ /**
+ * @param message
+ */
+ public ExpressionParseException(String message) {
+ super(message);
+ }
+
+ /**
+ * @param cause
+ */
+ public ExpressionParseException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public ExpressionParseException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
+
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/ExpressionTerm.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/ExpressionTerm.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/ExpressionTerm.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/ExpressionTerm.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,232 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.script.el;
+
+import org.apache.ti.script.Expression;
+import org.apache.ti.script.el.tokens.ArrayIndexToken;
+import org.apache.ti.script.el.tokens.ContextToken;
+import org.apache.ti.script.el.tokens.ExpressionToken;
+import org.apache.ti.script.el.tokens.IdentifierToken;
+import org.apache.ti.script.el.tokens.MapKeyToken;
+import org.apache.ti.script.el.util.BindingContext;
+import org.apache.ti.script.el.util.ParseUtils;
+import org.apache.ti.util.internal.InternalStringBuilder;
+import org.apache.ti.util.logging.Logger;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ *
+ */
+public class ExpressionTerm
+ extends Expression
+ implements Term {
+
+ private static Logger LOGGER = Logger.getInstance(ExpressionTerm.class);
+
+ private List _tokens = null;
+ private String _exprStr = null;
+ private ContextToken _context = null;
+ private ExpressionToken[] _tokenArray = null;
+ private List _noModTokens = null;
+
+ public ExpressionTerm() {
+ super();
+ _tokens = new ArrayList();
+ }
+
+ public void seal() {
+ _context = (ContextToken) _tokens.get(0);
+ _tokenArray = new ExpressionToken[_tokens.size()];
+
+ InternalStringBuilder buf = new InternalStringBuilder();
+ for (int i = 0; i < _tokens.size(); i++) {
+ buf.append(((ExpressionToken) _tokens.get(i)).getTokenString());
+ _tokenArray[i] = (ExpressionToken) _tokens.get(i);
+ }
+
+ _exprStr = buf.toString();
+
+ _noModTokens = Collections.unmodifiableList(_tokens);
+ }
+
+ public String getContext() {
+ return _context.getName();
+ }
+
+ public List getTokens() {
+ return _noModTokens;
+ }
+
+ public String getExpression(int start) {
+ if (start >= _tokens.size())
+ throw new IllegalStateException("The index \"" + start + "\" is an invalid reference into an expression with \"" +
+ _tokens.size() + "\" _tokens.");
+
+ boolean needDot = true;
+ InternalStringBuilder buf = new InternalStringBuilder();
+ buf.append("{");
+ for (int i = start; i < _tokens.size(); i++) {
+ ExpressionToken tok = (ExpressionToken) _tokens.get(i);
+ if (tok instanceof ArrayIndexToken) {
+ buf.append(tok.getTokenString());
+ needDot = false;
+ } else if (tok instanceof IdentifierToken) {
+ if (needDot && i != start) buf.append(".");
+ buf.append(tok.toString());
+ needDot = true;
+ } else if (tok instanceof MapKeyToken) {
+ buf.append(tok.getTokenString());
+ needDot = false;
+ }
+ }
+ buf.append("}");
+ return buf.toString();
+ }
+
+ public void addToken(ExpressionToken token) {
+ _tokens.add(token);
+ }
+
+ public Iterator getExpressionTokens() {
+ return _tokens.iterator();
+ }
+
+ public int getTokenCount() {
+ return _tokenArray.length;
+ }
+
+ public ExpressionToken getToken(int index) {
+ // @TODO: error checking
+ return _tokenArray[index];
+ }
+
+ public String getExpressionString() {
+ return _exprStr;
+ }
+
+ public Object evaluate(NetUIVariableResolver vr) {
+ return _evaluate(_tokens.size(), vr);
+ }
+
+ public void update(Object newValue, NetUIVariableResolver vr) {
+ // find leaf
+ Object branch = _evaluate(_tokens.size() - 1, vr);
+
+ ExpressionToken token = _tokenArray[_tokens.size() - 1];
+
+ if (LOGGER.isDebugEnabled()) LOGGER.debug("Update leaf token: " + token + " on object: " + branch);
+
+ // apply value
+ token.update(branch, newValue);
+ }
+
+ /* todo: perf. this could be done more effectively / efficiently */
+ public String changeContext(String oldContext, String newContext, Object index) {
+ String thisExpr = getExpressionString();
+
+ if (LOGGER.isDebugEnabled()) LOGGER.debug("oldContext: " + oldContext + " newContext: " + newContext + " thisExpr: " + thisExpr);
+
+ // needs to be checked for atomicity
+ ParsedExpression pe = ParseUtils.parse(newContext);
+
+ if (!pe.isExpression()) {
+ String msg = "The expression can not be qualified into new _context because the new _context is not atomic.";
+ if (LOGGER.isErrorEnabled()) LOGGER.error(msg);
+ throw new RuntimeException(msg);
+ }
+
+ // this isn't a failure; it just means that there isn't anything else to replace
+ if (!thisExpr.startsWith(oldContext)) {
+ return "{" + thisExpr + "}";
+ }
+
+ if (index instanceof Integer && ((Integer) index).intValue() > 32767) {
+ String msg = "Can not create an indexed expression with an array index greater than the Java array limit for the expression \"" +
+ thisExpr + "\"";
+
+ if (LOGGER.isWarnEnabled()) LOGGER.warn(msg);
+ throw new RuntimeException(msg);
+ }
+
+ String ctxStr = pe.getExpressionString();
+
+ ctxStr = ctxStr + "[" + index + "]";
+
+ if (LOGGER.isDebugEnabled()) LOGGER.debug("thisExpr: " + thisExpr + " ctxStr: " + ctxStr);
+
+ thisExpr = thisExpr.replaceFirst(oldContext, ctxStr);
+
+ InternalStringBuilder buf = new InternalStringBuilder();
+ buf.append("{");
+ buf.append(thisExpr);
+ buf.append("}");
+
+ return buf.toString();
+ }
+
+ public String qualify(String contextName) {
+ InternalStringBuilder buf = new InternalStringBuilder();
+ buf.append("{");
+ buf.append(contextName);
+ buf.append(".");
+ buf.append(getExpressionString());
+ buf.append("}");
+
+ return buf.toString();
+ }
+
+ public String toString() {
+ InternalStringBuilder buf = new InternalStringBuilder();
+ buf.append("ExpressionTerm:\n");
+ for (int i = 0; i < _tokens.size(); i++) {
+ buf.append(" " + _tokens.get(i).toString() + "\n");
+ }
+ return buf.toString();
+ }
+
+ private final Object _evaluate(int index, NetUIVariableResolver vr) {
+ Object result = null;
+
+ if (_tokens.size() == 1) {
+ if (LOGGER.isDebugEnabled()) LOGGER.debug("found single term expression");
+
+ result = vr.resolveVariable(_context.getName());
+
+ if (result != null && result instanceof BindingContext) {
+ if (LOGGER.isDebugEnabled())
+ LOGGER.debug("result is of type BindingContext; return type: " + (((BindingContext) result).unwrap().getClass()));
+
+ return ((BindingContext) result).unwrap();
+ } else
+ return result;
+ } else {
+ for (int i = 0; i < index; i++) {
+ if (i == 0) {
+ result = vr.resolveVariable(_context.getName());
+ } else
+ result = _tokenArray[i].evaluate(result);
+ }
+
+ return result;
+ }
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/LiteralTerm.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/LiteralTerm.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/LiteralTerm.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/LiteralTerm.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.script.el;
+
+import org.apache.ti.util.logging.Logger;
+
+/**
+ *
+ */
+public class LiteralTerm
+ implements Term {
+
+ private static final Logger LOGGER = Logger.getInstance(LiteralTerm.class);
+
+ private String text = null;
+
+ public LiteralTerm(String text) {
+ super();
+
+ /* todo: probably being lazy in not fixing the grammar */
+ if (text.equals("\\{"))
+ this.text = "{";
+ else
+ this.text = text;
+
+ if (LOGGER.isDebugEnabled())
+ LOGGER.debug("LiteralTerm text: " + text + " this.text: " + this.text);
+ }
+
+ public void seal() {
+ }
+
+ public String getExpressionString() {
+ return text;
+ }
+
+ public Object evaluate(NetUIVariableResolver vr) {
+ return text;
+ }
+
+ public String toString() {
+ return "LiteralTerm:\n " + text + "\n";
+ }
+}
+
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/NetUIEL.jj
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/NetUIEL.jj?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/NetUIEL.jj (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/NetUIEL.jj Thu Aug 25 22:46:03 2005
@@ -0,0 +1,717 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+options {
+ JAVA_UNICODE_ESCAPE = false;
+ UNICODE_INPUT = true;
+ STATIC = false;
+ DEBUG_PARSER=false;
+}
+
+PARSER_BEGIN(NetUIELParser)
+
+package org.apache.beehive.netui.script.el.parser;
+
+import org.apache.beehive.netui.script.el.ExpressionTerm;
+import org.apache.beehive.netui.script.el.LiteralTerm;
+import org.apache.beehive.netui.script.el.ParsedExpression;
+import org.apache.beehive.netui.script.el.Term;
+import org.apache.beehive.netui.script.el.tokens.*;
+
+public class NetUIELParser
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ NetUIELParser parser = new NetUIELParser(System.in);
+ parser.parse();
+ }
+}
+
+PARSER_END(NetUIELParser)
+
+<DEFAULT> TOKEN:
+{
+< NON_EXPRESSION_TEXT: (~["{", "\\"])+ | "\\{" | "\\" >
+|
+< START_EXPRESSION: "{" > : IN_EXPRESSION
+|
+< ESCAPED_START_EXPRESSION: "\\\\{" > : IN_EXPRESSION
+}
+
+<IN_EXPRESSION> TOKEN:
+{
+< END_EXPRESSION: "}" > : DEFAULT
+|
+ /* String Literal -- This will accept a Java String literal that is converted internally into an EcmaScript compliant literal
+ See: http://www.ecma-international.org/publications/files/ecma-st/Ecma-262.pdf -- Annex A, StringLiteral production
+ */
+< STRING_LITERAL:
+ ("\"" ((~["\"", "\\", "\n", "\r"])|<ECMA_ESCAPE_SEQUENCE>)* "\"") |
+ ("'" ((~["'", "\\", "\n", "\r"])|<ECMA_ESCAPE_SEQUENCE>)* "'")
+ >
+| <#ECMA_ESCAPE_SEQUENCE:
+ "\\" |
+ (
+ ["n", "t", "b", "r", "f", "\\", "'", "\""] |
+ ["0"-"7"] (["0"-"7"])? |
+ ["0"-"3"] ["0"-"7"] ["0"-"7"] |
+ ["x","X"] <HIT> <HIT> |
+ ["u","U"] <HIT> <HIT> <HIT> <HIT>
+ )
+ >
+| <#HIT: ["0"-"9","a"-"f","A"-"F"] >
+|
+/* Identifiers */
+< IDENTIFIER: (<LETTER>|<IMPL_OBJ_START>) (<LETTER>|<DIGIT>)* >
+| < #IMPL_OBJ_START: "#" >
+| < #LETTER:
+ [
+ "\u0024",
+ "\u0041"-"\u005a",
+ "\u005f",
+ "\u0061"-"\u007a",
+ "\u00c0"-"\u00d6",
+ "\u00d8"-"\u00f6",
+ "\u00f8"-"\u00ff",
+ "\u0100"-"\u1fff",
+ "\u3040"-"\u318f",
+ "\u3300"-"\u337f",
+ "\u3400"-"\u3d2d",
+ "\u4e00"-"\u9fff",
+ "\uf900"-"\ufaff"
+ ]
+ >
+|
+ < #DIGIT:
+ [
+ "\u0030"-"\u0039",
+ "\u0660"-"\u0669",
+ "\u06f0"-"\u06f9",
+ "\u0966"-"\u096f",
+ "\u09e6"-"\u09ef",
+ "\u0a66"-"\u0a6f",
+ "\u0ae6"-"\u0aef",
+ "\u0b66"-"\u0b6f",
+ "\u0be7"-"\u0bef",
+ "\u0c66"-"\u0c6f",
+ "\u0ce6"-"\u0cef",
+ "\u0d66"-"\u0d6f",
+ "\u0e50"-"\u0e59",
+ "\u0ed0"-"\u0ed9",
+ "\u1040"-"\u1049"
+ ]
+ >
+| < INTEGER: ["0"-"9"] (["0"-"9"])* >
+| <DOT: ".">
+| <DQUOTE: "\"">
+| <SQUOTE: "'">
+| <LBRACKET: "[">
+| <RBRACKET: "]">
+}
+
+// 3.
+ParsedExpression parse() :
+{
+Token t = null;
+ParsedExpression pe = new ParsedExpression();
+Term term = null;
+}
+{
+ (
+ (term = parseLiteralTerm() {pe.addTerm(term);}) |
+ (<START_EXPRESSION> term = parseExpression() <END_EXPRESSION> {pe.addTerm(term);}) |
+ (<ESCAPED_START_EXPRESSION> term = parseExpression() <END_EXPRESSION> {pe.addTerm(new LiteralTerm("\\")); pe.addTerm(term);})
+ )* <EOF>
+{
+return pe;
+}
+}
+
+LiteralTerm parseLiteralTerm() :
+{
+Token t = null;
+LiteralTerm ls = null;
+}
+{
+ (t = <NON_EXPRESSION_TEXT> {ls = new LiteralTerm(t.image); return ls;})
+}
+
+
+ExpressionTerm parseExpression() :
+{
+ExpressionTerm expr = new ExpressionTerm();
+ExpressionToken eTok = null;
+}
+{
+
+(
+eTok = Context()
+{
+expr.addToken(eTok);
+}
+(
+ (<DOT> eTok = ExprIdentifier() | LOOKAHEAD(2) eTok = MapKey() | eTok = ArrayIndex())
+ {
+ {
+ expr.addToken(eTok);
+ }
+ }
+
+)*
+)
+{
+expr.seal();
+return expr;
+}
+}
+
+ExpressionToken Context() :
+{
+Token t = null;
+ExpressionToken eTok = null;
+}
+{
+(t = <IDENTIFIER>)
+{
+//System.out.println("** Parser found context: " + t.image);
+eTok = new ContextToken(t.image);
+return eTok;
+}
+}
+
+ExpressionToken ExprIdentifier() :
+{
+Token t = null;
+ExpressionToken eTok = null;
+}
+{
+(t = <IDENTIFIER>)
+{
+//System.out.println("** Parser found identifier: " + t.image);
+eTok = new IdentifierToken(t.image);
+return eTok;
+}
+}
+
+// handle text inside of map braces as ["..."] or ['...']
+ExpressionToken MapKey() :
+{
+Token t = null;
+ExpressionToken eTok = null;
+}
+{
+(
+<LBRACKET> (t=<STRING_LITERAL>) <RBRACKET>
+)
+{
+eTok = new MapKeyToken(t.image);
+return eTok;
+}
+}
+
+ExpressionToken ArrayIndex() :
+{
+Token t = null;
+ExpressionToken eTok = null;
+}
+{
+(<LBRACKET> (t = <INTEGER>) <RBRACKET>)
+{
+//System.out.println("** Parser found array index: " + t.image);
+eTok = new ArrayIndexToken(t.image);
+return eTok;
+}
+}
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+options {
+ JAVA_UNICODE_ESCAPE = false;
+ UNICODE_INPUT = true;
+ STATIC = false;
+ DEBUG_PARSER=false;
+}
+
+PARSER_BEGIN(NetUIELParser)
+
+package org.apache.beehive.netui.script.el.parser;
+
+import org.apache.beehive.netui.script.el.ExpressionTerm;
+import org.apache.beehive.netui.script.el.LiteralTerm;
+import org.apache.beehive.netui.script.el.ParsedExpression;
+import org.apache.beehive.netui.script.el.Term;
+import org.apache.beehive.netui.script.el.tokens.*;
+
+public class NetUIELParser
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ NetUIELParser parser = new NetUIELParser(System.in);
+ parser.parse();
+ }
+}
+
+PARSER_END(NetUIELParser)
+
+<DEFAULT> TOKEN:
+{
+< NON_EXPRESSION_TEXT: (~["{", "\\"])+ | "\\{" | "\\" >
+|
+< START_EXPRESSION: "{" > : IN_EXPRESSION
+|
+< ESCAPED_START_EXPRESSION: "\\\\{" > : IN_EXPRESSION
+}
+
+<IN_EXPRESSION> TOKEN:
+{
+< END_EXPRESSION: "}" > : DEFAULT
+|
+ /* String Literal -- This will accept a Java String literal that is converted internally into an EcmaScript compliant literal
+ See: http://www.ecma-international.org/publications/files/ecma-st/Ecma-262.pdf -- Annex A, StringLiteral production
+ */
+< STRING_LITERAL:
+ ("\"" ((~["\"", "\\", "\n", "\r"])|<ECMA_ESCAPE_SEQUENCE>)* "\"") |
+ ("'" ((~["'", "\\", "\n", "\r"])|<ECMA_ESCAPE_SEQUENCE>)* "'")
+ >
+| <#ECMA_ESCAPE_SEQUENCE:
+ "\\" |
+ (
+ ["n", "t", "b", "r", "f", "\\", "'", "\""] |
+ ["0"-"7"] (["0"-"7"])? |
+ ["0"-"3"] ["0"-"7"] ["0"-"7"] |
+ ["x","X"] <HIT> <HIT> |
+ ["u","U"] <HIT> <HIT> <HIT> <HIT>
+ )
+ >
+| <#HIT: ["0"-"9","a"-"f","A"-"F"] >
+|
+/* Identifiers */
+< IDENTIFIER: (<LETTER>|<IMPL_OBJ_START>) (<LETTER>|<DIGIT>)* >
+| < #IMPL_OBJ_START: "#" >
+| < #LETTER:
+ [
+ "\u0024",
+ "\u0041"-"\u005a",
+ "\u005f",
+ "\u0061"-"\u007a",
+ "\u00c0"-"\u00d6",
+ "\u00d8"-"\u00f6",
+ "\u00f8"-"\u00ff",
+ "\u0100"-"\u1fff",
+ "\u3040"-"\u318f",
+ "\u3300"-"\u337f",
+ "\u3400"-"\u3d2d",
+ "\u4e00"-"\u9fff",
+ "\uf900"-"\ufaff"
+ ]
+ >
+|
+ < #DIGIT:
+ [
+ "\u0030"-"\u0039",
+ "\u0660"-"\u0669",
+ "\u06f0"-"\u06f9",
+ "\u0966"-"\u096f",
+ "\u09e6"-"\u09ef",
+ "\u0a66"-"\u0a6f",
+ "\u0ae6"-"\u0aef",
+ "\u0b66"-"\u0b6f",
+ "\u0be7"-"\u0bef",
+ "\u0c66"-"\u0c6f",
+ "\u0ce6"-"\u0cef",
+ "\u0d66"-"\u0d6f",
+ "\u0e50"-"\u0e59",
+ "\u0ed0"-"\u0ed9",
+ "\u1040"-"\u1049"
+ ]
+ >
+| < INTEGER: ["0"-"9"] (["0"-"9"])* >
+| <DOT: ".">
+| <DQUOTE: "\"">
+| <SQUOTE: "'">
+| <LBRACKET: "[">
+| <RBRACKET: "]">
+}
+
+// 3.
+ParsedExpression parse() :
+{
+Token t = null;
+ParsedExpression pe = new ParsedExpression();
+Term term = null;
+}
+{
+ (
+ (term = parseLiteralTerm() {pe.addTerm(term);}) |
+ (<START_EXPRESSION> term = parseExpression() <END_EXPRESSION> {pe.addTerm(term);}) |
+ (<ESCAPED_START_EXPRESSION> term = parseExpression() <END_EXPRESSION> {pe.addTerm(new LiteralTerm("\\")); pe.addTerm(term);})
+ )* <EOF>
+{
+return pe;
+}
+}
+
+LiteralTerm parseLiteralTerm() :
+{
+Token t = null;
+LiteralTerm ls = null;
+}
+{
+ (t = <NON_EXPRESSION_TEXT> {ls = new LiteralTerm(t.image); return ls;})
+}
+
+
+ExpressionTerm parseExpression() :
+{
+ExpressionTerm expr = new ExpressionTerm();
+ExpressionToken eTok = null;
+}
+{
+
+(
+eTok = Context()
+{
+expr.addToken(eTok);
+}
+(
+ (<DOT> eTok = ExprIdentifier() | LOOKAHEAD(2) eTok = MapKey() | eTok = ArrayIndex())
+ {
+ {
+ expr.addToken(eTok);
+ }
+ }
+
+)*
+)
+{
+expr.seal();
+return expr;
+}
+}
+
+ExpressionToken Context() :
+{
+Token t = null;
+ExpressionToken eTok = null;
+}
+{
+(t = <IDENTIFIER>)
+{
+//System.out.println("** Parser found context: " + t.image);
+eTok = new ContextToken(t.image);
+return eTok;
+}
+}
+
+ExpressionToken ExprIdentifier() :
+{
+Token t = null;
+ExpressionToken eTok = null;
+}
+{
+(t = <IDENTIFIER>)
+{
+//System.out.println("** Parser found identifier: " + t.image);
+eTok = new IdentifierToken(t.image);
+return eTok;
+}
+}
+
+// handle text inside of map braces as ["..."] or ['...']
+ExpressionToken MapKey() :
+{
+Token t = null;
+ExpressionToken eTok = null;
+}
+{
+(
+<LBRACKET> (t=<STRING_LITERAL>) <RBRACKET>
+)
+{
+eTok = new MapKeyToken(t.image);
+return eTok;
+}
+}
+
+ExpressionToken ArrayIndex() :
+{
+Token t = null;
+ExpressionToken eTok = null;
+}
+{
+(<LBRACKET> (t = <INTEGER>) <RBRACKET>)
+{
+//System.out.println("** Parser found array index: " + t.image);
+eTok = new ArrayIndexToken(t.image);
+return eTok;
+}
+}
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+options {
+ JAVA_UNICODE_ESCAPE = false;
+ UNICODE_INPUT = true;
+ STATIC = false;
+ DEBUG_PARSER=false;
+}
+
+PARSER_BEGIN(NetUIELParser)
+
+package org.apache.beehive.netui.script.el.parser;
+
+import org.apache.beehive.netui.script.el.ExpressionTerm;
+import org.apache.beehive.netui.script.el.LiteralTerm;
+import org.apache.beehive.netui.script.el.ParsedExpression;
+import org.apache.beehive.netui.script.el.Term;
+import org.apache.beehive.netui.script.el.tokens.*;
+
+public class NetUIELParser
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ NetUIELParser parser = new NetUIELParser(System.in);
+ parser.parse();
+ }
+}
+
+PARSER_END(NetUIELParser)
+
+<DEFAULT> TOKEN:
+{
+< NON_EXPRESSION_TEXT: (~["{", "\\"])+ | "\\{" | "\\" >
+|
+< START_EXPRESSION: "{" > : IN_EXPRESSION
+|
+< ESCAPED_START_EXPRESSION: "\\\\{" > : IN_EXPRESSION
+}
+
+<IN_EXPRESSION> TOKEN:
+{
+< END_EXPRESSION: "}" > : DEFAULT
+|
+ /* String Literal -- This will accept a Java String literal that is converted internally into an EcmaScript compliant literal
+ See: http://www.ecma-international.org/publications/files/ecma-st/Ecma-262.pdf -- Annex A, StringLiteral production
+ */
+< STRING_LITERAL:
+ ("\"" ((~["\"", "\\", "\n", "\r"])|<ECMA_ESCAPE_SEQUENCE>)* "\"") |
+ ("'" ((~["'", "\\", "\n", "\r"])|<ECMA_ESCAPE_SEQUENCE>)* "'")
+ >
+| <#ECMA_ESCAPE_SEQUENCE:
+ "\\" |
+ (
+ ["n", "t", "b", "r", "f", "\\", "'", "\""] |
+ ["0"-"7"] (["0"-"7"])? |
+ ["0"-"3"] ["0"-"7"] ["0"-"7"] |
+ ["x","X"] <HIT> <HIT> |
+ ["u","U"] <HIT> <HIT> <HIT> <HIT>
+ )
+ >
+| <#HIT: ["0"-"9","a"-"f","A"-"F"] >
+|
+/* Identifiers */
+< IDENTIFIER: (<LETTER>|<IMPL_OBJ_START>) (<LETTER>|<DIGIT>)* >
+| < #IMPL_OBJ_START: "#" >
+| < #LETTER:
+ [
+ "\u0024",
+ "\u0041"-"\u005a",
+ "\u005f",
+ "\u0061"-"\u007a",
+ "\u00c0"-"\u00d6",
+ "\u00d8"-"\u00f6",
+ "\u00f8"-"\u00ff",
+ "\u0100"-"\u1fff",
+ "\u3040"-"\u318f",
+ "\u3300"-"\u337f",
+ "\u3400"-"\u3d2d",
+ "\u4e00"-"\u9fff",
+ "\uf900"-"\ufaff"
+ ]
+ >
+|
+ < #DIGIT:
+ [
+ "\u0030"-"\u0039",
+ "\u0660"-"\u0669",
+ "\u06f0"-"\u06f9",
+ "\u0966"-"\u096f",
+ "\u09e6"-"\u09ef",
+ "\u0a66"-"\u0a6f",
+ "\u0ae6"-"\u0aef",
+ "\u0b66"-"\u0b6f",
+ "\u0be7"-"\u0bef",
+ "\u0c66"-"\u0c6f",
+ "\u0ce6"-"\u0cef",
+ "\u0d66"-"\u0d6f",
+ "\u0e50"-"\u0e59",
+ "\u0ed0"-"\u0ed9",
+ "\u1040"-"\u1049"
+ ]
+ >
+| < INTEGER: ["0"-"9"] (["0"-"9"])* >
+| <DOT: ".">
+| <DQUOTE: "\"">
+| <SQUOTE: "'">
+| <LBRACKET: "[">
+| <RBRACKET: "]">
+}
+
+// 3.
+ParsedExpression parse() :
+{
+Token t = null;
+ParsedExpression pe = new ParsedExpression();
+Term term = null;
+}
+{
+ (
+ (term = parseLiteralTerm() {pe.addTerm(term);}) |
+ (<START_EXPRESSION> term = parseExpression() <END_EXPRESSION> {pe.addTerm(term);}) |
+ (<ESCAPED_START_EXPRESSION> term = parseExpression() <END_EXPRESSION> {pe.addTerm(new LiteralTerm("\\")); pe.addTerm(term);})
+ )* <EOF>
+{
+return pe;
+}
+}
+
+LiteralTerm parseLiteralTerm() :
+{
+Token t = null;
+LiteralTerm ls = null;
+}
+{
+ (t = <NON_EXPRESSION_TEXT> {ls = new LiteralTerm(t.image); return ls;})
+}
+
+
+ExpressionTerm parseExpression() :
+{
+ExpressionTerm expr = new ExpressionTerm();
+ExpressionToken eTok = null;
+}
+{
+
+(
+eTok = Context()
+{
+expr.addToken(eTok);
+}
+(
+ (<DOT> eTok = ExprIdentifier() | LOOKAHEAD(2) eTok = MapKey() | eTok = ArrayIndex())
+ {
+ {
+ expr.addToken(eTok);
+ }
+ }
+
+)*
+)
+{
+expr.seal();
+return expr;
+}
+}
+
+ExpressionToken Context() :
+{
+Token t = null;
+ExpressionToken eTok = null;
+}
+{
+(t = <IDENTIFIER>)
+{
+//System.out.println("** Parser found context: " + t.image);
+eTok = new ContextToken(t.image);
+return eTok;
+}
+}
+
+ExpressionToken ExprIdentifier() :
+{
+Token t = null;
+ExpressionToken eTok = null;
+}
+{
+(t = <IDENTIFIER>)
+{
+//System.out.println("** Parser found identifier: " + t.image);
+eTok = new IdentifierToken(t.image);
+return eTok;
+}
+}
+
+// handle text inside of map braces as ["..."] or ['...']
+ExpressionToken MapKey() :
+{
+Token t = null;
+ExpressionToken eTok = null;
+}
+{
+(
+<LBRACKET> (t=<STRING_LITERAL>) <RBRACKET>
+)
+{
+eTok = new MapKeyToken(t.image);
+return eTok;
+}
+}
+
+ExpressionToken ArrayIndex() :
+{
+Token t = null;
+ExpressionToken eTok = null;
+}
+{
+(<LBRACKET> (t = <INTEGER>) <RBRACKET>)
+{
+//System.out.println("** Parser found array index: " + t.image);
+eTok = new ArrayIndexToken(t.image);
+return eTok;
+}
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/NetUIReadVariableResolver.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/NetUIReadVariableResolver.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/NetUIReadVariableResolver.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/NetUIReadVariableResolver.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.script.el;
+
+import org.apache.ti.script.IllegalExpressionException;
+import org.apache.ti.util.logging.Logger;
+
+import javax.servlet.jsp.el.VariableResolver;
+
+/**
+ *
+ */
+public class NetUIReadVariableResolver
+ extends NetUIVariableResolver {
+
+ private static final Logger LOGGER = Logger.getInstance(NetUIReadVariableResolver.class);
+
+ private VariableResolver _vr = null;
+
+ public NetUIReadVariableResolver(VariableResolver vr) {
+ assert vr != null;
+ _vr = vr;
+ }
+
+ public Object resolveVariable(String name) {
+
+ try {
+ return _vr.resolveVariable(name);
+ } catch (javax.servlet.jsp.el.ELException ele) {
+ RuntimeException re = new RuntimeException("Could not resolve variable named \"" + name + "\"", new IllegalExpressionException());
+
+ if (LOGGER.isErrorEnabled())
+ LOGGER.error("", re);
+
+ throw re;
+ }
+ }
+
+ public String[] getAvailableVariables() {
+ return new String[]{"actionForm", "pageFlow", "globalApp", "request", "session", "application", "pageContext", "bundle", "container", "url", "pageInput"};
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/NetUIUpdateVariableResolver.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/NetUIUpdateVariableResolver.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/NetUIUpdateVariableResolver.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/NetUIUpdateVariableResolver.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.script.el;
+
+import org.apache.ti.pageflow.PageFlowController;
+import org.apache.ti.pageflow.xwork.PageFlowActionContext;
+import org.apache.ti.script.IllegalExpressionException;
+import org.apache.ti.script.common.ImplicitObjectUtil;
+import org.apache.ti.util.logging.Logger;
+
+import java.util.Map;
+
+/**
+ *
+ */
+public class NetUIUpdateVariableResolver
+ extends NetUIVariableResolver {
+
+ private static final Logger LOGGER = Logger.getInstance(NetUIVariableResolver.class);
+
+ private boolean _requestParameter = true;
+ private Object _form = null;
+
+ public NetUIUpdateVariableResolver(Object form, boolean requestParameter) {
+ super();
+
+ _requestParameter = requestParameter;
+ _form = form;
+ }
+
+ public Object resolveVariable(String name) {
+ if (name.equals("actionForm"))
+ return _form;
+ else if (name.equals("pageFlow"))
+ return getPageFlow();
+ else if (name.equals("sharedFlow"))
+ return getSharedFlow();
+ else if (name.equals("requestScope")) {
+ if (_requestParameter == false)
+ return PageFlowActionContext.get().getWebContext().getRequestScope();
+ else
+ throw new IllegalExpressionException("The request data binding context can not be updated from a request parameter.");
+ } else if (name.equals("sessionScope")) {
+ if (_requestParameter == false)
+ return PageFlowActionContext.get().getWebContext().getSessionScope();
+ else
+ throw new IllegalExpressionException("The session data binding context can not be updated from a request parameter.");
+ } else if (name.equals("applicationScope")) {
+ if (_requestParameter == false)
+ return PageFlowActionContext.get().getWebContext().getApplicationScope();
+ else
+ throw new IllegalExpressionException("The application data binding context can not be updated from a request parameter.");
+ } else {
+ String msg = "Could not resolve variable named \"" + name + "\" for an expression update.";
+ if (LOGGER.isErrorEnabled())
+ LOGGER.error(msg);
+
+ throw new IllegalExpressionException(msg);
+ }
+ }
+
+ public String[] getAvailableVariables() {
+ if (_requestParameter)
+ return new String[]{"actionForm", "pageFlow", "globalApp"};
+ else
+ return new String[]{"actionForm", "pageFlow", "globalApp", "request", "session", "application"};
+ }
+
+ private static final Map/*<String, SharedFlowController>*/ getSharedFlow() {
+ return ImplicitObjectUtil.getSharedFlow();
+ }
+
+ private static final PageFlowController getPageFlow() {
+ return ImplicitObjectUtil.getPageFlow();
+ }
+
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/NetUIVariableResolver.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/NetUIVariableResolver.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/NetUIVariableResolver.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/script/el/NetUIVariableResolver.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.script.el;
+
+import javax.servlet.jsp.el.VariableResolver;
+
+/**
+ *
+ */
+public abstract class NetUIVariableResolver
+ implements VariableResolver {
+
+ public abstract Object resolveVariable(String name);
+
+ public abstract String[] getAvailableVariables();
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org