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

📄 loopsubcontentcachetransform.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            templateCtx.put("locale", locale);
        }

        String fromDateStr = (String)templateCtx.get("fromDateStr");
        Timestamp fromDate = null;
        if (UtilValidate.isNotEmpty(fromDateStr)) {
            fromDate = UtilDateTime.toTimestamp(fromDateStr);
        }
        if (fromDate == null)
            fromDate = UtilDateTime.nowTimestamp();
        GenericValue view = null;
       
        String contentId = (String)templateCtx.get("contentId");
        final String contentIdTo = contentId;
        String subContentId = (String)templateCtx.get("subContentId");
        String thisContentId = (String)templateCtx.get("contentId");
        if (UtilValidate.isEmpty(thisContentId)) {
            thisContentId = (String)templateCtx.get("subContentId");
        }
        List trail = (List)templateCtx.get("globalNodeTrail");
        List passedGlobalNodeTrail = null;
        if (trail != null && trail.size() > 0) 
            passedGlobalNodeTrail = new ArrayList(trail);
        else
            passedGlobalNodeTrail = new ArrayList();
        if (UtilValidate.isNotEmpty(subContentId) || UtilValidate.isNotEmpty(contentId) ) {

            // Don't want to duplicate a node value
            String passedContentId = null;
            if (passedGlobalNodeTrail.size() > 0) {
                Map nd = (Map)passedGlobalNodeTrail.get(passedGlobalNodeTrail.size() - 1);
                passedContentId = (String)nd.get("contentId");
            }
            if (UtilValidate.isNotEmpty(thisContentId)
                && ( UtilValidate.isEmpty(passedContentId) || !thisContentId.equals(passedContentId))) {
            
                try {
                    view = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", thisContentId));
                } catch (GenericEntityException e) {
                    Debug.logError(e, "Error getting sub-content", module);
                    throw new RuntimeException(e.getMessage());
                }
                passedGlobalNodeTrail.add(FreeMarkerWorker.makeNode(view));
            }
        }
Debug.logInfo("passedGlobalNodeTrail(write):" + passedGlobalNodeTrail, "");
        templateCtx.put("passedGlobalNodeTrail", passedGlobalNodeTrail);
        templateCtx.put("contentId", null);
        templateCtx.put("subContentId", null);

        String thisMapKey = (String)templateCtx.get("mapKey");
        Map results = null;
        try {
            results = ContentServicesComplex.getAssocAndContentAndDataResourceCacheMethod(delegator, thisContentId, thisMapKey, "From", fromDate, null, assocTypes, null);
        } catch(MiniLangException e2) {
            throw new RuntimeException(e2.getMessage());
        } catch(GenericEntityException e) {
            throw new RuntimeException(e.getMessage());
        }
        List longList = (List) results.get("entityList");
        String viewSizeStr = (String)templateCtx.get("viewSize");
        if (UtilValidate.isEmpty(viewSizeStr))
            viewSizeStr = "10";
        int viewSize = Integer.parseInt(viewSizeStr); 
Debug.logInfo("viewSize:" + viewSize, "");
        String viewIndexStr = (String)templateCtx.get("viewIndex");
Debug.logInfo("viewIndexStr:" + viewIndexStr, "");
        if (UtilValidate.isEmpty(viewIndexStr))
            viewIndexStr = "0";
        int viewIndex = Integer.parseInt(viewIndexStr); 
Debug.logInfo("viewIndex:" + viewIndex, "");
        int lowIndex = viewIndex * viewSize;
Debug.logInfo("lowIndex:" + lowIndex, "");
        int listSize = longList.size();
Debug.logInfo("listSize:" + listSize, "");
        int highIndex = (viewIndex + 1) * viewSize;
        if (highIndex > listSize)
            highIndex = listSize;
Debug.logInfo("highIndex:" + highIndex, "");
        Iterator it = longList.iterator();
        List entityList = longList.subList(lowIndex, highIndex);
        templateCtx.put("entityList", entityList);
        templateCtx.put("viewIndex", Integer.toString(viewIndex));
        templateCtx.put("viewSize", Integer.toString(viewSize));
        templateCtx.put("lowIndex", Integer.toString(lowIndex));
        templateCtx.put("highIndex", Integer.toString(highIndex));
        templateCtx.put("listSize", Integer.toString(listSize));

        return new LoopWriter(out) {

            public void write(char cbuf[], int off, int len) {
                buf.append(cbuf, off, len);
                //StringBuffer ctxBuf = (StringBuffer) templateCtx.get("buf");
                //ctxBuf.append(cbuf, off, len);
                if (Debug.verboseOn()) Debug.logVerbose("in LoopSubContentCache, buf:"+buf.toString(),module);
            }

            public void flush() throws IOException {
                out.flush();
            }

            public int onStart() throws TemplateModelException, IOException {
                templateCtx.put("entityIndex", new Integer(0));
                if (Debug.verboseOn()) Debug.logVerbose("in LoopSubContentCache, onStart", module);
                boolean inProgress = prepCtx(delegator, templateCtx);
                if (Debug.verboseOn()) Debug.logVerbose("in LoopSubContentCache, onStart, inProgress:" + inProgress, module);
                if (inProgress) {
                    return TransformControl.EVALUATE_BODY;
                } else {
                    return TransformControl.SKIP_BODY;
                }
            }

            public int afterBody() throws TemplateModelException, IOException {
                if (Debug.verboseOn()) Debug.logVerbose("in LoopSubContentCache, afterBody, start", module);
                if (Debug.verboseOn()) Debug.logVerbose(FreeMarkerWorker.logMap("(L)after body", templateCtx, 0),module);
                Integer idx = (Integer) templateCtx.get("entityIndex");
                if (Debug.verboseOn()) Debug.logVerbose("in LoopSubContentCache, prepCtx, idx :" + idx, module);
                int i = idx.intValue();
                if (Debug.verboseOn()) Debug.logVerbose("in LoopSubContentCache, afterBody, i:" + i, module);
                if (Debug.verboseOn()) Debug.logVerbose("in LoopSubContentCache, afterBody, templateCtx.entityIndex:" + templateCtx.get("entityIndex"), module);
                if (Debug.verboseOn()) Debug.logVerbose("buf:" + buf.toString(),module);
                boolean inProgress = prepCtx(delegator, templateCtx);
                if (Debug.verboseOn()) Debug.logVerbose("in LoopSubContentCache, afterBody, inProgress:" + inProgress + " inProgress:" + inProgress, module);
                //out.write(buf.toString());
                //buf.setLength(0);
                if (inProgress)
                    return TransformControl.REPEAT_EVALUATION;
                else
                    return TransformControl.END_EVALUATION;
            }

            public void close() throws IOException {

                String wrappedFTL = buf.toString();
                if (Debug.verboseOn()) Debug.logVerbose("in LoopSubContentCache, wrappedFTL:"+wrappedFTL,module);
                String encloseWrappedText = (String)templateCtx.get("encloseWrappedText");
                if (UtilValidate.isEmpty(encloseWrappedText) || encloseWrappedText.equalsIgnoreCase("false")) {
                    out.write(wrappedFTL);
                    wrappedFTL = ""; // So it won't get written again below.
                }
                String wrapTemplateId = (String)templateCtx.get("wrapTemplateId");
                    if (Debug.verboseOn()) Debug.logVerbose("in LoopSubContentCache, wrapTemplateId:" + wrapTemplateId, module);
                if (UtilValidate.isNotEmpty(wrapTemplateId)) {
                    templateCtx.put("wrappedFTL", wrappedFTL);
                    templateCtx.put("contentIdTo", contentIdTo);
                    //if (Debug.verboseOn()) Debug.logVerbose("in LoopSubContentCache, rootDir:" + rootDir, module);
                    
                    Map templateRoot = FreeMarkerWorker.createEnvironmentMap(env);
                    
                    templateRoot.put("wrapDataResourceTypeId", templateCtx.get("subDataResourceTypeId"));
                    templateRoot.put("wrapContentIdTo", templateCtx.get("contentId"));
                    templateRoot.put("wrapMimeTypeId", templateCtx.get("mimeTypeId"));
                    templateRoot.put("context", templateCtx);
                    
                    Locale locale = (Locale) templateCtx.get("locale");
                    if (locale == null)
                        locale = Locale.getDefault();
                    String mimeTypeId = (String) templateCtx.get("mimeTypeId");
                if (Debug.verboseOn()) Debug.logVerbose(FreeMarkerWorker.logMap("(L)close middle", templateCtx, 0),module);
                    try {
                        ContentWorker.renderContentAsTextCache(delegator, wrapTemplateId, out, templateRoot, null, locale, mimeTypeId);
                    } catch (GeneralException e) {
                        Debug.logError(e, "Error rendering content", module);
                        throw new IOException("Error rendering content" + e.toString());
                    }
                if (Debug.verboseOn()) Debug.logVerbose(FreeMarkerWorker.logMap("(L)close middle(2)", templateCtx, 0),module);
                } else {
                    if (UtilValidate.isNotEmpty(wrappedFTL))
                        out.write(wrappedFTL);
                }
                    if (Debug.verboseOn()) Debug.logVerbose(FreeMarkerWorker.logMap("(L)before remove", templateCtx, 0),module);
                    FreeMarkerWorker.removeValues(templateCtx, removeKeyNames);
                    if (Debug.verboseOn()) Debug.logVerbose(FreeMarkerWorker.logMap("(L)after remove", templateCtx, 0),module);
        if (Debug.verboseOn()) Debug.logVerbose("(L-1)savedValues: " + savedValues,module);
                    FreeMarkerWorker.reloadValues(templateCtx, savedValues);
                    if (Debug.verboseOn()) Debug.logVerbose(FreeMarkerWorker.logMap("(L)after reload", templateCtx, 0),module);
            }
        };
    }
}

⌨️ 快捷键说明

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