📄 modelscreenaction.java
字号:
/* * $Id: ModelScreenAction.java 6082 2005-11-06 06:32:16Z jonesde $ * * Copyright (c) 2004-2005 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. */package org.ofbiz.widget.screen;import java.io.Serializable;import java.text.MessageFormat;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.Locale;import java.util.Map;import java.util.regex.PatternSyntaxException;import javax.servlet.ServletContext;import javax.servlet.http.HttpSession;import javolution.util.FastList;import javolution.util.FastMap;import org.ofbiz.base.util.BshUtil;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.GeneralException;import org.ofbiz.base.util.ObjectType;import org.ofbiz.base.util.StringUtil;import org.ofbiz.base.util.UtilProperties;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.UtilXml;import org.ofbiz.base.util.collections.FlexibleMapAccessor;import org.ofbiz.base.util.collections.ResourceBundleMapWrapper;import org.ofbiz.base.util.string.FlexibleStringExpander;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.finder.ByAndFinder;import org.ofbiz.entity.finder.ByConditionFinder;import org.ofbiz.entity.finder.EntityFinderUtil;import org.ofbiz.entity.finder.PrimaryKeyFinder;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.ModelService;import org.w3c.dom.Element;/** * Widget Library - Screen model class * * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @version $Rev: 6082 $ * @since 3.1 */public abstract class ModelScreenAction implements Serializable { public static final String module = ModelScreenAction.class.getName(); protected ModelScreen modelScreen; public ModelScreenAction(ModelScreen modelScreen, Element actionElement) { this.modelScreen = modelScreen; if (Debug.verboseOn()) Debug.logVerbose("Reading Screen action with name: " + actionElement.getNodeName(), module); } public abstract void runAction(Map context) throws GeneralException; public static List readSubActions(ModelScreen modelScreen, Element parentElement) { List actions = FastList.newInstance(); List actionElementList = UtilXml.childElementList(parentElement); Iterator actionElementIter = actionElementList.iterator(); while (actionElementIter.hasNext()) { Element actionElement = (Element) actionElementIter.next(); if ("set".equals(actionElement.getNodeName())) { actions.add(new SetField(modelScreen, actionElement)); } else if ("property-map".equals(actionElement.getNodeName())) { actions.add(new PropertyMap(modelScreen, actionElement)); } else if ("property-to-field".equals(actionElement.getNodeName())) { actions.add(new PropertyToField(modelScreen, actionElement)); } else if ("script".equals(actionElement.getNodeName())) { actions.add(new Script(modelScreen, actionElement)); } else if ("service".equals(actionElement.getNodeName())) { actions.add(new Service(modelScreen, actionElement)); } else if ("entity-one".equals(actionElement.getNodeName())) { actions.add(new EntityOne(modelScreen, actionElement)); } else if ("entity-and".equals(actionElement.getNodeName())) { actions.add(new EntityAnd(modelScreen, actionElement)); } else if ("entity-condition".equals(actionElement.getNodeName())) { actions.add(new EntityCondition(modelScreen, actionElement)); } else if ("get-related-one".equals(actionElement.getNodeName())) { actions.add(new GetRelatedOne(modelScreen, actionElement)); } else if ("get-related".equals(actionElement.getNodeName())) { actions.add(new GetRelated(modelScreen, actionElement)); } else { throw new IllegalArgumentException("Action element not supported with name: " + actionElement.getNodeName()); } } return actions; } public static void runSubActions(List actions, Map context) throws GeneralException { if (actions == null) return; Iterator actionIter = actions.iterator(); while (actionIter.hasNext()) { ModelScreenAction action = (ModelScreenAction) actionIter.next(); if (Debug.verboseOn()) Debug.logVerbose("Running screen action " + action.getClass().getName(), module); action.runAction(context); } } public static class SetField extends ModelScreenAction { protected FlexibleMapAccessor field; protected FlexibleMapAccessor fromField; protected FlexibleStringExpander valueExdr; protected FlexibleStringExpander defaultExdr; protected FlexibleStringExpander globalExdr; protected String type; protected String toScope; protected String fromScope; public SetField(ModelScreen modelScreen, Element setElement) { super (modelScreen, setElement); this.field = new FlexibleMapAccessor(setElement.getAttribute("field")); this.fromField = new FlexibleMapAccessor(setElement.getAttribute("from-field")); this.valueExdr = new FlexibleStringExpander(setElement.getAttribute("value")); this.defaultExdr = new FlexibleStringExpander(setElement.getAttribute("default-value")); this.globalExdr = new FlexibleStringExpander(setElement.getAttribute("global")); this.type = setElement.getAttribute("type"); this.toScope = setElement.getAttribute("to-scope"); this.fromScope = setElement.getAttribute("from-scope"); if (!this.fromField.isEmpty() && !this.valueExdr.isEmpty()) { throw new IllegalArgumentException("Cannot specify a from-field [" + setElement.getAttribute("from-field") + "] and a value [" + setElement.getAttribute("value") + "] on the set action in a screen widget"); } } public void runAction(Map context) { String globalStr = this.globalExdr.expandString(context); // default to false boolean global = "true".equals(globalStr); Object newValue = null; if (this.fromScope != null && this.fromScope.equals("user")) { if (!this.fromField.isEmpty()) { HttpSession session = (HttpSession) context.get("session"); newValue = getInMemoryPersistedFromField(session, context); if (Debug.verboseOn()) Debug.logVerbose("In user getting value for field from [" + this.fromField.getOriginalName() + "]: " + newValue, module); } else if (!this.valueExdr.isEmpty()) { newValue = this.valueExdr.expandString(context); } } else if (this.fromScope != null && this.fromScope.equals("application")) { if (!this.fromField.isEmpty()) { ServletContext servletContext = (ServletContext) context.get("application"); newValue = getInMemoryPersistedFromField(servletContext, context); if (Debug.verboseOn()) Debug.logVerbose("In application getting value for field from [" + this.fromField.getOriginalName() + "]: " + newValue, module); } else if (!this.valueExdr.isEmpty()) { newValue = this.valueExdr.expandString(context); } } else { if (!this.fromField.isEmpty()) { newValue = this.fromField.get(context); if (Debug.verboseOn()) Debug.logVerbose("In screen getting value for field from [" + this.fromField.getOriginalName() + "]: " + newValue, module); } else if (!this.valueExdr.isEmpty()) { newValue = this.valueExdr.expandString(context); } } // If newValue is still empty, use the default value if (ObjectType.isEmpty(newValue) && !this.defaultExdr.isEmpty()) { newValue = this.defaultExdr.expandString(context); } if (UtilValidate.isNotEmpty(this.type)) { try { newValue = ObjectType.simpleTypeConvert(newValue, this.type, null, null); } catch (GeneralException e) { String errMsg = "Could not convert field value for the field: [" + this.field.getOriginalName() + "] to the [" + this.type + "] type for the value [" + newValue + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new IllegalArgumentException(errMsg); } } if (this.toScope != null && this.toScope.equals("user")) { String originalName = this.field.getOriginalName(); List currentWidgetTrail = (List)context.get("_WIDGETTRAIL_"); String newKey = ""; if (currentWidgetTrail != null) { newKey = StringUtil.join(currentWidgetTrail, "|"); } if (UtilValidate.isNotEmpty(newKey)) { newKey += "|"; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -