001: /*
002: * $Id: TraverseSubContentCacheTransform.java,v 1.5 2004/01/13 06:16:30 byersa Exp $
003: *
004: * Copyright (c) 2001-2003 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
007: * in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
009: *
010: * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
011: *
012: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
013: * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
014: * 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.
015: *
016: */
017: package org.ofbiz.content.webapp.ftl;
018:
019: import java.io.IOException;
020: import java.io.Writer;
021: import java.sql.Timestamp;
022: import java.util.List;
023: import java.util.Locale;
024: import java.util.Map;
025: import java.util.HashMap;
026: import java.util.ArrayList;
027: import java.io.StringWriter;
028: import javax.servlet.http.HttpServletRequest;
029:
030: import org.ofbiz.base.util.Debug;
031: import org.ofbiz.base.util.GeneralException;
032: import org.ofbiz.base.util.UtilDateTime;
033: import org.ofbiz.base.util.UtilMisc;
034: import org.ofbiz.base.util.UtilValidate;
035: import org.ofbiz.content.content.ContentServicesComplex;
036: import org.ofbiz.content.content.ContentWorker;
037: import org.ofbiz.entity.GenericDelegator;
038: import org.ofbiz.entity.GenericEntityException;
039: import org.ofbiz.entity.GenericValue;
040:
041: import freemarker.template.Environment;
042: import freemarker.template.SimpleHash;
043: import freemarker.template.TemplateHashModel;
044: import freemarker.template.TemplateTransformModel;
045: import freemarker.template.TransformControl;
046: import freemarker.template.TemplateModelException;
047:
048: /**
049: * TraverseSubContentCacheTransform - Freemarker Transform for URLs (links)
050: *
051: * @author <a href="mailto:byersa@automationgroups.com">Al Byers</a>
052: * @version $Revision: 1.5 $
053: * @since 3.0
054: */
055: public class TraverseSubContentCacheTransform implements
056: TemplateTransformModel {
057:
058: public static final String module = TraverseSubContentCacheTransform.class
059: .getName();
060: public static final String[] saveKeyNames = { "contentId",
061: "subContentId", "mimeTypeId", "subContentDataResourceView",
062: "wrapTemplateId", "templateContentId", "pickWhen",
063: "followWhen", "returnAfterPickWhen",
064: "returnBeforePickWhen", "globalNodeTrail", "entityList",
065: "viewSize", "viewIndex", "highIndex", "lowIndex",
066: "listSize", "thisViewIndex", "thisViewSize", "nodeTrail",
067: "passedGlobalNodeTrail" };
068: public static final String[] removeKeyNames = {
069: "templateContentId", "subDataResourceTypeId", "mapKey",
070: "wrappedFTL", "nodeTrail", "thisViewIndex", "thisViewSize" };
071:
072: /**
073: * A wrapper for the FreeMarkerWorker version.
074: */
075: public static Object getWrappedObject(String varName,
076: Environment env) {
077: return FreeMarkerWorker.getWrappedObject(varName, env);
078: }
079:
080: public static String getArg(Map args, String key, Environment env) {
081: return FreeMarkerWorker.getArg(args, key, env);
082: }
083:
084: public static String getArg(Map args, String key, Map ctx) {
085: return FreeMarkerWorker.getArg(args, key, ctx);
086: }
087:
088: public Writer getWriter(final Writer out, Map args) {
089: final StringBuffer buf = new StringBuffer();
090: final Environment env = Environment.getCurrentEnvironment();
091: final Map templateCtx = (Map) FreeMarkerWorker
092: .getWrappedObject("context", env);
093: //FreeMarkerWorker.convertContext(templateCtx);
094: if (Debug.verboseOn())
095: Debug.logVerbose(FreeMarkerWorker.logMap("(T)before save",
096: templateCtx, 0), module);
097: final Map savedValues = FreeMarkerWorker.saveValues(
098: templateCtx, saveKeyNames);
099: if (Debug.verboseOn())
100: Debug.logVerbose(FreeMarkerWorker.logMap("(T)after save",
101: templateCtx, 0), module);
102: FreeMarkerWorker.overrideWithArgs(templateCtx, args);
103: if (Debug.verboseOn())
104: Debug.logVerbose(FreeMarkerWorker.logMap(
105: "(T)after overrride", templateCtx, 0), module);
106: if (Debug.verboseOn())
107: Debug.logVerbose("args:" + args, module);
108: final GenericDelegator delegator = (GenericDelegator) FreeMarkerWorker
109: .getWrappedObject("delegator", env);
110: final HttpServletRequest request = (HttpServletRequest) FreeMarkerWorker
111: .getWrappedObject("request", env);
112: FreeMarkerWorker.getSiteParameters(request, templateCtx);
113: List trail = (List) templateCtx.get("globalNodeTrail");
114: List passedGlobalNodeTrail = null;
115: if (trail != null && trail.size() > 0)
116: passedGlobalNodeTrail = new ArrayList(trail);
117: else
118: passedGlobalNodeTrail = new ArrayList();
119: GenericValue view = null;
120: if (passedGlobalNodeTrail.size() > 0) {
121: view = (GenericValue) ((Map) passedGlobalNodeTrail
122: .get(passedGlobalNodeTrail.size() - 1))
123: .get("value");
124: }
125:
126: String contentId = (String) templateCtx.get("contentId");
127: String subContentId = (String) templateCtx.get("subContentId");
128: if (UtilValidate.isNotEmpty(subContentId)
129: || UtilValidate.isNotEmpty(contentId)) {
130: String this ContentId = subContentId;
131: if (UtilValidate.isEmpty(this ContentId))
132: this ContentId = contentId;
133:
134: // Don't want to duplicate a node value
135: String passedContentId = null;
136: if (passedGlobalNodeTrail.size() > 0) {
137: Map nd = (Map) passedGlobalNodeTrail
138: .get(passedGlobalNodeTrail.size() - 1);
139: passedContentId = (String) nd.get("contentId");
140: }
141: if (UtilValidate.isNotEmpty(this ContentId)
142: && (UtilValidate.isEmpty(passedContentId) || !this ContentId
143: .equals(passedContentId))) {
144:
145: try {
146: view = delegator.findByPrimaryKeyCache("Content",
147: UtilMisc.toMap("contentId", this ContentId));
148: } catch (GenericEntityException e) {
149: Debug.logError(e, "Error getting sub-content",
150: module);
151: throw new RuntimeException(e.getMessage());
152: }
153: passedGlobalNodeTrail.add(FreeMarkerWorker
154: .makeNode(view));
155: }
156: }
157: templateCtx.put("passedGlobalNodeTrail", passedGlobalNodeTrail);
158: templateCtx.put("contentId", null);
159: templateCtx.put("subContentId", null);
160:
161: final Map traverseContext = new HashMap();
162: String vwIdx = (String) templateCtx.get("viewIndex");
163: if (UtilValidate.isEmpty(vwIdx))
164: vwIdx = "0";
165: final int viewIndex = Integer.parseInt(vwIdx);
166: templateCtx.put("viewIndex", new Integer(viewIndex).toString());
167: String vwSz = (String) templateCtx.get("viewSize");
168: if (UtilValidate.isEmpty(vwSz))
169: vwSz = "10";
170: final int viewSize = Integer.parseInt(vwSz);
171: templateCtx.put("viewSize", new Integer(viewSize).toString());
172: traverseContext.put("delegator", delegator);
173: Map whenMap = new HashMap();
174: whenMap.put("followWhen", (String) templateCtx
175: .get("followWhen"));
176: whenMap.put("pickWhen", (String) templateCtx.get("pickWhen"));
177: whenMap.put("returnBeforePickWhen", (String) templateCtx
178: .get("returnBeforePickWhen"));
179: whenMap.put("returnAfterPickWhen", (String) templateCtx
180: .get("returnAfterPickWhen"));
181: traverseContext.put("whenMap", whenMap);
182: String fromDateStr = (String) templateCtx.get("fromDateStr");
183: String thruDateStr = (String) templateCtx.get("thruDateStr");
184: Timestamp fromDate = null;
185: if (fromDateStr != null && fromDateStr.length() > 0) {
186: fromDate = UtilDateTime.toTimestamp(fromDateStr);
187: }
188: traverseContext.put("fromDate", fromDate);
189: Timestamp thruDate = null;
190: if (thruDateStr != null && thruDateStr.length() > 0) {
191: thruDate = UtilDateTime.toTimestamp(thruDateStr);
192: }
193: traverseContext.put("thruDate", thruDate);
194: String startContentAssocTypeId = (String) templateCtx
195: .get("contentAssocTypeId");
196: if (startContentAssocTypeId != null)
197: startContentAssocTypeId = "SUB_CONTENT";
198: traverseContext.put("contentAssocTypeId",
199: startContentAssocTypeId);
200: String direction = (String) templateCtx.get("direction");
201: if (UtilValidate.isEmpty(direction))
202: direction = "From";
203: traverseContext.put("direction", direction);
204:
205: return new LoopWriter(out) {
206:
207: public void write(char cbuf[], int off, int len) {
208: //StringBuffer ctxBuf = (StringBuffer) templateContext.get("buf");
209: //ctxBuf.append(cbuf, off, len);
210: buf.append(cbuf, off, len);
211: }
212:
213: public void flush() throws IOException {
214: out.flush();
215: }
216:
217: public int onStart() throws TemplateModelException,
218: IOException {
219: //templateContext.put("buf", new StringBuffer());
220: templateCtx.put("thisViewIndex", new Integer(0));
221: templateCtx.put("thisViewSize", new Integer(0));
222: templateCtx.put("lowIndex", "-1");
223: templateCtx.put("highIndex", "0");
224: List nodeTrail = null;
225: GenericValue subContentDataResourceView = null;
226: List passedGlobalNodeTrail = (List) templateCtx
227: .get("passedGlobalNodeTrail");
228: if (passedGlobalNodeTrail.size() > 0) {
229: int sz = passedGlobalNodeTrail.size();
230: nodeTrail = new ArrayList();
231: //nodeTrail = passedGlobalNodeTrail.subList(sz - 1, sz);
232: subContentDataResourceView = (GenericValue) ((Map) passedGlobalNodeTrail
233: .get(sz - 1)).get("value");
234: } else {
235: // This really can't happen. Should probably throw exception
236: nodeTrail = new ArrayList();
237: }
238: traverseContext.put("nodeTrail", nodeTrail);
239: GenericValue content = null;
240: Map rootNode = FreeMarkerWorker
241: .makeNode(subContentDataResourceView);
242: if (Debug.verboseOn())
243: Debug.logVerbose(
244: "in TraverseSubContentCache, onStart, rootNode:"
245: + rootNode, module);
246: FreeMarkerWorker.traceNodeTrail("1", nodeTrail);
247: ContentWorker.selectKids(rootNode, traverseContext);
248: FreeMarkerWorker.traceNodeTrail("2", nodeTrail);
249: nodeTrail.add(rootNode);
250: boolean isPick = checkWhen(subContentDataResourceView,
251: (String) traverseContext
252: .get("contentAssocTypeId"));
253: rootNode.put("isPick", new Boolean(isPick));
254: if (Debug.verboseOn())
255: Debug.logVerbose(
256: "in TraverseSubContentCache, onStart, isPick(1):"
257: + isPick, module);
258: if (!isPick) {
259: FreeMarkerWorker.traceNodeTrail("3", nodeTrail);
260: isPick = ContentWorker
261: .traverseSubContent(traverseContext);
262: FreeMarkerWorker.traceNodeTrail("4", nodeTrail);
263: if (Debug.verboseOn())
264: Debug.logVerbose(
265: "in TraverseSubContentCache, onStart, isPick(2):"
266: + isPick, module);
267: }
268: Debug.logInfo("populateContext, nodeTrail csv(0):"
269: + FreeMarkerWorker
270: .nodeTrailToCsv((List) nodeTrail), "");
271: if (isPick) {
272: populateContext(traverseContext, templateCtx);
273: Debug.logInfo("populateContext, nodeTrail csv(1):"
274: + FreeMarkerWorker
275: .nodeTrailToCsv((List) nodeTrail),
276: "");
277: FreeMarkerWorker.traceNodeTrail("5", nodeTrail);
278: return TransformControl.EVALUATE_BODY;
279: } else {
280: return TransformControl.SKIP_BODY;
281: }
282: }
283:
284: public int afterBody() throws TemplateModelException,
285: IOException {
286: //out.write(buf.toString());
287: //buf.setLength(0);
288: //templateCtx.put("buf", new StringBuffer());
289: List nodeTrail = (List) traverseContext
290: .get("nodeTrail");
291: Debug.logInfo("after body, nodeTrail csv(2):"
292: + FreeMarkerWorker
293: .nodeTrailToCsv((List) nodeTrail), "");
294: List savedGlobalNodeTrail = (List) savedValues
295: .get("globalNodeTrail");
296: templateCtx
297: .put("globalNodeTrail", savedGlobalNodeTrail);
298: boolean inProgress = ContentWorker
299: .traverseSubContent(traverseContext);
300: Debug.logInfo("after body, nodeTrail csv(3):"
301: + FreeMarkerWorker
302: .nodeTrailToCsv((List) nodeTrail), "");
303: if (Debug.verboseOn())
304: Debug.logVerbose(
305: "in TraverseSubContentCache, inProgress:"
306: + inProgress, module);
307: Integer this ViewIndexInteger = (Integer) templateCtx
308: .get("thisViewIndex");
309: int this ViewIndex = this ViewIndexInteger.intValue();
310: Integer this ViewSizeInteger = (Integer) templateCtx
311: .get("thisViewSize");
312: int this ViewSize = this ViewSizeInteger.intValue();
313: if (Debug.verboseOn())
314: Debug.logVerbose(
315: "in TraverseSubContentCache, pickWhen(w):"
316: + templateCtx.get("pickWhen"),
317: module);
318: FreeMarkerWorker.traceNodeTrail("afterBody", nodeTrail);
319: int sz = nodeTrail.size();
320: if (Debug.verboseOn())
321: Debug.logVerbose(
322: "in TraverseSubContentCache, sz(w):" + sz,
323: module);
324: Object highIndexObj = templateCtx.get("highIndex");
325: int highIndex = 0;
326: if (highIndexObj != null) {
327: highIndex = Integer.parseInt((String) highIndexObj);
328: }
329: highIndex++;
330: templateCtx.put("highIndex", new Integer(highIndex)
331: .toString());
332: if (Debug.verboseOn())
333: Debug.logVerbose(
334: "in TraverseSubContentCache, highIndex(w):"
335: + highIndex, module);
336: if (Debug.verboseOn())
337: Debug.logVerbose(
338: "in TraverseSubContentCache, viewSize(w):"
339: + viewSize, module);
340: if (sz == 2) {
341: if (this ViewIndex == viewIndex) {
342: templateCtx.put("lowIndex", new Integer(
343: highIndex - 1).toString());
344: }
345: Object lowIndexObj = templateCtx.get("lowIndex");
346: if (lowIndexObj != null) {
347: int lowIndex = Integer
348: .parseInt((String) lowIndexObj);
349: if (Debug.verboseOn())
350: Debug.logVerbose(
351: "in TraverseSubContentCache, lowIndex(w):"
352: + lowIndex, module);
353: if ((highIndex - lowIndex) >= viewSize) {
354: return TransformControl.END_EVALUATION;
355: }
356: }
357: templateCtx.put("thisViewIndex", new Integer(
358: this ViewIndex + 1));
359: templateCtx.put("viewIndex", new Integer(
360: this ViewIndex).toString());
361: }
362: FreeMarkerWorker.traceNodeTrail("7", nodeTrail);
363: Debug.logInfo("after body, nodeTrail csv(4):"
364: + FreeMarkerWorker
365: .nodeTrailToCsv((List) nodeTrail), "");
366: if (inProgress) {
367: populateContext(traverseContext, templateCtx);
368: Debug.logInfo("after body, nodeTrail csv(5):"
369: + FreeMarkerWorker
370: .nodeTrailToCsv((List) nodeTrail),
371: "");
372: FreeMarkerWorker.traceNodeTrail("8", nodeTrail);
373: return TransformControl.REPEAT_EVALUATION;
374: } else
375: return TransformControl.END_EVALUATION;
376: }
377:
378: public void close() throws IOException {
379:
380: String wrappedFTL = buf.toString();
381: if (Debug.verboseOn())
382: Debug.logVerbose("in LoopSubContent, wrappedFTL:"
383: + wrappedFTL, module);
384:
385: String encloseWrappedText = (String) templateCtx
386: .get("encloseWrappedText");
387: String wrapTemplateId = (String) templateCtx
388: .get("wrapTemplateId");
389: if (UtilValidate.isEmpty(encloseWrappedText)
390: || encloseWrappedText.equalsIgnoreCase("false")) {
391:
392: out.write(wrappedFTL);
393: wrappedFTL = null; // So it won't get written again below.
394: }
395: if (UtilValidate.isNotEmpty(wrapTemplateId)) {
396: if (Debug.verboseOn())
397: Debug.logVerbose(
398: "in TraverseSubContentCache, wrappedFTL(0):"
399: + wrappedFTL, module);
400: templateCtx.put("wrappedFTL", wrappedFTL);
401:
402: Map templateRoot = FreeMarkerWorker
403: .createEnvironmentMap(env);
404:
405: templateRoot.put("context", templateCtx);
406: String mimeTypeId = (String) templateCtx
407: .get("mimeTypeId");
408: Locale locale = (Locale) templateCtx.get("locale");
409: if (locale == null)
410: locale = Locale.getDefault();
411: try {
412: ContentWorker.renderContentAsTextCache(
413: delegator, wrapTemplateId, out,
414: templateRoot, null, locale, mimeTypeId);
415: } catch (GeneralException e) {
416: Debug.logError(e, "Error rendering content",
417: module);
418: throw new IOException("Error rendering content"
419: + e.toString());
420: }
421: if (Debug.verboseOn())
422: Debug
423: .logVerbose(
424: "in TraverseSubContentCache, after renderContentAsText",
425: module);
426:
427: } else {
428: if (Debug.verboseOn())
429: Debug.logVerbose(
430: "in TraverseSubContentCache, wrappedFTL(1):"
431: + wrappedFTL, module);
432: if (UtilValidate.isNotEmpty(wrappedFTL))
433: out.write(wrappedFTL);
434: }
435: if (Debug.verboseOn())
436: Debug
437: .logVerbose(
438: FreeMarkerWorker.logMap(
439: "(T)before remove",
440: templateCtx, 0), module);
441: FreeMarkerWorker.removeValues(templateCtx,
442: removeKeyNames);
443: if (Debug.verboseOn())
444: Debug.logVerbose(FreeMarkerWorker.logMap(
445: "(T)after remove", templateCtx, 0), module);
446: FreeMarkerWorker.reloadValues(templateCtx, savedValues);
447: if (Debug.verboseOn())
448: Debug.logVerbose(FreeMarkerWorker.logMap(
449: "(T)after reload", templateCtx, 0), module);
450: }
451:
452: private boolean checkWhen(GenericValue this Content,
453: String contentAssocTypeId) {
454:
455: boolean isPick = false;
456: Map assocContext = new HashMap();
457: if (UtilValidate.isEmpty(contentAssocTypeId))
458: contentAssocTypeId = "";
459: assocContext.put("contentAssocTypeId",
460: contentAssocTypeId);
461: //assocContext.put("contentTypeId", assocValue.get("contentTypeId") );
462: String assocRelation = null;
463: String this Direction = (String) templateCtx
464: .get("direction");
465: String this ContentId = (String) templateCtx
466: .get("thisContentId");
467: String relatedDirection = null;
468: if (this Direction != null
469: && this Direction.equalsIgnoreCase("From")) {
470: assocContext.put("contentIdFrom", this ContentId);
471: assocRelation = "FromContent";
472: relatedDirection = "From";
473: } else {
474: assocContext.put("contentIdTo", this ContentId);
475: assocRelation = "ToContent";
476: relatedDirection = "To";
477: }
478: assocContext.put("content", this Content);
479: List purposes = ContentWorker.getPurposes(this Content);
480: assocContext.put("purposes", purposes);
481: List contentTypeAncestry = new ArrayList();
482: String contentTypeId = (String) this Content
483: .get("contentTypeId");
484: try {
485: ContentWorker.getContentTypeAncestry(delegator,
486: contentTypeId, contentTypeAncestry);
487: } catch (GenericEntityException e) {
488: if (Debug.verboseOn())
489: Debug.logVerbose(
490: "Error getting contentTypeAncestry:"
491: + e.getMessage(), null);
492: return false;
493: }
494: if (Debug.verboseOn())
495: Debug.logVerbose(
496: "in TraverseSubContentCache, checkWhen, contentTypeAncestry(1):"
497: + contentTypeAncestry, module);
498: assocContext.put("typeAncestry", contentTypeAncestry);
499: Map whenMap = (Map) traverseContext.get("whenMap");
500: if (Debug.verboseOn())
501: Debug.logVerbose(
502: "in TraverseSubContentCache, checkWhen, whenMap(1):"
503: + whenMap, module);
504: String pickWhen = (String) whenMap.get("pickWhen");
505: if (Debug.verboseOn())
506: Debug.logVerbose("pickWhen(checkWhen):" + pickWhen,
507: null);
508: if (Debug.verboseOn())
509: Debug.logVerbose("assocContext(checkWhen):"
510: + assocContext, null);
511: List nodeTrail = (List) traverseContext
512: .get("nodeTrail");
513: //int indentSz = indent.intValue() + nodeTrail.size();
514: //assocContext.put("indentObj", new Integer(indentSz));
515: isPick = ContentWorker.checkWhen(assocContext,
516: (String) whenMap.get("pickWhen"));
517: if (Debug.verboseOn())
518: Debug.logVerbose(
519: "in TraverseSubContentCache, checkWhen, isPick(1):"
520: + isPick, module);
521: return isPick;
522: }
523:
524: public void populateContext(Map traverseContext,
525: Map templateContext) {
526:
527: List nodeTrail = (List) traverseContext
528: .get("nodeTrail");
529: Debug.logInfo("populateContext, nodeTrail csv(a):"
530: + FreeMarkerWorker
531: .nodeTrailToCsv((List) nodeTrail), "");
532: int sz = nodeTrail.size();
533: Map node = (Map) nodeTrail.get(sz - 1);
534: GenericValue content = (GenericValue) node.get("value");
535: String contentId = (String) node.get("contentId");
536: if (Debug.verboseOn())
537: Debug.logVerbose(
538: "in TraverseSubContentCache, populateContext, contentId(1):"
539: + contentId, module);
540: String subContentId = (String) node.get("subContentId");
541: if (Debug.verboseOn())
542: Debug.logVerbose(
543: "in TraverseSubContentCache, populateContext, subContentId(1):"
544: + subContentId, module);
545: templateContext.put("subContentDataResourceView", null);
546: List passedGlobalNodeTrail = (List) templateContext
547: .get("passedGlobalNodeTrail");
548: Debug
549: .logInfo(
550: "populateContext, passedGlobalNodeTrail csv(a):"
551: + FreeMarkerWorker
552: .nodeTrailToCsv((List) passedGlobalNodeTrail),
553: "");
554: List globalNodeTrail = new ArrayList(
555: passedGlobalNodeTrail);
556: Map ndEnd = (Map) passedGlobalNodeTrail
557: .get(passedGlobalNodeTrail.size() - 1);
558: String contentIdEnd = (String) ndEnd.get("contentId");
559: Map ndStart = (Map) nodeTrail.get(0);
560: String contentIdStart = (String) ndStart
561: .get("contentId");
562: if (UtilValidate.isNotEmpty(contentIdEnd)
563: && UtilValidate.isNotEmpty(contentIdStart)
564: && contentIdStart.equals(contentIdEnd)) {
565: Debug
566: .logInfo(
567: "populateContext, nodeTrail subList csv:"
568: + FreeMarkerWorker
569: .nodeTrailToCsv((List) nodeTrail),
570: "");
571: globalNodeTrail.addAll(nodeTrail.subList(1, sz));
572: } else {
573: Debug.logInfo("populateContext, nodeTrail csv:"
574: + FreeMarkerWorker
575: .nodeTrailToCsv((List) nodeTrail),
576: "");
577: globalNodeTrail.addAll(nodeTrail);
578: }
579: int indentSz = globalNodeTrail.size();
580: if (Debug.infoOn())
581: Debug.logInfo(
582: "in TraverseSubContentCache, nodeTrail:"
583: + sz + " passedGlobalNodeTrail:"
584: + passedGlobalNodeTrail.size()
585: + " globalNodeTrail:" + indentSz,
586: module);
587: templateContext.put("indent", new Integer(indentSz));
588: templateContext.put("globalNodeTrail", globalNodeTrail);
589: Debug
590: .logInfo(
591: "populateContext, globalNodeTrail csv:"
592: + FreeMarkerWorker
593: .nodeTrailToCsv((List) globalNodeTrail),
594: "");
595: if (sz >= 2) {
596: Map parentNode = (Map) nodeTrail.get(sz - 2);
597: GenericValue parentContent = (GenericValue) parentNode
598: .get("value");
599: String parentContentId = (String) parentNode
600: .get("contentId");
601: templateContext.put("parentContentId",
602: parentContentId);
603: templateContext.put("parentContent", parentContent);
604: templateContext.put("nodeTrail", nodeTrail);
605: }
606: return;
607: }
608:
609: };
610: }
611: }
|