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

📄 traversesubcontenttransform.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                FreeMarkerWorker.traceNodeTrail("2",nodeTrail);
                nodeTrail.add(rootNode);
                boolean isPick = checkWhen(subContentDataResourceView, (String)traverseContext.get("contentAssocTypeId"));
                rootNode.put("isPick", new Boolean(isPick));
                if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, onStart, isPick(1):" + isPick, module);
                if (!isPick) {
                FreeMarkerWorker.traceNodeTrail("3",nodeTrail);
                    isPick = ContentWorker.traverseSubContent(traverseContext);
                FreeMarkerWorker.traceNodeTrail("4",nodeTrail);
                    if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, onStart, isPick(2):" + isPick, module);
                }
                if (isPick) {
                    populateContext(traverseContext, templateCtx);
                FreeMarkerWorker.traceNodeTrail("5",nodeTrail);
                    return TransformControl.EVALUATE_BODY;
                } else {
                    return TransformControl.SKIP_BODY;
                }
            }

            public int afterBody() throws TemplateModelException, IOException {
                //out.write(buf.toString());
                //buf.setLength(0);
                //templateContext.put("buf", new StringBuffer());
                if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, buf(w):" + buf.toString(), module);
                if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, pickWhen(w):" + templateCtx.get("pickWhen"), module);
                List nodeTrail = (List)traverseContext.get("nodeTrail");
                FreeMarkerWorker.traceNodeTrail("6",nodeTrail);
                boolean inProgress = ContentWorker.traverseSubContent(traverseContext);
                if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, inProgress:"+inProgress,module);
                FreeMarkerWorker.traceNodeTrail("7",nodeTrail);
                if (inProgress) {
                    populateContext(traverseContext, templateCtx);
                FreeMarkerWorker.traceNodeTrail("8",nodeTrail);
                    return TransformControl.REPEAT_EVALUATION;
                } else
                    return TransformControl.END_EVALUATION;
            }

            public void close() throws IOException {

                String wrappedFTL = buf.toString();
                if (Debug.verboseOn()) Debug.logVerbose("in LoopSubContent, wrappedFTL:"+wrappedFTL,module);
                String encloseWrappedText = (String)templateCtx.get("encloseWrappedText");
                if (UtilValidate.isEmpty(encloseWrappedText) || encloseWrappedText.equalsIgnoreCase("false")) {

                    out.write(wrappedFTL);
                    wrappedFTL = null; // So it won't get written again below.
                }
                String wrapTemplateId = (String)templateCtx.get("wrapTemplateId");
                if (UtilValidate.isNotEmpty(wrapTemplateId)) {
                    if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, wrappedFTL(0):" + wrappedFTL, module);
                    templateCtx.put("wrappedFTL", wrappedFTL);
                    
                    Map templateRoot = FreeMarkerWorker.createEnvironmentMap(env);
                    
/*
                    if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, rootDir:" + rootDir, module);
                    templateRoot.put("viewSize", viewSize);
                    templateRoot.put("viewIndex", viewIndex);
                    templateRoot.put("listSize", listSize);
                    templateRoot.put("highIndex", highIndex);
                    templateRoot.put("lowIndex", lowIndex);
                    templateRoot.put("queryString", queryString);
                    templateRoot.put("wrapDataResourceTypeId", subDataResourceTypeId);
                    templateRoot.put("wrapContentIdTo", contentId);
                    templateRoot.put("wrapMimeTypeId", mimeTypeId);
                    //templateRoot.put("wrapMapKey", mapKey);
                    
                    if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, wrapDataResourceTypeId:" + subDataResourceTypeId, module);
                    if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, wrapContentIdTo:" + contentId, module);
                    if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, wrapMimeTypeId:" + mimeTypeId, module);
                    //if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, wrapMapKey:" + mapKey,module);
                    if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, calling renderContentAsText, wrapTemplateId:" + wrapTemplateId, module);
*/
                    templateRoot.put("context", templateCtx);
                    String mimeTypeId = (String) templateCtx.get("mimeTypeId");
                    Locale locale = (Locale) templateCtx.get("locale");
                    if (locale == null)
                        locale = Locale.getDefault();
                    try {
                        ContentWorker.renderContentAsText(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("in TraverseSubContent, after renderContentAsText", module);
/*
                    Map resultsCtx = (Map) FreeMarkerWorker.getWrappedObject("context", env);
                    if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, contentId:" + resultsCtx.get("contentId"), module);
                    templateContext.put("contentId", contentId);
                    templateContext.put("locale", locale);
                    templateContext.put("mapKey", null);
                    templateContext.put("subContentId", null);
                    templateContext.put("templateContentId", null);
                    templateContext.put("subDataResourceTypeId", null);
                    templateContext.put("mimeTypeId", null);
                    if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, after.", module);
                    //if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, mapKey:" + mapKey, module);
                    if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, subDataResourceTypeId:" + subDataResourceTypeId, module);
                    if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, contentId:" + contentId, module);
                    if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, mimeTypeId:" + mimeTypeId, module);
                    if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, locale:" + locale, module);
                    if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, contentId2." + resultsCtx.get("contentId"), module);
*/


                } else {
                    if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, wrappedFTL(1):" + wrappedFTL, module);
                    if (UtilValidate.isNotEmpty(wrappedFTL))
                        out.write(wrappedFTL);
                }
                    if (Debug.verboseOn()) Debug.logVerbose(FreeMarkerWorker.logMap("(T)before remove", templateCtx, 0),module);
                    FreeMarkerWorker.removeValues(templateCtx, removeKeyNames);
                    if (Debug.verboseOn()) Debug.logVerbose(FreeMarkerWorker.logMap("(T)after remove", templateCtx, 0),module);
                    FreeMarkerWorker.reloadValues(templateCtx, savedValues);
                    if (Debug.verboseOn()) Debug.logVerbose(FreeMarkerWorker.logMap("(T)after reload", templateCtx, 0),module);
            }

            private boolean checkWhen (GenericValue thisContent, String contentAssocTypeId) {
        
                boolean isPick = false;
                Map assocContext = new HashMap();
                if (UtilValidate.isEmpty(contentAssocTypeId))
                    contentAssocTypeId = "";
                assocContext.put("contentAssocTypeId", contentAssocTypeId);
                //assocContext.put("contentTypeId", assocValue.get("contentTypeId") );
                String assocRelation = null;
                String thisDirection = (String)templateCtx.get("direction");
                String thisContentId = (String)templateCtx.get("thisContentId");
                String relatedDirection = null;
                if (thisDirection != null && thisDirection.equalsIgnoreCase("From")) {
                    assocContext.put("contentIdFrom", thisContentId);
                    assocRelation = "FromContent";
                    relatedDirection = "From";
                } else {
                    assocContext.put("contentIdTo", thisContentId);
                    assocRelation = "ToContent";
                    relatedDirection = "To";
                }
                assocContext.put("content", thisContent);
                List purposes = ContentWorker.getPurposes(thisContent);
                assocContext.put("purposes", purposes);
                List contentTypeAncestry = new ArrayList();
                String contentTypeId = (String)thisContent.get("contentTypeId");
                try {
                    ContentWorker.getContentTypeAncestry(delegator, contentTypeId, contentTypeAncestry);
                } catch(GenericEntityException e) {
                    if (Debug.verboseOn()) Debug.logVerbose("Error getting contentTypeAncestry:" + e.getMessage(),null);
                    return false;
                }
                if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, checkWhen, contentTypeAncestry(1):" + contentTypeAncestry, module);
                assocContext.put("typeAncestry", contentTypeAncestry);
                Map whenMap = (Map)traverseContext.get("whenMap");
                if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, checkWhen, whenMap(1):" + whenMap, module);
                String pickWhen = (String)whenMap.get("pickWhen");
                if (Debug.verboseOn()) Debug.logVerbose("pickWhen(checkWhen):" + pickWhen,null);
                if (Debug.verboseOn()) Debug.logVerbose("assocContext(checkWhen):" + assocContext,null);
                List nodeTrail = (List)traverseContext.get("nodeTrail");
                int indentSz = indent.intValue() + nodeTrail.size();
                assocContext.put("indentObj", new Integer(indentSz));
                isPick = ContentWorker.checkWhen(assocContext, (String)whenMap.get("pickWhen"));
                if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, checkWhen, isPick(1):" + isPick, module);
                return isPick;
           }


            public void populateContext(Map traverseContext, Map templateContext) {

                List nodeTrail = (List)traverseContext.get("nodeTrail");
                int sz = nodeTrail.size();
                Map node = (Map)nodeTrail.get(sz - 1);
                GenericValue content = (GenericValue)node.get("value");
                String contentId = (String)node.get("contentId");
                if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, populateContext, contentId(1):" + contentId, module);
                String subContentId = (String)node.get("subContentId");
                if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContent, populateContext, subContentId(1):" + subContentId, module);
                templateContext.put("subContentId", contentId);
                templateContext.put("subContentDataResourceView", null);
                int indentSz = indent.intValue() + nodeTrail.size();
                templateContext.put("indent", new Integer(indentSz));
                if (sz >= 2) {
                    Map parentNode = (Map)nodeTrail.get(sz - 2);
                    GenericValue parentContent = (GenericValue)parentNode.get("value");
                    String parentContentId = (String)parentNode.get("contentId");
                    templateContext.put("parentContentId", parentContentId);
                    templateContext.put("parentContent", parentContent);
                    templateContext.put("nodeTrail", nodeTrail);
                }
                return;
            }

        };
    }
}

⌨️ 快捷键说明

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