You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by sa...@apache.org on 2012/06/17 11:21:30 UTC
svn commit: r1351078 [4/4] - in /ofbiz/branches/jackrabbit20120501: ./
applications/accounting/script/org/ofbiz/accounting/rate/
applications/accounting/webapp/accounting/WEB-INF/
applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ appli...
Modified: ofbiz/branches/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/otherops/PropertyToField.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/otherops/PropertyToField.java?rev=1351078&r1=1351077&r2=1351078&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/otherops/PropertyToField.java (original)
+++ ofbiz/branches/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/otherops/PropertyToField.java Sun Jun 17 09:21:27 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/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/otherops/Trace.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/otherops/Trace.java?rev=1351078&r1=1351077&r2=1351078&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/otherops/Trace.java (original)
+++ ofbiz/branches/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/otherops/Trace.java Sun Jun 17 09:21:27 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/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/serviceops/FieldToResult.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/serviceops/FieldToResult.java?rev=1351078&r1=1351077&r2=1351078&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/serviceops/FieldToResult.java (original)
+++ ofbiz/branches/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/serviceops/FieldToResult.java Sun Jun 17 09:21:27 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/jackrabbit20120501/framework/security/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/security/ofbiz-component.xml?rev=1351078&r1=1351077&r2=1351078&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20120501/framework/security/ofbiz-component.xml (original)
+++ ofbiz/branches/jackrabbit20120501/framework/security/ofbiz-component.xml Sun Jun 17 09:21:27 2012
@@ -26,7 +26,7 @@ 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="security" loader="main" location="data/SecurityData.xml"/>
+ <entity-resource type="data" reader-name="seed" loader="main" location="data/SecuritySeedData.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/SecurityDemoData.xml"/>
Modified: ofbiz/branches/jackrabbit20120501/framework/service/data/ServiceSeedData.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/service/data/ServiceSeedData.xml?rev=1351078&r1=1351077&r2=1351078&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20120501/framework/service/data/ServiceSeedData.xml (original)
+++ ofbiz/branches/jackrabbit20120501/framework/service/data/ServiceSeedData.xml Sun Jun 17 09:21:27 2012
@@ -19,6 +19,11 @@ under the License.
-->
<entity-engine-xml>
+ <!-- Remote Service security -->
+ <SecurityPermission description="Permission to invoke any service remotely." permissionId="SERVICE_INVOKE_ANY"/>
+ <SecurityGroupPermission groupId="FULLADMIN" permissionId="SERVICE_INVOKE_ANY"/>
+ <SecurityGroupPermission groupId="FLEXADMIN" permissionId="SERVICE_INVOKE_ANY"/>
+
<!-- Temporal Expression seed data -->
<!-- Pre-define all 60 minutes -->
Modified: ofbiz/branches/jackrabbit20120501/framework/service/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/service/ofbiz-component.xml?rev=1351078&r1=1351077&r2=1351078&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20120501/framework/service/ofbiz-component.xml (original)
+++ ofbiz/branches/jackrabbit20120501/framework/service/ofbiz-component.xml Sun Jun 17 09:21:27 2012
@@ -31,7 +31,6 @@ 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="security" 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"/>