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

📄 loopsubcontentcachetransform.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: LoopSubContentCacheTransform.java 5462 2005-08-05 18:35:48Z jonesde $ *  * Copyright (c) 2001-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.webapp.ftl;import java.io.IOException;import java.io.Writer;import java.sql.Timestamp;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Locale;import java.util.Map;import javax.servlet.http.HttpServletRequest;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.GeneralException;import org.ofbiz.base.util.StringUtil;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.base.util.UtilProperties;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.template.FreeMarkerWorker;import org.ofbiz.content.content.ContentServicesComplex;import org.ofbiz.content.content.ContentWorker;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.minilang.MiniLangException;import org.ofbiz.webapp.ftl.LoopWriter;import freemarker.core.Environment;import freemarker.template.TemplateModelException;import freemarker.template.TemplateTransformModel;import freemarker.template.TransformControl;/** * LoopSubContentCacheTransform - Freemarker Transform for URLs (links) *  * @author <a href="mailto:byersa@automationgroups.com">Al Byers</a> * @version $Rev: 5462 $ * @since 3.0 */public class LoopSubContentCacheTransform implements TemplateTransformModel {    public static final String module = LoopSubContentCacheTransform.class.getName();    public static final String[] upSaveKeyNames = {"globalNodeTrail"};    public static final String[] saveKeyNames = {"contentId", "subContentId", "entityList", "entityIndex", "subDataResourceTypeId", "mimeTypeId", "whenMap", "locale", "entityList", "viewSize", "viewIndex", "highIndex", "lowIndex", "listSize", "wrapTemplateId", "encloseWrapText", "nullThruDatesOnly", "globalNodeTrail", "outputIndex"};    /**     * A wrapper for the FreeMarkerWorker version.     */    public static Object getWrappedObject(String varName, Environment env) {        return FreeMarkerWorker.getWrappedObject(varName, env);    }    public static String getArg(Map args, String key, Environment env) {        return FreeMarkerWorker.getArg(args, key, env);    }    public static String getArg(Map args, String key, Map ctx) {        return FreeMarkerWorker.getArg(args, key, ctx);    }    public static boolean prepCtx(GenericDelegator delegator, Map ctx, Environment env) throws GeneralException {        //String contentId = (String)ctx.get("contentId");        //String mimeTypeId = (String)ctx.get("mimeTypeId");        List lst = (List) ctx.get("entityList");        int entityIndex = ((Integer) ctx.get("entityIndex")).intValue();        //if (Debug.infoOn()) Debug.logInfo("in LoopSubContentCache, prepCtx, entityIndex :" + entityIndex, module);        if (entityIndex >= lst.size()) {            return false;        }        GenericValue view = (GenericValue) lst.get(entityIndex);        //if (Debug.infoOn()) Debug.logInfo("in LoopSubContentCache, subContentDataResourceView contentId/drDataResourceId:" + view.get("contentId")  + " / " + view.get("drDataResourceId") + " entityIndex:" + entityIndex, module);        String dataResourceId = (String) view.get("drDataResourceId");        String subContentIdSub = (String) view.get("contentId");        //String contentAssocTypeId = (String) view.get("caContentAssocTypeId");        //String mapKey = (String) view.get("caMapKey");        //if (Debug.infoOn()) Debug.logInfo("in LoopSubContentCache(0), subContentIdSub ." + subContentIdSub, module);        // This order is taken so that the dataResourceType can be overridden in the transform arguments.        String subDataResourceTypeId = (String) ctx.get("subDataResourceTypeId");        if (UtilValidate.isEmpty(subDataResourceTypeId)) {            subDataResourceTypeId = (String) view.get("drDataResourceTypeId");            // TODO: If this value is still empty then it is probably necessary to get a value from            // the parent context. But it will already have one and it is the same context that is            // being passed.        }        String mimeTypeId = ContentWorker.getMimeTypeId(delegator, view, ctx);        Map trailNode = ContentWorker.makeNode(view);        Map whenMap = (Map) ctx.get("whenMap");        Locale locale = (Locale) ctx.get("locale");        if (locale == null)            locale = Locale.getDefault();        GenericValue assocContent = null;        ContentWorker.checkConditions(delegator, trailNode, assocContent, whenMap);        Boolean isReturnBeforeObj = (Boolean) trailNode.get("isReturnBefore");        Boolean isReturnAfterObj = (Boolean) trailNode.get("isReturnAfter");        Boolean isPickObj = (Boolean) trailNode.get("isPick");        Boolean isFollowObj = (Boolean) trailNode.get("isFollow");        //if (Debug.infoOn()) Debug.logInfo("in LoopSubContentCache, isReturnBeforeObj" + isReturnBeforeObj + " isPickObj:" + isPickObj + " isFollowObj:" + isFollowObj + " isReturnAfterObj:" + isReturnAfterObj, module);        if ((isReturnBeforeObj == null || !isReturnBeforeObj.booleanValue()) && ((isPickObj != null &&                isPickObj.booleanValue()) || (isFollowObj != null && isFollowObj.booleanValue()))) {            List globalNodeTrail = (List) ctx.get("globalNodeTrail");            globalNodeTrail.add(trailNode);            ctx.put("globalNodeTrail", globalNodeTrail);            String csvTrail = ContentWorker.nodeTrailToCsv(globalNodeTrail);            ctx.put("nodeTrailCsv", csvTrail);            //if (Debug.infoOn()) Debug.logInfo("prepCtx, csvTrail(2):" + csvTrail, "");            int indentSz = globalNodeTrail.size();            ctx.put("indent", new Integer(indentSz));            //if (Debug.infoOn()) Debug.logInfo("prepCtx, trail(2):" + trail, "");            //if (Debug.infoOn()) Debug.logInfo("prepCtx, globalNodeTrail csv:" + FreeMarkerWorker.nodeTrailToCsv((List)trail), "");            /*            GenericValue electronicText = null;            try {                electronicText = view.getRelatedOneCache("ElectronicText");            } catch (GenericEntityException e) {                throw new GeneralException(e.getMessage());            }            if (electronicText != null)                ctx.put("textData", electronicText.get("textData"));            else                ctx.put("textData", null);            */            ctx.put("subDataResourceTypeId", subDataResourceTypeId);            ctx.put("mimeTypeId", mimeTypeId);            ctx.put("subContentId", subContentIdSub);            ctx.put("content", view);            //ctx.put("drDataResourceId", dataResourceId);            //ctx.put("dataResourceId", dataResourceId);            //ctx.put("subContentIdSub", subContentIdSub);            env.setVariable("subDataResourceTypeId", FreeMarkerWorker.autoWrap(subDataResourceTypeId, env));            env.setVariable("indent", FreeMarkerWorker.autoWrap(new Integer(indentSz), env));            env.setVariable("nodeTrailCsv", FreeMarkerWorker.autoWrap(csvTrail, env));            env.setVariable("globalNodeTrail", FreeMarkerWorker.autoWrap(globalNodeTrail, env));            env.setVariable("content", FreeMarkerWorker.autoWrap(view, env));            env.setVariable("mimeTypeId", FreeMarkerWorker.autoWrap(mimeTypeId, env));            env.setVariable("subContentId", FreeMarkerWorker.autoWrap(subContentIdSub, env));            return true;        } else {            return false;        }    }    public static boolean getNextMatchingEntity(Map templateRoot, GenericDelegator delegator, Environment env) throws IOException {        int lowIndex = ((Integer) templateRoot.get("lowIndex")).intValue();        int entityIndex = ((Integer) templateRoot.get("entityIndex")).intValue();        int outputIndex = ((Integer) templateRoot.get("outputIndex")).intValue();        int listSize = ((Integer) templateRoot.get("listSize")).intValue();        boolean matchFound = false;        while (!matchFound && entityIndex < listSize) {            try {                matchFound = prepCtx(delegator, templateRoot, env);            } catch (GeneralException e) {                throw new IOException(e.getMessage());            }            entityIndex++;            templateRoot.put("entityIndex", new Integer(entityIndex));            if (matchFound) {                outputIndex++;                if (outputIndex >= lowIndex) {                    break;                } else {                    matchFound = false;                }            }        }        //if (Debug.infoOn()) Debug.logInfo("in LoopSubContentCache, getNextMatchingEntity, outputIndex :" + outputIndex, module);        templateRoot.put("outputIndex", new Integer(outputIndex));        env.setVariable("outputIndex", FreeMarkerWorker.autoWrap(new Integer(outputIndex), env));        env.setVariable("entityIndex", FreeMarkerWorker.autoWrap(new Integer(entityIndex), env));        return matchFound;    }    public Writer getWriter(final Writer out, Map args) {        //Profiler.begin("Loop");        final StringBuffer buf = new StringBuffer();        final Environment env = Environment.getCurrentEnvironment();        //final Map templateRoot = (Map) FreeMarkerWorker.getWrappedObject("context", env);        final Map templateRoot = FreeMarkerWorker.createEnvironmentMap(env);        //FreeMarkerWorker.convertContext(templateRoot);        final GenericDelegator delegator = (GenericDelegator) FreeMarkerWorker.getWrappedObject("delegator", env);        final HttpServletRequest request = (HttpServletRequest) FreeMarkerWorker.getWrappedObject("request", env);        FreeMarkerWorker.getSiteParameters(request, templateRoot);        //templateRoot.put("buf", buf);        final Map savedValuesUp = new HashMap();        FreeMarkerWorker.saveContextValues(templateRoot, upSaveKeyNames, savedValuesUp);        final Map savedValues = new HashMap();        FreeMarkerWorker.overrideWithArgs(templateRoot, args);        String contentAssocTypeId = (String) templateRoot.get("contentAssocTypeId");        //if (UtilValidate.isEmpty(contentAssocTypeId)) {        //throw new RuntimeException("contentAssocTypeId is empty");        //}        List assocTypes = StringUtil.split(contentAssocTypeId, "|");

⌨️ 快捷键说明

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