You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2014/11/03 07:54:24 UTC
svn commit: r1636282 [14/20] - in
/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23: ./
applications/content/config/ applications/content/data/
applications/humanres/src/org/ofbiz/humanres/
applications/humanres/webapp/humanres/WEB-INF/ applica...
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java?rev=1636282&r1=1636281&r2=1636282&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java (original)
+++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/ModelWidgetAction.java Mon Nov 3 06:54:16 2014
@@ -21,6 +21,9 @@ package org.ofbiz.widget;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -30,10 +33,6 @@ import java.util.regex.PatternSyntaxExce
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
-import javolution.util.FastList;
-import javolution.util.FastMap;
-
-import org.w3c.dom.Element;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralException;
import org.ofbiz.base.util.ObjectType;
@@ -59,6 +58,7 @@ import org.ofbiz.minilang.method.MethodC
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.ModelService;
+import org.w3c.dom.Element;
@SuppressWarnings("serial")
public abstract class ModelWidgetAction implements Serializable {
@@ -75,43 +75,53 @@ public abstract class ModelWidgetAction
public abstract void runAction(Map<String, Object> context) throws GeneralException;
+ public abstract void accept(ModelActionVisitor visitor);
+
+ public static ModelWidgetAction toModelWidgetAction(ModelWidget modelWidget, Element actionElement) {
+ if ("set".equals(actionElement.getNodeName())) {
+ return new SetField(modelWidget, actionElement);
+ } else if ("property-map".equals(actionElement.getNodeName())) {
+ return new PropertyMap(modelWidget, actionElement);
+ } else if ("property-to-field".equals(actionElement.getNodeName())) {
+ return new PropertyToField(modelWidget, actionElement);
+ } else if ("script".equals(actionElement.getNodeName())) {
+ return new Script(modelWidget, actionElement);
+ } else if ("service".equals(actionElement.getNodeName())) {
+ return new Service(modelWidget, actionElement);
+ } else if ("entity-one".equals(actionElement.getNodeName())) {
+ return new EntityOne(modelWidget, actionElement);
+ } else if ("entity-and".equals(actionElement.getNodeName())) {
+ return new EntityAnd(modelWidget, actionElement);
+ } else if ("entity-condition".equals(actionElement.getNodeName())) {
+ return new EntityCondition(modelWidget, actionElement);
+ } else if ("get-related-one".equals(actionElement.getNodeName())) {
+ return new GetRelatedOne(modelWidget, actionElement);
+ } else if ("get-related".equals(actionElement.getNodeName())) {
+ return new GetRelated(modelWidget, actionElement);
+ } else {
+ throw new IllegalArgumentException("Action element not supported with name: " + actionElement.getNodeName());
+ }
+ }
+
public static List<ModelWidgetAction> readSubActions(ModelWidget modelWidget, Element parentElement) {
List<? extends Element> actionElementList = UtilXml.childElementList(parentElement);
List<ModelWidgetAction> actions = new ArrayList<ModelWidgetAction>(actionElementList.size());
for (Element actionElement: actionElementList) {
- if ("set".equals(actionElement.getNodeName())) {
- actions.add(new SetField(modelWidget, actionElement));
- } else if ("property-map".equals(actionElement.getNodeName())) {
- actions.add(new PropertyMap(modelWidget, actionElement));
- } else if ("property-to-field".equals(actionElement.getNodeName())) {
- actions.add(new PropertyToField(modelWidget, actionElement));
- } else if ("script".equals(actionElement.getNodeName())) {
- actions.add(new Script(modelWidget, actionElement));
- } else if ("service".equals(actionElement.getNodeName())) {
- actions.add(new Service(modelWidget, actionElement));
- } else if ("entity-one".equals(actionElement.getNodeName())) {
- actions.add(new EntityOne(modelWidget, actionElement));
- } else if ("entity-and".equals(actionElement.getNodeName())) {
- actions.add(new EntityAnd(modelWidget, actionElement));
- } else if ("entity-condition".equals(actionElement.getNodeName())) {
- actions.add(new EntityCondition(modelWidget, actionElement));
- } else if ("get-related-one".equals(actionElement.getNodeName())) {
- actions.add(new GetRelatedOne(modelWidget, actionElement));
- } else if ("get-related".equals(actionElement.getNodeName())) {
- actions.add(new GetRelated(modelWidget, actionElement));
- } else {
- throw new IllegalArgumentException("Action element not supported with name: " + actionElement.getNodeName());
- }
+ actions.add(toModelWidgetAction(modelWidget, actionElement));
}
- return actions;
+ return Collections.unmodifiableList(actions);
}
- public static void runSubActions(List<ModelWidgetAction> actions, Map<String, Object> context) throws GeneralException {
+ public static void runSubActions(List<ModelWidgetAction> actions, Map<String, Object> context) {
if (actions == null) return;
-
- for (ModelWidgetAction action: actions) {
- if (Debug.verboseOn()) Debug.logVerbose("Running widget action " + action.getClass().getName(), module);
- action.runAction(context);
+ for (ModelWidgetAction action : actions) {
+ if (Debug.verboseOn())
+ Debug.logVerbose("Running action " + action.getClass().getName(), module);
+ try {
+ action.runAction(context);
+ } catch (GeneralException e) {
+ throw new RuntimeException(e);
+ }
}
}
@@ -140,6 +150,7 @@ public abstract class ModelWidgetAction
}
}
+ @SuppressWarnings("rawtypes")
@Override
public void runAction(Map<String, Object> context) {
String globalStr = this.globalExdr.expandString(context);
@@ -179,9 +190,9 @@ public abstract class ModelWidgetAction
if (UtilValidate.isNotEmpty(this.type)) {
if ("NewMap".equals(this.type)) {
- newValue = FastMap.newInstance();
+ newValue = new HashMap();
} else if ("NewList".equals(this.type)) {
- newValue = FastList.newInstance();
+ newValue = new LinkedList();
} else {
try {
newValue = ObjectType.simpleTypeConvert(newValue, this.type, null, (TimeZone) context.get("timeZone"), (Locale) context.get("locale"), true);
@@ -273,6 +284,11 @@ public abstract class ModelWidgetAction
}
return newValue;
}
+
+ @Override
+ public void accept(ModelActionVisitor visitor) {
+ visitor.visit(this);
+ }
}
public static class PropertyMap extends ModelWidgetAction {
@@ -328,6 +344,11 @@ public abstract class ModelWidgetAction
}
}
}
+
+ @Override
+ public void accept(ModelActionVisitor visitor) {
+ visitor.visit(this);
+ }
}
public static class PropertyToField extends ModelWidgetAction {
@@ -384,6 +405,11 @@ public abstract class ModelWidgetAction
}
fieldAcsr.put(context, value);
}
+
+ @Override
+ public void accept(ModelActionVisitor visitor) {
+ visitor.visit(this);
+ }
}
public static class Script extends ModelWidgetAction {
@@ -400,7 +426,7 @@ public abstract class ModelWidgetAction
@Override
public void runAction(Map<String, Object> context) throws GeneralException {
if (location.endsWith(".xml")) {
- Map<String, Object> localContext = FastMap.newInstance();
+ Map<String, Object> localContext = new HashMap<String, Object>();
localContext.putAll(context);
DispatchContext ctx = WidgetWorker.getDispatcher(context).getDispatchContext();
MethodContext methodContext = new MethodContext(ctx, localContext, null);
@@ -414,6 +440,11 @@ public abstract class ModelWidgetAction
ScriptUtil.executeScript(this.location, this.method, context);
}
}
+
+ @Override
+ public void accept(ModelActionVisitor visitor) {
+ visitor.visit(this);
+ }
}
public static class Service extends ModelWidgetAction {
@@ -445,7 +476,7 @@ public abstract class ModelWidgetAction
if ("true".equals(autoFieldMapString)) {
DispatchContext dc = WidgetWorker.getDispatcher(context).getDispatchContext();
// try a map called "parameters", try it first so values from here are overriden by values in the main context
- Map<String, Object> combinedMap = FastMap.newInstance();
+ Map<String, Object> combinedMap = new HashMap<String, Object>();
Map<String, Object> parametersObj = UtilGenerics.toMap(context.get("parameters"));
if (parametersObj != null) {
combinedMap.putAll(parametersObj);
@@ -460,7 +491,7 @@ public abstract class ModelWidgetAction
}
}
if (serviceContext == null) {
- serviceContext = FastMap.newInstance();
+ serviceContext = new HashMap<String, Object>();
}
if (this.fieldMap != null) {
@@ -495,6 +526,11 @@ public abstract class ModelWidgetAction
public FlexibleStringExpander getServiceNameExdr() {
return this.serviceNameExdr;
}
+
+ @Override
+ public void accept(ModelActionVisitor visitor) {
+ visitor.visit(this);
+ }
}
public static class EntityOne extends ModelWidgetAction {
@@ -519,6 +555,11 @@ public abstract class ModelWidgetAction
public PrimaryKeyFinder getFinder() {
return this.finder;
}
+
+ @Override
+ public void accept(ModelActionVisitor visitor) {
+ visitor.visit(this);
+ }
}
public static class EntityAnd extends ModelWidgetAction {
@@ -543,6 +584,11 @@ public abstract class ModelWidgetAction
public ByAndFinder getFinder() {
return this.finder;
}
+
+ @Override
+ public void accept(ModelActionVisitor visitor) {
+ visitor.visit(this);
+ }
}
public static class EntityCondition extends ModelWidgetAction {
@@ -567,6 +613,11 @@ public abstract class ModelWidgetAction
public ByConditionFinder getFinder() {
return this.finder;
}
+
+ @Override
+ public void accept(ModelActionVisitor visitor) {
+ visitor.visit(this);
+ }
}
public static class GetRelatedOne extends ModelWidgetAction {
@@ -610,6 +661,11 @@ public abstract class ModelWidgetAction
public String getRelationName() {
return this.relationName;
}
+
+ @Override
+ public void accept(ModelActionVisitor visitor) {
+ visitor.visit(this);
+ }
}
public static class GetRelated extends ModelWidgetAction {
@@ -667,5 +723,10 @@ public abstract class ModelWidgetAction
public String getRelationName() {
return this.relationName;
}
+
+ @Override
+ public void accept(ModelActionVisitor visitor) {
+ visitor.visit(this);
+ }
}
}
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/WidgetFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/WidgetFactory.java?rev=1636282&r1=1636281&r2=1636282&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/WidgetFactory.java (original)
+++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/WidgetFactory.java Mon Nov 3 06:54:16 2014
@@ -24,8 +24,7 @@ import java.lang.reflect.Modifier;
import java.util.Iterator;
import java.util.Map;
import java.util.ServiceLoader;
-
-import javolution.util.FastMap;
+import java.util.concurrent.ConcurrentHashMap;
import org.ofbiz.base.util.Assert;
import org.ofbiz.base.util.Debug;
@@ -42,7 +41,7 @@ import org.w3c.dom.Element;
public class WidgetFactory {
public static final String module = WidgetFactory.class.getName();
- protected static final Map<String, Constructor<? extends ModelScreenWidget>> screenWidgets = FastMap.newInstance();
+ protected static final Map<String, Constructor<? extends ModelScreenWidget>> screenWidgets = new ConcurrentHashMap<String, Constructor<? extends ModelScreenWidget>>();
static {
loadStandardWidgets();
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/WidgetWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/WidgetWorker.java?rev=1636282&r1=1636281&r2=1636282&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/WidgetWorker.java (original)
+++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/WidgetWorker.java Mon Nov 3 06:54:16 2014
@@ -25,6 +25,8 @@ import java.math.BigDecimal;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -34,9 +36,6 @@ import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javolution.util.FastList;
-import javolution.util.FastMap;
-
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.StringUtil;
import org.ofbiz.base.util.UtilDateTime;
@@ -414,7 +413,7 @@ public class WidgetWorker {
public static class AutoServiceParameters {
private String serviceName;
- List<String> excludeList = FastList.newInstance();
+ List<String> excludeList = new ArrayList<String>();
boolean includePk;
boolean includeNonPk;
boolean sendIfEmpty;
@@ -433,7 +432,7 @@ public class WidgetWorker {
@SuppressWarnings("unchecked")
public Map<String, String> getParametersMap(Map<String, Object> context, String defaultServiceName) {
- Map<String, String> autServiceParams = FastMap.newInstance();
+ Map<String, String> autServiceParams = new HashMap<String, String>();
LocalDispatcher dispatcher = (LocalDispatcher) context.get("dispatcher");
if (dispatcher == null) {
Debug.logError("We can not append auto service Parameters since we could not find dispatcher in the current context", module);
@@ -477,7 +476,7 @@ public class WidgetWorker {
public static class AutoEntityParameters {
private String entityName;
private String includeType;
- List<String> excludeList = FastList.newInstance();
+ List<String> excludeList = new ArrayList<String>();
boolean includePk;
boolean includeNonPk;
boolean sendIfEmpty;
@@ -499,7 +498,7 @@ public class WidgetWorker {
@SuppressWarnings("unchecked")
public Map<String, String> getParametersMap(Map<String, Object> context, String defaultEntityName) {
- Map<String, String> autEntityParams = FastMap.newInstance();
+ Map<String, String> autEntityParams = new HashMap<String, String>();
Delegator delegator = (Delegator) context.get("delegator");
if (delegator == null) {
Debug.logError("We can not append auto entity Parameters since we could not find delegator in the current context", module);
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/cache/WidgetContextCacheKey.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/cache/WidgetContextCacheKey.java?rev=1636282&r1=1636281&r2=1636282&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/cache/WidgetContextCacheKey.java (original)
+++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/cache/WidgetContextCacheKey.java Mon Nov 3 06:54:16 2014
@@ -18,24 +18,24 @@
*******************************************************************************/
package org.ofbiz.widget.cache;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import javolution.util.FastMap;
-import javolution.util.FastSet;
-
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilGenerics;
import org.ofbiz.base.util.UtilMisc;
-public class WidgetContextCacheKey {
+public final class WidgetContextCacheKey {
public static final String module = WidgetContextCacheKey.class.getName();
- private static Set<String> fieldNamesToSkip;
+ private static Set<String> fieldNamesToSkip = createFieldNamesToSkip();
- static {
- fieldNamesToSkip = FastSet.newInstance();
+ private static Set<String> createFieldNamesToSkip(){
+ Set<String> fieldNamesToSkip = new HashSet<String>();
fieldNamesToSkip.add("globalContext");
fieldNamesToSkip.add("delegator");
fieldNamesToSkip.add("dispatcher");
@@ -76,13 +76,13 @@ public class WidgetContextCacheKey {
// parameters
fieldNamesToSkip.add("visit");
fieldNamesToSkip.add("visitor");
+ return Collections.unmodifiableSet(fieldNamesToSkip);
}
- protected Map<String, Object> context;
+ private final Map<String, Object> context;
public WidgetContextCacheKey(Map<String, ? extends Object> context) {
- this.context = FastMap.newInstance();
- this.context.putAll(context);
+ this.context = Collections.unmodifiableMap(new HashMap<String, Object>(context));
}
@Override
@@ -103,7 +103,7 @@ public class WidgetContextCacheKey {
return false;
}
- Set<String> unifiedContext = FastSet.newInstance();
+ Set<String> unifiedContext = new HashSet<String>();
unifiedContext.addAll(this.context.keySet());
unifiedContext.addAll(key.context.keySet());
for (String fieldName: unifiedContext) {
@@ -135,7 +135,7 @@ public class WidgetContextCacheKey {
@Override
public String toString() {
- Map<String, Object> printableMap = FastMap.newInstance();
+ Map<String, Object> printableMap = new HashMap<String, Object>();
for (String fieldName: this.context.keySet()) {
if (!fieldNamesToSkip.contains(fieldName) && !"parameters".equals(fieldName)) {
printableMap.put(fieldName, this.context.get(fieldName));
@@ -146,7 +146,7 @@ public class WidgetContextCacheKey {
}
public static String printMap(Map<String, ? extends Object> map) {
- Map<String, Object> printableMap = FastMap.newInstance();
+ Map<String, Object> printableMap = new HashMap<String, Object>();
for (Map.Entry<String, ? extends Object> entry : map.entrySet()) {
String fieldName = entry.getKey();
if (!fieldNamesToSkip.contains(fieldName) &&
@@ -160,7 +160,7 @@ public class WidgetContextCacheKey {
}
public static boolean parametersAreEqual(Map<String, ? extends Object> map1, Map<String, ? extends Object> map2) {
- Set<String> unifiedContext = FastSet.newInstance();
+ Set<String> unifiedContext = new HashSet<String>();
unifiedContext.addAll(map1.keySet());
unifiedContext.addAll(map2.keySet());
for (String fieldName: unifiedContext) {
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java?rev=1636282&r1=1636281&r2=1636282&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java (original)
+++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/fo/FoScreenRenderer.java Mon Nov 3 06:54:16 2014
@@ -62,13 +62,13 @@ public class FoScreenRenderer extends Ht
}
public void renderSectionBegin(Appendable writer, Map<String, Object> context, ModelScreenWidget.Section section) throws IOException {
- if (section.isMainSection) {
+ if (section.isMainSection()) {
this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context);
}
- renderBeginningBoundaryComment(writer, section.isMainSection?"Screen":"Section Widget", section);
+ renderBeginningBoundaryComment(writer, section.isMainSection()?"Screen":"Section Widget", section);
}
public void renderSectionEnd(Appendable writer, Map<String, Object> context, ModelScreenWidget.Section section) throws IOException {
- renderEndingBoundaryComment(writer, section.isMainSection?"Screen":"Section Widget", section);
+ renderEndingBoundaryComment(writer, section.isMainSection()?"Screen":"Section Widget", section);
}
public void renderContainerBegin(Appendable writer, Map<String, Object> context, ModelScreenWidget.Container container) throws IOException {
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/form/FormFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/form/FormFactory.java?rev=1636282&r1=1636281&r2=1636282&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/form/FormFactory.java (original)
+++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/form/FormFactory.java Mon Nov 3 06:54:16 2014
@@ -59,7 +59,9 @@ public class FormFactory {
public static ModelForm getFormFromLocation(String resourceName, String formName, ModelReader entityModelReader, DispatchContext dispatchContext)
throws IOException, SAXException, ParserConfigurationException {
- String cacheKey = resourceName + "#" + formName;
+ StringBuilder sb = new StringBuilder(dispatchContext.getDelegator().getDelegatorName());
+ sb.append(":").append(resourceName).append("#").append(formName);
+ String cacheKey = sb.toString();
ModelForm modelForm = formLocationCache.get(cacheKey);
if (modelForm == null) {
URL formFileUrl = FlexibleLocation.resolveLocation(resourceName);
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java?rev=1636282&r1=1636281&r2=1636282&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java (original)
+++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java Mon Nov 3 06:54:16 2014
@@ -26,6 +26,7 @@ import java.rmi.server.UID;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -37,8 +38,6 @@ import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javolution.util.FastList;
-
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.StringUtil;
import org.ofbiz.base.util.UtilFormatOut;
@@ -87,18 +86,18 @@ import freemarker.template.TemplateExcep
* Widget Library - Form Renderer implementation based on Freemarker macros
*
*/
-public class MacroFormRenderer implements FormStringRenderer {
+public final class MacroFormRenderer implements FormStringRenderer {
public static final String module = MacroFormRenderer.class.getName();
- private Template macroLibrary;
- private WeakHashMap<Appendable, Environment> environments = new WeakHashMap<Appendable, Environment>();
- private StringUtil.SimpleEncoder internalEncoder;
- protected RequestHandler rh;
- protected HttpServletRequest request;
- protected HttpServletResponse response;
- protected boolean javaScriptEnabled = false;
- protected boolean renderPagination = true;
- protected boolean widgetCommentsEnabled = false;
+ private final Template macroLibrary;
+ private final WeakHashMap<Appendable, Environment> environments = new WeakHashMap<Appendable, Environment>();
+ private final StringUtil.SimpleEncoder internalEncoder;
+ private final RequestHandler rh;
+ private final HttpServletRequest request;
+ private final HttpServletResponse response;
+ private final boolean javaScriptEnabled;
+ private boolean renderPagination = true;
+ private boolean widgetCommentsEnabled = false;
public MacroFormRenderer(String macroLibraryPath, HttpServletRequest request, HttpServletResponse response) throws TemplateException, IOException {
macroLibrary = FreeMarkerWorker.getTemplate(macroLibraryPath);
@@ -1087,7 +1086,7 @@ public class MacroFormRenderer implement
String backgroundSubmitRefreshTarget = submitField.getBackgroundSubmitRefreshTarget(context);
if (UtilValidate.isNotEmpty(backgroundSubmitRefreshTarget)) {
if (updateAreas == null) {
- updateAreas = FastList.newInstance();
+ updateAreas = new LinkedList<ModelForm.UpdateArea>();
}
updateAreas.add(new ModelForm.UpdateArea("submit", formId, backgroundSubmitRefreshTarget));
}
@@ -1414,8 +1413,8 @@ public class MacroFormRenderer implement
this.renderNextPrev(writer, context, modelForm);
}
List<ModelFormField> childFieldList = modelForm.getFieldList();
- List<String> columnStyleList = FastList.newInstance();
- List<String> fieldNameList = FastList.newInstance();
+ List<String> columnStyleList = new LinkedList<String>();
+ List<String> fieldNameList = new LinkedList<String>();
for (ModelFormField childField : childFieldList) {
int childFieldType = childField.getFieldInfo().getFieldType();
if (childFieldType == ModelFormField.FieldInfo.HIDDEN || childFieldType == ModelFormField.FieldInfo.IGNORED) {
@@ -2012,7 +2011,7 @@ public class MacroFormRenderer implement
autoCompleterTarget = lookupFieldFormName + "&amp;";
}
autoCompleterTarget = autoCompleterTarget + "ajaxLookup=Y";
- updateAreas = FastList.newInstance();
+ updateAreas = new LinkedList<ModelForm.UpdateArea>();
updateAreas.add(new ModelForm.UpdateArea("change", id, autoCompleterTarget));
}
boolean ajaxEnabled = updateAreas != null && this.javaScriptEnabled;
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=1636282&r1=1636281&r2=1636282&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/form/ModelForm.java (original)
+++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Mon Nov 3 06:54:16 2014
@@ -21,7 +21,10 @@ package org.ofbiz.widget.form;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -30,13 +33,8 @@ import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
-import javolution.util.FastList;
-import javolution.util.FastMap;
-import javolution.util.FastSet;
-
import org.ofbiz.base.util.BshUtil;
import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.GeneralException;
import org.ofbiz.base.util.StringUtil;
import org.ofbiz.base.util.UtilGenerics;
import org.ofbiz.base.util.UtilMisc;
@@ -56,8 +54,9 @@ import org.ofbiz.service.DispatchContext
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.ModelParam;
import org.ofbiz.service.ModelService;
-import org.ofbiz.webapp.control.ConfigXMLReader;
import org.ofbiz.widget.ModelWidget;
+import org.ofbiz.widget.ModelWidgetAction;
+import org.ofbiz.widget.ModelWidgetVisitor;
import org.ofbiz.widget.WidgetWorker;
import org.w3c.dom.Element;
@@ -73,9 +72,6 @@ public class ModelForm extends ModelWidg
public static final String module = ModelForm.class.getName();
public static final String DEFAULT_FORM_RESULT_LIST_NAME = "defaultFormResultList";
- protected ModelReader entityModelReader;
- protected DispatchContext dispatchContext;
-
protected String formLocation;
protected String parentFormName;
protected String parentFormLocation;
@@ -131,12 +127,12 @@ public class ModelForm extends ModelWidg
protected boolean overridenListSize = false;
protected boolean clientAutocompleteFields = true;
- protected List<AltTarget> altTargets = FastList.newInstance();
- protected List<AutoFieldsService> autoFieldsServices = FastList.newInstance();
- protected List<AutoFieldsEntity> autoFieldsEntities = FastList.newInstance();
- protected List<String> lastOrderFields = FastList.newInstance();
- protected List<SortField> sortOrderFields = FastList.newInstance();
- protected List<AltRowStyle> altRowStyles = FastList.newInstance();
+ protected List<AltTarget> altTargets = new ArrayList<AltTarget>();
+ protected List<AutoFieldsService> autoFieldsServices = new ArrayList<AutoFieldsService>();
+ protected List<AutoFieldsEntity> autoFieldsEntities = new ArrayList<AutoFieldsEntity>();
+ protected List<String> lastOrderFields = new ArrayList<String>();
+ protected List<SortField> sortOrderFields = new ArrayList<SortField>();
+ protected List<AltRowStyle> altRowStyles = new ArrayList<AltRowStyle>();
/** This List will contain one copy of each field for each field name in the order
* they were encountered in the service, entity, or form definition; field definitions
@@ -147,25 +143,25 @@ public class ModelForm extends ModelWidg
* necessary to use the Map. The Map is used when loading the form definition to keep the
* list clean and implement the override features for field definitions.
*/
- protected List<ModelFormField> fieldList = FastList.newInstance();
+ protected List<ModelFormField> fieldList = new ArrayList<ModelFormField>();
/** This Map is keyed with the field name and has a ModelFormField for the value.
*/
- protected Map<String, ModelFormField> fieldMap = FastMap.newInstance();
+ protected Map<String, ModelFormField> fieldMap = new HashMap<String, ModelFormField>();
/** Keeps track of conditional fields to help ensure that only one is rendered
*/
- protected Set<String> useWhenFields = FastSet.newInstance();
+ protected Set<String> useWhenFields = new HashSet<String>();
/** This is a list of FieldGroups in the order they were created.
* Can also include Banner objects.
*/
- protected List<FieldGroupBase> fieldGroupList = FastList.newInstance();
+ protected List<FieldGroupBase> fieldGroupList = new ArrayList<FieldGroupBase>();
/** This Map is keyed with the field name and has a FieldGroup for the value.
* Can also include Banner objects.
*/
- protected Map<String, FieldGroupBase> fieldGroupMap = FastMap.newInstance();
+ protected Map<String, FieldGroupBase> fieldGroupMap = new HashMap<String, FieldGroupBase>();
/** This field group will be the "catch-all" group for fields that are not
* included in an explicit field-group.
@@ -189,10 +185,10 @@ public class ModelForm extends ModelWidg
public static String DEFAULT_SORT_FIELD_ASC_STYLE = "sort-order-asc";
public static String DEFAULT_SORT_FIELD_DESC_STYLE = "sort-order-desc";
- protected List<ModelFormAction> actions;
- protected List<ModelFormAction> rowActions;
+ protected List<ModelWidgetAction> actions;
+ protected List<ModelWidgetAction> rowActions;
protected FlexibleStringExpander rowCountExdr;
- protected List<ModelFormField> multiSubmitFields = FastList.newInstance();
+ protected List<ModelFormField> multiSubmitFields = new ArrayList<ModelFormField>();
protected int rowCount = 0;
private String sortFieldParameterName = "sortField";
@@ -204,28 +200,43 @@ public class ModelForm extends ModelWidg
protected List<UpdateArea> onSortColumnUpdateAreas;
// ===== CONSTRUCTORS =====
- /** Default Constructor */
- public ModelForm() {}
/** XML Constructor */
public ModelForm(Element formElement, ModelReader entityModelReader, DispatchContext dispatchContext) {
super(formElement);
- this.entityModelReader = entityModelReader;
- this.dispatchContext = dispatchContext;
try {
- initForm(formElement);
+ initForm(formElement, entityModelReader, dispatchContext);
} catch (RuntimeException e) {
Debug.logError(e, "Error parsing form [" + formElement.getAttribute("name") + "]: " + e.toString(), module);
throw e;
}
}
- public ModelForm(Element formElement) {
- super(formElement);
- initForm(formElement);
+ public String getTarget() {
+ return target.getOriginal();
+ }
+
+ public List<AltTarget> getAltTargets() {
+ return altTargets;
+ }
+
+ public List<ModelWidgetAction> getActions() {
+ return actions;
+ }
+
+ public List<ModelWidgetAction> getRowActions() {
+ return rowActions;
+ }
+
+ public List<AutoFieldsEntity> getAutoFieldsEntities() {
+ return autoFieldsEntities;
+ }
+
+ public List<AutoFieldsService> getAutoFieldsServices() {
+ return autoFieldsServices;
}
- public void initForm(Element formElement) {
+ public void initForm(Element formElement, ModelReader entityModelReader, DispatchContext dispatchContext) {
setDefaultViewSize(UtilProperties.getPropertyValue("widget.properties", "widget.form.defaultViewSize"));
// check if there is a parent form to inherit from
@@ -513,19 +524,19 @@ public class ModelForm extends ModelWidg
// auto-fields-service
for (Element autoFieldsServiceElement: UtilXml.childElementList(formElement, "auto-fields-service")) {
AutoFieldsService autoFieldsService = new AutoFieldsService(autoFieldsServiceElement);
- this.addAutoFieldsFromService(autoFieldsService);
+ this.addAutoFieldsFromService(autoFieldsService, entityModelReader, dispatchContext);
}
// auto-fields-entity
for (Element autoFieldsEntityElement: UtilXml.childElementList(formElement, "auto-fields-entity")) {
AutoFieldsEntity autoFieldsEntity = new AutoFieldsEntity(autoFieldsEntityElement);
- this.addAutoFieldsFromEntity(autoFieldsEntity);
+ this.addAutoFieldsFromEntity(autoFieldsEntity, entityModelReader);
}
// read in add field defs, add/override one by one using the fieldList and fieldMap
String thisType = this.getType();
for (Element fieldElement: UtilXml.childElementList(formElement, "field")) {
- ModelFormField modelFormField = new ModelFormField(fieldElement, this);
+ ModelFormField modelFormField = new ModelFormField(fieldElement, this, entityModelReader, dispatchContext);
ModelFormField.FieldInfo fieldInfo = modelFormField.getFieldInfo();
if (thisType.equals("multi") && fieldInfo instanceof ModelFormField.SubmitField) {
multiSubmitFields.add(modelFormField);
@@ -571,7 +582,7 @@ public class ModelForm extends ModelWidg
// reorder fields according to sort order
if (sortOrderFields.size() > 0) {
- List<ModelFormField> sortedFields = FastList.newInstance();
+ List<ModelFormField> sortedFields = new LinkedList<ModelFormField>();
for (SortField sortField: this.sortOrderFields) {
String fieldName = sortField.getFieldName();
if (UtilValidate.isEmpty(fieldName)) {
@@ -599,7 +610,7 @@ public class ModelForm extends ModelWidg
}
if (UtilValidate.isNotEmpty(this.lastOrderFields)) {
- List<ModelFormField> lastedFields = FastList.newInstance();
+ List<ModelFormField> lastedFields = new LinkedList<ModelFormField>();
for (String fieldName: this.lastOrderFields) {
if (UtilValidate.isEmpty(fieldName)) {
continue;
@@ -695,7 +706,7 @@ public class ModelForm extends ModelWidg
protected void addOnSubmitUpdateArea(UpdateArea updateArea) {
if (onSubmitUpdateAreas == null) {
- onSubmitUpdateAreas = FastList.newInstance();
+ onSubmitUpdateAreas = new ArrayList<UpdateArea>();
}
int index = onSubmitUpdateAreas.indexOf(updateArea);
if (index != -1) {
@@ -707,7 +718,7 @@ public class ModelForm extends ModelWidg
protected void addOnPaginateUpdateArea(UpdateArea updateArea) {
if (onPaginateUpdateAreas == null) {
- onPaginateUpdateAreas = FastList.newInstance();
+ onPaginateUpdateAreas = new ArrayList<UpdateArea>();
}
int index = onPaginateUpdateAreas.indexOf(updateArea);
if (index != -1) {
@@ -724,7 +735,7 @@ public class ModelForm extends ModelWidg
protected void addOnSortColumnUpdateArea(UpdateArea updateArea) {
if (onSortColumnUpdateAreas == null) {
- onSortColumnUpdateAreas = FastList.newInstance();
+ onSortColumnUpdateAreas = new ArrayList<UpdateArea>();
}
int index = onSortColumnUpdateAreas.indexOf(updateArea);
if (index != -1) {
@@ -739,13 +750,13 @@ public class ModelForm extends ModelWidg
}
}
- public void addAutoFieldsFromService(AutoFieldsService autoFieldsService) {
+ private void addAutoFieldsFromService(AutoFieldsService autoFieldsService, ModelReader entityModelReader, DispatchContext dispatchContext) {
autoFieldsServices.add(autoFieldsService);
// read service def and auto-create fields
ModelService modelService = null;
try {
- modelService = this.dispatchContext.getModelService(autoFieldsService.serviceName);
+ modelService = dispatchContext.getModelService(autoFieldsService.serviceName);
} catch (GenericServiceException e) {
String errmsg = "Error finding Service with name " + autoFieldsService.serviceName + " for auto-fields-service in a form widget";
Debug.logError(e, errmsg, module);
@@ -761,7 +772,7 @@ public class ModelForm extends ModelWidg
if (UtilValidate.isNotEmpty(modelParam.entityName) && UtilValidate.isNotEmpty(modelParam.fieldName)) {
ModelEntity modelEntity;
try {
- modelEntity = this.entityModelReader.getModelEntity(modelParam.entityName);
+ modelEntity = entityModelReader.getModelEntity(modelParam.entityName);
if (modelEntity != null) {
ModelField modelField = modelEntity.getField(modelParam.fieldName);
if (modelField != null) {
@@ -788,7 +799,7 @@ public class ModelForm extends ModelWidg
}
}
- public ModelFormField addFieldFromServiceParam(ModelService modelService, ModelParam modelParam, String defaultFieldType, int defaultPosition) {
+ private ModelFormField addFieldFromServiceParam(ModelService modelService, ModelParam modelParam, String defaultFieldType, int defaultPosition) {
// create field def from service param def
ModelFormField newFormField = new ModelFormField(this);
newFormField.setName(modelParam.name);
@@ -801,12 +812,12 @@ public class ModelForm extends ModelWidg
return this.addUpdateField(newFormField);
}
- public void addAutoFieldsFromEntity(AutoFieldsEntity autoFieldsEntity) {
+ private void addAutoFieldsFromEntity(AutoFieldsEntity autoFieldsEntity, ModelReader entityModelReader) {
autoFieldsEntities.add(autoFieldsEntity);
// read entity def and auto-create fields
ModelEntity modelEntity = null;
try {
- modelEntity = this.entityModelReader.getModelEntity(autoFieldsEntity.entityName);
+ modelEntity = entityModelReader.getModelEntity(autoFieldsEntity.entityName);
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
@@ -828,7 +839,7 @@ public class ModelForm extends ModelWidg
}
}
- public ModelFormField addFieldFromEntityField(ModelEntity modelEntity, ModelField modelField, String defaultFieldType, int defaultPosition) {
+ private ModelFormField addFieldFromEntityField(ModelEntity modelEntity, ModelField modelField, String defaultFieldType, int defaultPosition) {
// create field def from entity field def
ModelFormField newFormField = new ModelFormField(this);
newFormField.setName(modelField.getName());
@@ -840,7 +851,7 @@ public class ModelForm extends ModelWidg
}
public void runFormActions(Map<String, Object> context) {
- ModelFormAction.runSubActions(this.actions, context);
+ ModelWidgetAction.runSubActions(this.actions, context);
}
/**
@@ -916,7 +927,7 @@ public class ModelForm extends ModelWidg
}
public void renderSingleFormString(Appendable writer, Map<String, Object> context, FormStringRenderer formStringRenderer, int positions) throws IOException {
- List<ModelFormField> tempFieldList = FastList.newInstance();
+ List<ModelFormField> tempFieldList = new LinkedList<ModelFormField>();
tempFieldList.addAll(this.fieldList);
// Check to see if there is a field, same name and same use-when (could come from extended form)
@@ -1212,7 +1223,7 @@ public class ModelForm extends ModelWidg
// in this model: we can have more fields with the same name when use-when
// conditions are used or when a form is extended or when the fields are
// automatically retrieved by a service or entity definition.
- List<ModelFormField> tempFieldList = FastList.newInstance();
+ List<ModelFormField> tempFieldList = new LinkedList<ModelFormField>();
tempFieldList.addAll(this.fieldList);
for (int j = 0; j < tempFieldList.size(); j++) {
ModelFormField modelFormField = tempFieldList.get(j);
@@ -1230,13 +1241,13 @@ public class ModelForm extends ModelWidg
// We get a sorted (by position, ascending) set of lists;
// each list contains all the fields with that position.
Collection<List<ModelFormField>> fieldListsByPosition = this.getFieldListsByPosition(tempFieldList);
- List<Map<String, List<ModelFormField>>> fieldRowsByPosition = FastList.newInstance(); // this list will contain maps, each one containing the list of fields for a position
+ List<Map<String, List<ModelFormField>>> fieldRowsByPosition = new LinkedList<Map<String, List<ModelFormField>>>(); // this list will contain maps, each one containing the list of fields for a position
for (List<ModelFormField> mainFieldList: fieldListsByPosition) {
int numOfColumns = 0;
- List<ModelFormField> innerDisplayHyperlinkFieldsBegin = FastList.newInstance();
- List<ModelFormField> innerFormFields = FastList.newInstance();
- List<ModelFormField> innerDisplayHyperlinkFieldsEnd = FastList.newInstance();
+ List<ModelFormField> innerDisplayHyperlinkFieldsBegin = new LinkedList<ModelFormField>();
+ List<ModelFormField> innerFormFields = new LinkedList<ModelFormField>();
+ List<ModelFormField> innerDisplayHyperlinkFieldsEnd = new LinkedList<ModelFormField>();
// render title for each field, except hidden & ignored, etc
@@ -1522,7 +1533,7 @@ public class ModelForm extends ModelWidg
int itemIndex = -1;
Object item = null;
context.put("wholeFormContext", context);
- Map<String, Object> previousItem = FastMap.newInstance();
+ Map<String, Object> previousItem = new HashMap<String, Object>();
while ((item = this.safeNext(iter)) != null) {
itemIndex++;
if (itemIndex >= highIndex) {
@@ -1556,10 +1567,10 @@ public class ModelForm extends ModelWidg
this.resetBshInterpreter(localContext);
localContext.push();
localContext.put("previousItem", previousItem);
- previousItem = FastMap.newInstance();
+ previousItem = new HashMap<String, Object>();
previousItem.putAll(itemMap);
- ModelFormAction.runSubActions(this.rowActions, localContext);
+ ModelWidgetAction.runSubActions(this.rowActions, localContext);
localContext.put("itemIndex", Integer.valueOf(itemIndex - lowIndex));
if (UtilValidate.isNotEmpty(context.get("renderFormSeqNumber"))) {
@@ -1571,7 +1582,7 @@ public class ModelForm extends ModelWidg
if (Debug.verboseOn()) Debug.logVerbose("In form got another row, context is: " + localContext, module);
// Check to see if there is a field, same name and same use-when (could come from extended form)
- List<ModelFormField> tempFieldList = FastList.newInstance();
+ List<ModelFormField> tempFieldList = new LinkedList<ModelFormField>();
tempFieldList.addAll(this.fieldList);
for (int j = 0; j < tempFieldList.size(); j++) {
ModelFormField modelFormField = tempFieldList.get(j);
@@ -1608,9 +1619,9 @@ public class ModelForm extends ModelWidg
// we have two phases: preprocessing and rendering
this.rowCount++;
- List<ModelFormField> innerDisplayHyperlinkFieldsBegin = FastList.newInstance();
- List<ModelFormField> innerFormFields = FastList.newInstance();
- List<ModelFormField> innerDisplayHyperlinkFieldsEnd = FastList.newInstance();
+ List<ModelFormField> innerDisplayHyperlinkFieldsBegin = new LinkedList<ModelFormField>();
+ List<ModelFormField> innerFormFields = new LinkedList<ModelFormField>();
+ List<ModelFormField> innerDisplayHyperlinkFieldsEnd = new LinkedList<ModelFormField>();
// Preprocessing:
// all the form fields are evaluated and the ones that will
@@ -1737,7 +1748,7 @@ public class ModelForm extends ModelWidg
// render row formatting open
formStringRenderer.renderFormatItemRowOpen(writer, localContext, this);
Iterator<ModelFormField> innerDisplayHyperlinkFieldsBeginIter = innerDisplayHyperlinkFieldsBegin.iterator();
- Map<String, Integer> fieldCount = FastMap.newInstance();
+ Map<String, Integer> fieldCount = new HashMap<String, Integer>();
while(innerDisplayHyperlinkFieldsBeginIter.hasNext()){
ModelFormField modelFormField = innerDisplayHyperlinkFieldsBeginIter.next();
if(fieldCount.containsKey(modelFormField.getFieldName())){
@@ -1862,7 +1873,7 @@ public class ModelForm extends ModelWidg
}
public List<ModelFormField> getHiddenIgnoredFields(Map<String, Object> context, Set<String> alreadyRendered, List<ModelFormField> fieldList, int position) {
- List<ModelFormField> hiddenIgnoredFieldList = FastList.newInstance();
+ List<ModelFormField> hiddenIgnoredFieldList = new LinkedList<ModelFormField>();
for (ModelFormField modelFormField: fieldList) {
// with position == -1 then gets all the hidden fields
if (position != -1 && modelFormField.getPosition() != position) {
@@ -1927,7 +1938,7 @@ public class ModelForm extends ModelWidg
Integer position = Integer.valueOf(modelFormField.getPosition());
List<ModelFormField> fieldListByPosition = fieldsByPosition.get(position);
if (fieldListByPosition == null) {
- fieldListByPosition = FastList.newInstance();
+ fieldListByPosition = new LinkedList<ModelFormField>();
fieldsByPosition.put(position, fieldListByPosition);
}
fieldListByPosition.add(modelFormField);
@@ -1936,7 +1947,7 @@ public class ModelForm extends ModelWidg
}
public List<ModelFormField> getFieldListByPosition(List<ModelFormField> modelFormFieldList, int position) {
- List<ModelFormField> fieldListByPosition = FastList.newInstance();
+ List<ModelFormField> fieldListByPosition = new LinkedList<ModelFormField>();
for (ModelFormField modelFormField: modelFormFieldList) {
if (modelFormField.getPosition() == position) {
fieldListByPosition.add(modelFormField);
@@ -2061,11 +2072,6 @@ public class ModelForm extends ModelWidg
return lstNm;
}
- @Override
- public String getName() {
- return this.name;
- }
-
public String getCurrentFormName(Map<String, Object> context) {
Integer itemIndex = (Integer) context.get("itemIndex");
String formName = (String) context.get("formName");
@@ -2103,7 +2109,7 @@ public class ModelForm extends ModelWidg
condTrue = boolVal.booleanValue();
} else {
throw new IllegalArgumentException(
- "Return value from target condition eval was not a Boolean: " + retVal.getClass().getName() + " [" + retVal + "] of form " + this.name);
+ "Return value from target condition eval was not a Boolean: " + retVal.getClass().getName() + " [" + retVal + "] of form " + getName());
}
if (condTrue && !targetType.equals("inter-app")) {
@@ -2111,7 +2117,7 @@ public class ModelForm extends ModelWidg
}
}
} catch (EvalError e) {
- String errmsg = "Error evaluating BeanShell target conditions on form " + this.name;
+ String errmsg = "Error evaluating BeanShell target conditions on form " + getName();
Debug.logError(e, errmsg, module);
throw new IllegalArgumentException(errmsg);
}
@@ -2163,7 +2169,7 @@ public class ModelForm extends ModelWidg
@Override
public String getBoundaryCommentName() {
- return formLocation + "#" + name;
+ return formLocation + "#" + getName();
}
public void resetBshInterpreter(Map<String, Object> context) {
@@ -2312,13 +2318,6 @@ public class ModelForm extends ModelWidg
/**
* @param string
*/
- public void setName(String string) {
- this.name = string;
- }
-
- /**
- * @param string
- */
public void setTarget(String string) {
this.target = FlexibleStringExpander.getInstance(string);
}
@@ -2812,7 +2811,7 @@ public class ModelForm extends ModelWidg
}
public void setDefaultEntityNameOnUpdateAreas() {
- List<UpdateArea> allUpdateAreas = FastList.newInstance();
+ List<UpdateArea> allUpdateAreas = new LinkedList<UpdateArea>();
if (UtilValidate.isNotEmpty(this.onSubmitUpdateAreas)) allUpdateAreas.addAll(this.onSubmitUpdateAreas);
if (UtilValidate.isNotEmpty(this.onPaginateUpdateAreas)) allUpdateAreas.addAll(this.onPaginateUpdateAreas);
for (UpdateArea updateArea : allUpdateAreas) {
@@ -2823,7 +2822,7 @@ public class ModelForm extends ModelWidg
}
public void setDefaultServiceNameOnUpdateAreas() {
- List<UpdateArea> allUpdateAreas = FastList.newInstance();
+ List<UpdateArea> allUpdateAreas = new LinkedList<UpdateArea>();
if (UtilValidate.isNotEmpty(this.onSubmitUpdateAreas)) allUpdateAreas.addAll(this.onSubmitUpdateAreas);
if (UtilValidate.isNotEmpty(this.onPaginateUpdateAreas)) allUpdateAreas.addAll(this.onPaginateUpdateAreas);
for (UpdateArea updateArea : allUpdateAreas) {
@@ -2861,11 +2860,11 @@ public class ModelForm extends ModelWidg
}
} else {
throw new IllegalArgumentException(
- "Return value from style condition eval was not a Boolean: " + retVal.getClass().getName() + " [" + retVal + "] of form " + this.name);
+ "Return value from style condition eval was not a Boolean: " + retVal.getClass().getName() + " [" + retVal + "] of form " + getName());
}
}
} catch (EvalError e) {
- String errmsg = "Error evaluating BeanShell style conditions on form " + this.name;
+ String errmsg = "Error evaluating BeanShell style conditions on form " + getName();
Debug.logError(e, errmsg, module);
throw new IllegalArgumentException(errmsg);
}
@@ -2901,7 +2900,7 @@ public class ModelForm extends ModelWidg
protected String defaultEntityName;
protected WidgetWorker.AutoEntityParameters autoEntityParameters;
protected WidgetWorker.AutoEntityParameters autoServiceParameters;
- List<WidgetWorker.Parameter> parameterList = FastList.newInstance();
+ protected List<WidgetWorker.Parameter> parameterList = new ArrayList<WidgetWorker.Parameter>();
/** XML constructor.
* @param updateAreaElement The <code><on-xxx-update-area></code>
* XML element.
@@ -2950,7 +2949,7 @@ public class ModelForm extends ModelWidg
return FlexibleStringExpander.expandString(areaTarget, context);
}
public Map<String, String> getParameterMap(Map<String, Object> context) {
- Map<String, String> fullParameterMap = FastMap.newInstance();
+ Map<String, String> fullParameterMap = new HashMap<String, String>();
if (autoServiceParameters != null) {
fullParameterMap.putAll(autoServiceParameters.getParametersMap(context, defaultServiceName));
}
@@ -3174,163 +3173,8 @@ public class ModelForm extends ModelWidg
}
}
- public Set<String> getAllEntityNamesUsed() {
- Set<String> allEntityNamesUsed = FastSet.newInstance();
- for (AutoFieldsEntity autoFieldsEntity: this.autoFieldsEntities) {
- allEntityNamesUsed.add(autoFieldsEntity.entityName);
- }
- if (this.actions != null) {
- for (ModelFormAction modelFormAction: this.actions) {
- if (modelFormAction instanceof ModelFormAction.EntityOne) {
- allEntityNamesUsed.add(((ModelFormAction.EntityOne)modelFormAction).finder.getEntityName());
- } else if (modelFormAction instanceof ModelFormAction.EntityAnd) {
- allEntityNamesUsed.add(((ModelFormAction.EntityAnd)modelFormAction).finder.getEntityName());
- } else if (modelFormAction instanceof ModelFormAction.EntityCondition) {
- allEntityNamesUsed.add(((ModelFormAction.EntityCondition)modelFormAction).finder.getEntityName());
- }
-
- }
- }
- if (this.rowActions != null) {
- for (ModelFormAction modelFormAction: this.rowActions) {
- if (modelFormAction instanceof ModelFormAction.EntityOne) {
- allEntityNamesUsed.add(((ModelFormAction.EntityOne)modelFormAction).finder.getEntityName());
- } else if (modelFormAction instanceof ModelFormAction.EntityAnd) {
- allEntityNamesUsed.add(((ModelFormAction.EntityAnd)modelFormAction).finder.getEntityName());
- } else if (modelFormAction instanceof ModelFormAction.EntityCondition) {
- allEntityNamesUsed.add(((ModelFormAction.EntityCondition)modelFormAction).finder.getEntityName());
- }
- }
- }
- for (ModelFormField modelFormField: this.fieldList) {
- if (UtilValidate.isNotEmpty(modelFormField.getEntityName())) {
- allEntityNamesUsed.add(modelFormField.getEntityName());
- }
- if (modelFormField.getFieldInfo() instanceof ModelFormField.DisplayEntityField) {
- allEntityNamesUsed.add(((ModelFormField.DisplayEntityField)modelFormField.getFieldInfo()).entityName);
- }
- if (modelFormField.getFieldInfo() instanceof ModelFormField.FieldInfoWithOptions) {
- for (ModelFormField.OptionSource optionSource: ((ModelFormField.FieldInfoWithOptions)modelFormField.getFieldInfo()).optionSources) {
- if (optionSource instanceof ModelFormField.EntityOptions) {
- allEntityNamesUsed.add(((ModelFormField.EntityOptions)optionSource).entityName);
- }
- }
- }
- }
- return allEntityNamesUsed;
- }
-
- public Set<String> getAllServiceNamesUsed() {
- Set<String> allServiceNamesUsed = FastSet.newInstance();
- for (AutoFieldsService autoFieldsService: this.autoFieldsServices) {
- allServiceNamesUsed.add(autoFieldsService.serviceName);
- }
- if (this.actions != null) {
- for (ModelFormAction modelFormAction: this.actions) {
- try {
- ModelFormAction.Service service = (ModelFormAction.Service) modelFormAction;
- if (!service.serviceNameExdr.isEmpty()) {
- allServiceNamesUsed.add(service.serviceNameExdr.toString());
- }
- } catch (ClassCastException e) {}
- }
- }
- if (this.rowActions != null) {
- for (ModelFormAction modelFormAction: this.rowActions) {
- try {
- ModelFormAction.Service service = (ModelFormAction.Service) modelFormAction;
- if (!service.serviceNameExdr.isEmpty()) {
- allServiceNamesUsed.add(service.serviceNameExdr.toString());
- }
- } catch (ClassCastException e) {}
- }
- }
- for (ModelFormField modelFormField: this.fieldList) {
- if (UtilValidate.isNotEmpty(modelFormField.getServiceName())) {
- allServiceNamesUsed.add(modelFormField.getServiceName());
- }
- }
- return allServiceNamesUsed;
- }
-
- public Set<String> getLinkedRequestsLocationAndUri() throws GeneralException {
- Set<String> allRequestsUsed = FastSet.newInstance();
-
- if (this.fieldList != null) {
- for (ModelFormField modelFormField: this.fieldList) {
- if (modelFormField.getFieldInfo() instanceof ModelFormField.HyperlinkField) {
- ModelFormField.HyperlinkField link = (ModelFormField.HyperlinkField) modelFormField.getFieldInfo();
- String target = link.getTarget(null);
- String urlMode = link.getTargetType();
-
- Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(target, urlMode);
- if (controllerLocAndRequestSet != null) {
- allRequestsUsed.addAll(controllerLocAndRequestSet);
- }
- } else if (modelFormField.getFieldInfo() instanceof ModelFormField.DisplayEntityField) {
- ModelFormField.DisplayEntityField parentField = (ModelFormField.DisplayEntityField) modelFormField.getFieldInfo();
- if (parentField.subHyperlink != null) {
- Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(parentField.subHyperlink.getTarget(null), parentField.subHyperlink.getTargetType());
- if (controllerLocAndRequestSet != null) {
- allRequestsUsed.addAll(controllerLocAndRequestSet);
- }
- }
- } else if (modelFormField.getFieldInfo() instanceof ModelFormField.TextField) {
- ModelFormField.TextField parentField = (ModelFormField.TextField) modelFormField.getFieldInfo();
- if (parentField.subHyperlink != null) {
- Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(parentField.subHyperlink.getTarget(null), parentField.subHyperlink.getTargetType());
- if (controllerLocAndRequestSet != null) {
- allRequestsUsed.addAll(controllerLocAndRequestSet);
- }
- }
- } else if (modelFormField.getFieldInfo() instanceof ModelFormField.DropDownField) {
- ModelFormField.DropDownField parentField = (ModelFormField.DropDownField) modelFormField.getFieldInfo();
- if (parentField.subHyperlink != null) {
- Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(parentField.subHyperlink.getTarget(null), parentField.subHyperlink.getTargetType());
- if (controllerLocAndRequestSet != null) {
- allRequestsUsed.addAll(controllerLocAndRequestSet);
- }
- }
- } else if (modelFormField.getFieldInfo() instanceof ModelFormField.ImageField) {
- ModelFormField.ImageField parentField = (ModelFormField.ImageField) modelFormField.getFieldInfo();
- if (parentField.subHyperlink != null) {
- Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(parentField.subHyperlink.getTarget(null), parentField.subHyperlink.getTargetType());
- if (controllerLocAndRequestSet != null) {
- allRequestsUsed.addAll(controllerLocAndRequestSet);
- }
- }
- }
- }
- }
- return allRequestsUsed;
- }
-
- public Set<String> getTargetedRequestsLocationAndUri() throws GeneralException {
- Set<String> allRequestsUsed = FastSet.newInstance();
-
- if (this.altTargets != null) {
- for (AltTarget altTarget: this.altTargets) {
- String target = altTarget.targetExdr.getOriginal();
- String urlMode = "intra-app";
-
- Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(target, urlMode);
- if (controllerLocAndRequestSet != null) {
- allRequestsUsed.addAll(controllerLocAndRequestSet);
- }
- }
- }
-
- if (!this.target.isEmpty()) {
- String target = this.target.getOriginal();
- String urlMode = UtilValidate.isNotEmpty(this.targetType) ? this.targetType : "intra-app";
- if (target.indexOf("${") < 0) {
- Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(target, urlMode);
- if (controllerLocAndRequestSet != null) {
- allRequestsUsed.addAll(controllerLocAndRequestSet);
- }
- }
- }
-
- return allRequestsUsed;
+ @Override
+ public void accept(ModelWidgetVisitor visitor) {
+ visitor.visit(this);
}
}
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java?rev=1636282&r1=1636281&r2=1636282&view=diff
==============================================================================
--- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java (original)
+++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java Mon Nov 3 06:54:16 2014
@@ -18,25 +18,17 @@
*******************************************************************************/
package org.ofbiz.widget.form;
-import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
-import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
-import java.util.Locale;
import java.util.Map;
-import java.util.TimeZone;
import java.util.regex.PatternSyntaxException;
-import javolution.util.FastList;
-import javolution.util.FastMap;
-
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralException;
-import org.ofbiz.base.util.ObjectType;
-import org.ofbiz.base.util.ScriptUtil;
import org.ofbiz.base.util.UtilGenerics;
-import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.UtilXml;
import org.ofbiz.base.util.collections.FlexibleMapAccessor;
@@ -44,49 +36,26 @@ import org.ofbiz.base.util.string.Flexib
import org.ofbiz.entity.finder.ByAndFinder;
import org.ofbiz.entity.finder.ByConditionFinder;
import org.ofbiz.entity.finder.EntityFinderUtil;
-import org.ofbiz.entity.finder.PrimaryKeyFinder;
-import org.ofbiz.entity.util.EntityUtilProperties;
-import org.ofbiz.minilang.MiniLangException;
-import org.ofbiz.minilang.SimpleMethod;
-import org.ofbiz.minilang.method.MethodContext;
-import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.ModelService;
+import org.ofbiz.widget.ModelActionVisitor;
+import org.ofbiz.widget.ModelWidgetAction;
import org.ofbiz.widget.WidgetWorker;
import org.w3c.dom.Element;
-
/**
* Widget Library - Screen model class
*/
public abstract class ModelFormAction {
- public static final String module = ModelFormAction.class.getName();
-
- protected ModelForm modelForm;
-
- public ModelFormAction(ModelForm modelForm, Element actionElement) {
- this.modelForm = modelForm;
- if (Debug.verboseOn()) Debug.logVerbose("Reading Screen action with name: " + actionElement.getNodeName(), module);
- }
- public abstract void runAction(Map<String, Object> context);
-
- public static List<ModelFormAction> readSubActions(ModelForm modelForm, Element parentElement) {
- List<ModelFormAction> actions = new LinkedList<ModelFormAction>();
+ public static final String module = ModelFormAction.class.getName();
- for (Element actionElement: UtilXml.childElementList(parentElement)) {
- if ("set".equals(actionElement.getNodeName())) {
- actions.add(new SetField(modelForm, actionElement));
- } else if ("property-map".equals(actionElement.getNodeName())) {
- actions.add(new PropertyMap(modelForm, actionElement));
- } else if ("property-to-field".equals(actionElement.getNodeName())) {
- actions.add(new PropertyToField(modelForm, actionElement));
- } else if ("script".equals(actionElement.getNodeName())) {
- actions.add(new Script(modelForm, actionElement));
- } else if ("service".equals(actionElement.getNodeName())) {
+ public static List<ModelWidgetAction> readSubActions(ModelForm modelForm, Element parentElement) {
+ List<? extends Element> actionElementList = UtilXml.childElementList(parentElement);
+ List<ModelWidgetAction> actions = new ArrayList<ModelWidgetAction>(actionElementList.size());
+ for (Element actionElement : UtilXml.childElementList(parentElement)) {
+ if ("service".equals(actionElement.getNodeName())) {
actions.add(new Service(modelForm, actionElement));
- } else if ("entity-one".equals(actionElement.getNodeName())) {
- actions.add(new EntityOne(modelForm, actionElement));
} else if ("entity-and".equals(actionElement.getNodeName())) {
actions.add(new EntityAnd(modelForm, actionElement));
} else if ("entity-condition".equals(actionElement.getNodeName())) {
@@ -94,215 +63,14 @@ public abstract class ModelFormAction {
} else if ("call-parent-actions".equals(actionElement.getNodeName())) {
actions.add(new CallParentActions(modelForm, actionElement));
} else {
- throw new IllegalArgumentException("Action element not supported with name: " + actionElement.getNodeName());
- }
- }
-
- return actions;
- }
-
- public static void runSubActions(List<ModelFormAction> actions, Map<String, Object> context) {
- if (actions == null) return;
-
- for (ModelFormAction action: actions) {
- if (Debug.verboseOn()) Debug.logVerbose("Running screen action " + action.getClass().getName(), module);
- action.runAction(context);
- }
- }
-
- public static class SetField extends ModelFormAction {
- protected FlexibleMapAccessor<Object> field;
- protected FlexibleMapAccessor<String> fromField;
- protected FlexibleStringExpander valueExdr;
- protected FlexibleStringExpander defaultExdr;
- protected FlexibleStringExpander globalExdr;
- protected String type;
-
- public SetField(ModelForm modelForm, Element setElement) {
- super (modelForm, setElement);
- this.field = FlexibleMapAccessor.getInstance(setElement.getAttribute("field"));
- this.fromField = FlexibleMapAccessor.getInstance(setElement.getAttribute("from-field"));
- this.valueExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("value"));
- this.defaultExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("default-value"));
- this.globalExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("global"));
- this.type = setElement.getAttribute("type");
- if (!this.fromField.isEmpty() && !this.valueExdr.isEmpty()) {
- throw new IllegalArgumentException("Cannot specify a from-field [" + setElement.getAttribute("from-field") + "] and a value [" + setElement.getAttribute("value") + "] on the set action in a screen widget");
- }
- }
-
- @Override
- public void runAction(Map<String, Object> context) {
- String globalStr = this.globalExdr.expandString(context);
- // default to false
- boolean global = "true".equals(globalStr);
-
- Object newValue = null;
- if (!this.fromField.isEmpty()) {
- newValue = this.fromField.get(context);
- if (Debug.verboseOn()) Debug.logVerbose("In screen getting value for field from [" + this.fromField.getOriginalName() + "]: " + newValue, module);
- } else if (!this.valueExdr.isEmpty()) {
- newValue = this.valueExdr.expand(context);
- }
-
- // If newValue is still empty, use the default value
- if (ObjectType.isEmpty(newValue) && !this.defaultExdr.isEmpty()) {
- newValue = this.defaultExdr.expand(context);
- }
-
- if (UtilValidate.isNotEmpty(this.type)) {
- if ("NewMap".equals(this.type)) {
- newValue = FastMap.newInstance();
- } else if ("NewList".equals(this.type)) {
- newValue = FastList.newInstance();
- } else {
- try {
- newValue = ObjectType.simpleTypeConvert(newValue, this.type, null, (TimeZone) context.get("timeZone"), (Locale) context.get("locale"), true);
- } catch (GeneralException e) {
- String errMsg = "Could not convert field value for the field: [" + this.field.getOriginalName() + "] to the [" + this.type + "] type for the value [" + newValue + "]: " + e.toString();
- Debug.logError(e, errMsg, module);
- throw new IllegalArgumentException(errMsg);
- }
- }
- }
- if (Debug.verboseOn()) Debug.logVerbose("In screen setting field [" + this.field.getOriginalName() + "] to value: " + newValue, module);
- this.field.put(context, newValue);
-
- if (global) {
- Map<String, Object> globalCtx = UtilGenerics.checkMap(context.get("globalContext"));
- if (globalCtx != null) {
- this.field.put(globalCtx, newValue);
- }
- }
-
- // this is a hack for backward compatibility with the JPublish page object
- Map<String, Object> page = UtilGenerics.checkMap(context.get("page"));
- if (page != null) {
- this.field.put(page, newValue);
- }
- }
- }
-
- public static class PropertyMap extends ModelFormAction {
- protected FlexibleStringExpander resourceExdr;
- protected FlexibleMapAccessor<Map<String, Object>> mapNameAcsr;
- protected FlexibleStringExpander globalExdr;
-
- public PropertyMap(ModelForm modelForm, Element setElement) {
- super (modelForm, setElement);
- this.resourceExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("resource"));
- this.mapNameAcsr = FlexibleMapAccessor.getInstance(setElement.getAttribute("map-name"));
- this.globalExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("global"));
- }
-
- @Override
- public void runAction(Map<String, Object> context) {
- String globalStr = this.globalExdr.expandString(context);
- // default to false
- boolean global = "true".equals(globalStr);
-
- Locale locale = (Locale) context.get("locale");
- String resource = this.resourceExdr.expandString(context, locale);
- Map<String, Object> propertyMap = UtilProperties.getResourceBundleMap(resource, locale);
- this.mapNameAcsr.put(context, propertyMap);
-
- if (global) {
- Map<String, Object> globalCtx = UtilGenerics.checkMap(context.get("globalContext"));
- if (globalCtx != null) {
- this.mapNameAcsr.put(globalCtx, propertyMap);
- }
- }
- }
- }
-
- public static class PropertyToField extends ModelFormAction {
-
- protected FlexibleStringExpander resourceExdr;
- protected FlexibleStringExpander propertyExdr;
- protected FlexibleMapAccessor<String> fieldAcsr;
- protected FlexibleStringExpander defaultExdr;
- protected boolean noLocale;
- protected FlexibleMapAccessor<List<Object>> argListAcsr;
- protected FlexibleStringExpander globalExdr;
-
- public PropertyToField(ModelForm modelForm, Element setElement) {
- super (modelForm, setElement);
- this.resourceExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("resource"));
- this.propertyExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("property"));
- this.fieldAcsr = FlexibleMapAccessor.getInstance(setElement.getAttribute("field"));
- this.defaultExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("default"));
- noLocale = "true".equals(setElement.getAttribute("no-locale"));
- this.argListAcsr = FlexibleMapAccessor.getInstance(setElement.getAttribute("arg-list-name"));
- this.globalExdr = FlexibleStringExpander.getInstance(setElement.getAttribute("global"));
- }
-
- @Override
- public void runAction(Map<String, Object> context) {
- //String globalStr = this.globalExdr.expandString(context);
- // default to false
- //boolean global = "true".equals(globalStr);
-
- Locale locale = (Locale) context.get("locale");
- String resource = this.resourceExdr.expandString(context, locale);
- String property = this.propertyExdr.expandString(context, locale);
-
- String value = null;
- if (noLocale) {
- value = EntityUtilProperties.getPropertyValue(resource, property, WidgetWorker.getDelegator(context));
- } else {
- value = EntityUtilProperties.getMessage(resource, property, locale, WidgetWorker.getDelegator(context));
- }
- if (UtilValidate.isEmpty(value)) {
- value = this.defaultExdr.expandString(context);
- }
-
- // note that expanding the value string here will handle defaultValue and the string from
- // the properties file; if we decide later that we don't want the string from the properties
- // file to be expanded we should just expand the defaultValue at the beginning of this method.
- value = FlexibleStringExpander.expandString(value, context);
-
- if (!argListAcsr.isEmpty()) {
- List<Object> argList = argListAcsr.get(context);
- if (UtilValidate.isNotEmpty(argList)) {
- value = MessageFormat.format(value, argList.toArray());
- }
+ actions.add(ModelWidgetAction.toModelWidgetAction(modelForm, actionElement));
}
-
- fieldAcsr.put(context, value);
}
+ return Collections.unmodifiableList(actions);
}
- public static class Script extends ModelFormAction {
- protected String location;
- protected String method;
-
- public Script(ModelForm modelForm, Element scriptElement) {
- super (modelForm, scriptElement);
- String scriptLocation = scriptElement.getAttribute("location");
- this.location = WidgetWorker.getScriptLocation(scriptLocation);
- this.method = WidgetWorker.getScriptMethodName(scriptLocation);
- }
-
- @Override
- public void runAction(Map<String, Object> context) {
- if (location.endsWith(".xml")) {
- Map<String, Object> localContext = FastMap.newInstance();
- localContext.putAll(context);
- DispatchContext ctx = this.modelForm.dispatchContext;
- MethodContext methodContext = new MethodContext(ctx, localContext, null);
- try {
- SimpleMethod.runSimpleMethod(location, method, methodContext);
- context.putAll(methodContext.getResults());
- } catch (MiniLangException e) {
- throw new IllegalArgumentException("Error running simple method at location [" + location + "]", e);
- }
- } else {
- ScriptUtil.executeScript(this.location, this.method, context);
- }
- }
- }
-
- public static class Service extends ModelFormAction {
+ @SuppressWarnings("serial")
+ public static class Service extends ModelWidgetAction {
protected FlexibleStringExpander serviceNameExdr;
protected FlexibleMapAccessor<Map<String, Object>> resultMapNameAcsr;
protected FlexibleStringExpander autoFieldMapExdr;
@@ -391,44 +159,33 @@ public abstract class ModelFormAction {
Object listObj = result.get(listName);
if (listObj != null) {
if (!(listObj instanceof List<?>) && !(listObj instanceof ListIterator<?>)) {
- throw new IllegalArgumentException("Error in form [" + this.modelForm.getName() + "] calling service with name [" + serviceNameExpanded + "]: the result that is supposed to be a List or ListIterator and is not.");
+ throw new IllegalArgumentException("Error in form [" + this.modelWidget.getName() + "] calling service with name [" + serviceNameExpanded + "]: the result that is supposed to be a List or ListIterator and is not.");
}
context.put("listName", listName);
context.put(listName, listObj);
}
} catch (GenericServiceException e) {
- String errMsg = "Error in form [" + this.modelForm.getName() + "] calling service with name [" + serviceNameExpanded + "]: " + e.toString();
+ String errMsg = "Error in form [" + this.modelWidget.getName() + "] calling service with name [" + serviceNameExpanded + "]: " + e.toString();
Debug.logError(e, errMsg, module);
if (!this.ignoreError) {
throw new IllegalArgumentException(errMsg);
}
}
}
- }
- public static class EntityOne extends ModelFormAction {
- protected PrimaryKeyFinder finder;
-
- public EntityOne(ModelForm modelForm, Element entityOneElement) {
- super (modelForm, entityOneElement);
- finder = new PrimaryKeyFinder(entityOneElement);
+ @Override
+ public void accept(ModelActionVisitor visitor) {
+ visitor.visit(this);
}
- @Override
- public void runAction(Map<String, Object> context) {
- try {
- finder.runFind(context, WidgetWorker.getDelegator(context));
- } catch (GeneralException e) {
- String errMsg = "Error doing entity query by condition: " + e.toString();
- Debug.logError(e, errMsg, module);
- throw new IllegalArgumentException(errMsg);
- }
+ public String getServiceName() {
+ return serviceNameExdr.getOriginal();
}
}
- public static class EntityAnd extends ModelFormAction {
+ @SuppressWarnings("serial")
+ public static class EntityAnd extends ModelWidgetAction {
protected ByAndFinder finder;
- String actualListName;
public EntityAnd(ModelForm modelForm, Element entityAndElement) {
super (modelForm, entityAndElement);
@@ -446,8 +203,6 @@ public abstract class ModelFormAction {
}
entityAndElement.setAttribute("list", lstNm);
}
- this.actualListName = entityAndElement.getAttribute("list");
- if (UtilValidate.isEmpty(this.actualListName)) this.actualListName = entityAndElement.getAttribute("list-name");
finder = new ByAndFinder(entityAndElement);
}
@@ -474,9 +229,18 @@ public abstract class ModelFormAction {
}
}
+ @Override
+ public void accept(ModelActionVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ public ByAndFinder getFinder() {
+ return finder;
+ }
}
- public static class EntityCondition extends ModelFormAction {
+ @SuppressWarnings("serial")
+ public static class EntityCondition extends ModelWidgetAction {
ByConditionFinder finder;
String actualListName;
@@ -523,15 +287,26 @@ public abstract class ModelFormAction {
throw new IllegalArgumentException(errMsg);
}
}
+
+ @Override
+ public void accept(ModelActionVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ public ByConditionFinder getFinder() {
+ return finder;
+ }
}
- public static class CallParentActions extends ModelFormAction {
+ @SuppressWarnings("serial")
+ public static class CallParentActions extends ModelWidgetAction {
protected static enum ActionsKind {
ACTIONS,
ROW_ACTIONS
};
protected ActionsKind kind;
+ private final ModelForm modelForm;
public CallParentActions(ModelForm modelForm, Element callParentActionsElement) {
super(modelForm, callParentActionsElement);
@@ -548,6 +323,7 @@ public abstract class ModelFormAction {
if (parentModel == null) {
throw new IllegalArgumentException("call-parent-actions can only be used with form extending another form");
}
+ this.modelForm = modelForm;
}
@Override
@@ -558,9 +334,14 @@ public abstract class ModelFormAction {
parentModel.runFormActions(context);
break;
case ROW_ACTIONS:
- ModelFormAction.runSubActions(parentModel.rowActions, context);
+ ModelWidgetAction.runSubActions(parentModel.rowActions, context);
break;
}
}
+
+ @Override
+ public void accept(ModelActionVisitor visitor) {
+ visitor.visit(this);
+ }
}
}