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.accounts;
029
030import org.opencms.db.CmsUserSettings;
031import org.opencms.file.CmsResource;
032import org.opencms.jsp.CmsJspActionElement;
033import org.opencms.main.CmsException;
034import org.opencms.main.OpenCms;
035import org.opencms.workplace.list.A_CmsListExplorerDialog;
036import org.opencms.workplace.list.CmsListIndependentAction;
037import org.opencms.workplace.list.CmsListItem;
038import org.opencms.workplace.list.CmsListMetadata;
039import org.opencms.workplace.list.I_CmsListResourceCollector;
040
041import java.util.ArrayList;
042import java.util.Collections;
043import java.util.List;
044
045/**
046 * List for org unit resources.<p>
047 *
048 * @since 6.5.4
049 */
050public class CmsShowOrgUnitResourceList extends A_CmsListExplorerDialog {
051
052    /** list id constant. */
053    public static final String LIST_ID = "our";
054
055    /** The internal collector instance. */
056    private I_CmsListResourceCollector m_collector;
057
058    /** Stores the value of the request parameter for the user id. */
059    private String m_paramOufqn;
060
061    /**
062     * Public constructor.<p>
063     *
064     * @param jsp an initialized JSP action element
065     */
066    public CmsShowOrgUnitResourceList(CmsJspActionElement jsp) {
067
068        super(jsp, LIST_ID, Messages.get().container(Messages.GUI_ORGUNIT_RESOURCES_LIST_NAME_0));
069        List<CmsResource> resourceList;
070        try {
071            resourceList = OpenCms.getOrgUnitManager().getResourcesForOrganizationalUnit(getCms(), getParamOufqn());
072        } catch (CmsException e) {
073            resourceList = new ArrayList<CmsResource>();
074        }
075        Collections.sort(resourceList);
076        m_collector = new CmsShowOrgUnitResourcesCollector(this, resourceList);
077        getList().getMetadata().getIndependentAction(CmsListIndependentAction.ACTION_EXPLORER_SWITCH_ID).setVisible(
078            false);
079    }
080
081    /**
082     * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
083     */
084    @Override
085    public void executeListMultiActions() {
086
087        throwListUnsupportedActionException();
088    }
089
090    /**
091     * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
092     */
093    @Override
094    public void executeListSingleActions() {
095
096        throwListUnsupportedActionException();
097    }
098
099    /**
100     * @see org.opencms.workplace.list.A_CmsListExplorerDialog#getCollector()
101     */
102    @Override
103    public I_CmsListResourceCollector getCollector() {
104
105        return m_collector;
106    }
107
108    /**
109     * Returns the organizational unit fqn parameter value.<p>
110     *
111     * @return the organizational unit fqn parameter value
112     */
113    public String getParamOufqn() {
114
115        return m_paramOufqn;
116    }
117
118    /**
119     * Sets the organizational unit fqn parameter value.<p>
120     *
121     * @param ouFqn the organizational unit fqn parameter value
122     */
123    public void setParamOufqn(String ouFqn) {
124
125        if (ouFqn == null) {
126            ouFqn = "";
127        }
128        m_paramOufqn = ouFqn;
129    }
130
131    /**
132     * @see org.opencms.workplace.list.A_CmsListDialog#defaultActionHtmlStart()
133     */
134    @Override
135    protected String defaultActionHtmlStart() {
136
137        return getList().listJs() + dialogContentStart(getParamTitle());
138    }
139
140    /**
141     * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
142     */
143    @Override
144    protected void fillDetails(String detailId) {
145
146        // no op
147    }
148
149    /**
150     * @see org.opencms.workplace.list.A_CmsListExplorerDialog#getListItems()
151     */
152    @Override
153    protected List<CmsListItem> getListItems() throws CmsException {
154
155        String storedSiteRoot = getCms().getRequestContext().getSiteRoot();
156        try {
157            getCms().getRequestContext().setSiteRoot("");
158            return super.getListItems();
159        } finally {
160            getCms().getRequestContext().setSiteRoot(storedSiteRoot);
161        }
162    }
163
164    /**
165     * @see org.opencms.workplace.list.A_CmsListExplorerDialog#isColumnVisible(int)
166     */
167    @Override
168    protected boolean isColumnVisible(int colFlag) {
169
170        boolean isVisible = (colFlag == CmsUserSettings.FILELIST_TITLE);
171        isVisible = isVisible || (colFlag == LIST_COLUMN_TYPEICON.hashCode());
172        isVisible = isVisible || (colFlag == LIST_COLUMN_LOCKICON.hashCode());
173        isVisible = isVisible || (colFlag == LIST_COLUMN_PROJSTATEICON.hashCode());
174        isVisible = isVisible || (colFlag == LIST_COLUMN_NAME.hashCode());
175        return isVisible;
176    }
177
178    /**
179     * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
180     */
181    @Override
182    protected void setMultiActions(CmsListMetadata metadata) {
183
184        // no LMAs, and remove default search action
185        metadata.setSearchAction(null);
186    }
187}