📄 contentmanagementworker.java
字号:
/* * $Id: ContentManagementWorker.java 5462 2005-08-05 18:35:48Z 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.content;import java.sql.Timestamp;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpSession;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.GeneralException;import org.ofbiz.base.util.StringUtil;import org.ofbiz.base.util.UtilHttp;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.collections.LifoSet;import org.ofbiz.content.content.ContentServicesComplex;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntity;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericPK;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.condition.EntityCondition;import org.ofbiz.entity.condition.EntityConditionList;import org.ofbiz.entity.condition.EntityExpr;import org.ofbiz.entity.condition.EntityOperator;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.entityext.permission.EntityPermissionChecker;import org.ofbiz.minilang.MiniLangException;import org.ofbiz.security.Security;/** * ContentManagementWorker Class * * @author <a href="mailto:byersa@automationgroups.com">Al Byers</a> * @version $Rev: 5462 $ * @since 3.0 */public class ContentManagementWorker { public static final String module = ContentManagementWorker.class.getName(); public static Map cachedWebSitePublishPoints = new HashMap(); public static Map cachedStaticValues = new HashMap(); public static void mruAdd(HttpServletRequest request, GenericEntity pk, String suffix ) { HttpSession session = request.getSession(); mruAdd(session, pk); } public static void mruAdd(HttpServletRequest request, GenericEntity pk ) { HttpSession session = request.getSession(); mruAdd(session, pk); } public static void mruAdd(HttpSession session, GenericEntity pk) { if (pk == null) return; Map lookupCaches = (Map)session.getAttribute("lookupCaches"); if(lookupCaches == null){ lookupCaches = new HashMap(); session.setAttribute("lookupCaches", lookupCaches); } String entityName = pk.getEntityName(); mruAddByEntityName( entityName, pk, lookupCaches); return; } /** * Makes an entry in the "most recently used" cache. It picks the cache * by the entity name and builds a signature from the primary key values. * * @param entityName * @param lookupCaches * @param pk either a GenericValue or GenericPK - populated */ public static void mruAddByEntityName(String entityName, GenericEntity pk, Map lookupCaches) { String cacheEntityName = entityName; LifoSet lkupCache = (LifoSet)lookupCaches.get(cacheEntityName); if(lkupCache == null){ lkupCache = new LifoSet(); lookupCaches.put(cacheEntityName, lkupCache); } lkupCache.add(pk.getPrimaryKey()); if (Debug.infoOn()) Debug.logInfo("in mruAddByEntityName, entityName:" + entityName + " lifoSet.size()" + lkupCache.size(), module); return; } public static Iterator mostRecentlyViewedIterator(String entityName, Map lookupCaches) { String cacheEntityName = entityName; LifoSet lkupCache = (LifoSet)lookupCaches.get(cacheEntityName); if(lkupCache == null){ lkupCache = new LifoSet(); lookupCaches.put(cacheEntityName, lkupCache); } Iterator mrvIterator = lkupCache.iterator(); return mrvIterator; } /** * Builds a string signature from a GenericValue or GenericPK. * * @param pk either a populated GenericValue or GenericPK. * @param suffix a string that can be used to distinguish the signature (probably not used). */ public static String buildPKSig( GenericEntity pk, String suffix ) { String sig = ""; Collection keyColl = pk.getPrimaryKey().getAllKeys(); List keyList = new ArrayList(keyColl); Collections.sort(keyList); Iterator it = keyList.iterator(); while (it.hasNext()) { String ky = (String)it.next(); String val = (String)pk.get(ky); if (val != null && val.length() > 0) { if (sig.length() > 0) sig += "_"; sig += val; } } if (suffix != null && suffix.length() > 0) { if (sig.length() > 0) sig += "_"; sig += suffix; } return sig; } public static void setCurrentEntityMap(HttpServletRequest request, GenericEntity ent) { String entityName = ent.getEntityName(); setCurrentEntityMap(request, entityName, ent); } public static void setCurrentEntityMap(HttpServletRequest request, String entityName, GenericEntity ent) { HttpSession session = request.getSession(); Map currentEntityMap = (Map)session.getAttribute("currentEntityMap"); if(currentEntityMap == null){ currentEntityMap = new HashMap(); session.setAttribute("currentEntityMap", currentEntityMap); } currentEntityMap.put(entityName, ent); } //public static String getFromSomewhere(String name, org.ofbiz.base.util.collections.OrderedMap paramMap, HttpServletRequest request, org.jpublish.JPublishContext context) { public static String getFromSomewhere(String name, Map paramMap, HttpServletRequest request, Map context) { String ret = null; if (paramMap != null) ret = (String)paramMap.get(name); if (UtilValidate.isEmpty(ret)) { Object obj = request.getAttribute(name); if (obj != null) { ret = obj.toString(); } else { obj = context.get(name); if (obj != null) { ret = obj.toString(); } } } return ret; } //public static String getFromSomewhere(String name, org.ofbiz.base.util.collections.OrderedMap paramMap, HttpServletRequest request, org.jpublish.JPublishContext context) { public static String getFromSomewhere(String name, Map paramMap, HttpServletRequest request, org.jpublish.JPublishContext context) { String ret = null; if (paramMap != null) ret = (String)paramMap.get(name); if (UtilValidate.isEmpty(ret)) { Object obj = request.getAttribute(name); if (obj != null) { ret = obj.toString(); } else { obj = context.get(name); if (obj != null) { ret = obj.toString(); } } } return ret; } public static void getCurrentValue(HttpServletRequest request, GenericDelegator delegator) { HttpSession session = request.getSession(); Map currentEntityMap = (Map)session.getAttribute("currentEntityMap"); if(currentEntityMap == null){ currentEntityMap = new HashMap(); session.setAttribute("currentEntityMap", currentEntityMap); } Map paramMap = UtilHttp.getParameterMap(request); String entityName = (String)paramMap.get("entityName"); if (UtilValidate.isEmpty(entityName)) entityName = (String)request.getAttribute("entityName"); GenericPK cachedPK = null; if (UtilValidate.isNotEmpty(entityName)) cachedPK = (GenericPK)currentEntityMap.get(entityName); getCurrentValueWithCachedPK( request, delegator, cachedPK, entityName); GenericPK currentPK = (GenericPK)request.getAttribute("currentPK"); currentEntityMap.put(entityName, currentPK); return; } public static void getCurrentValueWithCachedPK(HttpServletRequest request, GenericDelegator delegator, GenericPK cachedPK, String entityName) { Map paramMap = UtilHttp.getParameterMap(request); // Build the primary key that may have been passed in as key values GenericValue v = delegator.makeValue(entityName, null); GenericPK passedPK = v.getPrimaryKey(); Collection keyColl = passedPK.getAllKeys(); Iterator keyIt = keyColl.iterator(); while (keyIt.hasNext()) { String attrName = (String)keyIt.next(); String attrVal = (String)request.getAttribute(attrName); if (UtilValidate.isEmpty(attrVal)) { attrVal = (String)paramMap.get(attrName); } if (UtilValidate.isNotEmpty(attrVal)) { passedPK.put(attrName,attrVal); } } // If a full passed primary key exists, it takes precedence over a cached key // I cannot determine if the key testing utils of GenericEntity take into account // whether or not a field is populated. boolean useCached = false; boolean usePassed = true; if(cachedPK != null ) { useCached = true; keyColl = cachedPK.getPrimaryKey().getAllKeys(); keyIt = keyColl.iterator(); while(keyIt.hasNext()) { String sCached = null; String sPassed = null; Object oPassed = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -