⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modelmenuaction.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: ModelMenuAction.java 5462 2005-08-05 18:35:48Z jonesde $ * * Copyright (c) 2004 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.menu;import java.text.MessageFormat;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Locale;import java.util.Map;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.UtilFormatOut;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.string.FlexibleStringExpander;import org.ofbiz.entity.finder.ByAndFinder;import org.ofbiz.entity.finder.ByConditionFinder;import org.ofbiz.entity.finder.PrimaryKeyFinder;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.ModelService;import org.w3c.dom.Element;import javax.servlet.*;import javax.servlet.http.*;/** * Widget Library - Screen model class * * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @version    $Rev: 5462 $ * @since      3.1 */public abstract class ModelMenuAction {    public static final String module = ModelMenuAction.class.getName();    protected ModelMenu modelMenu;    protected ModelMenuItem modelMenuItem;    public ModelMenuAction(ModelMenu modelMenu, Element actionElement) {        this.modelMenu = modelMenu;        if (Debug.verboseOn()) Debug.logVerbose("Reading Screen action with name: " + actionElement.getNodeName(), module);    }        public ModelMenuAction(ModelMenuItem modelMenuItem, Element actionElement) {        this.modelMenuItem = modelMenuItem;        this.modelMenu = modelMenuItem.getModelMenu();        if (Debug.verboseOn()) Debug.logVerbose("Reading Screen action with name: " + actionElement.getNodeName(), module);    }        public abstract void runAction(Map context);        public static List readSubActions(ModelMenuItem modelMenuItem, Element parentElement) {        return readSubActions(modelMenuItem.getModelMenu(), parentElement);    }        public static List readSubActions(ModelMenu modelMenu, Element parentElement) {        List actions = new LinkedList();                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(modelMenu, actionElement));            } else if ("property-map".equals(actionElement.getNodeName())) {                actions.add(new PropertyMap(modelMenu, actionElement));            } else if ("property-to-field".equals(actionElement.getNodeName())) {                actions.add(new PropertyToField(modelMenu, actionElement));            } else if ("script".equals(actionElement.getNodeName())) {                actions.add(new Script(modelMenu, actionElement));            } else if ("service".equals(actionElement.getNodeName())) {                actions.add(new Service(modelMenu, actionElement));            } else if ("entity-one".equals(actionElement.getNodeName())) {                actions.add(new EntityOne(modelMenu, actionElement));            } else if ("entity-and".equals(actionElement.getNodeName())) {                actions.add(new EntityAnd(modelMenu, actionElement));            } else if ("entity-condition".equals(actionElement.getNodeName())) {                actions.add(new EntityCondition(modelMenu, actionElement));            } else {                throw new IllegalArgumentException("Action element not supported with name: " + actionElement.getNodeName());            }        }                return actions;    }        public static void runSubActions(List actions, Map context) {        if (actions == null) return;                Iterator actionIter = actions.iterator();        while (actionIter.hasNext()) {            ModelMenuAction action = (ModelMenuAction) actionIter.next();            if (Debug.verboseOn()) Debug.logVerbose("Running screen action " + action.getClass().getName(), module);            action.runAction(context);        }    }        public static class SetField extends ModelMenuAction {        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(ModelMenu modelMenu, Element setElement) {            super (modelMenu, setElement);            this.field = new FlexibleMapAccessor(setElement.getAttribute("field"));            this.fromField = UtilValidate.isNotEmpty(setElement.getAttribute("from-field")) ? new FlexibleMapAccessor(setElement.getAttribute("from-field")) : null;            this.valueExdr = UtilValidate.isNotEmpty(setElement.getAttribute("value")) ? new FlexibleStringExpander(setElement.getAttribute("value")) : null;            this.defaultExdr = UtilValidate.isNotEmpty(setElement.getAttribute("default-value")) ? new FlexibleStringExpander(setElement.getAttribute("default-value")) : null;            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 != null && this.valueExdr != null) {                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 != null) {                    String originalName = this.fromField.getOriginalName();                    String currentWidgetTrail = (String)context.get("_WIDGETTRAIL_");                    String newKey = currentWidgetTrail + "|" + originalName;                    HttpSession session = (HttpSession)context.get("session");                    newValue = session.getAttribute(newKey);                    if (Debug.verboseOn()) Debug.logVerbose("In user getting value for field from [" + this.fromField.getOriginalName() + "]: " + newValue, module);                } else if (this.valueExdr != null) {                    newValue = this.valueExdr.expandString(context);                }                            } else if (this.fromScope != null && this.fromScope.equals("application")) {                if (this.fromField != null) {                    String originalName = this.fromField.getOriginalName();                    String currentWidgetTrail = (String)context.get("_WIDGETTRAIL_");                    String newKey = currentWidgetTrail + "|" + originalName;                    ServletContext servletContext = (ServletContext)context.get("application");                    newValue = servletContext.getAttribute(newKey);                    if (Debug.verboseOn()) Debug.logVerbose("In application getting value for field from [" + this.fromField.getOriginalName() + "]: " + newValue, module);                } else if (this.valueExdr != null) {                    newValue = this.valueExdr.expandString(context);                }                            } else {                if (this.fromField != null) {                    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 != null) {                    newValue = this.valueExdr.expandString(context);                }            }            // If newValue is still empty, use the default value           	if (this.defaultExdr != null) {           		if (ObjectType.isEmpty(newValue)) {            		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();                    String currentWidgetTrail = (String)context.get("_WIDGETTRAIL_");                    String newKey = currentWidgetTrail + "|" + originalName;                    HttpSession session = (HttpSession)context.get("session");                    session.setAttribute(newKey, newValue);                    if (Debug.verboseOn()) Debug.logVerbose("In user setting value for field from [" + this.field.getOriginalName() + "]: " + newValue, module);                            } else if (this.toScope != null && this.toScope.equals("application")) {                    String originalName = this.field.getOriginalName();                    String currentWidgetTrail = (String)context.get("_WIDGETTRAIL_");                    String newKey = currentWidgetTrail + "|" + originalName;                    ServletContext servletContext = (ServletContext)context.get("application");                    servletContext.setAttribute(newKey, newValue);                    if (Debug.verboseOn()) Debug.logVerbose("In application setting value for field from [" + this.field.getOriginalName() + "]: " + newValue, module);                            } else {            	if (Debug.verboseOn()) Debug.logVerbose("In screen setting field [" + this.field.getOriginalName() + "] to value: " + newValue, module);                this.field.put(context, newValue);            }                        if (global) {                Map globalCtx = (Map) context.get("globalContext");                if (globalCtx != null) {                    this.field.put(globalCtx, newValue);                }            }                        // this is a hack for backward compatibility with the JPublish page object            Map page = (Map) context.get("page");            if (page != null) {                this.field.put(page, newValue);            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -