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

📄 limitedsubcontentcachetransform.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            public void flush() throws IOException {                out.flush();            }            public int onStart() throws TemplateModelException, IOException {                List globalNodeTrail = (List) templateRoot.get("globalNodeTrail");                String trailCsv = ContentWorker.nodeTrailToCsv(globalNodeTrail);                boolean inProgress = false;                //if (Debug.infoOn()) Debug.logInfo("in limited, returnLimit:" + returnLimit , "");                //if (Debug.infoOn()) Debug.logInfo("in limited, pickedEntityIds:" + pickedEntityIds , "");                if (pickedEntityIds.size() < returnLimit) {                    inProgress = getNextMatchingEntity(templateRoot, delegator, env);                }                FreeMarkerWorker.saveContextValues(templateRoot, saveKeyNames, savedValues);                if (inProgress) {                    return TransformControl.EVALUATE_BODY;                } else {                    return TransformControl.SKIP_BODY;                }            }            public int afterBody() throws TemplateModelException, IOException {                FreeMarkerWorker.reloadValues(templateRoot, savedValues, env);                List list = (List) templateRoot.get("globalNodeTrail");                List subList = list.subList(0, list.size() - 1);                templateRoot.put("globalNodeTrail", subList);                env.setVariable("globalNodeTrail", FreeMarkerWorker.autoWrap(subList, env));                                //if (Debug.infoOn()) Debug.logInfo("highIndex(2):" + highIndexInteger , "");                //if (Debug.infoOn()) Debug.logInfo("in limited, returnLimit(2):" + returnLimit , "");                //if (Debug.verboseOn()) Debug.logVerbose("in limited, pickedEntityIds(2):" + pickedEntityIds , "");                boolean inProgress = false;                if (pickedEntityIds.size() < returnLimit) {                    inProgress = getNextMatchingEntity(templateRoot, delegator, env);                }                FreeMarkerWorker.saveContextValues(templateRoot, saveKeyNames, savedValues);                if (inProgress) {                    return TransformControl.REPEAT_EVALUATION;                } else {                    return TransformControl.END_EVALUATION;                }            }            public void close() throws IOException {                FreeMarkerWorker.reloadValues(templateRoot, savedValuesUp, env);                String wrappedContent = buf.toString();                out.write(wrappedContent);                //try {                //Profiler.end("Limited");                //FileOutputStream fw = new FileOutputStream(new File("/usr/local/agi/ofbiz/hot-deploy/sfmp/misc/profile.data"));                //Profiler.print(fw);                //fw.close();                //} catch (IOException e) {                //Debug.logError("[PROFILER] " + e.getMessage(),"");                //}            }            public boolean prepCtx(GenericDelegator delegator, Map ctx, Environment env, GenericValue view) throws GeneralException {                String dataResourceId = (String) view.get("drDataResourceId");                String subContentIdSub = (String) view.get("contentId");                // 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 LimitedSubContentCache, 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");                    if (globalNodeTrail == null) {                        globalNodeTrail = new ArrayList();                    }                    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));                    ctx.put("subDataResourceTypeId", subDataResourceTypeId);                    ctx.put("mimeTypeId", mimeTypeId);                    ctx.put("subContentId", subContentIdSub);                    ctx.put("content", view);                    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 GenericValue getRandomEntity() {                GenericValue pickEntity = null;                List lst = (List) templateRoot.get("entityList");                if (Debug.verboseOn()) Debug.logVerbose("in limited, lst:" + lst, "");                while (pickEntity == null && lst.size() > 0) {                    double randomValue = Math.random();                    //if (Debug.infoOn()) Debug.logInfo("in limited, randomValue:" + randomValue , "");                    int idx = (int) (lst.size() * randomValue);                    //if (Debug.infoOn()) Debug.logInfo("in limited, idx:" + idx , "");                    pickEntity = (GenericValue) lst.get(idx);                    String pickEntityId = pickEntity.getString("contentId");                    if (pickedEntityIds.get(pickEntityId) == null) {                        pickedEntityIds.put(pickEntityId, pickEntity);                        lst.remove(idx);                    } else {                        pickEntity = null;                    }                }                return pickEntity;            }            public boolean getNextMatchingEntity(Map templateRoot, GenericDelegator delegator, Environment env) throws IOException {                boolean matchFound = false;                GenericValue pickEntity = getRandomEntity();                while (pickEntity != null && !matchFound) {                    try {                        matchFound = prepCtx(delegator, templateRoot, env, pickEntity);                    } catch (GeneralException e) {                        throw new IOException(e.getMessage());                    }                    if (!matchFound)                        pickEntity = getRandomEntity();                }                return matchFound;            }        };    }}

⌨️ 快捷键说明

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