You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2012/04/19 17:09:08 UTC
svn commit: r1327981 [8/9] - in
/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang: ./ method/
method/callops/ method/conditional/ method/entityops/ method/envops/
method/eventops/ method/ifops/ method/otherops/ method/serviceops/ operation/
Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/eventops/SessionToField.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/eventops/SessionToField.java?rev=1327981&r1=1327980&r2=1327981&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/eventops/SessionToField.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/eventops/SessionToField.java Thu Apr 19 15:09:03 2012
@@ -34,22 +34,13 @@ import org.w3c.dom.Element;
* Copies a Servlet session attribute to a map field
*/
public class SessionToField extends MethodOperation {
- public static final class SessionToFieldFactory implements Factory<SessionToField> {
- public SessionToField createMethodOperation(Element element, SimpleMethod simpleMethod) {
- return new SessionToField(element, simpleMethod);
- }
-
- public String getName() {
- return "session-to-field";
- }
- }
public static final String module = SessionToField.class.getName();
- ContextAccessor<Map<String, Object>> mapAcsr;
+ String defaultVal;
ContextAccessor<Object> fieldAcsr;
+ ContextAccessor<Map<String, Object>> mapAcsr;
FlexibleServletAccessor<Object> sessionAcsr;
- String defaultVal;
public SessionToField(Element element, SimpleMethod simpleMethod) {
super(element, simpleMethod);
@@ -57,14 +48,12 @@ public class SessionToField extends Meth
mapAcsr = new ContextAccessor<Map<String, Object>>(element.getAttribute("map-name"));
fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field"), element.getAttribute("field-name"));
sessionAcsr = new FlexibleServletAccessor<Object>(element.getAttribute("session-name"), fieldAcsr.toString());
-
defaultVal = element.getAttribute("default");
}
@Override
public boolean exec(MethodContext methodContext) {
String defaultVal = methodContext.expandString(this.defaultVal);
-
Object fieldVal = null;
// only run this if it is in an EVENT context
if (methodContext.getMethodType() == MethodContext.EVENT) {
@@ -73,27 +62,22 @@ public class SessionToField extends Meth
Debug.logWarning("Session attribute value not found with name " + sessionAcsr, module);
}
}
-
// if fieldVal is null, or is a String and has zero length, use defaultVal
if (fieldVal == null) {
fieldVal = defaultVal;
} else if (fieldVal instanceof String) {
String strVal = (String) fieldVal;
-
if (strVal.length() == 0) {
fieldVal = defaultVal;
}
}
-
if (!mapAcsr.isEmpty()) {
Map<String, Object> fromMap = mapAcsr.get(methodContext);
-
if (fromMap == null) {
Debug.logWarning("Map not found with name " + mapAcsr + " creating a new map", module);
fromMap = FastMap.newInstance();
mapAcsr.put(methodContext, fromMap);
}
-
fieldAcsr.put(fromMap, fieldVal, methodContext);
} else {
fieldAcsr.put(methodContext, fieldVal);
@@ -102,13 +86,24 @@ public class SessionToField extends Meth
}
@Override
+ public String expandedString(MethodContext methodContext) {
+ // TODO: something more than a stub/dummy
+ return this.rawString();
+ }
+
+ @Override
public String rawString() {
// TODO: add all attributes and other info
return "<session-to-field session-name=\"" + this.sessionAcsr + "\" field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>";
}
- @Override
- public String expandedString(MethodContext methodContext) {
- // TODO: something more than a stub/dummy
- return this.rawString();
+
+ public static final class SessionToFieldFactory implements Factory<SessionToField> {
+ public SessionToField createMethodOperation(Element element, SimpleMethod simpleMethod) {
+ return new SessionToField(element, simpleMethod);
+ }
+
+ public String getName() {
+ return "session-to-field";
+ }
}
}
Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/eventops/WebappPropertyToField.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/eventops/WebappPropertyToField.java?rev=1327981&r1=1327980&r2=1327981&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/eventops/WebappPropertyToField.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/eventops/WebappPropertyToField.java Thu Apr 19 15:09:03 2012
@@ -18,44 +18,40 @@
*******************************************************************************/
package org.ofbiz.minilang.method.eventops;
-import java.net.*;
-import java.util.*;
-import javax.servlet.*;
+import java.net.URL;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
-import org.w3c.dom.*;
import javolution.util.FastMap;
-import org.ofbiz.base.util.*;
-import org.ofbiz.minilang.*;
-import org.ofbiz.minilang.method.*;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.minilang.SimpleMethod;
+import org.ofbiz.minilang.method.ContextAccessor;
+import org.ofbiz.minilang.method.MethodContext;
+import org.ofbiz.minilang.method.MethodOperation;
+import org.w3c.dom.Element;
/**
* Copies a property value from a properties file in a ServletContext resource to a field
*/
public class WebappPropertyToField extends MethodOperation {
- public static final class WebappPropertyToFieldFactory implements Factory<WebappPropertyToField> {
- public WebappPropertyToField createMethodOperation(Element element, SimpleMethod simpleMethod) {
- return new WebappPropertyToField(element, simpleMethod);
- }
-
- public String getName() {
- return "webapp-property-to-field";
- }
- }
public static final String module = WebappPropertyToField.class.getName();
- String resource;
- String property;
String defaultVal;
- ContextAccessor<Map<String, Object>> mapAcsr;
ContextAccessor<Object> fieldAcsr;
+ ContextAccessor<Map<String, Object>> mapAcsr;
+ String property;
+ String resource;
public WebappPropertyToField(Element element, SimpleMethod simpleMethod) {
super(element, simpleMethod);
resource = element.getAttribute("resource");
property = element.getAttribute("property");
defaultVal = element.getAttribute("default");
-
// the schema for this element now just has the "field" attribute, though the old "field-name" and "map-name" pair is still supported
fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field"), element.getAttribute("field-name"));
mapAcsr = new ContextAccessor<Map<String, Object>>(element.getAttribute("map-name"));
@@ -66,20 +62,16 @@ public class WebappPropertyToField exten
String resource = methodContext.expandString(this.resource);
String property = methodContext.expandString(this.property);
String defaultVal = methodContext.expandString(this.defaultVal);
-
String fieldVal = null;
-
// only run this if it is in an EVENT context
if (methodContext.getMethodType() == MethodContext.EVENT) {
ServletContext servletContext = (ServletContext) methodContext.getRequest().getAttribute("servletContext");
URL propsUrl = null;
-
try {
propsUrl = servletContext.getResource(resource);
} catch (java.net.MalformedURLException e) {
Debug.logWarning(e, "Error finding webapp resource (properties file) not found with name " + resource, module);
}
-
if (propsUrl == null) {
Debug.logWarning("Webapp resource (properties file) not found with name " + resource, module);
} else {
@@ -89,19 +81,16 @@ public class WebappPropertyToField exten
}
}
}
-
// if fieldVal is null, or has zero length, use defaultVal
- if (UtilValidate.isEmpty(fieldVal)) fieldVal = defaultVal;
-
+ if (UtilValidate.isEmpty(fieldVal))
+ fieldVal = defaultVal;
if (!mapAcsr.isEmpty()) {
Map<String, Object> fromMap = mapAcsr.get(methodContext);
-
if (fromMap == null) {
Debug.logWarning("Map not found with name " + mapAcsr + " creating a new map", module);
fromMap = FastMap.newInstance();
mapAcsr.put(methodContext, fromMap);
}
-
fieldAcsr.put(fromMap, fieldVal, methodContext);
} else {
fieldAcsr.put(methodContext, fieldVal);
@@ -110,13 +99,24 @@ public class WebappPropertyToField exten
}
@Override
+ public String expandedString(MethodContext methodContext) {
+ // TODO: something more than a stub/dummy
+ return this.rawString();
+ }
+
+ @Override
public String rawString() {
// TODO: add all attributes and other info
return "<webapp-property-to-field field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>";
}
- @Override
- public String expandedString(MethodContext methodContext) {
- // TODO: something more than a stub/dummy
- return this.rawString();
+
+ public static final class WebappPropertyToFieldFactory implements Factory<WebappPropertyToField> {
+ public WebappPropertyToField createMethodOperation(Element element, SimpleMethod simpleMethod) {
+ return new WebappPropertyToField(element, simpleMethod);
+ }
+
+ public String getName() {
+ return "webapp-property-to-field";
+ }
}
}
Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/CheckId.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/CheckId.java?rev=1327981&r1=1327980&r2=1327981&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/CheckId.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/CheckId.java Thu Apr 19 15:09:03 2012
@@ -18,38 +18,34 @@
*******************************************************************************/
package org.ofbiz.minilang.method.ifops;
-import java.util.*;
+import java.util.List;
+import java.util.Map;
-import org.w3c.dom.*;
import javolution.util.FastList;
-import org.ofbiz.base.util.*;
-import org.ofbiz.minilang.*;
-import org.ofbiz.minilang.method.*;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.minilang.SimpleMethod;
+import org.ofbiz.minilang.method.ContextAccessor;
+import org.ofbiz.minilang.method.MethodContext;
+import org.ofbiz.minilang.method.MethodOperation;
+import org.w3c.dom.Element;
/**
- * Iff the given ID field is not valid the fail-message
- * or fail-property sub-elements are used to add a message to the error-list.
+ * If the given ID field is not valid the fail-message or fail-property sub-elements are used to add a message to the error-list.
*/
public class CheckId extends MethodOperation {
- public static final class CheckIdFactory implements Factory<CheckId> {
- public CheckId createMethodOperation(Element element, SimpleMethod simpleMethod) {
- return new CheckId(element, simpleMethod);
- }
-
- public String getName() {
- return "check-id";
- }
- }
public static final String module = CheckId.class.getName();
- String message = null;
- String propertyResource = null;
- boolean isProperty = false;
-
+ ContextAccessor<List<Object>> errorListAcsr;
ContextAccessor<Object> fieldAcsr;
+ boolean isProperty = false;
ContextAccessor<Map<String, ? extends Object>> mapAcsr;
- ContextAccessor<List<Object>> errorListAcsr;
+ String message = null;
+ String propertyResource = null;
public CheckId(Element element, SimpleMethod simpleMethod) {
super(element, simpleMethod);
@@ -57,11 +53,9 @@ public class CheckId extends MethodOpera
this.fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field"), element.getAttribute("field-name"));
this.mapAcsr = new ContextAccessor<Map<String, ? extends Object>>(element.getAttribute("map-name"));
this.errorListAcsr = new ContextAccessor<List<Object>>(element.getAttribute("error-list-name"), "error_list");
-
- //note: if no fail-message or fail-property then message will be null
+ // note: if no fail-message or fail-property then message will be null
Element failMessage = UtilXml.firstChildElement(element, "fail-message");
Element failProperty = UtilXml.firstChildElement(element, "fail-property");
-
if (failMessage != null) {
this.message = failMessage.getAttribute("message");
this.isProperty = false;
@@ -72,22 +66,38 @@ public class CheckId extends MethodOpera
}
}
+ public void addMessage(List<Object> messages, MethodContext methodContext, String defaultMessage, String errorDetails) {
+ String message = methodContext.expandString(this.message);
+ String propertyResource = methodContext.expandString(this.propertyResource);
+ if (!isProperty && message != null) {
+ messages.add(message + errorDetails);
+ } else if (isProperty && propertyResource != null && message != null) {
+ // String propMsg = UtilProperties.getPropertyValue(UtilURL.fromResource(propertyResource, loader), message);
+ String propMsg = UtilProperties.getMessage(propertyResource, message, methodContext.getEnvMap(), methodContext.getLocale());
+ if (UtilValidate.isEmpty(propMsg)) {
+ messages.add(defaultMessage + errorDetails);
+ } else {
+ messages.add(methodContext.expandString(propMsg) + errorDetails);
+ }
+ } else {
+ messages.add(defaultMessage + errorDetails);
+ }
+ }
+
@Override
public boolean exec(MethodContext methodContext) {
boolean isValid = true;
-
List<Object> messages = errorListAcsr.get(methodContext);
if (messages == null) {
messages = FastList.newInstance();
errorListAcsr.put(methodContext, messages);
}
-
Object fieldVal = null;
if (!mapAcsr.isEmpty()) {
Map<String, ? extends Object> fromMap = mapAcsr.get(methodContext);
-
if (fromMap == null) {
- if (Debug.infoOn()) Debug.logInfo("Map not found with name " + mapAcsr + ", running operations", module);
+ if (Debug.infoOn())
+ Debug.logInfo("Map not found with name " + mapAcsr + ", running operations", module);
} else {
fieldVal = fieldAcsr.get(fromMap, methodContext);
}
@@ -95,39 +105,20 @@ public class CheckId extends MethodOpera
// no map name, try the env
fieldVal = fieldAcsr.get(methodContext);
}
-
String fieldStr = fieldVal.toString();
StringBuilder errorDetails = new StringBuilder();
-
- //check various illegal characters, etc for ids
+ // check various illegal characters, etc for ids
isValid = UtilValidate.isValidDatabaseId(fieldStr, errorDetails);
-
if (!isValid) {
this.addMessage(messages, methodContext, "The ID value in the field [" + fieldAcsr + "] was not valid", ": " + errorDetails.toString());
}
-
return true;
}
- public void addMessage(List<Object> messages, MethodContext methodContext, String defaultMessage, String errorDetails) {
-
- String message = methodContext.expandString(this.message);
- String propertyResource = methodContext.expandString(this.propertyResource);
-
- if (!isProperty && message != null) {
- messages.add(message + errorDetails);
- } else if (isProperty && propertyResource != null && message != null) {
- //String propMsg = UtilProperties.getPropertyValue(UtilURL.fromResource(propertyResource, loader), message);
- String propMsg = UtilProperties.getMessage(propertyResource, message, methodContext.getEnvMap(), methodContext.getLocale());
-
- if (UtilValidate.isEmpty(propMsg)) {
- messages.add(defaultMessage + errorDetails);
- } else {
- messages.add(methodContext.expandString(propMsg) + errorDetails);
- }
- } else {
- messages.add(defaultMessage + errorDetails);
- }
+ @Override
+ public String expandedString(MethodContext methodContext) {
+ // TODO: something more than a stub/dummy
+ return this.rawString();
}
@Override
@@ -135,9 +126,14 @@ public class CheckId extends MethodOpera
// TODO: add all attributes and other info
return "<check-id field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>";
}
- @Override
- public String expandedString(MethodContext methodContext) {
- // TODO: something more than a stub/dummy
- return this.rawString();
+
+ public static final class CheckIdFactory implements Factory<CheckId> {
+ public CheckId createMethodOperation(Element element, SimpleMethod simpleMethod) {
+ return new CheckId(element, simpleMethod);
+ }
+
+ public String getName() {
+ return "check-id";
+ }
}
}
Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/CheckPermission.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/CheckPermission.java?rev=1327981&r1=1327980&r2=1327981&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/CheckPermission.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/CheckPermission.java Thu Apr 19 15:09:03 2012
@@ -36,49 +36,34 @@ import org.ofbiz.security.authz.Authoriz
import org.w3c.dom.Element;
/**
- * If the user does not have the specified permission the fail-message
- * or fail-property sub-elements are used to add a message to the error-list.
+ * If the user does not have the specified permission the fail-message or fail-property sub-elements are used to add a message to the error-list.
*/
public class CheckPermission extends MethodOperation {
- public static final class CheckPermissionFactory implements Factory<CheckPermission> {
- public CheckPermission createMethodOperation(Element element, SimpleMethod simpleMethod) {
- return new CheckPermission(element, simpleMethod);
- }
-
- public String getName() {
- return "check-permission";
- }
- }
-
- String message = null;
- String propertyResource = null;
- boolean isProperty = false;
/** If null no partyId env-name will be checked against the userLogin.partyId and accepted as permission */
ContextAccessor<String> acceptUlPartyIdEnvNameAcsr = null;
-
- PermissionInfo permissionInfo;
- ContextAccessor<List<Object>> errorListAcsr;
List<PermissionInfo> altPermissions = null;
+ ContextAccessor<List<Object>> errorListAcsr;
+ boolean isProperty = false;
+ String message = null;
+ PermissionInfo permissionInfo;
+ String propertyResource = null;
public CheckPermission(Element element, SimpleMethod simpleMethod) {
super(element, simpleMethod);
permissionInfo = new PermissionInfo(element);
this.errorListAcsr = new ContextAccessor<List<Object>>(element.getAttribute("error-list-name"), "error_list");
-
Element acceptUserloginPartyElement = UtilXml.firstChildElement(element, "accept-userlogin-party");
if (acceptUserloginPartyElement != null) {
acceptUlPartyIdEnvNameAcsr = new ContextAccessor<String>(acceptUserloginPartyElement.getAttribute("party-id-env-name"), "partyId");
}
-
List<? extends Element> altPermElements = UtilXml.childElementList(element, "alt-permission");
if (!altPermElements.isEmpty()) {
altPermissions = FastList.newInstance();
}
- for (Element altPermElement: altPermElements) {
+ for (Element altPermElement : altPermElements) {
altPermissions.add(new PermissionInfo(altPermElement));
}
-
Element failMessage = UtilXml.firstChildElement(element, "fail-message");
Element failProperty = UtilXml.firstChildElement(element, "fail-property");
if (failMessage != null) {
@@ -91,16 +76,35 @@ public class CheckPermission extends Met
}
}
+ public void addMessage(List<Object> messages, MethodContext methodContext) {
+ String message = methodContext.expandString(this.message);
+ String propertyResource = methodContext.expandString(this.propertyResource);
+ if (!isProperty && message != null) {
+ messages.add(message);
+ // if (Debug.infoOn()) Debug.logInfo("[SimpleMapOperation.addMessage] Adding message: " + message, module);
+ } else if (isProperty && propertyResource != null && message != null) {
+ // String propMsg = UtilProperties.getPropertyValue(UtilURL.fromResource(propertyResource, loader), message);
+ String propMsg = UtilProperties.getMessage(propertyResource, message, methodContext.getEnvMap(), methodContext.getLocale());
+ if (UtilValidate.isEmpty(propMsg)) {
+ messages.add("Simple Method Permission error occurred, but no message was found, sorry.");
+ } else {
+ messages.add(methodContext.expandString(propMsg));
+ }
+ // if (Debug.infoOn()) Debug.logInfo("[SimpleMapOperation.addMessage] Adding property message: " + propMsg, module);
+ } else {
+ messages.add("Simple Method Permission error occurred, but no message was found, sorry.");
+ // if (Debug.infoOn()) Debug.logInfo("[SimpleMapOperation.addMessage] ERROR: No message found", module);
+ }
+ }
+
@Override
public boolean exec(MethodContext methodContext) {
boolean hasPermission = false;
-
List<Object> messages = errorListAcsr.get(methodContext);
if (messages == null) {
messages = FastList.newInstance();
errorListAcsr.put(methodContext, messages);
}
-
// if no user is logged in, treat as if the user does not have permission: do not run subops
GenericValue userLogin = methodContext.getUserLogin();
if (userLogin != null) {
@@ -109,10 +113,9 @@ public class CheckPermission extends Met
if (this.permissionInfo.hasPermission(methodContext, userLogin, authz, security)) {
hasPermission = true;
}
-
// if failed, check alternate permissions
if (!hasPermission && altPermissions != null) {
- for (PermissionInfo altPermInfo: altPermissions) {
+ for (PermissionInfo altPermInfo : altPermissions) {
if (altPermInfo.hasPermission(methodContext, userLogin, authz, security)) {
hasPermission = true;
break;
@@ -120,7 +123,6 @@ public class CheckPermission extends Met
}
}
}
-
if (!hasPermission && acceptUlPartyIdEnvNameAcsr != null) {
String acceptPartyId = acceptUlPartyIdEnvNameAcsr.get(methodContext);
if (UtilValidate.isEmpty(acceptPartyId)) {
@@ -134,40 +136,37 @@ public class CheckPermission extends Met
hasPermission = true;
}
}
-
if (!hasPermission) {
this.addMessage(messages, methodContext);
}
-
return true;
}
- public void addMessage(List<Object> messages, MethodContext methodContext) {
+ @Override
+ public String expandedString(MethodContext methodContext) {
+ // TODO: something more than a stub/dummy
+ return this.rawString();
+ }
- String message = methodContext.expandString(this.message);
- String propertyResource = methodContext.expandString(this.propertyResource);
+ @Override
+ public String rawString() {
+ // TODO: add all attributes and other info
+ return "<check-permission/>";
+ }
- if (!isProperty && message != null) {
- messages.add(message);
- // if (Debug.infoOn()) Debug.logInfo("[SimpleMapOperation.addMessage] Adding message: " + message, module);
- } else if (isProperty && propertyResource != null && message != null) {
- //String propMsg = UtilProperties.getPropertyValue(UtilURL.fromResource(propertyResource, loader), message);
- String propMsg = UtilProperties.getMessage(propertyResource, message, methodContext.getEnvMap(), methodContext.getLocale());
- if (UtilValidate.isEmpty(propMsg)) {
- messages.add("Simple Method Permission error occurred, but no message was found, sorry.");
- } else {
- messages.add(methodContext.expandString(propMsg));
- }
- // if (Debug.infoOn()) Debug.logInfo("[SimpleMapOperation.addMessage] Adding property message: " + propMsg, module);
- } else {
- messages.add("Simple Method Permission error occurred, but no message was found, sorry.");
- // if (Debug.infoOn()) Debug.logInfo("[SimpleMapOperation.addMessage] ERROR: No message found", module);
+ public static final class CheckPermissionFactory implements Factory<CheckPermission> {
+ public CheckPermission createMethodOperation(Element element, SimpleMethod simpleMethod) {
+ return new CheckPermission(element, simpleMethod);
+ }
+
+ public String getName() {
+ return "check-permission";
}
}
public static class PermissionInfo {
- String permission;
String action;
+ String permission;
public PermissionInfo(Element altPermissionElement) {
this.permission = altPermissionElement.getAttribute("permission");
@@ -187,15 +186,4 @@ public class CheckPermission extends Met
}
}
}
-
- @Override
- public String rawString() {
- // TODO: add all attributes and other info
- return "<check-permission/>";
- }
- @Override
- public String expandedString(MethodContext methodContext) {
- // TODO: something more than a stub/dummy
- return this.rawString();
- }
}
Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfCompare.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfCompare.java?rev=1327981&r1=1327980&r2=1327981&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfCompare.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfCompare.java Thu Apr 19 15:09:03 2012
@@ -18,43 +18,35 @@
*******************************************************************************/
package org.ofbiz.minilang.method.ifops;
-import java.util.*;
+import java.util.List;
+import java.util.Map;
import javolution.util.FastList;
-import org.w3c.dom.*;
-import org.ofbiz.base.util.*;
-import org.ofbiz.minilang.*;
-import org.ofbiz.minilang.method.*;
-
-import org.ofbiz.minilang.operation.*;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.minilang.SimpleMethod;
+import org.ofbiz.minilang.method.ContextAccessor;
+import org.ofbiz.minilang.method.MethodContext;
+import org.ofbiz.minilang.method.MethodOperation;
+import org.ofbiz.minilang.operation.BaseCompare;
+import org.w3c.dom.Element;
/**
* Iff the comparison between the constant and the specified field is true process sub-operations
*/
public class IfCompare extends MethodOperation {
- public static final class IfCompareFactory implements Factory<IfCompare> {
- public IfCompare createMethodOperation(Element element, SimpleMethod simpleMethod) {
- return new IfCompare(element, simpleMethod);
- }
-
- public String getName() {
- return "if-compare";
- }
- }
public static final String module = IfCompare.class.getName();
- protected List<MethodOperation> subOps = FastList.newInstance();
protected List<MethodOperation> elseSubOps = null;
-
- protected ContextAccessor<Map<String, ? extends Object>> mapAcsr;
protected ContextAccessor<Object> fieldAcsr;
- protected String value;
-
+ protected String format;
+ protected ContextAccessor<Map<String, ? extends Object>> mapAcsr;
protected String operator;
+ protected List<MethodOperation> subOps = FastList.newInstance();
protected String type;
- protected String format;
+ protected String value;
public IfCompare(Element element, SimpleMethod simpleMethod) {
super(element, simpleMethod);
@@ -66,11 +58,9 @@ public class IfCompare extends MethodOpe
this.fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field-name"));
}
this.value = element.getAttribute("value");
-
this.operator = element.getAttribute("operator");
this.type = element.getAttribute("type");
this.format = element.getAttribute("format");
-
SimpleMethod.readOperations(element, subOps, simpleMethod);
Element elseElement = UtilXml.firstChildElement(element, "else");
if (elseElement != null) {
@@ -83,17 +73,16 @@ public class IfCompare extends MethodOpe
public boolean exec(MethodContext methodContext) {
// if conditions fails, always return true; if a sub-op returns false
// return false and stop, otherwise return true
-
String value = methodContext.expandString(this.value);
String operator = methodContext.expandString(this.operator);
String type = methodContext.expandString(this.type);
String format = methodContext.expandString(this.format);
-
Object fieldVal = null;
if (!mapAcsr.isEmpty()) {
Map<String, ? extends Object> fromMap = mapAcsr.get(methodContext);
if (fromMap == null) {
- if (Debug.infoOn()) Debug.logInfo("Map not found with name " + mapAcsr + ", using empty string for comparison", module);
+ if (Debug.infoOn())
+ Debug.logInfo("Map not found with name " + mapAcsr + ", using empty string for comparison", module);
} else {
fieldVal = fieldAcsr.get(fromMap, methodContext);
}
@@ -101,24 +90,20 @@ public class IfCompare extends MethodOpe
// no map name, try the env
fieldVal = fieldAcsr.get(methodContext);
}
-
// always use an empty string by default
if (fieldVal == null) {
fieldVal = "";
}
-
List<Object> messages = FastList.newInstance();
Boolean resultBool = BaseCompare.doRealCompare(fieldVal, value, operator, type, format, messages, null, methodContext.getLoader(), true);
if (messages.size() > 0) {
messages.add(0, "Error with comparison in if-compare between field [" + mapAcsr.toString() + "." + fieldAcsr.toString() + "] with value [" + fieldVal + "] and value [" + value + "] with operator [" + operator + "] and type [" + type + "]: ");
if (methodContext.getMethodType() == MethodContext.EVENT) {
StringBuilder fullString = new StringBuilder();
-
- for (Object message: messages) {
+ for (Object message : messages) {
fullString.append(message);
}
Debug.logWarning(fullString.toString(), module);
-
methodContext.putEnv(simpleMethod.getEventErrorMessageName(), fullString.toString());
methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode());
} else if (methodContext.getMethodType() == MethodContext.SERVICE) {
@@ -127,7 +112,6 @@ public class IfCompare extends MethodOpe
}
return false;
}
-
if (resultBool != null && resultBool.booleanValue()) {
return SimpleMethod.runSubOps(subOps, methodContext);
} else {
@@ -139,10 +123,17 @@ public class IfCompare extends MethodOpe
}
}
+ @Override
+ public String expandedString(MethodContext methodContext) {
+ // TODO: something more than a stub/dummy
+ return this.rawString();
+ }
+
public List<MethodOperation> getAllSubOps() {
List<MethodOperation> allSubOps = FastList.newInstance();
allSubOps.addAll(this.subOps);
- if (this.elseSubOps != null) allSubOps.addAll(this.elseSubOps);
+ if (this.elseSubOps != null)
+ allSubOps.addAll(this.elseSubOps);
return allSubOps;
}
@@ -151,9 +142,14 @@ public class IfCompare extends MethodOpe
// TODO: add all attributes and other info
return "<if-compare field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\" value=\"" + value + "\"/>";
}
- @Override
- public String expandedString(MethodContext methodContext) {
- // TODO: something more than a stub/dummy
- return this.rawString();
+
+ public static final class IfCompareFactory implements Factory<IfCompare> {
+ public IfCompare createMethodOperation(Element element, SimpleMethod simpleMethod) {
+ return new IfCompare(element, simpleMethod);
+ }
+
+ public String getName() {
+ return "if-compare";
+ }
}
}
Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfCompareField.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfCompareField.java?rev=1327981&r1=1327980&r2=1327981&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfCompareField.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfCompareField.java Thu Apr 19 15:09:03 2012
@@ -18,44 +18,36 @@
*******************************************************************************/
package org.ofbiz.minilang.method.ifops;
-import java.util.*;
+import java.util.List;
+import java.util.Map;
import javolution.util.FastList;
-import org.w3c.dom.*;
-import org.ofbiz.base.util.*;
-import org.ofbiz.minilang.*;
-import org.ofbiz.minilang.method.*;
-
-import org.ofbiz.minilang.operation.*;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.minilang.SimpleMethod;
+import org.ofbiz.minilang.method.ContextAccessor;
+import org.ofbiz.minilang.method.MethodContext;
+import org.ofbiz.minilang.method.MethodOperation;
+import org.ofbiz.minilang.operation.BaseCompare;
+import org.w3c.dom.Element;
/**
- * Iff the comparison between the specified field and the other field is true process sub-operations
+ * If the comparison between the specified field and the other field is true process sub-operations
*/
public class IfCompareField extends MethodOperation {
- public static final class IfCompareFieldFactory implements Factory<IfCompareField> {
- public IfCompareField createMethodOperation(Element element, SimpleMethod simpleMethod) {
- return new IfCompareField(element, simpleMethod);
- }
-
- public String getName() {
- return "if-compare-field";
- }
- }
public static final String module = IfCompareField.class.getName();
- protected List<MethodOperation> subOps = FastList.newInstance();
protected List<MethodOperation> elseSubOps = null;
-
- protected ContextAccessor<Map<String, ? extends Object>> mapAcsr;
protected ContextAccessor<Object> fieldAcsr;
- protected ContextAccessor<Map<String, ? extends Object>> toMapAcsr;
- protected ContextAccessor<Object> toFieldAcsr;
-
+ protected String format;
+ protected ContextAccessor<Map<String, ? extends Object>> mapAcsr;
protected String operator;
+ protected List<MethodOperation> subOps = FastList.newInstance();
+ protected ContextAccessor<Object> toFieldAcsr;
+ protected ContextAccessor<Map<String, ? extends Object>> toMapAcsr;
protected String type;
- protected String format;
public IfCompareField(Element element, SimpleMethod simpleMethod) {
super(element, simpleMethod);
@@ -66,7 +58,6 @@ public class IfCompareField extends Meth
// NOTE: this is still supported, but is deprecated
this.fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field-name"));
}
-
// NOTE: this is still supported, but is deprecated
this.toMapAcsr = new ContextAccessor<Map<String, ? extends Object>>(element.getAttribute("to-map-name"));
// set fieldAcsr to their defualt value of fieldAcsr if empty
@@ -75,15 +66,12 @@ public class IfCompareField extends Meth
// NOTE: this is still supported, but is deprecated
this.toFieldAcsr = new ContextAccessor<Object>(element.getAttribute("to-field-name"), element.getAttribute("field-name"));
}
-
// do NOT default the to-map-name to the map-name because that
- //would make it impossible to compare from a map field to an
- //environment field
-
+ // would make it impossible to compare from a map field to an
+ // environment field
this.operator = element.getAttribute("operator");
this.type = element.getAttribute("type");
this.format = element.getAttribute("format");
-
SimpleMethod.readOperations(element, subOps, simpleMethod);
Element elseElement = UtilXml.firstChildElement(element, "else");
if (elseElement != null) {
@@ -96,18 +84,16 @@ public class IfCompareField extends Meth
public boolean exec(MethodContext methodContext) {
// if conditions fails, always return true; if a sub-op returns false
// return false and stop, otherwise return true
-
String operator = methodContext.expandString(this.operator);
String type = methodContext.expandString(this.type);
String format = methodContext.expandString(this.format);
-
Object fieldVal1 = null;
Object fieldVal2 = null;
-
if (!mapAcsr.isEmpty()) {
Map<String, ? extends Object> fromMap = mapAcsr.get(methodContext);
if (fromMap == null) {
- if (Debug.infoOn()) Debug.logInfo("Map not found with name " + mapAcsr + ", using null for comparison", module);
+ if (Debug.infoOn())
+ Debug.logInfo("Map not found with name " + mapAcsr + ", using null for comparison", module);
} else {
fieldVal1 = fieldAcsr.get(fromMap, methodContext);
}
@@ -115,11 +101,11 @@ public class IfCompareField extends Meth
// no map name, try the env
fieldVal1 = fieldAcsr.get(methodContext);
}
-
if (!toMapAcsr.isEmpty()) {
Map<String, ? extends Object> toMap = toMapAcsr.get(methodContext);
if (toMap == null) {
- if (Debug.infoOn()) Debug.logInfo("To Map not found with name " + toMapAcsr + ", using null for comparison", module);
+ if (Debug.infoOn())
+ Debug.logInfo("To Map not found with name " + toMapAcsr + ", using null for comparison", module);
} else {
fieldVal2 = toFieldAcsr.get(toMap, methodContext);
}
@@ -127,20 +113,17 @@ public class IfCompareField extends Meth
// no map name, try the env
fieldVal2 = toFieldAcsr.get(methodContext);
}
-
List<Object> messages = FastList.newInstance();
Boolean resultBool = BaseCompare.doRealCompare(fieldVal1, fieldVal2, operator, type, format, messages, null, methodContext.getLoader(), false);
-
if (messages.size() > 0) {
- messages.add(0, "Error with comparison in if-compare-field between fields [" + mapAcsr.toString() + "." + fieldAcsr.toString() + "] with value [" + fieldVal1 + "] and [" + toMapAcsr.toString() + "." + toFieldAcsr.toString() + "] with value [" + fieldVal2 + "] with operator [" + operator + "] and type [" + type + "]: ");
+ messages.add(0, "Error with comparison in if-compare-field between fields [" + mapAcsr.toString() + "." + fieldAcsr.toString() + "] with value [" + fieldVal1 + "] and [" + toMapAcsr.toString() + "." + toFieldAcsr.toString() + "] with value [" + fieldVal2 + "] with operator [" + operator
+ + "] and type [" + type + "]: ");
if (methodContext.getMethodType() == MethodContext.EVENT) {
StringBuilder fullString = new StringBuilder();
-
- for (Object message: messages) {
+ for (Object message : messages) {
fullString.append(message);
}
Debug.logWarning(fullString.toString(), module);
-
methodContext.putEnv(simpleMethod.getEventErrorMessageName(), fullString.toString());
methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode());
} else if (methodContext.getMethodType() == MethodContext.SERVICE) {
@@ -149,7 +132,6 @@ public class IfCompareField extends Meth
}
return false;
}
-
if (resultBool != null && resultBool.booleanValue()) {
return SimpleMethod.runSubOps(subOps, methodContext);
} else {
@@ -161,10 +143,17 @@ public class IfCompareField extends Meth
}
}
+ @Override
+ public String expandedString(MethodContext methodContext) {
+ // TODO: something more than a stub/dummy
+ return this.rawString();
+ }
+
public List<MethodOperation> getAllSubOps() {
List<MethodOperation> allSubOps = FastList.newInstance();
allSubOps.addAll(this.subOps);
- if (this.elseSubOps != null) allSubOps.addAll(this.elseSubOps);
+ if (this.elseSubOps != null)
+ allSubOps.addAll(this.elseSubOps);
return allSubOps;
}
@@ -173,9 +162,14 @@ public class IfCompareField extends Meth
// TODO: add all attributes and other info
return "<if-compare-field field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>";
}
- @Override
- public String expandedString(MethodContext methodContext) {
- // TODO: something more than a stub/dummy
- return this.rawString();
+
+ public static final class IfCompareFieldFactory implements Factory<IfCompareField> {
+ public IfCompareField createMethodOperation(Element element, SimpleMethod simpleMethod) {
+ return new IfCompareField(element, simpleMethod);
+ }
+
+ public String getName() {
+ return "if-compare-field";
+ }
}
}
Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfEmpty.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfEmpty.java?rev=1327981&r1=1327980&r2=1327981&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfEmpty.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfEmpty.java Thu Apr 19 15:09:03 2012
@@ -18,36 +18,31 @@
*******************************************************************************/
package org.ofbiz.minilang.method.ifops;
-import java.util.*;
+import java.util.List;
+import java.util.Map;
import javolution.util.FastList;
-import org.w3c.dom.*;
-import org.ofbiz.base.util.*;
-import org.ofbiz.minilang.*;
-import org.ofbiz.minilang.method.*;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.ObjectType;
+import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.minilang.SimpleMethod;
+import org.ofbiz.minilang.method.ContextAccessor;
+import org.ofbiz.minilang.method.MethodContext;
+import org.ofbiz.minilang.method.MethodOperation;
+import org.w3c.dom.Element;
/**
- * Iff the specified field is not empty process sub-operations
+ * If the specified field is not empty process sub-operations
*/
public class IfEmpty extends MethodOperation {
- public static final class IfEmptyFactory implements Factory<IfEmpty> {
- public IfEmpty createMethodOperation(Element element, SimpleMethod simpleMethod) {
- return new IfEmpty(element, simpleMethod);
- }
-
- public String getName() {
- return "if-empty";
- }
- }
public static final String module = IfEmpty.class.getName();
- List<MethodOperation> subOps = FastList.newInstance();
List<MethodOperation> elseSubOps = null;
-
- ContextAccessor<Map<String, ? extends Object>> mapAcsr;
ContextAccessor<Object> fieldAcsr;
+ ContextAccessor<Map<String, ? extends Object>> mapAcsr;
+ List<MethodOperation> subOps = FastList.newInstance();
public IfEmpty(Element element, SimpleMethod simpleMethod) {
super(element, simpleMethod);
@@ -58,9 +53,7 @@ public class IfEmpty extends MethodOpera
// NOTE: this is still supported, but is deprecated
this.fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field-name"));
}
-
SimpleMethod.readOperations(element, subOps, simpleMethod);
-
Element elseElement = UtilXml.firstChildElement(element, "else");
if (elseElement != null) {
elseSubOps = FastList.newInstance();
@@ -73,15 +66,14 @@ public class IfEmpty extends MethodOpera
// if conditions fails, always return true; if a sub-op returns false
// return false and stop, otherwise return true
// return true;
-
// only run subOps if element is empty/null
boolean runSubOps = false;
Object fieldVal = null;
-
if (!mapAcsr.isEmpty()) {
Map<String, ? extends Object> fromMap = mapAcsr.get(methodContext);
if (fromMap == null) {
- if (Debug.infoOn()) Debug.logInfo("Map not found with name " + mapAcsr + ", running operations", module);
+ if (Debug.infoOn())
+ Debug.logInfo("Map not found with name " + mapAcsr + ", running operations", module);
} else {
fieldVal = fieldAcsr.get(fromMap, methodContext);
}
@@ -89,9 +81,7 @@ public class IfEmpty extends MethodOpera
// no map name, try the env
fieldVal = fieldAcsr.get(methodContext);
}
-
runSubOps = ObjectType.isEmpty(fieldVal);
-
if (runSubOps) {
return SimpleMethod.runSubOps(subOps, methodContext);
} else {
@@ -103,10 +93,17 @@ public class IfEmpty extends MethodOpera
}
}
+ @Override
+ public String expandedString(MethodContext methodContext) {
+ // TODO: something more than a stub/dummy
+ return this.rawString();
+ }
+
public List<MethodOperation> getAllSubOps() {
List<MethodOperation> allSubOps = FastList.newInstance();
allSubOps.addAll(this.subOps);
- if (this.elseSubOps != null) allSubOps.addAll(this.elseSubOps);
+ if (this.elseSubOps != null)
+ allSubOps.addAll(this.elseSubOps);
return allSubOps;
}
@@ -114,9 +111,14 @@ public class IfEmpty extends MethodOpera
public String rawString() {
return "<if-empty field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>";
}
- @Override
- public String expandedString(MethodContext methodContext) {
- // TODO: something more than a stub/dummy
- return this.rawString();
+
+ public static final class IfEmptyFactory implements Factory<IfEmpty> {
+ public IfEmpty createMethodOperation(Element element, SimpleMethod simpleMethod) {
+ return new IfEmpty(element, simpleMethod);
+ }
+
+ public String getName() {
+ return "if-empty";
+ }
}
}
Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfHasPermission.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfHasPermission.java?rev=1327981&r1=1327980&r2=1327981&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfHasPermission.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfHasPermission.java Thu Apr 19 15:09:03 2012
@@ -34,33 +34,20 @@ import org.ofbiz.security.authz.Authoriz
import org.w3c.dom.Element;
/**
- * Iff the user has the specified permission, process the sub-operations. Otherwise
- * process else operations if specified.
+ * If the user has the specified permission, process the sub-operations. Otherwise process else operations if specified.
*/
public class IfHasPermission extends MethodOperation {
- public static final class IfHasPermissionFactory implements Factory<IfHasPermission> {
- public IfHasPermission createMethodOperation(Element element, SimpleMethod simpleMethod) {
- return new IfHasPermission(element, simpleMethod);
- }
-
- public String getName() {
- return "if-has-permission";
- }
- }
- protected List<MethodOperation> subOps = FastList.newInstance();
+ protected FlexibleStringExpander actionExdr;
protected List<MethodOperation> elseSubOps = null;
-
protected FlexibleStringExpander permissionExdr;
- protected FlexibleStringExpander actionExdr;
+ protected List<MethodOperation> subOps = FastList.newInstance();
public IfHasPermission(Element element, SimpleMethod simpleMethod) {
super(element, simpleMethod);
this.permissionExdr = FlexibleStringExpander.getInstance(element.getAttribute("permission"));
this.actionExdr = FlexibleStringExpander.getInstance(element.getAttribute("action"));
-
SimpleMethod.readOperations(element, subOps, simpleMethod);
-
Element elseElement = UtilXml.firstChildElement(element, "else");
if (elseElement != null) {
elseSubOps = FastList.newInstance();
@@ -73,16 +60,13 @@ public class IfHasPermission extends Met
// if conditions fails, always return true; if a sub-op returns false
// return false and stop, otherwise return true
// return true;
-
// only run subOps if element is empty/null
boolean runSubOps = false;
-
// if no user is logged in, treat as if the user does not have permission: do not run subops
GenericValue userLogin = methodContext.getUserLogin();
if (userLogin != null) {
String permission = methodContext.expandString(permissionExdr);
String action = methodContext.expandString(actionExdr);
-
Authorization authz = methodContext.getAuthz();
Security security = methodContext.getSecurity();
if (UtilValidate.isNotEmpty(action)) {
@@ -97,7 +81,6 @@ public class IfHasPermission extends Met
}
}
}
-
if (runSubOps) {
return SimpleMethod.runSubOps(subOps, methodContext);
} else {
@@ -109,10 +92,17 @@ public class IfHasPermission extends Met
}
}
+ @Override
+ public String expandedString(MethodContext methodContext) {
+ // TODO: something more than a stub/dummy
+ return this.rawString();
+ }
+
public List<MethodOperation> getAllSubOps() {
List<MethodOperation> allSubOps = FastList.newInstance();
allSubOps.addAll(this.subOps);
- if (this.elseSubOps != null) allSubOps.addAll(this.elseSubOps);
+ if (this.elseSubOps != null)
+ allSubOps.addAll(this.elseSubOps);
return allSubOps;
}
@@ -120,9 +110,14 @@ public class IfHasPermission extends Met
public String rawString() {
return "<if-has-permission permission=\"" + this.permissionExdr + "\" action=\"" + this.actionExdr + "\"/>";
}
- @Override
- public String expandedString(MethodContext methodContext) {
- // TODO: something more than a stub/dummy
- return this.rawString();
+
+ public static final class IfHasPermissionFactory implements Factory<IfHasPermission> {
+ public IfHasPermission createMethodOperation(Element element, SimpleMethod simpleMethod) {
+ return new IfHasPermission(element, simpleMethod);
+ }
+
+ public String getName() {
+ return "if-has-permission";
+ }
}
}
Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfInstanceOf.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfInstanceOf.java?rev=1327981&r1=1327980&r2=1327981&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfInstanceOf.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfInstanceOf.java Thu Apr 19 15:09:03 2012
@@ -23,35 +23,24 @@ import java.util.Map;
import javolution.util.FastList;
-import org.ofbiz.minilang.method.MethodOperation;
-import org.ofbiz.minilang.method.MethodContext;
-import org.ofbiz.minilang.method.ContextAccessor;
-import org.ofbiz.minilang.SimpleMethod;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.ObjectType;
import org.ofbiz.base.util.UtilXml;
-
+import org.ofbiz.minilang.SimpleMethod;
+import org.ofbiz.minilang.method.ContextAccessor;
+import org.ofbiz.minilang.method.MethodContext;
+import org.ofbiz.minilang.method.MethodOperation;
import org.w3c.dom.Element;
public class IfInstanceOf extends MethodOperation {
- public static final class IfInstanceOfFactory implements Factory<IfInstanceOf> {
- public IfInstanceOf createMethodOperation(Element element, SimpleMethod simpleMethod) {
- return new IfInstanceOf(element, simpleMethod);
- }
-
- public String getName() {
- return "if-instance-of";
- }
- }
public static final String module = IfInstanceOf.class.getName();
- protected List<MethodOperation> subOps = FastList.newInstance();
+ protected String className = null;
protected List<MethodOperation> elseSubOps = null;
-
- protected ContextAccessor<Map<String, ? extends Object>> mapAcsr = null;
protected ContextAccessor<Object> fieldAcsr = null;
- protected String className = null;
+ protected ContextAccessor<Map<String, ? extends Object>> mapAcsr = null;
+ protected List<MethodOperation> subOps = FastList.newInstance();
public IfInstanceOf(Element element, SimpleMethod simpleMethod) {
super(element, simpleMethod);
@@ -59,9 +48,7 @@ public class IfInstanceOf extends Method
this.fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field"), element.getAttribute("field-name"));
this.mapAcsr = new ContextAccessor<Map<String, ? extends Object>>(element.getAttribute("map-name"));
this.className = element.getAttribute("class");
-
SimpleMethod.readOperations(element, subOps, simpleMethod);
-
Element elseElement = UtilXml.firstChildElement(element, "else");
if (elseElement != null) {
elseSubOps = FastList.newInstance();
@@ -74,11 +61,11 @@ public class IfInstanceOf extends Method
// only run subOps if element is instanceOf
boolean runSubOps = false;
Object fieldVal = null;
-
if (!mapAcsr.isEmpty()) {
Map<String, ? extends Object> fromMap = mapAcsr.get(methodContext);
if (fromMap == null) {
- if (Debug.infoOn()) Debug.logInfo("Map not found with name " + mapAcsr + ", running operations", module);
+ if (Debug.infoOn())
+ Debug.logInfo("Map not found with name " + mapAcsr + ", running operations", module);
} else {
fieldVal = fieldAcsr.get(fromMap, methodContext);
}
@@ -86,9 +73,7 @@ public class IfInstanceOf extends Method
// no map name, try the env
fieldVal = fieldAcsr.get(methodContext);
}
-
runSubOps = ObjectType.instanceOf(fieldVal, className);
-
if (runSubOps) {
return SimpleMethod.runSubOps(subOps, methodContext);
} else {
@@ -100,10 +85,17 @@ public class IfInstanceOf extends Method
}
}
+ @Override
+ public String expandedString(MethodContext methodContext) {
+ // TODO: something more than a stub/dummy
+ return this.rawString();
+ }
+
public List<MethodOperation> getAllSubOps() {
List<MethodOperation> allSubOps = FastList.newInstance();
allSubOps.addAll(this.subOps);
- if (this.elseSubOps != null) allSubOps.addAll(this.elseSubOps);
+ if (this.elseSubOps != null)
+ allSubOps.addAll(this.elseSubOps);
return allSubOps;
}
@@ -112,9 +104,14 @@ public class IfInstanceOf extends Method
// TODO: add all attributes and other info
return "<if-instance-of field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>";
}
- @Override
- public String expandedString(MethodContext methodContext) {
- // TODO: something more than a stub/dummy
- return this.rawString();
+
+ public static final class IfInstanceOfFactory implements Factory<IfInstanceOf> {
+ public IfInstanceOf createMethodOperation(Element element, SimpleMethod simpleMethod) {
+ return new IfInstanceOf(element, simpleMethod);
+ }
+
+ public String getName() {
+ return "if-instance-of";
+ }
}
}
Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfNotEmpty.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfNotEmpty.java?rev=1327981&r1=1327980&r2=1327981&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfNotEmpty.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfNotEmpty.java Thu Apr 19 15:09:03 2012
@@ -18,36 +18,31 @@
*******************************************************************************/
package org.ofbiz.minilang.method.ifops;
-import java.util.*;
+import java.util.List;
+import java.util.Map;
import javolution.util.FastList;
-import org.w3c.dom.*;
-import org.ofbiz.base.util.*;
-import org.ofbiz.minilang.*;
-import org.ofbiz.minilang.method.*;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.ObjectType;
+import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.minilang.SimpleMethod;
+import org.ofbiz.minilang.method.ContextAccessor;
+import org.ofbiz.minilang.method.MethodContext;
+import org.ofbiz.minilang.method.MethodOperation;
+import org.w3c.dom.Element;
/**
- * Iff the specified field is not empty process sub-operations
+ * If the specified field is not empty process sub-operations
*/
public class IfNotEmpty extends MethodOperation {
- public static final class IfNotEmptyFactory implements Factory<IfNotEmpty> {
- public IfNotEmpty createMethodOperation(Element element, SimpleMethod simpleMethod) {
- return new IfNotEmpty(element, simpleMethod);
- }
-
- public String getName() {
- return "if-not-empty";
- }
- }
public static final String module = IfNotEmpty.class.getName();
- protected List<MethodOperation> subOps = FastList.newInstance();
protected List<MethodOperation> elseSubOps = null;
-
- protected ContextAccessor<Map<String, ? extends Object>> mapAcsr;
protected ContextAccessor<Object> fieldAcsr;
+ protected ContextAccessor<Map<String, ? extends Object>> mapAcsr;
+ protected List<MethodOperation> subOps = FastList.newInstance();
public IfNotEmpty(Element element, SimpleMethod simpleMethod) {
super(element, simpleMethod);
@@ -58,11 +53,8 @@ public class IfNotEmpty extends MethodOp
// NOTE: this is still supported, but is deprecated
this.fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field-name"));
}
-
SimpleMethod.readOperations(element, subOps, simpleMethod);
-
Element elseElement = UtilXml.firstChildElement(element, "else");
-
if (elseElement != null) {
elseSubOps = FastList.newInstance();
SimpleMethod.readOperations(elseElement, elseSubOps, simpleMethod);
@@ -74,13 +66,12 @@ public class IfNotEmpty extends MethodOp
// if conditions fails, always return true; if a sub-op returns false
// return false and stop, otherwise return true
// return true;
-
Object fieldVal = null;
-
if (!mapAcsr.isEmpty()) {
Map<String, ? extends Object> fromMap = mapAcsr.get(methodContext);
if (fromMap == null) {
- if (Debug.verboseOn()) Debug.logVerbose("Map not found with name " + mapAcsr + ", not running operations", module);
+ if (Debug.verboseOn())
+ Debug.logVerbose("Map not found with name " + mapAcsr + ", not running operations", module);
} else {
fieldVal = fieldAcsr.get(fromMap, methodContext);
}
@@ -88,14 +79,12 @@ public class IfNotEmpty extends MethodOp
// no map name, try the env
fieldVal = fieldAcsr.get(methodContext);
}
-
if (fieldVal == null) {
- if (Debug.verboseOn()) Debug.logVerbose("Field value not found with name " + fieldAcsr + " in Map with name " + mapAcsr + ", not running operations", module);
+ if (Debug.verboseOn())
+ Debug.logVerbose("Field value not found with name " + fieldAcsr + " in Map with name " + mapAcsr + ", not running operations", module);
}
-
// only run subOps if element is not empty/null
boolean runSubOps = !ObjectType.isEmpty(fieldVal);
-
if (runSubOps) {
// if (Debug.verboseOn()) Debug.logVerbose("IfNotEmpty: Running if operations mapAcsr=" + mapAcsr + " fieldAcsr=" + fieldAcsr, module);
return SimpleMethod.runSubOps(subOps, methodContext);
@@ -110,10 +99,17 @@ public class IfNotEmpty extends MethodOp
}
}
+ @Override
+ public String expandedString(MethodContext methodContext) {
+ // TODO: something more than a stub/dummy
+ return this.rawString();
+ }
+
public List<MethodOperation> getAllSubOps() {
List<MethodOperation> allSubOps = FastList.newInstance();
allSubOps.addAll(this.subOps);
- if (this.elseSubOps != null) allSubOps.addAll(this.elseSubOps);
+ if (this.elseSubOps != null)
+ allSubOps.addAll(this.elseSubOps);
return allSubOps;
}
@@ -122,9 +118,14 @@ public class IfNotEmpty extends MethodOp
// TODO: add all attributes and other info
return "<if-not-empty field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>";
}
- @Override
- public String expandedString(MethodContext methodContext) {
- // TODO: something more than a stub/dummy
- return this.rawString();
+
+ public static final class IfNotEmptyFactory implements Factory<IfNotEmpty> {
+ public IfNotEmpty createMethodOperation(Element element, SimpleMethod simpleMethod) {
+ return new IfNotEmpty(element, simpleMethod);
+ }
+
+ public String getName() {
+ return "if-not-empty";
+ }
}
}
Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfRegexp.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfRegexp.java?rev=1327981&r1=1327980&r2=1327981&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfRegexp.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfRegexp.java Thu Apr 19 15:09:03 2012
@@ -37,43 +37,27 @@ import org.ofbiz.minilang.method.MethodO
import org.w3c.dom.Element;
/**
- * Iff the specified field complies with the pattern specified by the regular expression, process sub-operations
+ * If the specified field complies with the pattern specified by the regular expression, process sub-operations
*/
public class IfRegexp extends MethodOperation {
- public static final class IfRegexpFactory implements Factory<IfRegexp> {
- public IfRegexp createMethodOperation(Element element, SimpleMethod simpleMethod) {
- return new IfRegexp(element, simpleMethod);
- }
-
- public String getName() {
- return "if-regexp";
- }
- }
public static final String module = IfRegexp.class.getName();
-
private transient static ThreadLocal<CompilerMatcher> compilerMatcher = CompilerMatcher.getThreadLocal();
- List<MethodOperation> subOps = FastList.newInstance();
List<MethodOperation> elseSubOps = null;
-
- ContextAccessor<Map<String, ? extends Object>> mapAcsr;
- ContextAccessor<Object> fieldAcsr;
-
FlexibleStringExpander exprExdr;
+ ContextAccessor<Object> fieldAcsr;
+ ContextAccessor<Map<String, ? extends Object>> mapAcsr;
+ List<MethodOperation> subOps = FastList.newInstance();
public IfRegexp(Element element, SimpleMethod simpleMethod) {
super(element, simpleMethod);
// the schema for this element now just has the "field" attribute, though the old "field-name" and "map-name" pair is still supported
this.fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field"), element.getAttribute("field-name"));
this.mapAcsr = new ContextAccessor<Map<String, ? extends Object>>(element.getAttribute("map-name"));
-
this.exprExdr = FlexibleStringExpander.getInstance(element.getAttribute("expr"));
-
SimpleMethod.readOperations(element, subOps, simpleMethod);
-
Element elseElement = UtilXml.firstChildElement(element, "else");
-
if (elseElement != null) {
elseSubOps = FastList.newInstance();
SimpleMethod.readOperations(elseElement, elseSubOps, simpleMethod);
@@ -84,14 +68,13 @@ public class IfRegexp extends MethodOper
public boolean exec(MethodContext methodContext) {
// if conditions fails, always return true; if a sub-op returns false
// return false and stop, otherwise return true
-
String fieldString = null;
Object fieldVal = null;
-
if (!mapAcsr.isEmpty()) {
Map<String, ? extends Object> fromMap = mapAcsr.get(methodContext);
if (fromMap == null) {
- if (Debug.infoOn()) Debug.logInfo("Map not found with name " + mapAcsr + ", using empty string for comparison", module);
+ if (Debug.infoOn())
+ Debug.logInfo("Map not found with name " + mapAcsr + ", using empty string for comparison", module);
} else {
fieldVal = fieldAcsr.get(fromMap, methodContext);
}
@@ -99,7 +82,6 @@ public class IfRegexp extends MethodOper
// no map name, try the env
fieldVal = fieldAcsr.get(methodContext);
}
-
if (fieldVal != null) {
try {
fieldString = (String) ObjectType.simpleTypeConvert(fieldVal, "String", null, methodContext.getTimeZone(), methodContext.getLocale(), true);
@@ -108,15 +90,14 @@ public class IfRegexp extends MethodOper
}
}
// always use an empty string by default
- if (fieldString == null) fieldString = "";
-
+ if (fieldString == null)
+ fieldString = "";
boolean matches = false;
try {
matches = compilerMatcher.get().matches(fieldString, methodContext.expandString(this.exprExdr));
} catch (MalformedPatternException e) {
Debug.logError(e, "Regular Expression [" + this.exprExdr + "] is mal-formed: " + e.toString(), module);
}
-
if (matches) {
return SimpleMethod.runSubOps(subOps, methodContext);
} else {
@@ -128,10 +109,17 @@ public class IfRegexp extends MethodOper
}
}
+ @Override
+ public String expandedString(MethodContext methodContext) {
+ // TODO: something more than a stub/dummy
+ return this.rawString();
+ }
+
public List<MethodOperation> getAllSubOps() {
List<MethodOperation> allSubOps = FastList.newInstance();
allSubOps.addAll(this.subOps);
- if (this.elseSubOps != null) allSubOps.addAll(this.elseSubOps);
+ if (this.elseSubOps != null)
+ allSubOps.addAll(this.elseSubOps);
return allSubOps;
}
@@ -140,9 +128,14 @@ public class IfRegexp extends MethodOper
// TODO: add all attributes and other info
return "<if-regexp field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>";
}
- @Override
- public String expandedString(MethodContext methodContext) {
- // TODO: something more than a stub/dummy
- return this.rawString();
+
+ public static final class IfRegexpFactory implements Factory<IfRegexp> {
+ public IfRegexp createMethodOperation(Element element, SimpleMethod simpleMethod) {
+ return new IfRegexp(element, simpleMethod);
+ }
+
+ public String getName() {
+ return "if-regexp";
+ }
}
}
Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfValidateMethod.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfValidateMethod.java?rev=1327981&r1=1327980&r2=1327981&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfValidateMethod.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfValidateMethod.java Thu Apr 19 15:09:03 2012
@@ -35,28 +35,18 @@ import org.ofbiz.minilang.method.MethodO
import org.w3c.dom.Element;
/**
- * Iff the validate method returns true with the specified field process sub-operations
+ * If the validate method returns true with the specified field process sub-operations
*/
public class IfValidateMethod extends MethodOperation {
- public static final class IfValidateMethodFactory implements Factory<IfValidateMethod> {
- public IfValidateMethod createMethodOperation(Element element, SimpleMethod simpleMethod) {
- return new IfValidateMethod(element, simpleMethod);
- }
-
- public String getName() {
- return "if-validate-method";
- }
- }
public static final String module = IfValidateMethod.class.getName();
- List<MethodOperation> subOps = FastList.newInstance();
+ String className;
List<MethodOperation> elseSubOps = null;
-
- ContextAccessor<Map<String, ? extends Object>> mapAcsr;
ContextAccessor<Object> fieldAcsr;
+ ContextAccessor<Map<String, ? extends Object>> mapAcsr;
String methodName;
- String className;
+ List<MethodOperation> subOps = FastList.newInstance();
public IfValidateMethod(Element element, SimpleMethod simpleMethod) {
super(element, simpleMethod);
@@ -65,9 +55,7 @@ public class IfValidateMethod extends Me
this.mapAcsr = new ContextAccessor<Map<String, ? extends Object>>(element.getAttribute("map-name"));
this.methodName = element.getAttribute("method");
this.className = element.getAttribute("class");
-
SimpleMethod.readOperations(element, subOps, simpleMethod);
-
Element elseElement = UtilXml.firstChildElement(element, "else");
if (elseElement != null) {
elseSubOps = FastList.newInstance();
@@ -79,17 +67,15 @@ public class IfValidateMethod extends Me
public boolean exec(MethodContext methodContext) {
// if conditions fails, always return true; if a sub-op returns false
// return false and stop, otherwise return true
-
String methodName = methodContext.expandString(this.methodName);
String className = methodContext.expandString(this.className);
-
String fieldString = null;
Object fieldVal = null;
-
if (!mapAcsr.isEmpty()) {
Map<String, ? extends Object> fromMap = mapAcsr.get(methodContext);
if (fromMap == null) {
- if (Debug.infoOn()) Debug.logInfo("Map not found with name " + mapAcsr + ", using empty string for comparison", module);
+ if (Debug.infoOn())
+ Debug.logInfo("Map not found with name " + mapAcsr + ", using empty string for comparison", module);
} else {
fieldVal = fieldAcsr.get(fromMap, methodContext);
}
@@ -97,7 +83,6 @@ public class IfValidateMethod extends Me
// no map name, try the env
fieldVal = fieldAcsr.get(methodContext);
}
-
if (fieldVal != null) {
try {
fieldString = (String) ObjectType.simpleTypeConvert(fieldVal, "String", null, methodContext.getTimeZone(), methodContext.getLocale(), true);
@@ -105,13 +90,11 @@ public class IfValidateMethod extends Me
Debug.logError(e, "Could not convert object to String, using empty String", module);
}
}
-
// always use an empty string by default
- if (fieldString == null) fieldString = "";
-
- Class<?>[] paramTypes = new Class[] {String.class};
- Object[] params = new Object[] {fieldString};
-
+ if (fieldString == null)
+ fieldString = "";
+ Class<?>[] paramTypes = new Class[] { String.class };
+ Object[] params = new Object[] { fieldString };
Class<?> valClass;
try {
valClass = methodContext.getLoader().loadClass(className);
@@ -119,7 +102,6 @@ public class IfValidateMethod extends Me
Debug.logError("Could not find validation class: " + className, module);
return false;
}
-
Method valMethod;
try {
valMethod = valClass.getMethod(methodName, paramTypes);
@@ -127,14 +109,12 @@ public class IfValidateMethod extends Me
Debug.logError("Could not find validation method: " + methodName + " of class " + className, module);
return false;
}
-
Boolean resultBool = Boolean.FALSE;
try {
resultBool = (Boolean) valMethod.invoke(null, params);
} catch (Exception e) {
Debug.logError(e, "Error in IfValidationMethod " + methodName + " of class " + className + ", not processing sub-ops ", module);
}
-
if (resultBool.booleanValue()) {
return SimpleMethod.runSubOps(subOps, methodContext);
} else {
@@ -146,10 +126,17 @@ public class IfValidateMethod extends Me
}
}
+ @Override
+ public String expandedString(MethodContext methodContext) {
+ // TODO: something more than a stub/dummy
+ return this.rawString();
+ }
+
public List<MethodOperation> getAllSubOps() {
List<MethodOperation> allSubOps = FastList.newInstance();
allSubOps.addAll(this.subOps);
- if (this.elseSubOps != null) allSubOps.addAll(this.elseSubOps);
+ if (this.elseSubOps != null)
+ allSubOps.addAll(this.elseSubOps);
return allSubOps;
}
@@ -158,9 +145,14 @@ public class IfValidateMethod extends Me
// TODO: add all attributes and other info
return "<if-validate-method field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>";
}
- @Override
- public String expandedString(MethodContext methodContext) {
- // TODO: something more than a stub/dummy
- return this.rawString();
+
+ public static final class IfValidateMethodFactory implements Factory<IfValidateMethod> {
+ public IfValidateMethod createMethodOperation(Element element, SimpleMethod simpleMethod) {
+ return new IfValidateMethod(element, simpleMethod);
+ }
+
+ public String getName() {
+ return "if-validate-method";
+ }
}
}