KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > content > webapp > ftl > LoopSubContentCacheTransform


1 /*
2  * $Id: LoopSubContentCacheTransform.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
13  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
14  * 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.
15  *
16  */

17 package org.ofbiz.content.webapp.ftl;
18
19 import java.io.IOException JavaDoc;
20 import java.io.Writer JavaDoc;
21 import java.sql.Timestamp JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Locale JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29
30 import org.ofbiz.base.util.Debug;
31 import org.ofbiz.base.util.GeneralException;
32 import org.ofbiz.base.util.StringUtil;
33 import org.ofbiz.base.util.UtilDateTime;
34 import org.ofbiz.base.util.UtilProperties;
35 import org.ofbiz.base.util.UtilValidate;
36 import org.ofbiz.base.util.template.FreeMarkerWorker;
37 import org.ofbiz.content.content.ContentServicesComplex;
38 import org.ofbiz.content.content.ContentWorker;
39 import org.ofbiz.entity.GenericDelegator;
40 import org.ofbiz.entity.GenericEntityException;
41 import org.ofbiz.entity.GenericValue;
42 import org.ofbiz.minilang.MiniLangException;
43 import org.ofbiz.webapp.ftl.LoopWriter;
44
45 import freemarker.core.Environment;
46 import freemarker.template.TemplateModelException;
47 import freemarker.template.TemplateTransformModel;
48 import freemarker.template.TransformControl;
49
50 /**
51  * LoopSubContentCacheTransform - Freemarker Transform for URLs (links)
52  *
53  * @author <a HREF="mailto:byersa@automationgroups.com">Al Byers</a>
54  * @version $Rev: 5462 $
55  * @since 3.0
56  */

57 public class LoopSubContentCacheTransform implements TemplateTransformModel {
58
59     public static final String JavaDoc module = LoopSubContentCacheTransform.class.getName();
60
61     public static final String JavaDoc[] upSaveKeyNames = {"globalNodeTrail"};
62     public static final String JavaDoc[] saveKeyNames = {"contentId", "subContentId", "entityList", "entityIndex", "subDataResourceTypeId", "mimeTypeId", "whenMap", "locale", "entityList", "viewSize", "viewIndex", "highIndex", "lowIndex", "listSize", "wrapTemplateId", "encloseWrapText", "nullThruDatesOnly", "globalNodeTrail", "outputIndex"};
63
64     /**
65      * A wrapper for the FreeMarkerWorker version.
66      */

67     public static Object JavaDoc getWrappedObject(String JavaDoc varName, Environment env) {
68         return FreeMarkerWorker.getWrappedObject(varName, env);
69     }
70
71     public static String JavaDoc getArg(Map JavaDoc args, String JavaDoc key, Environment env) {
72         return FreeMarkerWorker.getArg(args, key, env);
73     }
74
75     public static String JavaDoc getArg(Map JavaDoc args, String JavaDoc key, Map JavaDoc ctx) {
76         return FreeMarkerWorker.getArg(args, key, ctx);
77     }
78
79     public static boolean prepCtx(GenericDelegator delegator, Map JavaDoc ctx, Environment env) throws GeneralException {
80
81         //String contentId = (String)ctx.get("contentId");
82
//String mimeTypeId = (String)ctx.get("mimeTypeId");
83
List JavaDoc lst = (List JavaDoc) ctx.get("entityList");
84         int entityIndex = ((Integer JavaDoc) ctx.get("entityIndex")).intValue();
85         //if (Debug.infoOn()) Debug.logInfo("in LoopSubContentCache, prepCtx, entityIndex :" + entityIndex, module);
86
if (entityIndex >= lst.size()) {
87             return false;
88         }
89         GenericValue view = (GenericValue) lst.get(entityIndex);
90         //if (Debug.infoOn()) Debug.logInfo("in LoopSubContentCache, subContentDataResourceView contentId/drDataResourceId:" + view.get("contentId") + " / " + view.get("drDataResourceId") + " entityIndex:" + entityIndex, module);
91

92         String JavaDoc dataResourceId = (String JavaDoc) view.get("drDataResourceId");
93         String JavaDoc subContentIdSub = (String JavaDoc) view.get("contentId");
94         //String contentAssocTypeId = (String) view.get("caContentAssocTypeId");
95
//String mapKey = (String) view.get("caMapKey");
96
//if (Debug.infoOn()) Debug.logInfo("in LoopSubContentCache(0), subContentIdSub ." + subContentIdSub, module);
97
// This order is taken so that the dataResourceType can be overridden in the transform arguments.
98
String JavaDoc subDataResourceTypeId = (String JavaDoc) ctx.get("subDataResourceTypeId");
99         if (UtilValidate.isEmpty(subDataResourceTypeId)) {
100             subDataResourceTypeId = (String JavaDoc) view.get("drDataResourceTypeId");
101             // TODO: If this value is still empty then it is probably necessary to get a value from
102
// the parent context. But it will already have one and it is the same context that is
103
// being passed.
104
}
105
106         String JavaDoc mimeTypeId = ContentWorker.getMimeTypeId(delegator, view, ctx);
107         Map JavaDoc trailNode = ContentWorker.makeNode(view);
108         Map JavaDoc whenMap = (Map JavaDoc) ctx.get("whenMap");
109         Locale JavaDoc locale = (Locale JavaDoc) ctx.get("locale");
110         if (locale == null)
111             locale = Locale.getDefault();
112         GenericValue assocContent = null;
113         ContentWorker.checkConditions(delegator, trailNode, assocContent, whenMap);
114         Boolean JavaDoc isReturnBeforeObj = (Boolean JavaDoc) trailNode.get("isReturnBefore");
115         Boolean JavaDoc isReturnAfterObj = (Boolean JavaDoc) trailNode.get("isReturnAfter");
116         Boolean JavaDoc isPickObj = (Boolean JavaDoc) trailNode.get("isPick");
117         Boolean JavaDoc isFollowObj = (Boolean JavaDoc) trailNode.get("isFollow");
118         //if (Debug.infoOn()) Debug.logInfo("in LoopSubContentCache, isReturnBeforeObj" + isReturnBeforeObj + " isPickObj:" + isPickObj + " isFollowObj:" + isFollowObj + " isReturnAfterObj:" + isReturnAfterObj, module);
119
if ((isReturnBeforeObj == null || !isReturnBeforeObj.booleanValue()) && ((isPickObj != null &&
120                 isPickObj.booleanValue()) || (isFollowObj != null && isFollowObj.booleanValue()))) {
121             List JavaDoc globalNodeTrail = (List JavaDoc) ctx.get("globalNodeTrail");
122             globalNodeTrail.add(trailNode);
123             ctx.put("globalNodeTrail", globalNodeTrail);
124             String JavaDoc csvTrail = ContentWorker.nodeTrailToCsv(globalNodeTrail);
125             ctx.put("nodeTrailCsv", csvTrail);
126             //if (Debug.infoOn()) Debug.logInfo("prepCtx, csvTrail(2):" + csvTrail, "");
127
int indentSz = globalNodeTrail.size();
128             ctx.put("indent", new Integer JavaDoc(indentSz));
129             //if (Debug.infoOn()) Debug.logInfo("prepCtx, trail(2):" + trail, "");
130
//if (Debug.infoOn()) Debug.logInfo("prepCtx, globalNodeTrail csv:" + FreeMarkerWorker.nodeTrailToCsv((List)trail), "");
131

132             /*
133             GenericValue electronicText = null;
134             try {
135                 electronicText = view.getRelatedOneCache("ElectronicText");
136             } catch (GenericEntityException e) {
137                 throw new GeneralException(e.getMessage());
138             }
139             if (electronicText != null)
140                 ctx.put("textData", electronicText.get("textData"));
141             else
142                 ctx.put("textData", null);
143             */

144
145             ctx.put("subDataResourceTypeId", subDataResourceTypeId);
146             ctx.put("mimeTypeId", mimeTypeId);
147             ctx.put("subContentId", subContentIdSub);
148             ctx.put("content", view);
149             //ctx.put("drDataResourceId", dataResourceId);
150
//ctx.put("dataResourceId", dataResourceId);
151
//ctx.put("subContentIdSub", subContentIdSub);
152

153             env.setVariable("subDataResourceTypeId", FreeMarkerWorker.autoWrap(subDataResourceTypeId, env));
154             env.setVariable("indent", FreeMarkerWorker.autoWrap(new Integer JavaDoc(indentSz), env));
155             env.setVariable("nodeTrailCsv", FreeMarkerWorker.autoWrap(csvTrail, env));
156             env.setVariable("globalNodeTrail", FreeMarkerWorker.autoWrap(globalNodeTrail, env));
157             env.setVariable("content", FreeMarkerWorker.autoWrap(view, env));
158             env.setVariable("mimeTypeId", FreeMarkerWorker.autoWrap(mimeTypeId, env));
159             env.setVariable("subContentId", FreeMarkerWorker.autoWrap(subContentIdSub, env));
160             return true;
161         } else {
162             return false;
163         }
164     }
165
166     public static boolean getNextMatchingEntity(Map JavaDoc templateRoot, GenericDelegator delegator, Environment env) throws IOException JavaDoc {
167         int lowIndex = ((Integer JavaDoc) templateRoot.get("lowIndex")).intValue();
168         int entityIndex = ((Integer JavaDoc) templateRoot.get("entityIndex")).intValue();
169         int outputIndex = ((Integer JavaDoc) templateRoot.get("outputIndex")).intValue();
170         int listSize = ((Integer JavaDoc) templateRoot.get("listSize")).intValue();
171         boolean matchFound = false;
172
173         while (!matchFound && entityIndex < listSize) {
174             try {
175                 matchFound = prepCtx(delegator, templateRoot, env);
176             } catch (GeneralException e) {
177                 throw new IOException JavaDoc(e.getMessage());
178             }
179             entityIndex++;
180             templateRoot.put("entityIndex", new Integer JavaDoc(entityIndex));
181             if (matchFound) {
182                 outputIndex++;
183                 if (outputIndex >= lowIndex) {
184                     break;
185                 } else {
186                     matchFound = false;
187                 }
188             }
189         }
190         //if (Debug.infoOn()) Debug.logInfo("in LoopSubContentCache, getNextMatchingEntity, outputIndex :" + outputIndex, module);
191
templateRoot.put("outputIndex", new Integer JavaDoc(outputIndex));
192         env.setVariable("outputIndex", FreeMarkerWorker.autoWrap(new Integer JavaDoc(outputIndex), env));
193         env.setVariable("entityIndex", FreeMarkerWorker.autoWrap(new Integer JavaDoc(entityIndex), env));
194         return matchFound;
195     }
196
197     public Writer JavaDoc getWriter(final Writer JavaDoc out, Map JavaDoc args) {
198         //Profiler.begin("Loop");
199
final StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
200         final Environment env = Environment.getCurrentEnvironment();
201         //final Map templateRoot = (Map) FreeMarkerWorker.getWrappedObject("context", env);
202
final Map JavaDoc templateRoot = FreeMarkerWorker.createEnvironmentMap(env);
203         //FreeMarkerWorker.convertContext(templateRoot);
204
final GenericDelegator delegator = (GenericDelegator) FreeMarkerWorker.getWrappedObject("delegator", env);
205         final HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) FreeMarkerWorker.getWrappedObject("request", env);
206         FreeMarkerWorker.getSiteParameters(request, templateRoot);
207         //templateRoot.put("buf", buf);
208
final Map JavaDoc savedValuesUp = new HashMap JavaDoc();
209         FreeMarkerWorker.saveContextValues(templateRoot, upSaveKeyNames, savedValuesUp);
210         final Map JavaDoc savedValues = new HashMap JavaDoc();
211         FreeMarkerWorker.overrideWithArgs(templateRoot, args);
212         String JavaDoc contentAssocTypeId = (String JavaDoc) templateRoot.get("contentAssocTypeId");
213         //if (UtilValidate.isEmpty(contentAssocTypeId)) {
214
//throw new RuntimeException("contentAssocTypeId is empty");
215
//}
216
List JavaDoc assocTypes = StringUtil.split(contentAssocTypeId, "|");
217
218         String JavaDoc contentPurposeTypeId = (String JavaDoc) templateRoot.get("contentPurposeTypeId");
219         List JavaDoc purposeTypes = StringUtil.split(contentPurposeTypeId, "|");
220         templateRoot.put("purposeTypes", purposeTypes);
221         Locale JavaDoc locale = (Locale JavaDoc) templateRoot.get("locale");
222         if (locale == null) {
223             locale = Locale.getDefault();
224             templateRoot.put("locale", locale);
225         }
226
227         Map JavaDoc whenMap = new HashMap JavaDoc();
228         whenMap.put("followWhen", (String JavaDoc) templateRoot.get("followWhen"));
229         whenMap.put("pickWhen", (String JavaDoc) templateRoot.get("pickWhen"));
230         whenMap.put("returnBeforePickWhen", (String JavaDoc) templateRoot.get("returnBeforePickWhen"));
231         whenMap.put("returnAfterPickWhen", (String JavaDoc) templateRoot.get("returnAfterPickWhen"));
232         templateRoot.put("whenMap", whenMap);
233
234         String JavaDoc fromDateStr = (String JavaDoc) templateRoot.get("fromDateStr");
235         Timestamp JavaDoc fromDate = null;
236         if (UtilValidate.isNotEmpty(fromDateStr)) {
237             fromDate = UtilDateTime.toTimestamp(fromDateStr);
238         }
239         if (fromDate == null)
240             fromDate = UtilDateTime.nowTimestamp();
241
242         final GenericValue userLogin = (GenericValue) FreeMarkerWorker.getWrappedObject("userLogin", env);
243         List JavaDoc globalNodeTrail = (List JavaDoc) templateRoot.get("globalNodeTrail");
244         //if (Debug.infoOn()) Debug.logInfo("in LoopSubContentCache(0), nodeTrailCsv ." + FreeMarkerWorker.nodeTrailToCsv(globalNodeTrail), module);
245
String JavaDoc strNullThruDatesOnly = (String JavaDoc) templateRoot.get("nullThruDatesOnly");
246         String JavaDoc orderBy = (String JavaDoc) templateRoot.get("orderBy");
247         Boolean JavaDoc nullThruDatesOnly = (strNullThruDatesOnly != null && strNullThruDatesOnly.equalsIgnoreCase("true")) ? new Boolean JavaDoc(true) : new Boolean JavaDoc(false);
248         GenericValue val = null;
249         try {
250             val = ContentWorker.getCurrentContent(delegator, globalNodeTrail, userLogin, templateRoot, nullThruDatesOnly, null);
251         } catch (GeneralException e) {
252             Debug.logError(e, module);
253         }
254         final GenericValue view = val;
255
256         if (view != null) {
257             templateRoot.put("contentId", null);
258             templateRoot.put("subContentId", null);
259
260             String JavaDoc contentId = (String JavaDoc) view.get("contentId");
261             //if (Debug.infoOn()) Debug.logInfo("in LoopSubContentCache(0), contentId ." + contentId, module);
262
final String JavaDoc contentIdTo = contentId;
263
264             String JavaDoc thisMapKey = (String JavaDoc) templateRoot.get("mapKey");
265             //if (Debug.infoOn()) Debug.logInfo("in LoopSubContentCache(0), thisMapKey ." + thisMapKey, module);
266
Map JavaDoc results = null;
267             //if (Debug.infoOn()) Debug.logInfo("in LoopSubContentCache(0), assocTypes ." + assocTypes, module);
268
String JavaDoc contentAssocPredicateId = (String JavaDoc) templateRoot.get("contentAssocPredicateId");
269             try {
270                 results = ContentServicesComplex.getAssocAndContentAndDataResourceCacheMethod(delegator, contentId, thisMapKey, "From", fromDate, null, assocTypes, null, new Boolean JavaDoc(true), contentAssocPredicateId, orderBy);
271             } catch (MiniLangException e2) {
272                 throw new RuntimeException JavaDoc(e2.getMessage());
273             } catch (GenericEntityException e) {
274                 throw new RuntimeException JavaDoc(e.getMessage());
275             }
276             List JavaDoc longList = (List JavaDoc) results.get("entityList");
277             //if (Debug.infoOn()) Debug.logInfo("in LoopSubContentCache(0), longList ." + longList.size(), module);
278
String JavaDoc viewSizeStr = (String JavaDoc) templateRoot.get("viewSize");
279             if (UtilValidate.isEmpty(viewSizeStr))
280                 viewSizeStr = UtilProperties.getPropertyValue("content", "viewSize");
281             if (UtilValidate.isEmpty(viewSizeStr))
282                 viewSizeStr = "10";
283             int viewSize = Integer.parseInt(viewSizeStr);
284             String JavaDoc viewIndexStr = (String JavaDoc) templateRoot.get("viewIndex");
285             if (UtilValidate.isEmpty(viewIndexStr))
286                 viewIndexStr = "0";
287             int viewIndex = Integer.parseInt(viewIndexStr);
288             int lowIndex = viewIndex * viewSize;
289             int listSize = longList.size();
290             int highIndex = (viewIndex + 1) * viewSize;
291             if (highIndex > listSize)
292                 highIndex = listSize;
293             //if (Debug.infoOn()) Debug.logInfo("viewIndexStr(0):" + viewIndexStr + " viewIndex:" + viewIndex, "");
294
//if (Debug.infoOn()) Debug.logInfo("viewSizeStr(0):" + viewSizeStr + " viewSize:" + viewSize, "");
295
//if (Debug.infoOn()) Debug.logInfo("listSize(0):" + listSize , "");
296
//if (Debug.infoOn()) Debug.logInfo("highIndex(0):" + highIndex , "");
297
//if (Debug.infoOn()) Debug.logInfo("lowIndex(0):" + lowIndex , "");
298
Iterator JavaDoc it = longList.iterator();
299             //List entityList = longList.subList(lowIndex, highIndex);
300
List JavaDoc entityList = longList;
301             templateRoot.put("entityList", entityList);
302             templateRoot.put("viewIndex", new Integer JavaDoc(viewIndex));
303             templateRoot.put("viewSize", new Integer JavaDoc(viewSize));
304             templateRoot.put("lowIndex", new Integer JavaDoc(lowIndex));
305             templateRoot.put("highIndex", new Integer JavaDoc(highIndex));
306             templateRoot.put("listSize", new Integer JavaDoc(listSize));
307
308             env.setVariable("entityList", FreeMarkerWorker.autoWrap(entityList, env));
309             env.setVariable("viewIndex", FreeMarkerWorker.autoWrap(new Integer JavaDoc(viewIndex), env));
310             env.setVariable("viewSize", FreeMarkerWorker.autoWrap(new Integer JavaDoc(viewSize), env));
311             env.setVariable("lowIndex", FreeMarkerWorker.autoWrap(new Integer JavaDoc(lowIndex), env));
312             env.setVariable("highIndex", FreeMarkerWorker.autoWrap(new Integer JavaDoc(highIndex), env));
313             env.setVariable("listSize", FreeMarkerWorker.autoWrap(new Integer JavaDoc(listSize), env));
314         }
315
316         return new LoopWriter(out) {
317
318             public void write(char cbuf[], int off, int len) {
319                 buf.append(cbuf, off, len);
320                 //StringBuffer ctxBuf = (StringBuffer) templateRoot.get("buf");
321
//ctxBuf.append(cbuf, off, len);
322
}
323
324             public void flush() throws IOException JavaDoc {
325                 out.flush();
326             }
327
328             public int onStart() throws TemplateModelException, IOException JavaDoc {
329
330                 if (view == null) {
331                     return TransformControl.SKIP_BODY;
332                 }
333
334                 List JavaDoc globalNodeTrail = (List JavaDoc) templateRoot.get("globalNodeTrail");
335                 String JavaDoc trailCsv = ContentWorker.nodeTrailToCsv(globalNodeTrail);
336                 //if (Debug.infoOn()) Debug.logInfo("in Loop, onStart, trailCsv:" + trailCsv, "");
337
int viewIndex = ((Integer JavaDoc) templateRoot.get("viewIndex")).intValue();
338                 int viewSize = ((Integer JavaDoc) templateRoot.get("viewSize")).intValue();
339                 int listSize = ((Integer JavaDoc) templateRoot.get("listSize")).intValue();
340                 int lowIndex = viewIndex * viewSize;
341                 int highIndex = (viewIndex + 1) * viewSize;
342                 if (highIndex > listSize)
343                     highIndex = listSize;
344                 int outputIndex = 0;
345                 Integer JavaDoc highIndexInteger = new Integer JavaDoc(highIndex);
346                 Integer JavaDoc lowIndexInteger = new Integer JavaDoc(lowIndex);
347                 Integer JavaDoc outputIndexInteger = new Integer JavaDoc(outputIndex);
348                 Integer JavaDoc entityIndexInteger = new Integer JavaDoc(0);
349                 templateRoot.put("lowIndex", lowIndexInteger);
350                 templateRoot.put("highIndex", highIndexInteger);
351                 templateRoot.put("outputIndex", outputIndexInteger);
352                 templateRoot.put("entityIndex", outputIndexInteger);
353
354                 env.setVariable("lowIndex", FreeMarkerWorker.autoWrap(lowIndexInteger, env));
355                 env.setVariable("highIndex", FreeMarkerWorker.autoWrap(highIndexInteger, env));
356                 env.setVariable("outputIndex", FreeMarkerWorker.autoWrap(outputIndexInteger, env));
357                 env.setVariable("entityIndex", FreeMarkerWorker.autoWrap(outputIndexInteger, env));
358                 //if (Debug.infoOn()) Debug.logInfo( " viewIndex:" + viewIndex, "");
359
//if (Debug.infoOn()) Debug.logInfo( " viewSize:" + viewSize, "");
360
//if (Debug.infoOn()) Debug.logInfo("listSize(1):" + listSize , "");
361
//if (Debug.infoOn()) Debug.logInfo("highIndex(1):" + highIndexInteger , "");
362
//if (Debug.infoOn()) Debug.logInfo("lowIndex(1):" + lowIndexInteger , "");
363
boolean inProgress = false;
364                 if (outputIndex < highIndex) {
365                     inProgress = getNextMatchingEntity(templateRoot, delegator, env);
366                 }
367                 FreeMarkerWorker.saveContextValues(templateRoot, saveKeyNames, savedValues);
368                 if (inProgress) {
369                     return TransformControl.EVALUATE_BODY;
370                 } else {
371                     return TransformControl.SKIP_BODY;
372                 }
373             }
374
375             public int afterBody() throws TemplateModelException, IOException JavaDoc {
376                 FreeMarkerWorker.reloadValues(templateRoot, savedValues, env);
377                 List JavaDoc list = (List JavaDoc) templateRoot.get("globalNodeTrail");
378                 List JavaDoc subList = list.subList(0, list.size() - 1);
379                 templateRoot.put("globalNodeTrail", subList);
380                 env.setVariable("globalNodeTrail", FreeMarkerWorker.autoWrap(subList, env));
381
382                 int outputIndex = ((Integer JavaDoc) templateRoot.get("outputIndex")).intValue();
383                 int highIndex = ((Integer JavaDoc) templateRoot.get("highIndex")).intValue();
384                 Integer JavaDoc highIndexInteger = new Integer JavaDoc(highIndex);
385                 env.setVariable("highIndex", FreeMarkerWorker.autoWrap(highIndexInteger, env));
386                 //if (Debug.infoOn()) Debug.logInfo("highIndex(2):" + highIndexInteger , "");
387
boolean inProgress = false;
388                 if (outputIndex < highIndex) {
389                     inProgress = getNextMatchingEntity(templateRoot, delegator, env);
390                 }
391
392                 FreeMarkerWorker.saveContextValues(templateRoot, saveKeyNames, savedValues);
393                 if (inProgress) {
394                     return TransformControl.REPEAT_EVALUATION;
395                 } else {
396                     return TransformControl.END_EVALUATION;
397                 }
398             }
399
400             public void close() throws IOException JavaDoc {
401                 if (view == null) {
402                     return;
403                 }
404                 FreeMarkerWorker.reloadValues(templateRoot, savedValuesUp, env);
405                 int outputIndex = ((Integer JavaDoc) templateRoot.get("outputIndex")).intValue();
406                 //if (Debug.infoOn()) Debug.logInfo("outputIndex(3):" + outputIndex , "");
407
int highIndex = ((Integer JavaDoc) templateRoot.get("highIndex")).intValue();
408                 Integer JavaDoc highIndexInteger = new Integer JavaDoc(highIndex);
409                 env.setVariable("highIndex", FreeMarkerWorker.autoWrap(highIndexInteger, env));
410                 //if (Debug.infoOn()) Debug.logInfo("highIndex(3):" + highIndexInteger , "");
411
if (outputIndex < highIndex) {
412                     templateRoot.put("highIndex", new Integer JavaDoc(outputIndex));
413                     //if (Debug.infoOn()) Debug.logInfo("highIndex(4):" + highIndex , "");
414
templateRoot.put("listSize", new Integer JavaDoc(outputIndex));
415                 }
416                 Object JavaDoc highIndexObj = FreeMarkerWorker.getWrappedObject("highIndex", env);
417                 //if (Debug.infoOn()) Debug.logInfo("highIndex(3b):" + highIndexObj , "");
418
String JavaDoc wrappedContent = buf.toString();
419                 out.write(wrappedContent);
420                 //if (Debug.infoOn()) Debug.logInfo("in LoopSubContent, wrappedContent:" + wrappedContent, module);
421
//try {
422
//Profiler.end("Loop");
423
//FileOutputStream fw = new FileOutputStream(new File("/usr/local/agi/ofbiz/hot-deploy/sfmp/misc/profile.data"));
424
//Profiler.print(fw);
425
//fw.close();
426
//} catch (IOException e) {
427
//Debug.logError("[PROFILER] " + e.getMessage(),"");
428
//}
429
}
430         };
431     }
432 }
433
Popular Tags