📄 currentvalprep.bsh
字号:
/* * $Id: currentvalprep.bsh 5462 2005-08-05 18:35:48Z jonesde $ * * Copyright (c) 2003 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. * *//** * * @author <a href="mailto:byersa@automationgroups.com">Al Byers</a> * @version $Rev: 5462 $ * @since 3.0 * A commonly called script to find the "current" entity (either Content or DataResource * usually) from either a cached key or overridden by current values in the parameter map * or request attributes. */import org.ofbiz.base.util.*;import org.ofbiz.entity.*;import org.ofbiz.security.*;import org.ofbiz.service.*;import org.ofbiz.entity.model.*;import org.ofbiz.widget.html.*;import org.ofbiz.widget.form.*;import org.ofbiz.content.ContentManagementWorker;import javax.servlet.*;import javax.servlet.http.*;String module = "currentvalprep.bsh";LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");currentEntityMap = session.getAttribute("currentEntityMap");if (currentEntityMap == null) { currentEntityMap = new HashMap(); session.setAttribute("currentEntityMap", currentEntityMap);}entityName = page.getProperty("entityName");currentEntityPropertyName = page.getProperty("currentEntityPropertyName");if (currentEntityPropertyName == null) { currentEntityName = entityName;} else { currentEntityName = page.getProperty(currentEntityPropertyName);}if (Debug.verboseOn()) Debug.logVerbose("in currentvalprep, currentEntityName:" + currentEntityName,module);cachedPK = currentEntityMap.get(currentEntityName);if (Debug.verboseOn()) Debug.logVerbose("in currentvalprep, cachedPK:" + cachedPK,module);// Build a key from param or attribute values.Map paramMap = UtilHttp.getParameterMap(request);if (Debug.verboseOn()) Debug.logVerbose("paramMap:" + paramMap, null);GenericValue v = delegator.makeValue(currentEntityName, null);passedPK = v.getPrimaryKey();keyColl = passedPK.getAllKeys();keyIt = keyColl.iterator();while (keyIt.hasNext()) { attrName = (String)keyIt.next(); attrVal = request.getAttribute(attrName); if (attrVal == null) { attrVal = paramMap.get(attrName); }if (Debug.verboseOn()) Debug.logVerbose("in currentvalprep, attrName:" + attrName,module);if (Debug.verboseOn()) Debug.logVerbose("in currentvalprep, attrVal:" + attrVal,module); if (attrVal != null && attrVal != void) { passedPK.put(attrName,attrVal); }}if (Debug.verboseOn()) Debug.logVerbose("in currentvalprep, passedPK:" + passedPK,module);// messed up code to determine whether or not the cached or passed keys have missing fields,// in which case, the valid one is used to retrieve the current valueboolean pksEqual = true;if(cachedPK != null ) { keyColl = cachedPK.getPrimaryKey().getAllKeys(); keyIt = keyColl.iterator(); while(keyIt.hasNext()) { String sCached = null; String sPassed = null; Object oCached = null; Object oCached = null; String ky = (String)keyIt.next(); oPassed = passedPK.get(ky); if(oPassed != null) { sPassed = oPassed.toString(); if(sPassed == null || sPassed.length() == 0){ pksEqual = false; } else { oCached = cachedPK.get(ky); if(oCached != null) { sCached = oCached.toString(); if(sPassed == null || sPassed.length() == 0){ pksEqual = false; } else { if(!sPassed.equals(sCached)) { //pksEqual = true; } } } } } else { pksEqual = false; } }} currentPK = passedPK;if(!pksEqual) { currentPK = cachedPK; // all other condition result in currentPK = passedPK}if (Debug.verboseOn()) Debug.logVerbose("in currentvalprep, currentPK:" + currentPK,module);currentEntityMap.put(currentEntityName, currentPK);request.setAttribute("currentPK", currentPK);context.put("currentPK", currentPK);currentValue = delegator.findByPrimaryKey(currentPK.getPrimaryKey()); context.put("currentValue", currentValue);request.setAttribute("currentValue", currentValue);if (Debug.verboseOn()) Debug.logVerbose("in currentvalprep, currentValue:" + request.getAttribute("currentValue"),module);if (currentValue != null) { if (currentEntityName.indexOf("DataResource") >=0) { String suffix = ""; String s= null; try { s = (String)currentValue.get("dataResourceTypeId"); if (UtilValidate.isNotEmpty(s)) { suffix = "_" + s; } } catch(IllegalArgumentException e) { // ignore } try { if (UtilValidate.isEmpty(suffix)) { s = (String)currentValue.get("drDataResourceTypeId"); if (UtilValidate.isNotEmpty(s)) { suffix += "_" + s; } } } catch(IllegalArgumentException e) { // ignore } if (UtilValidate.isNotEmpty(suffix) && suffix.equals("_ELECTRONIC_TEXT")) { try { s = (String)currentValue.get("mimeTypeId"); if (UtilValidate.isNotEmpty(s)) { suffix += "_" + s; } } catch(IllegalArgumentException e) { // ignore } try { if (UtilValidate.isEmpty(s)) { s = (String)currentValue.get("drMimeTypeId"); if (UtilValidate.isNotEmpty(s)) { suffix += "_" + s; } } } catch(IllegalArgumentException e) { // ignore } }if (Debug.verboseOn()) Debug.logVerbose("in currentvalprep, suffix:" + suffix,module); ContentManagementWorker.mruAdd(session, (GenericEntity)currentPK); } else { ContentManagementWorker.mruAdd(session, (GenericEntity)currentPK); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -