1 31 32 package org.opencms.jsp.util; 33 34 import org.opencms.file.types.I_CmsResourceType; 35 import org.opencms.i18n.CmsMessages; 36 import org.opencms.jsp.CmsJspActionElement; 37 import org.opencms.main.OpenCms; 38 import org.opencms.util.CmsMacroResolver; 39 import org.opencms.util.CmsStringUtil; 40 41 import java.util.HashMap ; 42 import java.util.List ; 43 import java.util.Map ; 44 45 import javax.servlet.jsp.JspException ; 46 47 58 public class CmsTemplateContentListItem { 59 60 int todo = 0; 62 63 64 public static final String DISPLAYAREA_CENTER = "center"; 65 66 67 public static final String DISPLAYAREA_LEFT = "left"; 68 69 70 public static final String DISPLAYAREA_RIGHT = "right"; 71 72 73 public static final String [] DISPLAYAREAS = {DISPLAYAREA_CENTER, DISPLAYAREA_LEFT, DISPLAYAREA_RIGHT}; 74 75 76 public static final String LISTVARIATION_LONG = "long"; 77 78 79 public static final String LISTVARIATION_SHORT = "short"; 80 81 82 public static final String [] LISTVARIATIONS = {"", '.' + LISTVARIATION_LONG, '.' + LISTVARIATION_SHORT}; 83 84 85 public static final String MACRO_LISTINDEX = "index"; 86 87 88 public static final String MACRO_MICROSITEFOLDER = "microsite.folder"; 89 90 91 public static final String PARAM_COLLECTOR = "collector"; 92 93 94 public static final String PARAM_COUNT = "count"; 95 96 97 public static final String PARAM_ELEMENTCOUNT = "elementcount"; 98 99 100 public static final String PARAM_FOLDER = "folder"; 101 102 103 public static final String PARAM_LISTELEMENT = "listelement"; 104 105 106 public static final String PROPERTY_LAYOUT_COLLECTOR = "layout.${" + MACRO_LISTINDEX + "}." + PARAM_COLLECTOR; 107 108 109 public static final String PROPERTY_LAYOUT_COUNT = "layout.${" + MACRO_LISTINDEX + "}." + PARAM_COUNT; 110 111 112 public static final String PROPERTY_LAYOUT_FOLDER = "layout.${" + MACRO_LISTINDEX + "}." + PARAM_FOLDER; 113 114 115 public static final String PROPERTY_LAYOUT_TYPE = "layout.${" + MACRO_LISTINDEX + "}.type"; 116 117 118 public static final String PROPERTY_LAYOUT_VARIATION = "layout.${" + MACRO_LISTINDEX + "}.variation"; 119 120 121 public static final String PROPERTY_VALUE_NONE = "none"; 122 123 private String m_collector; 124 private int m_count; 125 private String m_displayArea; 126 private String m_folder; 127 private String m_listElement; 128 private String m_type; 129 private String m_variation; 130 131 138 public static Map getDefaultValuesFromMessages(CmsMessages messages) { 139 140 HashMap result = new HashMap (); 141 List resTypes = OpenCms.getResourceManager().getResourceTypes(); 142 143 for (int i = 0; i < resTypes.size(); i++) { 144 I_CmsResourceType type = (I_CmsResourceType)resTypes.get(i); 145 if (type.isAdditionalModuleResourceType()) { 146 for (int k = 0; k < DISPLAYAREAS.length; k++) { 148 String area = DISPLAYAREAS[k]; 150 String typeName = type.getTypeName(); 151 StringBuffer keyPrefix = new StringBuffer (8); 152 keyPrefix.append("layout.").append(typeName).append('.').append(area).append('.'); 153 String key = keyPrefix + PARAM_COLLECTOR; 155 String value = messages.key(key); 156 if (CmsStringUtil.isEmptyOrWhitespaceOnly(value) 157 || value.startsWith(CmsMessages.UNKNOWN_KEY_EXTENSION)) { 158 continue; 160 } 161 result.put(key, value); 162 key = keyPrefix + PARAM_COUNT; 164 result.put(key, messages.key(key)); 165 key = keyPrefix + PARAM_FOLDER; 167 result.put(key, messages.key(key)); 168 for (int m = 0; m < LISTVARIATIONS.length; m++) { 170 key = keyPrefix + PARAM_LISTELEMENT + LISTVARIATIONS[m]; 171 value = messages.key(key); 172 if (!value.startsWith(CmsMessages.UNKNOWN_KEY_EXTENSION)) { 173 result.put(key, value); 174 } 175 } 176 } 177 } 178 } 179 return result; 180 } 181 182 195 public static CmsTemplateContentListItem newInstance( 196 Map defaultValues, 197 Map properties, 198 String microSiteFolder, 199 String displayArea, 200 int index) { 201 202 CmsMacroResolver resolver = CmsMacroResolver.newInstance(); 204 resolver.addMacro(MACRO_LISTINDEX, Integer.toString(index)); 205 resolver.addMacro(MACRO_MICROSITEFOLDER, microSiteFolder); 206 207 String type = (String )properties.get(resolver.resolveMacros(PROPERTY_LAYOUT_TYPE)); 209 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(type) && !PROPERTY_VALUE_NONE.equals(type)) { 210 CmsTemplateContentListItem listItem = new CmsTemplateContentListItem(); 212 listItem.setType(type); 213 StringBuffer keyPrefix = new StringBuffer (8); 215 keyPrefix.append("layout.").append(type).append('.').append(displayArea).append('.'); 216 String collector = (String )properties.get(resolver.resolveMacros(PROPERTY_LAYOUT_COLLECTOR)); 218 if (CmsStringUtil.isEmptyOrWhitespaceOnly(collector)) { 219 collector = (String )defaultValues.get(keyPrefix + PARAM_COLLECTOR); 220 } 221 listItem.setCollector(collector); 222 String count = (String )properties.get(resolver.resolveMacros(PROPERTY_LAYOUT_COUNT)); 224 String defaultCount = (String )defaultValues.get(keyPrefix + PARAM_COUNT); 225 if (CmsStringUtil.isEmptyOrWhitespaceOnly(count)) { 226 count = defaultCount; 227 } 228 try { 229 listItem.setCount(Integer.parseInt(count)); 230 } catch (NumberFormatException e) { 231 listItem.setCount(Integer.parseInt(defaultCount)); 233 } 234 String folder = (String )properties.get(resolver.resolveMacros(PROPERTY_LAYOUT_FOLDER)); 236 if (CmsStringUtil.isEmptyOrWhitespaceOnly(folder)) { 237 folder = (String )defaultValues.get(keyPrefix + PARAM_FOLDER); 238 } 239 listItem.setFolder(resolver.resolveMacros(folder)); 240 String variation = (String )properties.get(resolver.resolveMacros(PROPERTY_LAYOUT_VARIATION)); 242 if (CmsStringUtil.isEmptyOrWhitespaceOnly(variation)) { 243 variation = ""; 244 } else { 245 variation = '.' + variation; 246 } 247 String listElement = (String )defaultValues.get(keyPrefix + PARAM_LISTELEMENT + variation); 249 listItem.setListElement(listElement); 250 listItem.setDisplayArea(displayArea); 252 return listItem; 253 } else { 254 return null; 256 } 257 } 258 259 264 public String getCollector() { 265 266 return m_collector; 267 } 268 269 274 public int getCount() { 275 276 return m_count; 277 } 278 279 284 public String getDisplayArea() { 285 286 return m_displayArea; 287 } 288 289 294 public String getFolder() { 295 296 return m_folder; 297 } 298 299 304 public String getListElement() { 305 306 return m_listElement; 307 } 308 309 314 public String getType() { 315 316 return m_type; 317 } 318 319 324 public String getVariation() { 325 326 return m_variation; 327 } 328 329 337 public void includeListItem(CmsJspActionElement jsp, boolean showPageLinks) throws JspException { 338 339 Map properties = new HashMap (4); 340 properties.put(PARAM_COLLECTOR, getCollector()); 341 properties.put(PARAM_COUNT, Integer.toString(getCount())); 342 if (showPageLinks) { 343 properties.put(PARAM_ELEMENTCOUNT, Integer.toString(Integer.MAX_VALUE)); 344 } else { 345 properties.put(PARAM_ELEMENTCOUNT, Integer.toString(getCount())); 346 } 347 properties.put(PARAM_FOLDER, getFolder()); 348 jsp.include(getListElement(), null, properties); 349 } 350 351 356 protected void setCollector(String collector) { 357 358 m_collector = collector; 359 } 360 361 366 protected void setCount(int count) { 367 368 m_count = count; 369 } 370 371 376 protected void setDisplayArea(String displayArea) { 377 378 m_displayArea = displayArea; 379 } 380 381 386 protected void setFolder(String contentFolder) { 387 388 m_folder = contentFolder; 389 } 390 391 396 protected void setListElement(String listElement) { 397 398 m_listElement = listElement; 399 } 400 401 406 protected void setType(String type) { 407 408 m_type = type; 409 } 410 411 416 protected void setVariation(String variation) { 417 418 m_variation = variation; 419 } 420 } | Popular Tags |