001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.workplace.tools.searchindex.sourcesearch; 029 030import org.opencms.file.CmsProject; 031import org.opencms.file.CmsResource; 032import org.opencms.jsp.CmsJspActionElement; 033import org.opencms.main.CmsException; 034import org.opencms.util.CmsUUID; 035import org.opencms.workplace.explorer.CmsResourceUtil; 036import org.opencms.workplace.list.A_CmsListExplorerDialog; 037import org.opencms.workplace.list.CmsHtmlList; 038import org.opencms.workplace.list.CmsListColumnDefinition; 039import org.opencms.workplace.list.CmsListItem; 040import org.opencms.workplace.list.CmsListMetadata; 041import org.opencms.workplace.list.I_CmsListResourceCollector; 042 043import java.util.ArrayList; 044import java.util.Collection; 045import java.util.Date; 046import java.util.Iterator; 047import java.util.List; 048 049import javax.servlet.http.HttpServletRequest; 050import javax.servlet.http.HttpServletResponse; 051import javax.servlet.jsp.PageContext; 052 053/** 054 * Explorer dialog for the content search result list.<p> 055 * 056 * @since 7.5.3 057 */ 058public class CmsSourceSearchFilesDialog extends A_CmsListExplorerDialog { 059 060 /** list column id constant. */ 061 public static final String LIST_COLUMN_FILES = "cf"; 062 063 /** list independent action constant. */ 064 public static final String LIST_IACTION_FILTER = "iaf"; 065 066 /** list id constant. */ 067 public static final String LIST_ID = "lcs"; 068 069 /** The internal collector instance. */ 070 private I_CmsListResourceCollector m_collector; 071 072 /** The content sraech file list. */ 073 private Collection<CmsResource> m_files; 074 075 /** Stores the value of the request parameter for the project id. */ 076 private String m_paramProjectid; 077 078 /** 079 * Public constructor with JSP action element.<p> 080 * 081 * @param jsp an initialized JSP action element 082 */ 083 public CmsSourceSearchFilesDialog(CmsJspActionElement jsp) { 084 085 super(jsp, LIST_ID, Messages.get().container(Messages.GUI_SOURCESEARCH_FILES_LIST_NAME_0)); 086 } 087 088 /** 089 * Public constructor with JSP variables.<p> 090 * 091 * @param context the JSP page context 092 * @param req the JSP request 093 * @param res the JSP response 094 */ 095 public CmsSourceSearchFilesDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) { 096 097 this(new CmsJspActionElement(context, req, res)); 098 } 099 100 /** 101 * @see org.opencms.workplace.list.A_CmsListDialog#executeListIndepActions() 102 */ 103 @Override 104 public void executeListIndepActions() { 105 106 if (getParamListAction().equals(LIST_IACTION_FILTER)) { 107 // forward to the editor 108 getList().setCurrentPage(1); 109 m_collector = null; 110 refreshList(); 111 } else { 112 super.executeListIndepActions(); 113 } 114 } 115 116 /** 117 * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions() 118 */ 119 @Override 120 public void executeListMultiActions() { 121 122 throwListUnsupportedActionException(); 123 } 124 125 /** 126 * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions() 127 */ 128 @Override 129 public void executeListSingleActions() { 130 131 throwListUnsupportedActionException(); 132 } 133 134 /** 135 * @see org.opencms.workplace.list.A_CmsListExplorerDialog#getCollector() 136 */ 137 @Override 138 public I_CmsListResourceCollector getCollector() { 139 140 m_collector = new CmsSourceSearchCollector(this); 141 return m_collector; 142 } 143 144 /** 145 * Gets the content search result list.<p> 146 * 147 * @return the content search result list 148 */ 149 public Collection<CmsResource> getFiles() { 150 151 return m_files; 152 } 153 154 /** 155 * @see org.opencms.workplace.list.A_CmsListDialog#getList() 156 */ 157 @Override 158 public CmsHtmlList getList() { 159 160 return super.getList(); 161 } 162 163 /** 164 * Returns the project id parameter value.<p> 165 * 166 * @return the project id parameter value 167 */ 168 public String getParamProjectid() { 169 170 return m_paramProjectid; 171 } 172 173 /** 174 * Returns an appropiate initialized resource util object for the given item.<p> 175 * 176 * @param item the item representing the resource 177 * 178 * @return a resource util object 179 */ 180 @Override 181 public CmsResourceUtil getResourceUtil(CmsListItem item) { 182 183 CmsResourceUtil resUtil = getResourceUtil(); 184 resUtil.setResource(getCollector().getResource(getCms(), item)); 185 return resUtil; 186 } 187 188 /** 189 * @see org.opencms.workplace.list.A_CmsListDialog#refreshList() 190 */ 191 @Override 192 public synchronized void refreshList() { 193 194 if (LIST_IACTION_FILTER.equals(getParamListAction())) { 195 if (m_collector != null) { 196 // refresh only if really necessary 197 return; 198 } 199 } 200 super.refreshList(); 201 } 202 203 /** Sets the content search result list. 204 * 205 * @param files the found files 206 */ 207 public void seFiles(Collection<CmsResource> files) { 208 209 m_files = files; 210 } 211 212 /** 213 * Sets the project id parameter value.<p> 214 * 215 * @param projectId the project id parameter value 216 */ 217 public void setParamProjectid(String projectId) { 218 219 m_paramProjectid = projectId; 220 } 221 222 /** 223 * Returns a list item created from the resource information, differs between valid resources and invalid resources.<p> 224 * 225 * @param resource the resource to create the list item from 226 * @param list the list 227 * @param showPermissions if to show permissions 228 * @param showDateLastMod if to show the last modification date 229 * @param showUserLastMod if to show the last modification user 230 * @param showDateCreate if to show the creation date 231 * @param showUserCreate if to show the creation date 232 * @param showDateRel if to show the date released 233 * @param showDateExp if to show the date expired 234 * @param showState if to show the state 235 * @param showLockedBy if to show the lock user 236 * @param showSite if to show the site 237 * 238 * @return a list item created from the resource information 239 */ 240 protected CmsListItem createResourceListItem( 241 CmsResource resource, 242 CmsHtmlList list, 243 boolean showPermissions, 244 boolean showDateLastMod, 245 boolean showUserLastMod, 246 boolean showDateCreate, 247 boolean showUserCreate, 248 boolean showDateRel, 249 boolean showDateExp, 250 boolean showState, 251 boolean showLockedBy, 252 boolean showSite) { 253 254 CmsListItem item = list.newItem(resource.getStructureId().toString()); 255 // get an initialized resource utility 256 CmsResourceUtil resUtil = getResourceUtil(); 257 resUtil.setResource(resource); 258 item.set(A_CmsListExplorerDialog.LIST_COLUMN_NAME, resUtil.getPath()); 259 item.set(A_CmsListExplorerDialog.LIST_COLUMN_ROOT_PATH, resUtil.getFullPath()); 260 item.set(A_CmsListExplorerDialog.LIST_COLUMN_TITLE, resUtil.getTitle()); 261 item.set(A_CmsListExplorerDialog.LIST_COLUMN_TYPE, resUtil.getResourceTypeName()); 262 item.set(A_CmsListExplorerDialog.LIST_COLUMN_SIZE, resUtil.getSizeString()); 263 if (showPermissions) { 264 item.set(A_CmsListExplorerDialog.LIST_COLUMN_PERMISSIONS, resUtil.getPermissionString()); 265 } 266 if (showDateLastMod) { 267 item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATELASTMOD, new Date(resource.getDateLastModified())); 268 } 269 if (showUserLastMod) { 270 item.set(A_CmsListExplorerDialog.LIST_COLUMN_USERLASTMOD, resUtil.getUserLastModified()); 271 } 272 if (showDateCreate) { 273 item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATECREATE, new Date(resource.getDateCreated())); 274 } 275 if (showUserCreate) { 276 item.set(A_CmsListExplorerDialog.LIST_COLUMN_USERCREATE, resUtil.getUserCreated()); 277 } 278 if (showDateRel) { 279 item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATEREL, new Date(resource.getDateReleased())); 280 } 281 if (showDateExp) { 282 item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATEEXP, new Date(resource.getDateExpired())); 283 } 284 if (showState) { 285 item.set(A_CmsListExplorerDialog.LIST_COLUMN_STATE, resUtil.getStateName()); 286 } 287 if (showLockedBy) { 288 item.set(A_CmsListExplorerDialog.LIST_COLUMN_LOCKEDBY, resUtil.getLockedByName()); 289 } 290 if (showSite) { 291 item.set(A_CmsListExplorerDialog.LIST_COLUMN_SITE, resUtil.getSiteTitle()); 292 } 293 return item; 294 } 295 296 /** 297 * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String) 298 */ 299 @Override 300 protected void fillDetails(String detailId) { 301 302 // no-details 303 } 304 305 /** 306 * Returns a list of list items from a list of resources.<p> 307 * 308 * @return a list of {@link CmsListItem} objects 309 */ 310 @Override 311 protected List<CmsListItem> getListItems() { 312 313 List<CmsListItem> ret = new ArrayList<CmsListItem>(); 314 applyColumnVisibilities(); 315 CmsHtmlList list = getList(); 316 317 CmsListColumnDefinition colPermissions = list.getMetadata().getColumnDefinition( 318 A_CmsListExplorerDialog.LIST_COLUMN_PERMISSIONS); 319 boolean showPermissions = (colPermissions.isVisible() || colPermissions.isPrintable()); 320 CmsListColumnDefinition colDateLastMod = list.getMetadata().getColumnDefinition( 321 A_CmsListExplorerDialog.LIST_COLUMN_DATELASTMOD); 322 boolean showDateLastMod = (colDateLastMod.isVisible() || colDateLastMod.isPrintable()); 323 CmsListColumnDefinition colUserLastMod = list.getMetadata().getColumnDefinition( 324 A_CmsListExplorerDialog.LIST_COLUMN_USERLASTMOD); 325 boolean showUserLastMod = (colUserLastMod.isVisible() || colUserLastMod.isPrintable()); 326 CmsListColumnDefinition colDateCreate = list.getMetadata().getColumnDefinition( 327 A_CmsListExplorerDialog.LIST_COLUMN_DATECREATE); 328 boolean showDateCreate = (colDateCreate.isVisible() || colDateCreate.isPrintable()); 329 CmsListColumnDefinition colUserCreate = list.getMetadata().getColumnDefinition( 330 A_CmsListExplorerDialog.LIST_COLUMN_USERCREATE); 331 boolean showUserCreate = (colUserCreate.isVisible() || colUserCreate.isPrintable()); 332 CmsListColumnDefinition colDateRel = list.getMetadata().getColumnDefinition( 333 A_CmsListExplorerDialog.LIST_COLUMN_DATEREL); 334 boolean showDateRel = (colDateRel.isVisible() || colDateRel.isPrintable()); 335 CmsListColumnDefinition colDateExp = list.getMetadata().getColumnDefinition( 336 A_CmsListExplorerDialog.LIST_COLUMN_DATEEXP); 337 boolean showDateExp = (colDateExp.isVisible() || colDateExp.isPrintable()); 338 CmsListColumnDefinition colState = list.getMetadata().getColumnDefinition( 339 A_CmsListExplorerDialog.LIST_COLUMN_STATE); 340 boolean showState = (colState.isVisible() || colState.isPrintable()); 341 CmsListColumnDefinition colLockedBy = list.getMetadata().getColumnDefinition( 342 A_CmsListExplorerDialog.LIST_COLUMN_LOCKEDBY); 343 boolean showLockedBy = (colLockedBy.isVisible() || colLockedBy.isPrintable()); 344 CmsListColumnDefinition colSite = list.getMetadata().getColumnDefinition( 345 A_CmsListExplorerDialog.LIST_COLUMN_SITE); 346 boolean showSite = (colSite.isVisible() || colSite.isPrintable()); 347 348 // get content 349 Iterator<CmsResource> itRes = m_files.iterator(); 350 while (itRes.hasNext()) { 351 352 CmsResource resource = itRes.next(); 353 354 CmsListItem item = createResourceListItem( 355 resource, 356 list, 357 showPermissions, 358 showDateLastMod, 359 showUserLastMod, 360 showDateCreate, 361 showUserCreate, 362 showDateRel, 363 showDateExp, 364 showState, 365 showLockedBy, 366 showSite); 367 368 ret.add(item); 369 } 370 return ret; 371 } 372 373 /** 374 * @see org.opencms.workplace.list.A_CmsListExplorerDialog#getProject() 375 */ 376 @Override 377 protected CmsProject getProject() { 378 379 CmsUUID projectId = new CmsUUID(getParamProjectid()); 380 try { 381 return getCms().readProject(projectId); 382 } catch (CmsException e) { 383 return super.getProject(); 384 } 385 } 386 387 /** 388 * @see org.opencms.workplace.CmsWorkplace#initMessages() 389 */ 390 @Override 391 protected void initMessages() { 392 393 // add specific dialog resource bundle 394 addMessages(Messages.get().getBundleName()); 395 // add default resource bundles 396 super.initMessages(); 397 } 398 399 /** 400 * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata) 401 */ 402 @Override 403 protected void setIndependentActions(CmsListMetadata metadata) { 404 405 super.setIndependentActions(metadata); 406 407 } 408 409 /** 410 * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata) 411 */ 412 @Override 413 protected void setMultiActions(CmsListMetadata metadata) { 414 415 // no LMAs 416 } 417 418 /** 419 * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters() 420 */ 421 @Override 422 protected void validateParamaters() throws Exception { 423 424 try { 425 getCms().readProject(new CmsUUID(getParamProjectid())); 426 } catch (Exception e) { 427 m_paramProjectid = getCms().getRequestContext().getCurrentProject().getUuid().toString(); 428 } 429 430 } 431}