|
Modified: ofbiz/branches/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/eventops/SessionToField.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/eventops/SessionToField.java?rev=1349976&r1=1349975&r2=1349976&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/eventops/SessionToField.java (original) +++ ofbiz/branches/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/eventops/SessionToField.java Wed Jun 13 18:01:08 2012 @@ -18,91 +18,89 @@ *******************************************************************************/ 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(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @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 + "\"/>"; + return toString(); + } + + @Override + 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/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/eventops/WebappPropertyToField.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/eventops/WebappPropertyToField.java?rev=1349976&r1=1349975&r2=1349976&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/eventops/WebappPropertyToField.java (original) +++ ofbiz/branches/jackrabbit20120501/framework/minilang/src/org/ofbiz/minilang/method/eventops/WebappPropertyToField.java Wed Jun 13 18:01:08 2012 @@ -19,103 +19,101 @@ 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(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override public String rawString() { - // TODO: add all attributes and other info - return "<webapp-property-to-field field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>"; + return toString(); + } + + @Override + 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/jackrabbit20120501/framework/webapp/dtd/site-conf.xsd URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/framework/webapp/dtd/site-conf.xsd?rev=1349976&r1=1349975&r2=1349976&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/framework/webapp/dtd/site-conf.xsd (original) +++ ofbiz/branches/jackrabbit20120501/framework/webapp/dtd/site-conf.xsd Wed Jun 13 18:01:08 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/jackrabbit20120501/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/web.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/web.xml?rev=1349976&r1=1349975&r2=1349976&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/web.xml (original) +++ ofbiz/branches/jackrabbit20120501/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/web.xml Wed Jun 13 18:01:08 2012 @@ -100,11 +100,6 @@ under the License. <url-pattern>/*</url-pattern> </filter-mapping> - <error-page> - <error-code>404</error-code> - <location>/error/404.jsp</location> - </error-page> - <listener><listener-class>org.ofbiz.webapp.control.ControlEventListener</listener-class></listener> <!-- NOTE: not all app servers support mounting implementations of the HttpSessionActivationListener interface --> <!-- <listener><listener-class>org.ofbiz.webapp.control.ControlActivationEventListener</listener-class></listener> --> @@ -162,4 +157,9 @@ under the License. <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> </welcome-file-list> + + <error-page> + <error-code>404</error-code> + <location>/error/404.jsp</location> + </error-page> </web-app> Modified: ofbiz/branches/jackrabbit20120501/specialpurpose/webpos/ofbiz-component.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20120501/specialpurpose/webpos/ofbiz-component.xml?rev=1349976&r1=1349975&r2=1349976&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20120501/specialpurpose/webpos/ofbiz-component.xml (original) +++ ofbiz/branches/jackrabbit20120501/specialpurpose/webpos/ofbiz-component.xml Wed Jun 13 18:01:08 2012 @@ -26,7 +26,7 @@ under the License. <classpath type="jar" location="build/lib/*"/> <entity-resource type="data" reader-name="demo" loader="main" location="data/DemoPosData.xml"/> - <entity-resource type="data" reader-name="demo" loader="main" location="data/WebPosSecurityData.xml"/> + <entity-resource type="data" reader-name="security" loader="main" location="data/WebPosSecurityData.xml"/> <service-resource type="model" loader="main" location="servicedef/services.xml"/> <service-resource type="model" loader="main" location="servicedef/services_cart.xml"/> |
| Free forum by Nabble | Edit this page |
