PageRenderTime 51ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src-modules/org/opencms/workplace/tools/cache/CmsImageCacheList.java

http://github.com/alkacon/opencms-core
Java | 326 lines | 177 code | 47 blank | 102 comment | 8 complexity | 949891067abe31fbb1b03d9298fa3f20 MD5 | raw file
Possible License(s): MIT, Apache-2.0, BSD-3-Clause, LGPL-2.1
  1. /*
  2. * This library is part of OpenCms -
  3. * the Open Source Content Management System
  4. *
  5. * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * For further information about Alkacon Software GmbH & Co. KG, please see the
  18. * company website: http://www.alkacon.com
  19. *
  20. * For further information about OpenCms, please see the
  21. * project website: http://www.opencms.org
  22. *
  23. * You should have received a copy of the GNU Lesser General Public
  24. * License along with this library; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. */
  27. package org.opencms.workplace.tools.cache;
  28. import org.opencms.jsp.CmsJspActionElement;
  29. import org.opencms.main.CmsRuntimeException;
  30. import org.opencms.ui.apps.cacheadmin.CmsImageCacheHelper;
  31. import org.opencms.workplace.list.A_CmsListDialog;
  32. import org.opencms.workplace.list.CmsListColumnAlignEnum;
  33. import org.opencms.workplace.list.CmsListColumnDefinition;
  34. import org.opencms.workplace.list.CmsListDefaultAction;
  35. import org.opencms.workplace.list.CmsListDirectAction;
  36. import org.opencms.workplace.list.CmsListItem;
  37. import org.opencms.workplace.list.CmsListItemDetails;
  38. import org.opencms.workplace.list.CmsListItemDetailsFormatter;
  39. import org.opencms.workplace.list.CmsListMetadata;
  40. import org.opencms.workplace.list.CmsListOpenResourceAction;
  41. import org.opencms.workplace.list.CmsListOrderEnum;
  42. import java.util.ArrayList;
  43. import java.util.Iterator;
  44. import java.util.List;
  45. import javax.servlet.http.HttpServletRequest;
  46. import javax.servlet.http.HttpServletResponse;
  47. import javax.servlet.jsp.PageContext;
  48. /**
  49. * Image Cache content view.<p>
  50. *
  51. * @since 7.0.5
  52. */
  53. public class CmsImageCacheList extends A_CmsListDialog {
  54. /** list action id constant. */
  55. public static final String LIST_ACTION_ICON = "ai";
  56. /** list column id constant. */
  57. public static final String LIST_COLUMN_ICON = "ci";
  58. /** list column id constant. */
  59. public static final String LIST_COLUMN_LENGTH = "cl";
  60. /** list column id constant. */
  61. public static final String LIST_COLUMN_RESOURCE = "cr";
  62. /** list column id constant. */
  63. public static final String LIST_COLUMN_SIZE = "cs";
  64. /** List default action id constant. */
  65. public static final String LIST_DEFACTION_OPEN = "edo";
  66. /** list item detail id constant. */
  67. public static final String LIST_DETAIL_SIZE = "ds";
  68. /** list item detail id constant. */
  69. public static final String LIST_DETAIL_VARIATIONS = "dv";
  70. /** list id constant. */
  71. public static final String LIST_ID = "lfc";
  72. /**
  73. * Public constructor.<p>
  74. *
  75. * @param jsp an initialized JSP action element
  76. */
  77. public CmsImageCacheList(CmsJspActionElement jsp) {
  78. super(
  79. jsp,
  80. LIST_ID,
  81. Messages.get().container(Messages.GUI_IMAGECACHE_LIST_NAME_0),
  82. LIST_COLUMN_RESOURCE,
  83. CmsListOrderEnum.ORDER_ASCENDING,
  84. LIST_COLUMN_RESOURCE);
  85. }
  86. /**
  87. * Public constructor with JSP variables.<p>
  88. *
  89. * @param context the JSP page context
  90. * @param req the JSP request
  91. * @param res the JSP response
  92. */
  93. public CmsImageCacheList(PageContext context, HttpServletRequest req, HttpServletResponse res) {
  94. this(new CmsJspActionElement(context, req, res));
  95. }
  96. /**
  97. * @see org.opencms.workplace.list.A_CmsListDialog#defaultActionHtmlStart()
  98. */
  99. @Override
  100. public String defaultActionHtmlStart() {
  101. return getList().listJs() + dialogContentStart(getParamTitle());
  102. }
  103. /**
  104. * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
  105. */
  106. @Override
  107. public void executeListMultiActions() throws CmsRuntimeException {
  108. throwListUnsupportedActionException();
  109. }
  110. /**
  111. * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
  112. */
  113. @Override
  114. public void executeListSingleActions() {
  115. throwListUnsupportedActionException();
  116. }
  117. /**
  118. * Checks if the image size should be shown or not.<p>
  119. *
  120. * @return <code>true</code> if the image size should be shown
  121. */
  122. public boolean showSize() {
  123. CmsListItemDetails details = getList().getMetadata().getItemDetailDefinition(LIST_DETAIL_SIZE);
  124. return (details != null) && details.isVisible();
  125. }
  126. /**
  127. * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
  128. */
  129. @Override
  130. protected void fillDetails(String detailId) {
  131. // get content
  132. CmsImageCacheHelper helper = new CmsImageCacheHelper(getCms(), true, showSize(), false);
  133. List entries = getList().getAllContent();
  134. Iterator itEntries = entries.iterator();
  135. while (itEntries.hasNext()) {
  136. CmsListItem item = (CmsListItem)itEntries.next();
  137. String resName = item.getId();
  138. StringBuffer html = new StringBuffer(512);
  139. try {
  140. // variations
  141. Iterator itVariations = helper.getVariations(resName).iterator();
  142. while (itVariations.hasNext()) {
  143. String var = (String)itVariations.next();
  144. html.append(var);
  145. if (itVariations.hasNext()) {
  146. html.append("<br>");
  147. }
  148. html.append("\n");
  149. }
  150. } catch (Exception e) {
  151. // ignore
  152. }
  153. item.set(LIST_DETAIL_VARIATIONS, html.toString());
  154. }
  155. }
  156. /**
  157. * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
  158. */
  159. @Override
  160. protected List getListItems() {
  161. List ret = new ArrayList();
  162. boolean showSize = showSize();
  163. getList().getMetadata().getColumnDefinition(LIST_COLUMN_SIZE).setVisible(showSize);
  164. String width = "80%";
  165. if (showSize) {
  166. width = "60%";
  167. }
  168. getList().getMetadata().getColumnDefinition(LIST_COLUMN_RESOURCE).setWidth(width);
  169. // get content
  170. CmsImageCacheHelper helper = new CmsImageCacheHelper(getCms(), false, showSize, false);
  171. Iterator itResources = helper.getAllCachedImages().iterator();
  172. while (itResources.hasNext()) {
  173. String resource = (String)itResources.next();
  174. CmsListItem item = getList().newItem(resource);
  175. String resName = resource;
  176. item.set(LIST_COLUMN_RESOURCE, resName);
  177. if (showSize) {
  178. item.set(LIST_COLUMN_SIZE, helper.getSize(resName));
  179. }
  180. item.set(LIST_COLUMN_LENGTH, helper.getLength(resName));
  181. ret.add(item);
  182. }
  183. return ret;
  184. }
  185. /**
  186. * @see org.opencms.workplace.CmsWorkplace#initMessages()
  187. */
  188. @Override
  189. protected void initMessages() {
  190. // add specific dialog resource bundle
  191. addMessages(Messages.get().getBundleName());
  192. // add default resource bundles
  193. super.initMessages();
  194. }
  195. /**
  196. * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
  197. */
  198. @Override
  199. protected void setColumns(CmsListMetadata metadata) {
  200. // create column for icon display
  201. CmsListColumnDefinition iconCol = new CmsListColumnDefinition(LIST_COLUMN_ICON);
  202. iconCol.setName(Messages.get().container(Messages.GUI_IMAGECACHE_LIST_COLS_ICON_0));
  203. iconCol.setWidth("20");
  204. iconCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
  205. iconCol.setSorteable(false);
  206. CmsListDirectAction iconAction = new CmsListDirectAction(LIST_ACTION_ICON);
  207. iconAction.setName(Messages.get().container(Messages.GUI_IMAGECACHE_LIST_ACTION_ICON_NAME_0));
  208. iconAction.setIconPath("tools/cache/buttons/imageentry.png");
  209. iconAction.setEnabled(false);
  210. iconCol.addDirectAction(iconAction);
  211. // add it to the list definition
  212. metadata.addColumn(iconCol);
  213. // create column for resource name
  214. CmsListColumnDefinition nameCol = new CmsListColumnDefinition(LIST_COLUMN_RESOURCE);
  215. nameCol.setName(Messages.get().container(Messages.GUI_IMAGECACHE_LIST_COLS_RESOURCE_0));
  216. nameCol.setWidth("60%");
  217. // add resource open action
  218. CmsListDefaultAction resourceOpenDefAction = new CmsListOpenResourceAction(
  219. LIST_DEFACTION_OPEN,
  220. LIST_COLUMN_RESOURCE);
  221. resourceOpenDefAction.setEnabled(true);
  222. nameCol.addDefaultAction(resourceOpenDefAction);
  223. // add it to the list definition
  224. metadata.addColumn(nameCol);
  225. // create column for size
  226. CmsListColumnDefinition sizeCol = new CmsListColumnDefinition(LIST_COLUMN_SIZE);
  227. sizeCol.setName(Messages.get().container(Messages.GUI_IMAGECACHE_LIST_COLS_SIZE_0));
  228. sizeCol.setWidth("20%");
  229. // add it to the list definition
  230. metadata.addColumn(sizeCol);
  231. // create column for length
  232. CmsListColumnDefinition lengthCol = new CmsListColumnDefinition(LIST_COLUMN_LENGTH);
  233. lengthCol.setName(Messages.get().container(Messages.GUI_IMAGECACHE_LIST_COLS_LENGTH_0));
  234. lengthCol.setWidth("20%");
  235. // add it to the list definition
  236. metadata.addColumn(lengthCol);
  237. }
  238. /**
  239. * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
  240. */
  241. @Override
  242. protected void setIndependentActions(CmsListMetadata metadata) {
  243. // add variations details
  244. CmsListItemDetails variationsDetails = new CmsListItemDetails(LIST_DETAIL_VARIATIONS);
  245. variationsDetails.setAtColumn(LIST_COLUMN_RESOURCE);
  246. variationsDetails.setVisible(false);
  247. variationsDetails.setShowActionName(
  248. Messages.get().container(Messages.GUI_IMAGECACHE_DETAIL_SHOW_VARIATIONS_NAME_0));
  249. variationsDetails.setShowActionHelpText(
  250. Messages.get().container(Messages.GUI_IMAGECACHE_DETAIL_SHOW_VARIATIONS_HELP_0));
  251. variationsDetails.setHideActionName(
  252. Messages.get().container(Messages.GUI_IMAGECACHE_DETAIL_HIDE_VARIATIONS_NAME_0));
  253. variationsDetails.setHideActionHelpText(
  254. Messages.get().container(Messages.GUI_IMAGECACHE_DETAIL_HIDE_VARIATIONS_HELP_0));
  255. variationsDetails.setName(Messages.get().container(Messages.GUI_IMAGECACHE_DETAIL_VARIATIONS_NAME_0));
  256. variationsDetails.setFormatter(
  257. new CmsListItemDetailsFormatter(
  258. Messages.get().container(Messages.GUI_IMAGECACHE_DETAIL_VARIATIONS_NAME_0)));
  259. metadata.addItemDetails(variationsDetails);
  260. // add size details
  261. CmsListItemDetails sizeDetails = new CmsListItemDetails(LIST_DETAIL_SIZE);
  262. sizeDetails.setShowActionName(Messages.get().container(Messages.GUI_IMAGECACHE_DETAIL_SHOW_SIZE_NAME_0));
  263. sizeDetails.setShowActionHelpText(Messages.get().container(Messages.GUI_IMAGECACHE_DETAIL_SHOW_SIZE_HELP_0));
  264. sizeDetails.setHideActionName(Messages.get().container(Messages.GUI_IMAGECACHE_DETAIL_HIDE_SIZE_NAME_0));
  265. sizeDetails.setHideActionHelpText(Messages.get().container(Messages.GUI_IMAGECACHE_DETAIL_HIDE_SIZE_HELP_0));
  266. sizeDetails.setName(Messages.get().container(Messages.GUI_IMAGECACHE_DETAIL_SIZE_NAME_0));
  267. sizeDetails.setFormatter(
  268. new CmsListItemDetailsFormatter(Messages.get().container(Messages.GUI_IMAGECACHE_DETAIL_SIZE_NAME_0)));
  269. sizeDetails.setVisible(false);
  270. metadata.addItemDetails(sizeDetails);
  271. }
  272. /**
  273. * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
  274. */
  275. @Override
  276. protected void setMultiActions(CmsListMetadata metadata) {
  277. // no multi actions
  278. }
  279. }