19 package org.turro.collections;
21 import java.io.IOException;
22 import java.io.Writer;
23 import java.lang.reflect.ParameterizedType;
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.List;
28 import java.util.logging.Level;
29 import java.util.logging.Logger;
30 import org.turro.string.ObjectString;
31 import org.turro.string.Strings;
32 import org.turro.action.content.IContentIterator;
33 import org.turro.elephant.context.ElephantContext;
34 import org.turro.elephant.context.IConstructor;
35 import org.turro.html.HTMLHelper;
36 import org.turro.marker.ElephantMarker;
37 import org.turro.marker.MarkerHelper;
52 private String summaryTemplate, fullTemplate;
53 private boolean navigatorTop =
true, navigatorBottom =
true, searchOption =
true, forceSummary =
false;
54 private int page, currentIndex, currentSize;
57 private final Class<ID> idClass;
58 private Writer writer;
59 private final Map<String, Object> markerAttributes;
62 this(collection,
marker,
null);
70 this.idClass = (Class<ID>) ((ParameterizedType) getClass()
71 .getGenericSuperclass()).getActualTypeArguments()[1];
72 markerAttributes =
new HashMap<>();
76 this.summaryTemplate = summaryTemplate;
80 return Strings.isBlank(summaryTemplate) ?
"summary" : summaryTemplate;
84 this.fullTemplate = fullTemplate;
88 return Strings.isBlank(fullTemplate) ?
"full" : fullTemplate;
96 this.navigatorTop = navigatorTop;
100 return navigatorBottom;
104 this.navigatorBottom = navigatorBottom;
128 this.searchOption = searchOption;
136 this.forceSummary = forceSummary;
144 return entity !=
null;
149 return markerAttributes.put(key, value);
156 }
catch (IOException ex) {
166 entity = entity(item);
173 entity = entity(item);
178 return entity !=
null ?
title(entity) :
null;
182 return entity !=
null ?
metas(entity) :
null;
190 marker.
put(
"navigatorTop", navigatorTop);
191 marker.
put(
"navigatorBottom", navigatorBottom);
192 marker.
put(
"searchOption", searchOption);
216 currentSize =
items.size();
217 if(currentSize == 0) {
241 return currentIndex == 0;
245 return currentIndex == currentSize - 1;
268 protected abstract String
title(E e);
269 protected abstract Collection<String>
metas(E e);
276 if(kvm !=
null && !kvm.isEmpty() && kvm.containsKey(
"item")) {
277 return parseId(kvm.get(
"item"));
290 return (ID) ObjectString.parseString(value, idClass,
false);
294 return String.valueOf(value);
String getSummaryTemplate()
CollectionHtmlIterator(List collection, ElephantMarker marker)
CollectionHtmlIterator(List collection, ElephantMarker marker, Writer writer)
void setSummaryTemplate(String summaryTemplate)
void setNavigatorTop(boolean navigatorTop)
abstract void renderItem(ElephantMarker marker, E e, int page)
String renderSearchEngine()
abstract E entity(ID value)
Object addAttribute(String key, Object value)
void setSearchOption(boolean searchOption)
Collection< String > getMetas()
String stringId(ID value)
boolean isNavigatorBottom()
abstract void renderSummary(ElephantMarker marker, E e, int page)
void setNavigatorBottom(boolean navigatorBottom)
void setFullTemplate(String fullTemplate)
String renderTreeSelection()
abstract String title(E e)
void setForceSummary(boolean forceSummary)
abstract Collection< String > metas(E e)
static String logMsg(String msg)
HTMLGenerator endAllTags()
IConstructor getConstructor()
Object put(Object key, Object value)
static KeyValueMap getObfuscatedParameters()
String getParameter(String param)