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.list;
029
030import org.opencms.ade.publish.CmsCollectorPublishListHelper;
031import org.opencms.file.CmsObject;
032import org.opencms.file.CmsResource;
033import org.opencms.file.CmsResourceFilter;
034import org.opencms.file.collectors.I_CmsResourceCollector;
035import org.opencms.gwt.shared.CmsGwtConstants;
036import org.opencms.gwt.shared.I_CmsContentLoadCollectorInfo;
037import org.opencms.main.CmsException;
038import org.opencms.main.CmsIllegalStateException;
039import org.opencms.main.CmsLog;
040import org.opencms.main.OpenCms;
041import org.opencms.util.CmsStringUtil;
042import org.opencms.util.CmsUUID;
043import org.opencms.workplace.commons.CmsProgressThread;
044import org.opencms.workplace.explorer.CmsResourceUtil;
045
046import java.util.ArrayList;
047import java.util.Collections;
048import java.util.Date;
049import java.util.HashMap;
050import java.util.Iterator;
051import java.util.List;
052import java.util.Map;
053import java.util.Set;
054
055import org.apache.commons.lang3.math.NumberUtils;
056import org.apache.commons.logging.Log;
057
058import com.google.common.collect.Lists;
059
060/**
061 * Collector to provide {@link CmsResource} objects for a explorer List.<p>
062 *
063 * @since 6.1.0
064 */
065public abstract class A_CmsListResourceCollector implements I_CmsListResourceCollector {
066
067    /** VFS path to use for a dummy resource object. */
068    public static final String VFS_PATH_NONE = "none";
069
070    /** The log object for this class. */
071    private static final Log LOG = CmsLog.getLog(A_CmsListResourceCollector.class);
072
073    /** The collector parameter. */
074    protected String m_collectorParameter;
075
076    /** List item cache. */
077    protected Map<String, CmsListItem> m_liCache = new HashMap<String, CmsListItem>();
078
079    /** Resource cache. */
080    protected Map<String, CmsResource> m_resCache = new HashMap<String, CmsResource>();
081
082    /** Cache for resource list result. */
083    protected List<CmsResource> m_resources;
084
085    /** The workplace object where the collector is used from. */
086    private A_CmsListExplorerDialog m_wp;
087
088    /**
089     * Constructor, creates a new list collector.<p>
090     *
091     * @param wp the workplace object where the collector is used from
092     */
093    protected A_CmsListResourceCollector(A_CmsListExplorerDialog wp) {
094
095        m_wp = wp;
096        CmsListState state = (wp != null ? wp.getListStateForCollector() : new CmsListState());
097        if (state.getPage() < 1) {
098            state.setPage(1);
099        }
100        if (CmsStringUtil.isEmptyOrWhitespaceOnly(state.getColumn())) {
101            state.setColumn(A_CmsListExplorerDialog.LIST_COLUMN_NAME);
102        }
103        if (state.getOrder() == null) {
104            state.setOrder(CmsListOrderEnum.ORDER_ASCENDING);
105        }
106        if (state.getFilter() == null) {
107            state.setFilter("");
108        }
109        m_collectorParameter = I_CmsListResourceCollector.PARAM_PAGE
110            + I_CmsListResourceCollector.SEP_KEYVAL
111            + state.getPage();
112        m_collectorParameter += I_CmsListResourceCollector.SEP_PARAM
113            + I_CmsListResourceCollector.PARAM_SORTBY
114            + I_CmsListResourceCollector.SEP_KEYVAL
115            + state.getColumn();
116        m_collectorParameter += I_CmsListResourceCollector.SEP_PARAM
117            + I_CmsListResourceCollector.PARAM_ORDER
118            + I_CmsListResourceCollector.SEP_KEYVAL
119            + state.getOrder();
120        m_collectorParameter += I_CmsListResourceCollector.SEP_PARAM
121            + I_CmsListResourceCollector.PARAM_FILTER
122            + I_CmsListResourceCollector.SEP_KEYVAL
123            + state.getFilter();
124    }
125
126    /**
127     * @see java.lang.Comparable#compareTo(java.lang.Object)
128     */
129    public int compareTo(I_CmsResourceCollector arg0) {
130
131        return 0;
132    }
133
134    /**
135     * @see org.opencms.file.collectors.I_CmsResourceCollector#getCreateLink(org.opencms.file.CmsObject)
136     */
137    public String getCreateLink(CmsObject cms) {
138
139        return null;
140    }
141
142    /**
143     * @see org.opencms.file.collectors.I_CmsResourceCollector#getCreateLink(org.opencms.file.CmsObject, java.lang.String, java.lang.String)
144     */
145    public String getCreateLink(CmsObject cms, String collectorName, String param) {
146
147        return null;
148    }
149
150    /**
151     * @see org.opencms.file.collectors.I_CmsResourceCollector#getCreateParam(org.opencms.file.CmsObject)
152     */
153    public String getCreateParam(CmsObject cms) {
154
155        return null;
156    }
157
158    /**
159     * @see org.opencms.file.collectors.I_CmsResourceCollector#getCreateParam(org.opencms.file.CmsObject, java.lang.String, java.lang.String)
160     */
161    public String getCreateParam(CmsObject cms, String collectorName, String param) {
162
163        return null;
164    }
165
166    /**
167     * @see org.opencms.file.collectors.I_CmsResourceCollector#getCreateTypeId(org.opencms.file.CmsObject, java.lang.String, java.lang.String)
168     */
169    public int getCreateTypeId(CmsObject cms, String collectorName, String param) {
170
171        return -1;
172    }
173
174    /**
175     * @see org.opencms.file.collectors.I_CmsResourceCollector#getDefaultCollectorName()
176     */
177    public String getDefaultCollectorName() {
178
179        return getCollectorNames().get(0);
180    }
181
182    /**
183     * @see org.opencms.file.collectors.I_CmsResourceCollector#getDefaultCollectorParam()
184     */
185    public String getDefaultCollectorParam() {
186
187        return m_collectorParameter;
188    }
189
190    /**
191     * Returns a list of list items from a list of resources.<p>
192     *
193     * @param parameter the collector parameter or <code>null</code> for default.<p>
194     *
195     * @return a list of {@link CmsListItem} objects
196     *
197     * @throws CmsException if something goes wrong
198     */
199    public List<CmsListItem> getListItems(String parameter) throws CmsException {
200
201        synchronized (this) {
202            if (parameter == null) {
203                parameter = m_collectorParameter;
204            }
205            Map<String, String> params = CmsStringUtil.splitAsMap(
206                parameter,
207                I_CmsListResourceCollector.SEP_PARAM,
208                I_CmsListResourceCollector.SEP_KEYVAL);
209            CmsListState state = getState(params);
210            List<CmsResource> resources = getInternalResources(getWp().getCms(), params);
211            List<CmsListItem> ret = new ArrayList<CmsListItem>();
212            if (LOG.isDebugEnabled()) {
213                LOG.debug(
214                    Messages.get().getBundle().key(
215                        Messages.LOG_COLLECTOR_PROCESS_ITEMS_START_1,
216                        new Integer(resources.size())));
217            }
218            getWp().applyColumnVisibilities();
219            CmsHtmlList list = getWp().getList();
220
221            // check if progress should be set in the thread
222            CmsProgressThread thread = null;
223            int progressOffset = 0;
224            if (Thread.currentThread() instanceof CmsProgressThread) {
225                thread = (CmsProgressThread)Thread.currentThread();
226                progressOffset = thread.getProgress();
227            }
228
229            CmsListColumnDefinition colPermissions = list.getMetadata().getColumnDefinition(
230                A_CmsListExplorerDialog.LIST_COLUMN_PERMISSIONS);
231            boolean showPermissions = (colPermissions.isVisible() || colPermissions.isPrintable());
232            CmsListColumnDefinition colDateLastMod = list.getMetadata().getColumnDefinition(
233                A_CmsListExplorerDialog.LIST_COLUMN_DATELASTMOD);
234            boolean showDateLastMod = (colDateLastMod.isVisible() || colDateLastMod.isPrintable());
235            CmsListColumnDefinition colUserLastMod = list.getMetadata().getColumnDefinition(
236                A_CmsListExplorerDialog.LIST_COLUMN_USERLASTMOD);
237            boolean showUserLastMod = (colUserLastMod.isVisible() || colUserLastMod.isPrintable());
238            CmsListColumnDefinition colDateCreate = list.getMetadata().getColumnDefinition(
239                A_CmsListExplorerDialog.LIST_COLUMN_DATECREATE);
240            boolean showDateCreate = (colDateCreate.isVisible() || colDateCreate.isPrintable());
241            CmsListColumnDefinition colUserCreate = list.getMetadata().getColumnDefinition(
242                A_CmsListExplorerDialog.LIST_COLUMN_USERCREATE);
243            boolean showUserCreate = (colUserCreate.isVisible() || colUserCreate.isPrintable());
244            CmsListColumnDefinition colDateRel = list.getMetadata().getColumnDefinition(
245                A_CmsListExplorerDialog.LIST_COLUMN_DATEREL);
246            boolean showDateRel = (colDateRel.isVisible() || colDateRel.isPrintable());
247            CmsListColumnDefinition colDateExp = list.getMetadata().getColumnDefinition(
248                A_CmsListExplorerDialog.LIST_COLUMN_DATEEXP);
249            boolean showDateExp = (colDateExp.isVisible() || colDateExp.isPrintable());
250            CmsListColumnDefinition colState = list.getMetadata().getColumnDefinition(
251                A_CmsListExplorerDialog.LIST_COLUMN_STATE);
252            boolean showState = (colState.isVisible() || colState.isPrintable());
253            CmsListColumnDefinition colLockedBy = list.getMetadata().getColumnDefinition(
254                A_CmsListExplorerDialog.LIST_COLUMN_LOCKEDBY);
255            boolean showLockedBy = (colLockedBy.isVisible() || colLockedBy.isPrintable());
256            CmsListColumnDefinition colSite = list.getMetadata().getColumnDefinition(
257                A_CmsListExplorerDialog.LIST_COLUMN_SITE);
258            boolean showSite = (colSite.isVisible() || colSite.isPrintable());
259
260            // get content
261            Iterator<CmsResource> itRes = resources.iterator();
262            int count = 0;
263            while (itRes.hasNext()) {
264                // set progress in thread
265                if (thread != null) {
266                    count++;
267                    if (thread.isInterrupted()) {
268                        throw new CmsIllegalStateException(
269                            org.opencms.workplace.commons.Messages.get().container(
270                                org.opencms.workplace.commons.Messages.ERR_PROGRESS_INTERRUPTED_0));
271                    }
272                    thread.setProgress(((count * 40) / resources.size()) + progressOffset);
273                    thread.setDescription(
274                        org.opencms.workplace.commons.Messages.get().getBundle(thread.getLocale()).key(
275                            org.opencms.workplace.commons.Messages.GUI_PROGRESS_PUBLISH_STEP2_2,
276                            new Integer(count),
277                            new Integer(resources.size())));
278                }
279
280                Object obj = itRes.next();
281                if (!(obj instanceof CmsResource)) {
282                    ret.add(getDummyListItem(list));
283                    continue;
284                }
285                CmsResource resource = (CmsResource)obj;
286                CmsListItem item = m_liCache.get(resource.getStructureId().toString());
287                if (item == null) {
288                    item = createResourceListItem(
289                        resource,
290                        list,
291                        showPermissions,
292                        showDateLastMod,
293                        showUserLastMod,
294                        showDateCreate,
295                        showUserCreate,
296                        showDateRel,
297                        showDateExp,
298                        showState,
299                        showLockedBy,
300                        showSite);
301                    m_liCache.put(resource.getStructureId().toString(), item);
302                }
303                ret.add(item);
304            }
305            CmsListMetadata metadata = list.getMetadata();
306            if (metadata != null) {
307                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(state.getFilter())) {
308                    // filter
309                    ret = metadata.getSearchAction().filter(ret, state.getFilter());
310                }
311                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(state.getColumn())) {
312                    if ((metadata.getColumnDefinition(state.getColumn()) != null)
313                        && metadata.getColumnDefinition(state.getColumn()).isSorteable()) {
314                        // sort
315                        I_CmsListItemComparator c = metadata.getColumnDefinition(
316                            state.getColumn()).getListItemComparator();
317                        Collections.sort(ret, c.getComparator(state.getColumn(), getWp().getLocale()));
318                        if (state.getOrder().equals(CmsListOrderEnum.ORDER_DESCENDING)) {
319                            Collections.reverse(ret);
320                        }
321                    }
322                }
323            }
324            if (LOG.isDebugEnabled()) {
325                LOG.debug(
326                    Messages.get().getBundle().key(
327                        Messages.LOG_COLLECTOR_PROCESS_ITEMS_END_1,
328                        new Integer(ret.size())));
329            }
330            return ret;
331        }
332    }
333
334    /**
335     * @see org.opencms.file.collectors.I_CmsResourceCollector#getOrder()
336     */
337    public int getOrder() {
338
339        return 0;
340    }
341
342    /**
343     * @see org.opencms.file.collectors.I_CmsCollectorPublishListProvider#getPublishResources(org.opencms.file.CmsObject, org.opencms.gwt.shared.I_CmsContentLoadCollectorInfo)
344     */
345    public Set<CmsResource> getPublishResources(final CmsObject cms, final I_CmsContentLoadCollectorInfo info)
346    throws CmsException {
347
348        int collectorLimit = NumberUtils.toInt(
349            OpenCms.getADEManager().getParameters(cms).get(CmsGwtConstants.COLLECTOR_PUBLISH_LIST_LIMIT),
350            DEFAULT_LIMIT);
351        CmsCollectorPublishListHelper helper = new CmsCollectorPublishListHelper(cms, info, collectorLimit);
352        return helper.getPublishListFiles();
353
354    }
355
356    /**
357     * Returns the resource for the given item.<p>
358     *
359     * @param cms the cms object
360     * @param item the item
361     *
362     * @return the resource
363     */
364    public CmsResource getResource(CmsObject cms, CmsListItem item) {
365
366        CmsResource res = m_resCache.get(item.getId());
367        if (res == null) {
368            CmsUUID id = new CmsUUID(item.getId());
369            if (!id.isNullUUID()) {
370                try {
371                    res = cms.readResource(id, CmsResourceFilter.ALL);
372                    m_resCache.put(item.getId(), res);
373                } catch (CmsException e) {
374                    // should never happen
375                    if (LOG.isErrorEnabled()) {
376                        LOG.error(e.getLocalizedMessage(), e);
377                    }
378                }
379            }
380        }
381        return res;
382    }
383
384    /**
385     * Returns all, unsorted and unfiltered, resources.<p>
386     *
387     * Be sure to cache the resources.<p>
388     *
389     * @param cms the cms object
390     * @param params the parameter map
391     *
392     * @return a list of {@link CmsResource} objects
393     *
394     * @throws CmsException if something goes wrong
395     */
396    public abstract List<CmsResource> getResources(CmsObject cms, Map<String, String> params) throws CmsException;
397
398    /**
399     * @see org.opencms.file.collectors.I_CmsResourceCollector#getResults(org.opencms.file.CmsObject)
400     */
401    public List<CmsResource> getResults(CmsObject cms) throws CmsException {
402
403        return getResults(cms, getDefaultCollectorName(), m_collectorParameter);
404    }
405
406    /**
407     * The parameter must follow the syntax "page:nr" where nr is the number of the page to be displayed.<p>
408     *
409     * @see org.opencms.file.collectors.I_CmsResourceCollector#getResults(org.opencms.file.CmsObject, java.lang.String, java.lang.String)
410     */
411    public List<CmsResource> getResults(CmsObject cms, String collectorName, String parameter) throws CmsException {
412
413        synchronized (this) {
414            if (LOG.isDebugEnabled()) {
415                LOG.debug(Messages.get().getBundle().key(Messages.LOG_COLLECTOR_GET_RESULTS_START_0));
416            }
417            if (parameter == null) {
418                parameter = m_collectorParameter;
419            }
420            List<CmsResource> resources = new ArrayList<CmsResource>();
421            if (getWp().getList() != null) {
422                Iterator<CmsListItem> itItems = getListItems(parameter).iterator();
423                while (itItems.hasNext()) {
424                    CmsListItem item = itItems.next();
425                    resources.add(getResource(cms, item));
426                }
427            } else {
428                Map<String, String> params = CmsStringUtil.splitAsMap(
429                    parameter,
430                    I_CmsListResourceCollector.SEP_PARAM,
431                    I_CmsListResourceCollector.SEP_KEYVAL);
432                resources = getInternalResources(cms, params);
433            }
434            if (LOG.isDebugEnabled()) {
435                LOG.debug(
436                    Messages.get().getBundle().key(
437                        Messages.LOG_COLLECTOR_GET_RESULTS_END_1,
438                        new Integer(resources.size())));
439            }
440            return resources;
441        }
442    }
443
444    /**
445     * @see org.opencms.file.collectors.I_CmsResourceCollector#getResults(org.opencms.file.CmsObject, java.lang.String, java.lang.String, int)
446     */
447    public List<CmsResource> getResults(CmsObject cms, String collectorName, String params, int numResults)
448    throws CmsException {
449
450        List<CmsResource> result = getResults(cms, collectorName, params);
451        if ((numResults > 0) && (result.size() > numResults)) {
452            return Lists.newArrayList(result.subList(0, numResults));
453        }
454
455        return result;
456    }
457
458    /**
459     * Returns the workplace object.<p>
460     *
461     * @return the workplace object
462     */
463    public A_CmsListExplorerDialog getWp() {
464
465        return m_wp;
466    }
467
468    /**
469     * @see org.opencms.file.collectors.I_CmsResourceCollector#setDefaultCollectorName(java.lang.String)
470     */
471    public void setDefaultCollectorName(String collectorName) {
472
473        // ignore
474    }
475
476    /**
477     * The parameter must follow the syntax "mode|projectId" where mode is either "new", "changed", "deleted"
478     * or "modified" and projectId is the id of the project to be displayed.<p>
479     *
480     * @see org.opencms.file.collectors.I_CmsResourceCollector#setDefaultCollectorParam(java.lang.String)
481     */
482    public void setDefaultCollectorParam(String param) {
483
484        m_collectorParameter = param;
485    }
486
487    /**
488     * @see org.opencms.file.collectors.I_CmsResourceCollector#setOrder(int)
489     */
490    public void setOrder(int order) {
491
492        // ignore
493    }
494
495    /**
496     * Sets the current display page.<p>
497     *
498     * @param page the new display page
499     */
500    public void setPage(int page) {
501
502        if (m_collectorParameter != null) {
503            int pos = m_collectorParameter.indexOf(I_CmsListResourceCollector.PARAM_PAGE);
504            if (pos >= 0) {
505                String params = "";
506                int endPos = m_collectorParameter.indexOf(I_CmsListResourceCollector.SEP_PARAM, pos);
507                if (pos > 0) {
508                    pos -= I_CmsListResourceCollector.SEP_PARAM.length(); // remove also the SEP_PARAM
509                    params += m_collectorParameter.substring(0, pos);
510                }
511                if (endPos >= 0) {
512                    if (pos == 0) {
513                        endPos += I_CmsListResourceCollector.SEP_PARAM.length(); // remove also the SEP_PARAM
514                    }
515                    params += m_collectorParameter.substring(endPos, m_collectorParameter.length());
516                }
517                m_collectorParameter = params;
518            }
519        }
520        if (m_collectorParameter == null) {
521            m_collectorParameter = "";
522        } else if (m_collectorParameter.length() > 0) {
523            m_collectorParameter += I_CmsListResourceCollector.SEP_PARAM;
524        }
525        m_collectorParameter += I_CmsListResourceCollector.PARAM_PAGE + I_CmsListResourceCollector.SEP_KEYVAL + page;
526        synchronized (this) {
527            m_resources = null;
528        }
529    }
530
531    /**
532     * Returns a list item created from the resource information, differs between valid resources and invalid resources.<p>
533     *
534     * @param resource the resource to create the list item from
535     * @param list the list
536     * @param showPermissions if to show permissions
537     * @param showDateLastMod if to show the last modification date
538     * @param showUserLastMod if to show the last modification user
539     * @param showDateCreate if to show the creation date
540     * @param showUserCreate if to show the creation date
541     * @param showDateRel if to show the date released
542     * @param showDateExp if to show the date expired
543     * @param showState if to show the state
544     * @param showLockedBy if to show the lock user
545     * @param showSite if to show the site
546     *
547     * @return a list item created from the resource information
548     */
549    protected CmsListItem createResourceListItem(
550        CmsResource resource,
551        CmsHtmlList list,
552        boolean showPermissions,
553        boolean showDateLastMod,
554        boolean showUserLastMod,
555        boolean showDateCreate,
556        boolean showUserCreate,
557        boolean showDateRel,
558        boolean showDateExp,
559        boolean showState,
560        boolean showLockedBy,
561        boolean showSite) {
562
563        CmsListItem item = list.newItem(resource.getStructureId().toString());
564        // get an initialized resource utility
565        CmsResourceUtil resUtil = getWp().getResourceUtil();
566        resUtil.setResource(resource);
567        item.set(A_CmsListExplorerDialog.LIST_COLUMN_NAME, resUtil.getPath());
568        item.set(A_CmsListExplorerDialog.LIST_COLUMN_ROOT_PATH, resUtil.getFullPath());
569        item.set(A_CmsListExplorerDialog.LIST_COLUMN_TITLE, resUtil.getTitle());
570        item.set(A_CmsListExplorerDialog.LIST_COLUMN_TYPE, resUtil.getResourceTypeName());
571        item.set(A_CmsListExplorerDialog.LIST_COLUMN_SIZE, resUtil.getSizeString());
572        if (showPermissions) {
573            item.set(A_CmsListExplorerDialog.LIST_COLUMN_PERMISSIONS, resUtil.getPermissionString());
574        }
575        if (showDateLastMod) {
576            item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATELASTMOD, new Date(resource.getDateLastModified()));
577        }
578        if (showUserLastMod) {
579            item.set(A_CmsListExplorerDialog.LIST_COLUMN_USERLASTMOD, resUtil.getUserLastModified());
580        }
581        if (showDateCreate) {
582            item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATECREATE, new Date(resource.getDateCreated()));
583        }
584        if (showUserCreate) {
585            item.set(A_CmsListExplorerDialog.LIST_COLUMN_USERCREATE, resUtil.getUserCreated());
586        }
587        if (showDateRel) {
588            item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATEREL, new Date(resource.getDateReleased()));
589        }
590        if (showDateExp) {
591            item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATEEXP, new Date(resource.getDateExpired()));
592        }
593        if (showState) {
594            item.set(A_CmsListExplorerDialog.LIST_COLUMN_STATE, resUtil.getStateName());
595        }
596        if (showLockedBy) {
597            item.set(A_CmsListExplorerDialog.LIST_COLUMN_LOCKEDBY, resUtil.getLockedByName());
598        }
599        if (showSite) {
600            item.set(A_CmsListExplorerDialog.LIST_COLUMN_SITE, resUtil.getSiteTitle());
601        }
602        setAdditionalColumns(item, resUtil);
603        return item;
604    }
605
606    /**
607     * Returns a dummy list item.<p>
608     *
609     * @param list the list object to create the entry for
610     *
611     * @return a dummy list item
612     */
613    protected CmsListItem getDummyListItem(CmsHtmlList list) {
614
615        CmsListItem item = list.newItem(CmsUUID.getNullUUID().toString());
616        item.set(A_CmsListExplorerDialog.LIST_COLUMN_NAME, "");
617        item.set(A_CmsListExplorerDialog.LIST_COLUMN_TITLE, "");
618        item.set(A_CmsListExplorerDialog.LIST_COLUMN_TYPE, "");
619        item.set(A_CmsListExplorerDialog.LIST_COLUMN_SIZE, "");
620        item.set(A_CmsListExplorerDialog.LIST_COLUMN_PERMISSIONS, "");
621        item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATELASTMOD, new Date());
622        item.set(A_CmsListExplorerDialog.LIST_COLUMN_USERLASTMOD, "");
623        item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATECREATE, new Date());
624        item.set(A_CmsListExplorerDialog.LIST_COLUMN_USERCREATE, "");
625        item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATEREL, new Date());
626        item.set(A_CmsListExplorerDialog.LIST_COLUMN_DATEEXP, new Date());
627        item.set(A_CmsListExplorerDialog.LIST_COLUMN_STATE, "");
628        item.set(A_CmsListExplorerDialog.LIST_COLUMN_LOCKEDBY, "");
629        return item;
630    }
631
632    /**
633     * Wrapper method for caching the result of {@link #getResources(CmsObject, Map)}.<p>
634     *
635     * @param cms the cms object
636     * @param params the parameter map
637     *
638     * @return the result of {@link #getResources(CmsObject, Map)}
639     *
640     * @throws CmsException if something goes wrong
641     */
642    protected List<CmsResource> getInternalResources(CmsObject cms, Map<String, String> params) throws CmsException {
643
644        synchronized (this) {
645            if (m_resources == null) {
646                m_resources = getResources(cms, params);
647                Iterator<CmsResource> it = m_resources.iterator();
648                while (it.hasNext()) {
649                    CmsResource resource = it.next();
650                    m_resCache.put(resource.getStructureId().toString(), resource);
651                }
652            }
653        }
654        return m_resources;
655    }
656
657    /**
658     * Returns the list of resource names from the parameter map.<p>
659     *
660     * @param params the parameter map
661     *
662     * @return the list of resource names
663     *
664     * @see I_CmsListResourceCollector#PARAM_RESOURCES
665     */
666    protected List<String> getResourceNamesFromParam(Map<String, String> params) {
667
668        String resourcesParam = "/";
669        if (params.containsKey(I_CmsListResourceCollector.PARAM_RESOURCES)) {
670            resourcesParam = params.get(I_CmsListResourceCollector.PARAM_RESOURCES);
671        }
672        if (resourcesParam.length() == 0) {
673            return Collections.emptyList();
674        }
675        return CmsStringUtil.splitAsList(resourcesParam, "#");
676    }
677
678    /**
679     * Returns the state of the parameter map.<p>
680     *
681     * @param params the parameter map
682     *
683     * @return the state of the list from the parameter map
684     */
685    protected CmsListState getState(Map<String, String> params) {
686
687        CmsListState state = new CmsListState();
688        try {
689            state.setPage(Integer.parseInt(params.get(I_CmsListResourceCollector.PARAM_PAGE)));
690        } catch (Throwable e) {
691            // ignore
692        }
693        try {
694            state.setOrder(CmsListOrderEnum.valueOf(params.get(I_CmsListResourceCollector.PARAM_ORDER)));
695        } catch (Throwable e) {
696            // ignore
697        }
698        try {
699            state.setFilter(params.get(I_CmsListResourceCollector.PARAM_FILTER));
700        } catch (Throwable e) {
701            // ignore
702        }
703        try {
704            state.setColumn(params.get(I_CmsListResourceCollector.PARAM_SORTBY));
705        } catch (Throwable e) {
706            // ignore
707        }
708        return state;
709    }
710
711    /**
712     * Set additional column entries for a resource.<p>
713     *
714     * Overwrite this method to set additional column entries.<p>
715     *
716     * @param item the current list item
717     * @param resUtil the resource util object for getting the info from
718     */
719    protected abstract void setAdditionalColumns(CmsListItem item, CmsResourceUtil resUtil);
720
721    /**
722     * Sets the resources parameter.<p>
723     *
724     * @param resources the list of resource names to use
725     */
726    protected void setResourcesParam(List<String> resources) {
727
728        m_collectorParameter += I_CmsListResourceCollector.SEP_PARAM
729            + I_CmsListResourceCollector.PARAM_RESOURCES
730            + I_CmsListResourceCollector.SEP_KEYVAL;
731        if (resources == null) {
732            // search anywhere
733            m_collectorParameter += "/";
734        } else {
735            m_collectorParameter += CmsStringUtil.collectionAsString(resources, "#");
736        }
737    }
738}