001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsOrgUnitsSubList.java,v $
003: * Date : $Date: 2008-02-27 12:05:27 $
004: * Version: $Revision: 1.7 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.tools.accounts;
033:
034: import org.opencms.jsp.CmsJspActionElement;
035: import org.opencms.main.CmsException;
036: import org.opencms.main.OpenCms;
037: import org.opencms.security.CmsOrganizationalUnit;
038: import org.opencms.security.CmsRole;
039: import org.opencms.workplace.CmsDialog;
040: import org.opencms.workplace.list.CmsListItem;
041:
042: import java.util.ArrayList;
043: import java.util.HashMap;
044: import java.util.Iterator;
045: import java.util.List;
046: import java.util.Map;
047:
048: import javax.servlet.http.HttpServletRequest;
049: import javax.servlet.http.HttpServletResponse;
050: import javax.servlet.jsp.PageContext;
051:
052: /**
053: * Sub organization units list.<p>
054: *
055: * @author Raphael Schnuck
056: *
057: * @version $Revision: 1.7 $
058: *
059: * @since 6.5.6
060: */
061: public class CmsOrgUnitsSubList extends A_CmsOrgUnitsList {
062:
063: /** list id constant. */
064: public static final String LIST_ID = "lsous";
065:
066: /** Stores the value of the request parameter for the user id. */
067: private String m_paramOufqn;
068:
069: /**
070: * Public constructor.<p>
071: *
072: * @param jsp an initialized JSP action element
073: */
074: public CmsOrgUnitsSubList(CmsJspActionElement jsp) {
075:
076: super (jsp, LIST_ID, Messages.get().container(
077: Messages.GUI_SUBORGUNITS_LIST_NAME_0));
078: }
079:
080: /**
081: * Public constructor with JSP variables.<p>
082: *
083: * @param context the JSP page context
084: * @param req the JSP request
085: * @param res the JSP response
086: */
087: public CmsOrgUnitsSubList(PageContext context,
088: HttpServletRequest req, HttpServletResponse res) {
089:
090: this (new CmsJspActionElement(context, req, res));
091: }
092:
093: /**
094: * Deletes the given organizational unit.<p>
095: *
096: * @throws Exception if something goes wrong
097: */
098: public void actionDelete() throws Exception {
099:
100: OpenCms.getOrgUnitManager().deleteOrganizationalUnit(getCms(),
101: getParamOufqn());
102: actionCloseDialog();
103: }
104:
105: /**
106: * Deletes the given organizational unit.<p>
107: *
108: * @throws Exception if something goes wrong
109: */
110: public void actionParent() throws Exception {
111:
112: String ouFqn = CmsOrganizationalUnit
113: .getParentFqn(getParamOufqn());
114:
115: Map params = new HashMap();
116: params.put(A_CmsOrgUnitDialog.PARAM_OUFQN, ouFqn);
117: params.put(CmsDialog.PARAM_ACTION, CmsDialog.DIALOG_INITIAL);
118: String toolPath = getCurrentToolPath().substring(0,
119: getCurrentToolPath().lastIndexOf("/"));
120: getToolManager().jspForwardTool(this , toolPath, params);
121: actionCloseDialog();
122: }
123:
124: /**
125: *
126: * @see org.opencms.workplace.list.A_CmsListDialog#defaultActionHtml()
127: */
128: public String defaultActionHtml() {
129:
130: if ((getList() != null) && getList().getAllContent().isEmpty()) {
131: // TODO: check the need for this
132: refreshList();
133: }
134: StringBuffer result = new StringBuffer(2048);
135: result.append(defaultActionHtmlStart());
136: result.append(customHtmlStart());
137: try {
138: if (hasSubOUs()) {
139: result.append(defaultActionHtmlContent());
140: }
141: } catch (CmsException e) {
142: // noop
143: }
144: result.append(customHtmlEnd());
145: result.append(defaultActionHtmlEnd());
146: return result.toString();
147: }
148:
149: /**
150: * Returns the organizational unit fqn parameter value.<p>
151: *
152: * @return the organizational unit fqn parameter value
153: */
154: public String getParamOufqn() {
155:
156: return m_paramOufqn;
157: }
158:
159: /**
160: * Checks if the user has more then one organizational unit to administrate.<p>
161: *
162: * @return true if the user has more then then one organizational unit to administrate
163: * otherwise false
164: * @throws CmsException if the organizational units can not be read
165: */
166: public boolean hasSubOUs() throws CmsException {
167:
168: List orgUnits = OpenCms.getOrgUnitManager()
169: .getOrganizationalUnits(getCms(), m_paramOufqn, true);
170: if (orgUnits == null) {
171: return false;
172: }
173: if (orgUnits.size() < 1) {
174: return false;
175: }
176: return true;
177: }
178:
179: /**
180: * Sets the organizational unit fqn parameter value.<p>
181: *
182: * @param ouFqn the organizational unit fqn parameter value
183: */
184: public void setParamOufqn(String ouFqn) {
185:
186: if (ouFqn == null) {
187: ouFqn = "";
188: }
189: m_paramOufqn = ouFqn;
190: }
191:
192: /**
193: * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
194: */
195: protected List getListItems() throws CmsException {
196:
197: List ret = new ArrayList();
198: List orgUnits = OpenCms.getOrgUnitManager()
199: .getOrganizationalUnits(getCms(), m_paramOufqn, true);
200: Iterator itOrgUnits = orgUnits.iterator();
201: while (itOrgUnits.hasNext()) {
202: CmsOrganizationalUnit childOrgUnit = (CmsOrganizationalUnit) itOrgUnits
203: .next();
204: CmsListItem item = getList()
205: .newItem(childOrgUnit.getName());
206: item.set(LIST_COLUMN_NAME, CmsOrganizationalUnit.SEPARATOR
207: + childOrgUnit.getName());
208: item.set(LIST_COLUMN_DESCRIPTION, childOrgUnit
209: .getDescription(getLocale()));
210: item.set(LIST_COLUMN_ADMIN, Boolean
211: .valueOf(OpenCms.getRoleManager()
212: .hasRole(
213: getCms(),
214: CmsRole.ADMINISTRATOR
215: .forOrgUnit(childOrgUnit
216: .getName()))));
217: item.set(LIST_COLUMN_WEBUSER, Boolean.valueOf(childOrgUnit
218: .hasFlagWebuser()));
219: ret.add(item);
220: }
221: return ret;
222: }
223:
224: /**
225: * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters()
226: */
227: protected void validateParamaters() throws Exception {
228:
229: // test the needed parameters
230: OpenCms.getRoleManager().checkRole(getCms(),
231: CmsRole.ACCOUNT_MANAGER.forOrgUnit(getParamOufqn()));
232: OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(),
233: m_paramOufqn).getName();
234: }
235: }
|