📄 traversesubcontentcachetransform.java
字号:
FreeMarkerWorker.traceNodeTrail("3",nodeTrail);
isPick = ContentWorker.traverseSubContent(traverseContext);
FreeMarkerWorker.traceNodeTrail("4",nodeTrail);
if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContentCache, onStart, isPick(2):" + isPick, module);
}
Debug.logInfo("populateContext, nodeTrail csv(0):" + FreeMarkerWorker.nodeTrailToCsv((List)nodeTrail), "");
if (isPick) {
populateContext(traverseContext, templateCtx);
Debug.logInfo("populateContext, nodeTrail csv(1):" + FreeMarkerWorker.nodeTrailToCsv((List)nodeTrail), "");
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);
//templateCtx.put("buf", new StringBuffer());
List nodeTrail = (List)traverseContext.get("nodeTrail");
Debug.logInfo("after body, nodeTrail csv(2):" + FreeMarkerWorker.nodeTrailToCsv((List)nodeTrail), "");
List savedGlobalNodeTrail = (List)savedValues.get("globalNodeTrail");
templateCtx.put("globalNodeTrail", savedGlobalNodeTrail);
boolean inProgress = ContentWorker.traverseSubContent(traverseContext);
Debug.logInfo("after body, nodeTrail csv(3):" + FreeMarkerWorker.nodeTrailToCsv((List)nodeTrail), "");
if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContentCache, inProgress:"+inProgress,module);
Integer thisViewIndexInteger = (Integer)templateCtx.get("thisViewIndex");
int thisViewIndex = thisViewIndexInteger.intValue();
Integer thisViewSizeInteger = (Integer)templateCtx.get("thisViewSize");
int thisViewSize = thisViewSizeInteger.intValue();
if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContentCache, pickWhen(w):" + templateCtx.get("pickWhen"), module);
FreeMarkerWorker.traceNodeTrail("afterBody",nodeTrail);
int sz = nodeTrail.size();
if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContentCache, sz(w):" + sz, module);
Object highIndexObj = templateCtx.get("highIndex");
int highIndex = 0;
if (highIndexObj != null) {
highIndex = Integer.parseInt((String)highIndexObj);
}
highIndex++;
templateCtx.put("highIndex", new Integer(highIndex).toString());
if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContentCache, highIndex(w):" + highIndex, module);
if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContentCache, viewSize(w):" + viewSize, module);
if (sz == 2) {
if (thisViewIndex == viewIndex) {
templateCtx.put("lowIndex", new Integer(highIndex - 1).toString());
}
Object lowIndexObj = templateCtx.get("lowIndex");
if (lowIndexObj != null) {
int lowIndex = Integer.parseInt((String)lowIndexObj);
if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContentCache, lowIndex(w):" + lowIndex, module);
if ((highIndex - lowIndex) >= viewSize) {
return TransformControl.END_EVALUATION;
}
}
templateCtx.put("thisViewIndex", new Integer(thisViewIndex + 1));
templateCtx.put("viewIndex", new Integer(thisViewIndex).toString());
}
FreeMarkerWorker.traceNodeTrail("7",nodeTrail);
Debug.logInfo("after body, nodeTrail csv(4):" + FreeMarkerWorker.nodeTrailToCsv((List)nodeTrail), "");
if (inProgress) {
populateContext(traverseContext, templateCtx);
Debug.logInfo("after body, nodeTrail csv(5):" + FreeMarkerWorker.nodeTrailToCsv((List)nodeTrail), "");
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");
String wrapTemplateId = (String)templateCtx.get("wrapTemplateId");
if (UtilValidate.isEmpty(encloseWrappedText) || encloseWrappedText.equalsIgnoreCase("false")) {
out.write(wrappedFTL);
wrappedFTL = null; // So it won't get written again below.
}
if (UtilValidate.isNotEmpty(wrapTemplateId)) {
if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContentCache, wrappedFTL(0):" + wrappedFTL, module);
templateCtx.put("wrappedFTL", wrappedFTL);
Map templateRoot = FreeMarkerWorker.createEnvironmentMap(env);
templateRoot.put("context", templateCtx);
String mimeTypeId = (String) templateCtx.get("mimeTypeId");
Locale locale = (Locale) templateCtx.get("locale");
if (locale == null)
locale = Locale.getDefault();
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("in TraverseSubContentCache, after renderContentAsText", module);
} else {
if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContentCache, 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 TraverseSubContentCache, checkWhen, contentTypeAncestry(1):" + contentTypeAncestry, module);
assocContext.put("typeAncestry", contentTypeAncestry);
Map whenMap = (Map)traverseContext.get("whenMap");
if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContentCache, 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 TraverseSubContentCache, checkWhen, isPick(1):" + isPick, module);
return isPick;
}
public void populateContext(Map traverseContext, Map templateContext) {
List nodeTrail = (List)traverseContext.get("nodeTrail");
Debug.logInfo("populateContext, nodeTrail csv(a):" + FreeMarkerWorker.nodeTrailToCsv((List)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 TraverseSubContentCache, populateContext, contentId(1):" + contentId, module);
String subContentId = (String)node.get("subContentId");
if (Debug.verboseOn()) Debug.logVerbose("in TraverseSubContentCache, populateContext, subContentId(1):" + subContentId, module);
templateContext.put("subContentDataResourceView", null);
List passedGlobalNodeTrail = (List)templateContext.get("passedGlobalNodeTrail");
Debug.logInfo("populateContext, passedGlobalNodeTrail csv(a):" + FreeMarkerWorker.nodeTrailToCsv((List)passedGlobalNodeTrail), "");
List globalNodeTrail = new ArrayList(passedGlobalNodeTrail);
Map ndEnd = (Map)passedGlobalNodeTrail.get(passedGlobalNodeTrail.size() - 1);
String contentIdEnd = (String)ndEnd.get("contentId");
Map ndStart = (Map)nodeTrail.get(0);
String contentIdStart = (String)ndStart.get("contentId");
if (UtilValidate.isNotEmpty(contentIdEnd)
&& UtilValidate.isNotEmpty(contentIdStart)
&& contentIdStart.equals(contentIdEnd)) {
Debug.logInfo("populateContext, nodeTrail subList csv:" + FreeMarkerWorker.nodeTrailToCsv((List)nodeTrail), "");
globalNodeTrail.addAll(nodeTrail.subList(1, sz));
} else {
Debug.logInfo("populateContext, nodeTrail csv:" + FreeMarkerWorker.nodeTrailToCsv((List)nodeTrail), "");
globalNodeTrail.addAll(nodeTrail);
}
int indentSz = globalNodeTrail.size();
if (Debug.infoOn()) Debug.logInfo("in TraverseSubContentCache, nodeTrail:" + sz + " passedGlobalNodeTrail:" + passedGlobalNodeTrail.size() + " globalNodeTrail:" + indentSz, module);
templateContext.put("indent", new Integer(indentSz));
templateContext.put("globalNodeTrail", globalNodeTrail);
Debug.logInfo("populateContext, globalNodeTrail csv:" + FreeMarkerWorker.nodeTrailToCsv((List)globalNodeTrail), "");
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 + -