You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by er...@apache.org on 2012/07/02 22:12:38 UTC
svn commit: r1356450 [9/10] - in /ofbiz/branches/20120329_portletWidget: ./
applications/accounting/ applications/accounting/config/
applications/accounting/script/org/ofbiz/accounting/rate/
applications/accounting/webapp/accounting/WEB-INF/ applicatio...
Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/eventops/RequestToField.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/eventops/RequestToField.java?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/eventops/RequestToField.java (original)
+++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/eventops/RequestToField.java Mon Jul 2 20:11:49 2012
@@ -18,92 +18,79 @@
*******************************************************************************/
package org.ofbiz.minilang.method.eventops;
-import java.util.Map;
-
-import javolution.util.FastMap;
-
-import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.collections.FlexibleServletAccessor;
+import org.ofbiz.base.util.collections.FlexibleMapAccessor;
+import org.ofbiz.base.util.string.FlexibleStringExpander;
import org.ofbiz.minilang.MiniLangException;
+import org.ofbiz.minilang.MiniLangValidate;
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 Servlet request attribute to a map field
+ * Implements the <request-to-field> element.
*/
-public class RequestToField extends MethodOperation {
-
- public static final String module = RequestToField.class.getName();
+public final class RequestToField extends MethodOperation {
- String defaultVal;
- ContextAccessor<Object> fieldAcsr;
- ContextAccessor<Map<String, Object>> mapAcsr;
- FlexibleServletAccessor<Object> requestAcsr;
+ private final FlexibleStringExpander defaultFse;
+ private final FlexibleMapAccessor<Object> fieldFma;
+ private final FlexibleStringExpander attributeNameFse;
public RequestToField(Element element, SimpleMethod simpleMethod) throws MiniLangException {
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
- mapAcsr = new ContextAccessor<Map<String, Object>>(element.getAttribute("map-name"));
- fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field"), element.getAttribute("field-name"));
- requestAcsr = new FlexibleServletAccessor<Object>(element.getAttribute("request-name"), fieldAcsr.toString());
- defaultVal = element.getAttribute("default");
+ if (MiniLangValidate.validationOn()) {
+ MiniLangValidate.attributeNames(simpleMethod, element, "field", "request-name", "default");
+ MiniLangValidate.requiredAttributes(simpleMethod, element, "field");
+ MiniLangValidate.expressionAttributes(simpleMethod, element, "field");
+ MiniLangValidate.noChildElements(simpleMethod, element);
+ }
+ this.fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field"));
+ String attributeName = element.getAttribute("request-name");
+ if (!attributeName.isEmpty()) {
+ this.attributeNameFse = FlexibleStringExpander.getInstance(attributeName);
+ } else {
+ this.attributeNameFse = FlexibleStringExpander.getInstance(this.fieldFma.toString());
+ }
+ this.defaultFse = FlexibleStringExpander.getInstance(element.getAttribute("default"));
}
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
- String defaultVal = methodContext.expandString(this.defaultVal);
- Object fieldVal = null;
- // only run this if it is in an EVENT context
if (methodContext.getMethodType() == MethodContext.EVENT) {
- fieldVal = requestAcsr.get(methodContext.getRequest(), methodContext.getEnvMap());
- if (fieldVal == null) {
- Debug.logWarning("Request attribute value not found with name " + requestAcsr, 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;
+ String attributeName = attributeNameFse.expandString(methodContext.getEnvMap());
+ Object value = methodContext.getRequest().getAttribute(attributeName);
+ if (value == null || (value instanceof String && ((String) value).isEmpty())) {
+ value = defaultFse.expandString(methodContext.getEnvMap());
}
- }
- 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);
+ fieldFma.put(methodContext.getEnvMap(), value);
}
return true;
}
@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 "<request-to-field request-name=\"" + this.requestAcsr + "\" field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>";
+ public String toString() {
+ StringBuilder sb = new StringBuilder("<request-to-field ");
+ sb.append("field=\"").append(this.fieldFma).append("\" ");
+ if (!this.attributeNameFse.isEmpty()) {
+ sb.append("request-name=\"").append(this.attributeNameFse).append("\" ");
+ }
+ if (!this.defaultFse.isEmpty()) {
+ sb.append("default=\"").append(this.defaultFse).append("\" ");
+ }
+ sb.append("/>");
+ return sb.toString();
}
+ /**
+ * A factory for the <request-to-field> element.
+ */
public static final class RequestToFieldFactory implements Factory<RequestToField> {
+ @Override
public RequestToField createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
return new RequestToField(element, simpleMethod);
}
+ @Override
public String getName() {
return "request-to-field";
}
Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/eventops/SessionToField.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/eventops/SessionToField.java?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/eventops/SessionToField.java (original)
+++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/eventops/SessionToField.java Mon Jul 2 20:11:49 2012
@@ -18,91 +18,79 @@
*******************************************************************************/
package org.ofbiz.minilang.method.eventops;
-import java.util.Map;
-
-import javolution.util.FastMap;
-
-import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.collections.FlexibleServletAccessor;
+import org.ofbiz.base.util.collections.FlexibleMapAccessor;
+import org.ofbiz.base.util.string.FlexibleStringExpander;
import org.ofbiz.minilang.MiniLangException;
+import org.ofbiz.minilang.MiniLangValidate;
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 Servlet session attribute to a map field
+ * Implements the <session-to-field> element.
*/
public class SessionToField extends MethodOperation {
- public static final String module = SessionToField.class.getName();
-
- String defaultVal;
- ContextAccessor<Object> fieldAcsr;
- ContextAccessor<Map<String, Object>> mapAcsr;
- FlexibleServletAccessor<Object> sessionAcsr;
+ private final FlexibleStringExpander defaultFse;
+ private final FlexibleMapAccessor<Object> fieldFma;
+ private final FlexibleStringExpander attributeNameFse;
public SessionToField(Element element, SimpleMethod simpleMethod) throws MiniLangException {
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
- 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");
+ if (MiniLangValidate.validationOn()) {
+ MiniLangValidate.attributeNames(simpleMethod, element, "field", "session-name", "default");
+ MiniLangValidate.requiredAttributes(simpleMethod, element, "field");
+ MiniLangValidate.expressionAttributes(simpleMethod, element, "field");
+ MiniLangValidate.noChildElements(simpleMethod, element);
+ }
+ this.fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field"));
+ String attributeName = element.getAttribute("session-name");
+ if (!attributeName.isEmpty()) {
+ this.attributeNameFse = FlexibleStringExpander.getInstance(attributeName);
+ } else {
+ this.attributeNameFse = FlexibleStringExpander.getInstance(this.fieldFma.toString());
+ }
+ this.defaultFse = FlexibleStringExpander.getInstance(element.getAttribute("default"));
}
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
- String defaultVal = methodContext.expandString(this.defaultVal);
- Object fieldVal = null;
- // only run this if it is in an EVENT context
if (methodContext.getMethodType() == MethodContext.EVENT) {
- fieldVal = sessionAcsr.get(methodContext.getRequest().getSession(), methodContext.getEnvMap());
- if (fieldVal == null) {
- 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;
+ String attributeName = attributeNameFse.expandString(methodContext.getEnvMap());
+ Object value = methodContext.getRequest().getSession().getAttribute(attributeName);
+ if (value == null || (value instanceof String && ((String) value).isEmpty())) {
+ value = defaultFse.expandString(methodContext.getEnvMap());
}
- }
- 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);
+ fieldFma.put(methodContext.getEnvMap(), value);
}
return true;
}
@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 + "\"/>";
+ public String toString() {
+ StringBuilder sb = new StringBuilder("<session-to-field ");
+ sb.append("field=\"").append(this.fieldFma).append("\" ");
+ if (!this.attributeNameFse.isEmpty()) {
+ sb.append("session-name=\"").append(this.attributeNameFse).append("\" ");
+ }
+ if (!this.defaultFse.isEmpty()) {
+ sb.append("default=\"").append(this.defaultFse).append("\" ");
+ }
+ sb.append("/>");
+ return sb.toString();
}
+ /**
+ * A factory for the <session-to-field> element.
+ */
public static final class SessionToFieldFactory implements Factory<SessionToField> {
+ @Override
public SessionToField createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
return new SessionToField(element, simpleMethod);
}
+ @Override
public String getName() {
return "session-to-field";
}
Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/eventops/WebappPropertyToField.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/eventops/WebappPropertyToField.java?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/eventops/WebappPropertyToField.java (original)
+++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/eventops/WebappPropertyToField.java Mon Jul 2 20:11:49 2012
@@ -19,103 +19,91 @@
package org.ofbiz.minilang.method.eventops;
import java.net.URL;
-import java.util.Map;
import javax.servlet.ServletContext;
-import javolution.util.FastMap;
-
-import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilProperties;
-import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.collections.FlexibleMapAccessor;
+import org.ofbiz.base.util.string.FlexibleStringExpander;
import org.ofbiz.minilang.MiniLangException;
+import org.ofbiz.minilang.MiniLangRuntimeException;
+import org.ofbiz.minilang.MiniLangValidate;
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
+ * Implements the <webapp-property-to-field> element.
*/
-public class WebappPropertyToField extends MethodOperation {
-
- public static final String module = WebappPropertyToField.class.getName();
+public final class WebappPropertyToField extends MethodOperation {
- String defaultVal;
- ContextAccessor<Object> fieldAcsr;
- ContextAccessor<Map<String, Object>> mapAcsr;
- String property;
- String resource;
+ private final FlexibleStringExpander defaultFse;
+ private final FlexibleMapAccessor<Object> fieldFma;
+ private final FlexibleStringExpander propertyFse;
+ private final FlexibleStringExpander resourceFse;
public WebappPropertyToField(Element element, SimpleMethod simpleMethod) throws MiniLangException {
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"));
+ if (MiniLangValidate.validationOn()) {
+ MiniLangValidate.attributeNames(simpleMethod, element, "field", "resource", "property", "default");
+ MiniLangValidate.requiredAttributes(simpleMethod, element, "field", "resource", "property");
+ MiniLangValidate.expressionAttributes(simpleMethod, element, "field");
+ MiniLangValidate.noChildElements(simpleMethod, element);
+ }
+ this.fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field"));
+ this.resourceFse = FlexibleStringExpander.getInstance(element.getAttribute("resource"));
+ this.propertyFse = FlexibleStringExpander.getInstance(element.getAttribute("property"));
+ this.defaultFse = FlexibleStringExpander.getInstance(element.getAttribute("default"));
}
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
- 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) {
+ String resource = resourceFse.expandString(methodContext.getEnvMap());
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);
+ throw new MiniLangRuntimeException("Exception thrown while finding properties file " + resource + ": " + e.getMessage(), this);
}
if (propsUrl == null) {
- Debug.logWarning("Webapp resource (properties file) not found with name " + resource, module);
- } else {
- fieldVal = UtilProperties.getPropertyValue(propsUrl, property);
- if (UtilValidate.isEmpty(fieldVal)) {
- Debug.logWarning("Webapp resource property value not found with name " + property + " in resource " + resource, module);
- }
+ throw new MiniLangRuntimeException("Properties file " + resource + " not found.", this);
}
- }
- // if fieldVal is null, or has zero length, use 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);
+ String property = propertyFse.expandString(methodContext.getEnvMap());
+ String fieldVal = UtilProperties.getPropertyValue(propsUrl, property);
+ if (fieldVal == null) {
+ fieldVal = defaultFse.expandString(methodContext.getEnvMap());
}
- fieldAcsr.put(fromMap, fieldVal, methodContext);
- } else {
- fieldAcsr.put(methodContext, fieldVal);
+ fieldFma.put(methodContext.getEnvMap(), fieldVal);
}
return true;
}
@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 + "\"/>";
+ public String toString() {
+ StringBuilder sb = new StringBuilder("<webapp-property-to-field ");
+ sb.append("field=\"").append(this.fieldFma).append("\" ");
+ sb.append("resource=\"").append(this.resourceFse).append("\" ");
+ sb.append("property=\"").append(this.propertyFse).append("\" ");
+ if (!this.defaultFse.isEmpty()) {
+ sb.append("default=\"").append(this.defaultFse).append("\" ");
+ }
+ sb.append("/>");
+ return sb.toString();
}
+ /**
+ * A factory for the <webapp-property-to-field> element.
+ */
public static final class WebappPropertyToFieldFactory implements Factory<WebappPropertyToField> {
+ @Override
public WebappPropertyToField createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
return new WebappPropertyToField(element, simpleMethod);
}
+ @Override
public String getName() {
return "webapp-property-to-field";
}
Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/ifops/CheckPermission.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/ifops/CheckPermission.java?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/ifops/CheckPermission.java (original)
+++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/ifops/CheckPermission.java Mon Jul 2 20:11:49 2012
@@ -100,16 +100,6 @@ public final class CheckPermission exten
}
@Override
- public String expandedString(MethodContext methodContext) {
- return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap());
- }
-
- @Override
- public String rawString() {
- return toString();
- }
-
- @Override
public String toString() {
StringBuilder sb = new StringBuilder("<check-permission ");
sb.append("permission=\"").append(this.primaryPermissionInfo.permissionFse).append("\" ");
Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfInstanceOf.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfInstanceOf.java?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfInstanceOf.java (original)
+++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfInstanceOf.java Mon Jul 2 20:11:49 2012
@@ -24,7 +24,6 @@ import java.util.List;
import org.ofbiz.base.util.ObjectType;
import org.ofbiz.base.util.UtilXml;
import org.ofbiz.base.util.collections.FlexibleMapAccessor;
-import org.ofbiz.base.util.string.FlexibleStringExpander;
import org.ofbiz.minilang.MiniLangException;
import org.ofbiz.minilang.MiniLangRuntimeException;
import org.ofbiz.minilang.MiniLangValidate;
@@ -95,11 +94,6 @@ public final class IfInstanceOf extends
}
@Override
- public String expandedString(MethodContext methodContext) {
- return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap());
- }
-
- @Override
public void gatherArtifactInfo(ArtifactInfoContext aic) {
for (MethodOperation method : this.subOps) {
method.gatherArtifactInfo(aic);
@@ -112,11 +106,6 @@ public final class IfInstanceOf extends
}
@Override
- public String rawString() {
- return toString();
- }
-
- @Override
public String toString() {
StringBuilder sb = new StringBuilder("<if-instance-of ");
sb.append("field=\"").append(this.fieldFma).append("\" ");
Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfNotEmpty.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfNotEmpty.java?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfNotEmpty.java (original)
+++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfNotEmpty.java Mon Jul 2 20:11:49 2012
@@ -24,7 +24,6 @@ import java.util.List;
import org.ofbiz.base.util.ObjectType;
import org.ofbiz.base.util.UtilXml;
import org.ofbiz.base.util.collections.FlexibleMapAccessor;
-import org.ofbiz.base.util.string.FlexibleStringExpander;
import org.ofbiz.minilang.MiniLangException;
import org.ofbiz.minilang.SimpleMethod;
import org.ofbiz.minilang.artifact.ArtifactInfoContext;
@@ -68,11 +67,6 @@ public final class IfNotEmpty extends Me
}
@Override
- public String expandedString(MethodContext methodContext) {
- return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap());
- }
-
- @Override
public void gatherArtifactInfo(ArtifactInfoContext aic) {
for (MethodOperation method : this.subOps) {
method.gatherArtifactInfo(aic);
@@ -85,11 +79,6 @@ public final class IfNotEmpty extends Me
}
@Override
- public String rawString() {
- return toString();
- }
-
- @Override
public String toString() {
StringBuilder sb = new StringBuilder("<if-not-empty ");
sb.append("field=\"").append(this.fieldFma).append("\"/>");
Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java (original)
+++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java Mon Jul 2 20:11:49 2012
@@ -22,26 +22,24 @@ import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Locale;
-import java.util.Map;
-import javolution.util.FastMap;
-
-import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.ObjectType;
-import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.base.util.collections.FlexibleMapAccessor;
+import org.ofbiz.base.util.string.FlexibleStringExpander;
+import org.ofbiz.minilang.MiniLangElement;
import org.ofbiz.minilang.MiniLangException;
+import org.ofbiz.minilang.MiniLangRuntimeException;
import org.ofbiz.minilang.MiniLangUtil;
+import org.ofbiz.minilang.MiniLangValidate;
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;
/**
- * Calculates a result based on nested calcops.
+ * Implements the <calculate> element.
*/
-public class Calculate extends MethodOperation {
+public final class Calculate extends MethodOperation {
public static final String module = Calculate.class.getName();
@@ -51,36 +49,40 @@ public class Calculate extends MethodOpe
public static final int TYPE_INTEGER = 4;
public static final int TYPE_STRING = 5;
public static final int TYPE_BIG_DECIMAL = 6;
- public static final BigDecimal ZERO = BigDecimal.ZERO;
- Calculate.SubCalc calcops[];
- String decimalFormatString;
- String decimalScaleString;
- ContextAccessor<Object> fieldAcsr;
- ContextAccessor<Map<String, Object>> mapAcsr;
- String roundingModeString;
- String typeString;
+ private final Calculate.SubCalc calcops[];
+ private final FlexibleStringExpander decimalFormatFse;
+ private final FlexibleStringExpander decimalScaleFse;
+ private final FlexibleMapAccessor<Object> fieldFma;
+ private final FlexibleStringExpander roundingModeFse;
+ private final FlexibleStringExpander typeFse;
public Calculate(Element element, SimpleMethod simpleMethod) throws MiniLangException {
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, Object>>(element.getAttribute("map-name"));
- decimalScaleString = element.getAttribute("decimal-scale");
- decimalFormatString = element.getAttribute("decimal-format");
- typeString = element.getAttribute("type");
- roundingModeString = element.getAttribute("rounding-mode");
+ if (MiniLangValidate.validationOn()) {
+ MiniLangValidate.handleError("<calculate> element is deprecated (use <set>)", simpleMethod, element);
+ MiniLangValidate.attributeNames(simpleMethod, element, "field", "decimal-scale", "decimal-format", "rounding-mode", "type");
+ MiniLangValidate.requiredAttributes(simpleMethod, element, "field");
+ MiniLangValidate.expressionAttributes(simpleMethod, element, "field");
+ MiniLangValidate.childElements(simpleMethod, element, "calcop", "number");
+ }
+ this.fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field"));
+ this.decimalFormatFse = FlexibleStringExpander.getInstance(element.getAttribute("decimal-format"));
+ this.decimalScaleFse = FlexibleStringExpander.getInstance(element.getAttribute("decimal-scale"));
+ this.roundingModeFse = FlexibleStringExpander.getInstance(element.getAttribute("rounding-mode"));
+ this.typeFse = FlexibleStringExpander.getInstance(element.getAttribute("type"));
List<? extends Element> calcopElements = UtilXml.childElementList(element);
calcops = new Calculate.SubCalc[calcopElements.size()];
int i = 0;
for (Element calcopElement : calcopElements) {
String nodeName = calcopElement.getNodeName();
if ("calcop".equals(nodeName)) {
- calcops[i] = new Calculate.CalcOp(calcopElement);
+ calcops[i] = new CalcOp(calcopElement, simpleMethod);
} else if ("number".equals(nodeName)) {
- calcops[i] = new Calculate.NumberOp(calcopElement);
+ calcops[i] = new NumberOp(calcopElement, simpleMethod);
} else {
- Debug.logError("Error: calculate operation with type " + nodeName, module);
+ MiniLangValidate.handleError("Invalid calculate sub-element.", simpleMethod, calcopElement);
+ calcops[i] = new InvalidOp(calcopElement, simpleMethod);
}
i++;
}
@@ -88,7 +90,7 @@ public class Calculate extends MethodOpe
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
- String typeString = methodContext.expandString(this.typeString);
+ String typeString = typeFse.expandString(methodContext.getEnvMap());
int type;
if ("Double".equals(typeString)) {
type = Calculate.TYPE_DOUBLE;
@@ -105,7 +107,7 @@ public class Calculate extends MethodOpe
} else {
type = Calculate.TYPE_BIG_DECIMAL;
}
- String roundingModeString = methodContext.expandString(this.roundingModeString);
+ String roundingModeString = roundingModeFse.expandString(methodContext.getEnvMap());
int roundingMode;
if ("Ceiling".equals(roundingModeString)) {
roundingMode = BigDecimal.ROUND_CEILING;
@@ -127,29 +129,21 @@ public class Calculate extends MethodOpe
// default to HalfEven, reduce cumulative errors
roundingMode = BigDecimal.ROUND_HALF_EVEN;
}
- String decimalScaleString = methodContext.expandString(this.decimalScaleString);
+ String decimalScaleString = decimalScaleFse.expandString(methodContext.getEnvMap());
int decimalScale = 2;
- if (UtilValidate.isNotEmpty(decimalScaleString)) {
+ if (!decimalScaleString.isEmpty()) {
decimalScale = Integer.valueOf(decimalScaleString).intValue();
}
- String decimalFormatString = methodContext.expandString(this.decimalFormatString);
+ String decimalFormatString = decimalFormatFse.expandString(methodContext.getEnvMap());
DecimalFormat df = null;
- if (UtilValidate.isNotEmpty(decimalFormatString)) {
+ if (!decimalFormatString.isEmpty()) {
df = new DecimalFormat(decimalFormatString);
}
- BigDecimal resultValue = ZERO;
- resultValue = resultValue.setScale(decimalScale, roundingMode);
+ BigDecimal resultValue = BigDecimal.ZERO.setScale(decimalScale, roundingMode);
for (Calculate.SubCalc calcop : calcops) {
resultValue = resultValue.add(calcop.calcValue(methodContext, decimalScale, roundingMode));
- // Debug.logInfo("main total so far: " + resultValue, module);
}
resultValue = resultValue.setScale(decimalScale, roundingMode);
- /*
- * the old thing that did conversion to string and back, may want to use somewhere sometime...: for now just doing the setScale above (before and after calc ops) try { resultValue = new
- * BigDecimal(df.format(resultValue)); } catch (ParseException e) { String errorMessage = "Unable to format [" + formatString + "] result [" + resultValue + "]"; Debug.logError(e,
- * errorMessage, module); if (methodContext.getMethodType() == MethodContext.EVENT) { methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errorMessage); } else if
- * (methodContext.getMethodType() == MethodContext.SERVICE) { methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errorMessage); } return false; }
- */
Object resultObj = null;
switch (type) {
case TYPE_DOUBLE:
@@ -168,7 +162,7 @@ public class Calculate extends MethodOpe
break;
case TYPE_STRING:
// run the decimal-formatting
- if (df != null && resultValue.compareTo(ZERO) > 0) {
+ if (df != null && resultValue.compareTo(BigDecimal.ZERO) > 0) {
resultObj = df.format(resultValue);
} else {
resultObj = resultValue.toString();
@@ -178,71 +172,80 @@ public class Calculate extends MethodOpe
resultObj = resultValue;
break;
}
-
- if (!mapAcsr.isEmpty()) {
- Map<String, Object> toMap = mapAcsr.get(methodContext);
- if (toMap == null) {
- if (Debug.verboseOn())
- Debug.logVerbose("Map not found with name " + mapAcsr + ", creating new map", module);
- toMap = FastMap.newInstance();
- mapAcsr.put(methodContext, toMap);
- }
- fieldAcsr.put(toMap, resultObj, methodContext);
- } else {
- fieldAcsr.put(methodContext, resultObj);
- }
-
+ fieldFma.put(methodContext.getEnvMap(), resultObj);
return true;
}
@Override
- public String expandedString(MethodContext methodContext) {
- // TODO: something more than a stub/dummy
- return this.rawString();
+ public String toString() {
+ StringBuilder sb = new StringBuilder("<set ");
+ sb.append("field=\"").append(this.fieldFma).append("\" ");
+ if (!this.roundingModeFse.isEmpty()) {
+ sb.append("rounding-mode=\"").append(this.roundingModeFse).append("\" ");
+ }
+ if (!this.decimalScaleFse.isEmpty()) {
+ sb.append("decimal-scale=\"").append(this.decimalScaleFse).append("\" ");
+ }
+ if (!this.decimalFormatFse.isEmpty()) {
+ sb.append("decimal-format=\"").append(this.decimalFormatFse).append("\" ");
+ }
+ if (!typeFse.isEmpty()) {
+ sb.append("type=\"").append(this.typeFse).append("\" ");
+ }
+ sb.append("/>");
+ return sb.toString();
}
- @Override
- public String rawString() {
- // TODO: add all attributes and other info
- return "<calculate field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>";
+ /**
+ * Interface for <calculate> sub-element implementations.
+ */
+ public interface SubCalc {
+ BigDecimal calcValue(MethodContext methodContext, int scale, int roundingMode) throws MiniLangException;
}
- protected static class CalcOp implements SubCalc {
- public static final int OPERATOR_ADD = 1;
- public static final int OPERATOR_DIVIDE = 4;
- public static final int OPERATOR_MULTIPLY = 3;
- public static final int OPERATOR_NEGATIVE = 5;
- public static final int OPERATOR_SUBTRACT = 2;
-
- Calculate.SubCalc calcops[];
- ContextAccessor<Object> fieldAcsr;
- ContextAccessor<Map<String, ? extends Object>> mapAcsr;
- String operatorStr;
-
- public CalcOp(Element element) {
- // 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"));
- operatorStr = element.getAttribute("operator");
+ /**
+ * Implements the <calcop> element.
+ */
+ public final class CalcOp extends MiniLangElement implements SubCalc {
+ private static final int OPERATOR_ADD = 1;
+ private static final int OPERATOR_DIVIDE = 4;
+ private static final int OPERATOR_MULTIPLY = 3;
+ private static final int OPERATOR_NEGATIVE = 5;
+ private static final int OPERATOR_SUBTRACT = 2;
+
+ private final Calculate.SubCalc calcops[];
+ private final FlexibleMapAccessor<Object> fieldFma;
+ private final FlexibleStringExpander operatorFse;
+
+ private CalcOp(Element element, SimpleMethod simpleMethod) throws MiniLangException {
+ super(element, simpleMethod);
+ if (MiniLangValidate.validationOn()) {
+ MiniLangValidate.attributeNames(simpleMethod, element, "field", "operator");
+ MiniLangValidate.requiredAttributes(simpleMethod, element, "field");
+ MiniLangValidate.expressionAttributes(simpleMethod, element, "field");
+ MiniLangValidate.childElements(simpleMethod, element, "calcop", "number");
+ }
+ this.fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field"));
+ this.operatorFse = FlexibleStringExpander.getInstance(element.getAttribute("operator"));
List<? extends Element> calcopElements = UtilXml.childElementList(element);
calcops = new Calculate.SubCalc[calcopElements.size()];
int i = 0;
-
for (Element calcopElement : calcopElements) {
- String nodeName = calcopElement.getNodeName();
if ("calcop".equals(calcopElement.getNodeName())) {
- calcops[i] = new Calculate.CalcOp(calcopElement);
+ calcops[i] = new Calculate.CalcOp(calcopElement, simpleMethod);
} else if ("number".equals(calcopElement.getNodeName())) {
- calcops[i] = new Calculate.NumberOp(calcopElement);
+ calcops[i] = new Calculate.NumberOp(calcopElement, simpleMethod);
} else {
- Debug.logError("Error: calculate operation unknown with type " + nodeName, module);
+ MiniLangValidate.handleError("Invalid calculate sub-element.", simpleMethod, calcopElement);
+ calcops[i] = new InvalidOp(calcopElement, simpleMethod);
}
i++;
}
}
- public BigDecimal calcValue(MethodContext methodContext, int scale, int roundingMode) {
- String operatorStr = methodContext.expandString(this.operatorStr);
+ @Override
+ public BigDecimal calcValue(MethodContext methodContext, int scale, int roundingMode) throws MiniLangException {
+ String operatorStr = operatorFse.expandString(methodContext.getEnvMap());
int operator = CalcOp.OPERATOR_ADD;
if ("get".equals(operatorStr)) {
operator = CalcOp.OPERATOR_ADD;
@@ -257,45 +260,26 @@ public class Calculate extends MethodOpe
} else if ("negative".equals(operatorStr)) {
operator = CalcOp.OPERATOR_NEGATIVE;
}
- BigDecimal resultValue = ZERO;
- resultValue = resultValue.setScale(scale, roundingMode);
+ BigDecimal resultValue = BigDecimal.ZERO.setScale(scale, roundingMode);
boolean isFirst = true;
- // if a fieldAcsr was specified, get the field from the map or result and use it as the initial value
- if (!fieldAcsr.isEmpty()) {
- Object fieldObj = 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 + ", creating new map", module);
- fromMap = FastMap.newInstance();
- mapAcsr.put(methodContext, fromMap);
- }
- fieldObj = fieldAcsr.get(fromMap, methodContext);
- } else {
- fieldObj = fieldAcsr.get(methodContext);
- }
- if (fieldObj != null) {
- if (fieldObj instanceof Double) {
- resultValue = new BigDecimal(((Double) fieldObj).doubleValue());
- } else if (fieldObj instanceof Long) {
- resultValue = BigDecimal.valueOf(((Long) fieldObj).longValue());
- } else if (fieldObj instanceof Float) {
- resultValue = new BigDecimal(((Float) fieldObj).floatValue());
- } else if (fieldObj instanceof Integer) {
- resultValue = BigDecimal.valueOf(((Integer) fieldObj).longValue());
- } else if (fieldObj instanceof String) {
- resultValue = new BigDecimal((String) fieldObj);
- } else if (fieldObj instanceof BigDecimal) {
- resultValue = (BigDecimal) fieldObj;
- }
- if (operator == OPERATOR_NEGATIVE)
- resultValue = resultValue.negate();
- isFirst = false;
- } else {
- if (Debug.infoOn())
- Debug.logInfo("Field not found with field-name " + fieldAcsr + ", and map-name " + mapAcsr + "using a default of 0", module);
+ Object fieldObj = fieldFma.get(methodContext.getEnvMap());
+ if (fieldObj != null) {
+ if (fieldObj instanceof Double) {
+ resultValue = new BigDecimal(((Double) fieldObj).doubleValue());
+ } else if (fieldObj instanceof Long) {
+ resultValue = BigDecimal.valueOf(((Long) fieldObj).longValue());
+ } else if (fieldObj instanceof Float) {
+ resultValue = new BigDecimal(((Float) fieldObj).floatValue());
+ } else if (fieldObj instanceof Integer) {
+ resultValue = BigDecimal.valueOf(((Integer) fieldObj).longValue());
+ } else if (fieldObj instanceof String) {
+ resultValue = new BigDecimal((String) fieldObj);
+ } else if (fieldObj instanceof BigDecimal) {
+ resultValue = (BigDecimal) fieldObj;
}
+ if (operator == OPERATOR_NEGATIVE)
+ resultValue = resultValue.negate();
+ isFirst = false;
}
for (SubCalc calcop : calcops) {
if (isFirst) {
@@ -325,42 +309,62 @@ public class Calculate extends MethodOpe
}
}
- public static final class CalculateFactory implements Factory<Calculate> {
- public Calculate createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
- return new Calculate(element, simpleMethod);
- }
-
- public String getName() {
- return "calculate";
- }
- }
-
- protected static class NumberOp implements SubCalc {
- String valueStr;
-
- public NumberOp(Element element) {
- valueStr = element.getAttribute("value");
+ /**
+ * Implements the <number> element.
+ */
+ public final class NumberOp extends MiniLangElement implements SubCalc {
+
+ private final FlexibleStringExpander valueFse;
+
+ private NumberOp(Element element, SimpleMethod simpleMethod) throws MiniLangException {
+ super(element, simpleMethod);
+ if (MiniLangValidate.validationOn()) {
+ MiniLangValidate.attributeNames(simpleMethod, element, "value");
+ MiniLangValidate.requiredAttributes(simpleMethod, element, "value");
+ MiniLangValidate.noChildElements(simpleMethod, element);
+ }
+ valueFse = FlexibleStringExpander.getInstance(element.getAttribute("value"));
}
- public BigDecimal calcValue(MethodContext methodContext, int scale, int roundingMode) {
- String valueStr = methodContext.expandString(this.valueStr);
+ @Override
+ public BigDecimal calcValue(MethodContext methodContext, int scale, int roundingMode) throws MiniLangException {
+ String valueStr = valueFse.expandString(methodContext.getEnvMap());
Locale locale = methodContext.getLocale();
if (locale == null)
locale = Locale.getDefault();
- BigDecimal value;
try {
- BigDecimal parseVal = (BigDecimal) MiniLangUtil.convertType(valueStr, java.math.BigDecimal.class, locale, null, null);
- value = parseVal.setScale(scale, roundingMode);
+ BigDecimal parsedVal = (BigDecimal) MiniLangUtil.convertType(valueStr, java.math.BigDecimal.class, locale, null, null);
+ return parsedVal.setScale(scale, roundingMode);
} catch (Exception e) {
- Debug.logError(e, "Could not parse the number string: " + valueStr, module);
- throw new IllegalArgumentException("Could not parse the number string: " + valueStr);
+ throw new MiniLangRuntimeException("Exception thrown while parsing value attribute: " + e.getMessage(), this);
}
- return value;
}
+ }
+
+ private final class InvalidOp extends MiniLangElement implements SubCalc {
+ private InvalidOp(Element element, SimpleMethod simpleMethod) throws MiniLangException {
+ super(element, simpleMethod);
+ }
+
+ @Override
+ public BigDecimal calcValue(MethodContext methodContext, int scale, int roundingMode) throws MiniLangException {
+ throw new MiniLangRuntimeException("Invalid calculate sub-element.", this);
+ }
}
- protected static interface SubCalc {
- public BigDecimal calcValue(MethodContext methodContext, int scale, int roundingMode);
+ /**
+ * A factory for the <calculate> element.
+ */
+ public static final class CalculateFactory implements Factory<Calculate> {
+ @Override
+ public Calculate createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
+ return new Calculate(element, simpleMethod);
+ }
+
+ @Override
+ public String getName() {
+ return "calculate";
+ }
}
}
Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/otherops/Log.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/otherops/Log.java?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/otherops/Log.java (original)
+++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/otherops/Log.java Mon Jul 2 20:11:49 2012
@@ -84,16 +84,6 @@ public final class Log extends MethodOpe
}
@Override
- public String expandedString(MethodContext methodContext) {
- return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap());
- }
-
- @Override
- public String rawString() {
- return toString();
- }
-
- @Override
public String toString() {
StringBuilder sb = new StringBuilder("<log ");
sb.append("level=\"").append(LEVEL_ARRAY[this.level]).append("\" ");
Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/otherops/PropertyToField.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/otherops/PropertyToField.java?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/otherops/PropertyToField.java (original)
+++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/otherops/PropertyToField.java Mon Jul 2 20:11:49 2012
@@ -20,103 +20,119 @@ package org.ofbiz.minilang.method.othero
import java.text.MessageFormat;
import java.util.List;
-import java.util.Map;
-import javolution.util.FastMap;
-
-import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.collections.FlexibleMapAccessor;
+import org.ofbiz.base.util.string.FlexibleStringExpander;
import org.ofbiz.entity.util.EntityUtilProperties;
import org.ofbiz.minilang.MiniLangException;
+import org.ofbiz.minilang.MiniLangRuntimeException;
+import org.ofbiz.minilang.MiniLangUtil;
+import org.ofbiz.minilang.MiniLangValidate;
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 an properties file property value to a field
+ * Implements the <property-to-field> element.
*/
-public class PropertyToField extends MethodOperation {
+public final class PropertyToField extends MethodOperation {
- public static final String module = PropertyToField.class.getName();
+ // This method is needed only during the v1 to v2 transition
+ private static boolean autoCorrect(Element element) {
+ // Correct deprecated arg-list-name attribute
+ String listAttr = element.getAttribute("arg-list-name");
+ if (listAttr.length() > 0) {
+ element.setAttribute("arg-list", listAttr);
+ element.removeAttribute("arg-list-name");
+ return true;
+ }
+ return false;
+ }
- ContextAccessor<List<? extends Object>> argListAcsr;
- String defaultVal;
- ContextAccessor<Object> fieldAcsr;
- ContextAccessor<Map<String, Object>> mapAcsr;
- boolean noLocale;
- String property;
- String resource;
+ private final FlexibleMapAccessor<List<? extends Object>> argListFma;
+ private final FlexibleStringExpander defaultFse;
+ private final FlexibleMapAccessor<Object> fieldFma;
+ private final boolean noLocale;
+ private final FlexibleStringExpander propertyFse;
+ private final FlexibleStringExpander resourceFse;
public PropertyToField(Element element, SimpleMethod simpleMethod) throws MiniLangException {
super(element, simpleMethod);
- resource = element.getAttribute("resource");
- property = element.getAttribute("property");
- // 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, Object>>(element.getAttribute("map-name"));
- defaultVal = element.getAttribute("default");
- // defaults to false, ie anything but true is false
+ if (MiniLangValidate.validationOn()) {
+ MiniLangValidate.deprecatedAttribute(simpleMethod, element, "arg-list-name", "replace with \"arg-list\"");
+ MiniLangValidate.attributeNames(simpleMethod, element, "field", "resource", "property", "arg-list", "default", "no-locale");
+ MiniLangValidate.requiredAttributes(simpleMethod, element, "field", "resource", "property");
+ MiniLangValidate.expressionAttributes(simpleMethod, element, "field", "arg-list");
+ MiniLangValidate.noChildElements(simpleMethod, element);
+ }
+ boolean elementModified = autoCorrect(element);
+ if (elementModified && MiniLangUtil.autoCorrectOn()) {
+ MiniLangUtil.flagDocumentAsCorrected(element);
+ }
+ fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field"));
+ resourceFse = FlexibleStringExpander.getInstance(element.getAttribute("resource"));
+ propertyFse = FlexibleStringExpander.getInstance(element.getAttribute("property"));
+ argListFma = FlexibleMapAccessor.getInstance(element.getAttribute("arg-list"));
+ defaultFse = FlexibleStringExpander.getInstance(element.getAttribute("default"));
noLocale = "true".equals(element.getAttribute("no-locale"));
- argListAcsr = new ContextAccessor<List<? extends Object>>(element.getAttribute("arg-list-name"));
}
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
- String resource = methodContext.expandString(this.resource);
- String property = methodContext.expandString(this.property);
+ String resource = resourceFse.expandString(methodContext.getEnvMap());
+ String property = propertyFse.expandString(methodContext.getEnvMap());
String value = null;
if (noLocale) {
value = EntityUtilProperties.getPropertyValue(resource, property, methodContext.getDelegator());
} else {
value = EntityUtilProperties.getMessage(resource, property, methodContext.getLocale(), methodContext.getDelegator());
}
- if (UtilValidate.isEmpty(value)) {
- value = defaultVal;
- }
- // 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 = methodContext.expandString(value);
- if (!argListAcsr.isEmpty()) {
- List<? extends Object> argList = argListAcsr.get(methodContext);
- if (UtilValidate.isNotEmpty(argList)) {
+ value = FlexibleStringExpander.expandString(value, methodContext.getEnvMap());
+ if (value.isEmpty()) {
+ value = defaultFse.expandString(methodContext.getEnvMap());
+ }
+ List<? extends Object> argList = argListFma.get(methodContext.getEnvMap());
+ if (argList != null) {
+ try {
value = MessageFormat.format(value, argList.toArray());
+ } catch (IllegalArgumentException e) {
+ throw new MiniLangRuntimeException("Exception thrown while formatting the property value: " + e.getMessage(), this);
}
}
- if (!mapAcsr.isEmpty()) {
- Map<String, Object> toMap = mapAcsr.get(methodContext);
- if (toMap == null) {
- if (Debug.infoOn())
- Debug.logInfo("Map not found with name " + mapAcsr + ", creating new map", module);
- toMap = FastMap.newInstance();
- mapAcsr.put(methodContext, toMap);
- }
- fieldAcsr.put(toMap, value, methodContext);
- } else {
- fieldAcsr.put(methodContext, value);
- }
+ fieldFma.put(methodContext.getEnvMap(), value);
return true;
}
@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 "<property-to-field field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>";
+ public String toString() {
+ StringBuilder sb = new StringBuilder("<property-to-field ");
+ sb.append("field=\"").append(this.fieldFma).append("\" ");
+ sb.append("resource=\"").append(this.resourceFse).append("\" ");
+ sb.append("property=\"").append(this.propertyFse).append("\" ");
+ if (!this.argListFma.isEmpty()) {
+ sb.append("arg-list=\"").append(this.argListFma).append("\" ");
+ }
+ if (!this.defaultFse.isEmpty()) {
+ sb.append("default=\"").append(this.defaultFse).append("\" ");
+ }
+ if (noLocale) {
+ sb.append("no-locale=\"true\" ");
+ }
+ sb.append("/>");
+ return sb.toString();
}
+ /**
+ * A factory for the <property-to-field> element.
+ */
public static final class PropertyToFieldFactory implements Factory<PropertyToField> {
+ @Override
public PropertyToField createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
return new PropertyToField(element, simpleMethod);
}
+ @Override
public String getName() {
return "property-to-field";
}
Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/otherops/Trace.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/otherops/Trace.java?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/otherops/Trace.java (original)
+++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/otherops/Trace.java Mon Jul 2 20:11:49 2012
@@ -22,7 +22,6 @@ import java.util.Collections;
import java.util.List;
import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.string.FlexibleStringExpander;
import org.ofbiz.minilang.MiniLangException;
import org.ofbiz.minilang.MiniLangValidate;
import org.ofbiz.minilang.SimpleMethod;
@@ -70,16 +69,6 @@ public final class Trace extends MethodO
}
@Override
- public String expandedString(MethodContext methodContext) {
- return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap());
- }
-
- @Override
- public String rawString() {
- return toString();
- }
-
- @Override
public String toString() {
StringBuilder sb = new StringBuilder("<trace ");
sb.append("level=\"").append(Log.LEVEL_ARRAY[this.level]).append("\" >");
Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/serviceops/FieldToResult.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/serviceops/FieldToResult.java?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/serviceops/FieldToResult.java (original)
+++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/serviceops/FieldToResult.java Mon Jul 2 20:11:49 2012
@@ -19,7 +19,6 @@
package org.ofbiz.minilang.method.serviceops;
import org.ofbiz.base.util.collections.FlexibleMapAccessor;
-import org.ofbiz.base.util.string.FlexibleStringExpander;
import org.ofbiz.minilang.MiniLangException;
import org.ofbiz.minilang.MiniLangValidate;
import org.ofbiz.minilang.SimpleMethod;
@@ -70,16 +69,6 @@ public final class FieldToResult extends
}
@Override
- public String expandedString(MethodContext methodContext) {
- return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap());
- }
-
- @Override
- public String rawString() {
- return toString();
- }
-
- @Override
public String toString() {
StringBuilder sb = new StringBuilder("<field-to-result ");
if (!this.fieldFma.isEmpty()) {
Modified: ofbiz/branches/20120329_portletWidget/framework/resources/templates/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/resources/templates/ofbiz-component.xml?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/resources/templates/ofbiz-component.xml (original)
+++ ofbiz/branches/20120329_portletWidget/framework/resources/templates/ofbiz-component.xml Mon Jul 2 20:11:49 2012
@@ -17,7 +17,7 @@
<entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>
<!-- <entity-resource type="eca" reader-name="main" loader="main" location="entitydef/eecas.xml"/> -->
<entity-resource type="data" reader-name="seed" loader="main" location="data/@component-resource-name@TypeData.xml"/>
- <entity-resource type="data" reader-name="seed" loader="main" location="data/@component-resource-name@SecurityData.xml"/><!-- leave the type at seed because this will be used in hot-deploy where the required security files need to be loaded. -->
+ <entity-resource type="data" reader-name="seed" loader="main" location="data/@component-resource-name@SecurityData.xml"/>
<entity-resource type="data" reader-name="demo" loader="main" location="data/@component-resource-name@DemoData.xml"/>
<!-- service resources: model(s), eca(s) and group definitions -->
Modified: ofbiz/branches/20120329_portletWidget/framework/security/config/SecurityEntityLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/security/config/SecurityEntityLabels.xml?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/security/config/SecurityEntityLabels.xml (original)
+++ ofbiz/branches/20120329_portletWidget/framework/security/config/SecurityEntityLabels.xml Mon Jul 2 20:11:49 2012
@@ -1824,46 +1824,6 @@
<value xml:lang="zh">ä½¿ç¨æå¡ç»´æ¤é¡µé¢ã</value>
<value xml:lang="zh_TW">ä½¿ç¨æåç¶è·é é¢ã</value>
</property>
- <property key="SecurityPermission.description.SHIPRATE_ADMIN">
- <value xml:lang="en">ALL operations in the Shipping Rate Editor.</value>
- <value xml:lang="es">TODAS las operaciones en el Editor de Tasas de EnvÃo.</value>
- <value xml:lang="fr">TOUTES les opérations dans l'éditeur de taux d'expédition.</value>
- <value xml:lang="it">Tutte le operazioni nelle percentuali di spedizione.</value>
- <value xml:lang="ru">ÐÑе опеÑаÑии в РедакÑоÑе ÑейÑинга поÑÑавки.</value>
- <value xml:lang="th">à¸à¸²à¸£à¸à¸³à¸à¸²à¸à¸à¸±à¹à¸à¸«à¸¡à¸à¹à¸à¸à¸²à¸£à¹à¸à¹à¹à¸à¸à¸±à¸à¸£à¸²à¸à¸²à¸£à¸à¸à¸ªà¹à¸</value>
- <value xml:lang="zh">å¨éè´§è´¹çç¼è¾å¨ä¸çå
¨é¨æä½ã</value>
- <value xml:lang="zh_TW">å¨é貨費ç編輯å¨ä¸çå
¨é¨æä½ã</value>
- </property>
- <property key="SecurityPermission.description.SHIPRATE_CREATE">
- <value xml:lang="en">Create operations in the Shipping Rate Editor.</value>
- <value xml:lang="es">Operaciones de Creación en el Editor de Tasas de EnvÃo.</value>
- <value xml:lang="fr">Opérations de création dans l'éditeur de taux d'expédition.</value>
- <value xml:lang="it">Operazioni di creazione nelle percentuali di spedizione.</value>
- <value xml:lang="ru">ÐпеÑаÑии ÑÐ¾Ð·Ð´Ð°Ð½Ð¸Ñ Ð² РедакÑоÑе ÑейÑинга поÑÑавки.</value>
- <value xml:lang="th">สรà¹à¸²à¸à¸à¸²à¸£à¸à¸³à¸à¸²à¸à¹à¸à¸à¸²à¸£à¹à¸à¹à¹à¸à¸à¸±à¸à¸£à¸²à¸à¸²à¸£à¸à¸à¸ªà¹à¸</value>
- <value xml:lang="zh">å¨éè´§è´¹çç¼è¾å¨ä¸çå建æä½ã</value>
- <value xml:lang="zh_TW">å¨é貨費ç編輯å¨ä¸çåµå»ºæä½ã</value>
- </property>
- <property key="SecurityPermission.description.SHIPRATE_DELETE">
- <value xml:lang="en">Delete operations in the Shipping Rate Editor.</value>
- <value xml:lang="es">Operaciones de Eliminación en el Editor de Tasas de EnvÃo.</value>
- <value xml:lang="fr">Opérations de suppression dans l'éditeur de taux d'expédition.</value>
- <value xml:lang="it">Operazioni di cancellazione nelle percentuali di spedizione.</value>
- <value xml:lang="ru">ÐпеÑаÑии ÑÐ´Ð°Ð»ÐµÐ½Ð¸Ñ Ð² РедакÑоÑе ÑейÑинга поÑÑавки.</value>
- <value xml:lang="th">ลà¸à¸à¸²à¸£à¸à¸³à¸à¸²à¸à¹à¸à¸à¸²à¸£à¹à¸à¹à¹à¸à¸à¸±à¸à¸£à¸²à¸à¸²à¸£à¸à¸à¸ªà¹à¸</value>
- <value xml:lang="zh">å¨éè´§è´¹çç¼è¾å¨ä¸çå 餿ä½ã</value>
- <value xml:lang="zh_TW">å¨é貨費ç編輯å¨ä¸çåªé¤æä½ã</value>
- </property>
- <property key="SecurityPermission.description.SHIPRATE_VIEW">
- <value xml:lang="en">View operations in the Shipping Rate Editor.</value>
- <value xml:lang="es">Operaciones de Visualización en el Editor de Tasas de EnvÃo.</value>
- <value xml:lang="fr">Opérations de visualisation dans l'éditeur de taux d'expédition.</value>
- <value xml:lang="it">Operazioni di visualizzazione nelle percentuali di spedizione.</value>
- <value xml:lang="ru">ÐпеÑаÑии пÑоÑмоÑÑа в РедакÑоÑе ÑейÑинга поÑÑавки.</value>
- <value xml:lang="th">à¹à¸ªà¸à¸à¸à¸²à¸£à¸à¸³à¸à¸²à¸à¹à¸à¸à¸²à¸£à¹à¸à¹à¹à¸à¸à¸±à¸à¸£à¸²à¸à¸²à¸£à¸à¸à¸ªà¹à¸</value>
- <value xml:lang="zh">å¨éè´§è´¹çç¼è¾å¨ä¸çæµè§æä½ã</value>
- <value xml:lang="zh_TW">å¨é貨費ç編輯å¨ä¸çç覽æä½ã</value>
- </property>
<property key="SecurityPermission.description.TAXRATE_ADMIN">
<value xml:lang="en">ALL operations in the Tax Rate Editor.</value>
<value xml:lang="es">TODAS las Operaciones el Editor de Tasas Impositivas.</value>
Propchange: ofbiz/branches/20120329_portletWidget/framework/security/data/PasswordSecurityData.xml
------------------------------------------------------------------------------
Merged /ofbiz/trunk/framework/security/data/PasswordSecurityData.xml:r1347755-1351865
Modified: ofbiz/branches/20120329_portletWidget/framework/security/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/security/ofbiz-component.xml?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/security/ofbiz-component.xml (original)
+++ ofbiz/branches/20120329_portletWidget/framework/security/ofbiz-component.xml Mon Jul 2 20:11:49 2012
@@ -26,8 +26,8 @@ under the License.
<classpath type="dir" location="dtd"/>
<classpath type="jar" location="build/lib/*"/>
<entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>
- <entity-resource type="data" reader-name="seed" loader="main" location="data/SecurityPermissionSeedData.xml"/>
+ <entity-resource type="data" reader-name="seed" loader="main" location="data/SecurityData.xml"/>
<!-- NOTE: comment this line out to ensure no resetting of passwords -->
<entity-resource type="data" reader-name="demo" loader="main" location="data/PasswordSecurityData.xml"/>
- <entity-resource type="data" reader-name="demo" loader="main" location="data/SecurityGroupDemoData.xml"/>
+ <entity-resource type="data" reader-name="demo" loader="main" location="data/SecurityDemoData.xml"/>
</ofbiz-component>
Modified: ofbiz/branches/20120329_portletWidget/framework/service/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/service/ofbiz-component.xml?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/service/ofbiz-component.xml (original)
+++ ofbiz/branches/20120329_portletWidget/framework/service/ofbiz-component.xml Mon Jul 2 20:11:49 2012
@@ -31,8 +31,7 @@ under the License.
<entity-resource type="data" reader-name="seed" loader="main" location="data/ScheduledServiceData.xml"/>
<entity-resource type="data" reader-name="seed-initial" loader="main" location="data/ScheduledServices.xml"/>
<entity-resource type="data" reader-name="seed" loader="main" location="data/ServiceSeedData.xml"/>
- <entity-resource type="data" reader-name="seed" loader="main" location="data/ServiceSecurityPermissionSeedData.xml"/>
- <entity-resource type="data" reader-name="demo" loader="main" location="data/ServiceSecurityGroupDemoData.xml"/>
+ <entity-resource type="data" reader-name="seed" loader="main" location="data/ServiceSecurityData.xml"/>
<entity-resource type="data" reader-name="demo" loader="main" location="data/ServiceDemoData.xml"/>
<service-resource type="model" loader="main" location="servicedef/services.xml"/>
Modified: ofbiz/branches/20120329_portletWidget/framework/webapp/dtd/site-conf.xsd
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/webapp/dtd/site-conf.xsd?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/webapp/dtd/site-conf.xsd (original)
+++ ofbiz/branches/20120329_portletWidget/framework/webapp/dtd/site-conf.xsd Mon Jul 2 20:11:49 2012
@@ -442,7 +442,8 @@ under the License.
request,
request-redirect,
request-redirect-noparam,
- url
+ url,
+ cross-redirect
</xs:documentation>
</xs:annotation>
<xs:simpleType>
@@ -502,7 +503,7 @@ under the License.
<xs:annotation>
<xs:documentation>
Send a redirect down to the browser telling it to go to the new request.
- Automatically redirect all current request parameters to the new request.
+ Automatically redirect all current request parameters to the new request or only redirected parameters if specified.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
@@ -510,14 +511,21 @@ under the License.
<xs:annotation>
<xs:documentation>
Send a redirect down to the browser telling it to go to the new request.
- No current request parameters are sent to the new request.
+ No current request parameters are sent to the new request, nor redirected parameters if specified.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="url">
<xs:annotation>
<xs:documentation>
- Any URL, relative or absolute
+ Any URL, relative or absolute. Redirected parameters are not used, you can put them in the url.
+ </xs:documentation>
+ </xs:annotation>
+ </xs:enumeration>
+ <xs:enumeration value="cross-redirect">
+ <xs:annotation>
+ <xs:documentation>
+ Works like URL but you can also pass redirected parameters.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
Modified: ofbiz/branches/20120329_portletWidget/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java (original)
+++ ofbiz/branches/20120329_portletWidget/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java Mon Jul 2 20:11:49 2012
@@ -39,16 +39,18 @@ import javolution.util.FastList;
import javolution.util.FastMap;
import org.ofbiz.base.component.ComponentConfig;
+import org.ofbiz.base.container.ContainerConfig;
+import org.ofbiz.base.container.ContainerException;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralException;
import org.ofbiz.base.util.KeyStoreUtil;
import org.ofbiz.base.util.StringUtil;
-import org.ofbiz.base.util.StringUtil.StringWrapper;
import org.ofbiz.base.util.UtilFormatOut;
import org.ofbiz.base.util.UtilHttp;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.StringUtil.StringWrapper;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.DelegatorFactory;
import org.ofbiz.entity.GenericEntityException;
@@ -445,7 +447,7 @@ public class LoginWorker {
if (setupNewDelegatorEtc) {
// now set the delegator and dispatcher in a bunch of places just in case they were changed
- setWebContextObjects(request, response, delegator, dispatcher);
+ setWebContextObjects(request, response, delegator, dispatcher, true);
}
// check to see if a password change is required for the user
@@ -475,28 +477,47 @@ public class LoginWorker {
}
}
- private static void setWebContextObjects(HttpServletRequest request, HttpServletResponse response, Delegator delegator, LocalDispatcher dispatcher) {
+ /* persistSerialized is set at false in the context of a cluster when using (at least) DeltaManager.
+ Because we have no easy ways to set DeltaManager.pathname to null from OFBiz
+ So persistSerialized is set to true when login out. This prevent a NPE due to non serialized objects put in session*/
+ private static void setWebContextObjects(HttpServletRequest request, HttpServletResponse response, Delegator delegator, LocalDispatcher dispatcher, Boolean persistSerialized) {
HttpSession session = request.getSession();
- // NOTE: we do NOT want to set this in the servletContext, only in the request and session
- // We also need to setup the security and authz objects since they are dependent on the delegator
- Security security = null;
- try {
- security = SecurityFactory.getInstance(delegator);
- } catch (SecurityConfigurationException e) {
- Debug.logError(e, module);
- }
- Authorization authz = null;
- try {
- authz = AuthorizationFactory.getInstance(delegator);
- } catch (SecurityConfigurationException e) {
- Debug.logError(e, module);
- }
+ // NOTE: we do NOT want to set this in the servletContet, only in the request and session
session.setAttribute("delegatorName", delegator.getDelegatorName());
+
request.setAttribute("delegator", delegator);
+ if (!persistSerialized) {
+ session.setAttribute("delegator", null);
+ } else {
+ session.setAttribute("delegator", delegator);
+ }
+
request.setAttribute("dispatcher", dispatcher);
- request.setAttribute("security", security);
- request.setAttribute("authz", authz);
+ if (!persistSerialized) {
+ session.setAttribute("dispatcher", null);
+ } else {
+ session.setAttribute("dispatcher", dispatcher);
+ }
+
+ if (persistSerialized) {
+ // we also need to setup the security and authz objects since they are dependent on the delegator
+ try {
+ Security security = SecurityFactory.getInstance(delegator);
+ request.setAttribute("security", security);
+ session.setAttribute("security", security);
+ } catch (SecurityConfigurationException e) {
+ Debug.logError(e, module);
+ }
+
+ try {
+ Authorization authz = AuthorizationFactory.getInstance(delegator);
+ request.setAttribute("authz", authz);
+ session.setAttribute("authz", authz);
+ } catch (SecurityConfigurationException e) {
+ Debug.logError(e, module);
+ }
+ }
// get rid of the visit info since it was pointing to the previous database, and get a new one
session.removeAttribute("visitor");
@@ -631,7 +652,22 @@ public class LoginWorker {
delegator = DelegatorFactory.getDelegator(delegatorName);
LocalDispatcher dispatcher = ContextFilter.makeWebappDispatcher(session.getServletContext(), delegator);
- setWebContextObjects(request, response, delegator, dispatcher);
+ // get the container configuration
+ String ofbizHome = System.getProperty("ofbiz.home");
+ String configFile = ofbizHome + "/framework/base/config/ofbiz-containers.xml";
+ ContainerConfig.Container cc = null;
+ String mgrClassName = null;
+ try {
+ cc = ContainerConfig.getContainer("catalina-container", configFile);
+ mgrClassName = ContainerConfig.getPropertyValue(cc, "manager-class", "");
+ } catch (ContainerException e) {
+ Debug.logError(e, "No catalina-container configuration found in container config!");
+ }
+ if ("org.apache.catalina.ha.session.DeltaManager".equals(mgrClassName)) {
+ setWebContextObjects(request, response, delegator, dispatcher, false);
+ } else {
+ setWebContextObjects(request, response, delegator, dispatcher, true);
+ }
}
// DON'T save the cart, causes too many problems: if (shoppingCart != null) session.setAttribute("shoppingCart", new WebShoppingCart(shoppingCart, session));
@@ -945,7 +981,7 @@ public class LoginWorker {
if (!oldDelegatorName.equals(userLogin.getDelegator().getDelegatorName())) {
delegator = DelegatorFactory.getDelegator(userLogin.getDelegator().getDelegatorName());
dispatcher = ContextFilter.makeWebappDispatcher(servletContext, delegator);
- setWebContextObjects(request, response, delegator, dispatcher);
+ setWebContextObjects(request, response, delegator, dispatcher, true);
}
// found userLogin, do the external login...
Modified: ofbiz/branches/20120329_portletWidget/framework/webtools/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/webtools/ofbiz-component.xml?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/framework/webtools/ofbiz-component.xml (original)
+++ ofbiz/branches/20120329_portletWidget/framework/webtools/ofbiz-component.xml Mon Jul 2 20:11:49 2012
@@ -24,8 +24,7 @@ under the License.
<resource-loader name="main" type="component"/>
<classpath type="jar" location="build/lib/*"/>
<classpath type="dir" location="config"/>
- <entity-resource type="data" reader-name="seed" loader="main" location="data/WebtoolsSecurityPermissionSeedData.xml"/>
- <entity-resource type="data" reader-name="demo" loader="main" location="data/WebtoolsSecurityGroupDemoData.xml"/>
+ <entity-resource type="data" reader-name="seed" loader="main" location="data/WebtoolsSecurityData.xml"/>
<service-resource type="model" loader="main" location="servicedef/services.xml"/>
<webapp name="webtools"
title="WebTools"
Modified: ofbiz/branches/20120329_portletWidget/specialpurpose/assetmaint/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/specialpurpose/assetmaint/ofbiz-component.xml?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/specialpurpose/assetmaint/ofbiz-component.xml (original)
+++ ofbiz/branches/20120329_portletWidget/specialpurpose/assetmaint/ofbiz-component.xml Mon Jul 2 20:11:49 2012
@@ -32,8 +32,7 @@
<!-- entity resources: model(s), eca(s), group, and data definitions -->
<entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>
- <entity-resource type="data" reader-name="seed" loader="main" location="data/AssetMaintSecurityPermissionSeedData.xml"/>
- <entity-resource type="data" reader-name="demo" loader="main" location="data/AssetMaintSecurityGroupDemoData.xml"/>
+ <entity-resource type="data" reader-name="seed" loader="main" location="data/AssetMaintSecurityData.xml"/>
<entity-resource type="data" reader-name="seed" loader="main" location="data/AssetMaintSeedData.xml"/>
<entity-resource type="data" reader-name="demo" loader="main" location="data/DemoAssetMaintData.xml"/>
Modified: ofbiz/branches/20120329_portletWidget/specialpurpose/ebay/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/specialpurpose/ebay/ofbiz-component.xml?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/specialpurpose/ebay/ofbiz-component.xml (original)
+++ ofbiz/branches/20120329_portletWidget/specialpurpose/ebay/ofbiz-component.xml Mon Jul 2 20:11:49 2012
@@ -26,8 +26,7 @@ under the License.
<classpath type="jar" location="build/lib/*"/>
<entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>
- <entity-resource type="data" reader-name="seed" loader="main" location="data/EbaySecurityPermissionSeedData.xml"/>
- <entity-resource type="data" reader-name="demo" loader="main" location="data/EbaySecurityGroupDemoData.xml"/>
+ <entity-resource type="data" reader-name="seed" loader="main" location="data/EbaySecurityData.xml"/>
<entity-resource type="data" reader-name="seed" loader="main" location="data/EbayTypeData.xml"/>
<entity-resource type="data" reader-name="seed" loader="main" location="data/EbayHelpData.xml"/>
<entity-resource type="data" reader-name="demo" loader="main" location="data/DemoEbayData.xml"/>
Propchange: ofbiz/branches/20120329_portletWidget/specialpurpose/ebaystore/lib/
------------------------------------------------------------------------------
Merged /ofbiz/trunk/specialpurpose/ebaystore/lib:r1347755-1351865
Modified: ofbiz/branches/20120329_portletWidget/specialpurpose/ebaystore/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/specialpurpose/ebaystore/ofbiz-component.xml?rev=1356450&r1=1356449&r2=1356450&view=diff
==============================================================================
--- ofbiz/branches/20120329_portletWidget/specialpurpose/ebaystore/ofbiz-component.xml (original)
+++ ofbiz/branches/20120329_portletWidget/specialpurpose/ebaystore/ofbiz-component.xml Mon Jul 2 20:11:49 2012
@@ -28,8 +28,7 @@ under the License.
<entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>
- <entity-resource type="data" reader-name="seed" loader="main" location="data/EbayStoreSecurityPermissionSeedData.xml"/>
- <entity-resource type="data" reader-name="demo" loader="main" location="data/EbayStoreSecurityGroupDemoData.xml"/>
+ <entity-resource type="data" reader-name="seed" loader="main" location="data/EbayStoreSecurityData.xml"/>
<entity-resource type="data" reader-name="seed" loader="main" location="data/EbayStoreTypeData.xml"/>
<entity-resource type="data" reader-name="seed" loader="main" location="data/EbayStoreHelpData.xml"/>
<entity-resource type="data" reader-name="seed" loader="main" location="data/EbayStorePortletData.xml"/>