001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsOrgUnitEditDialog.java,v $
003: * Date : $Date: 2008-02-27 12:05:26 $
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.file.CmsResource;
035: import org.opencms.jsp.CmsJspActionElement;
036: import org.opencms.main.OpenCms;
037: import org.opencms.security.CmsOrganizationalUnit;
038: import org.opencms.security.CmsRole;
039: import org.opencms.util.CmsFileUtil;
040: import org.opencms.widgets.CmsCheckboxWidget;
041: import org.opencms.widgets.CmsDisplayWidget;
042: import org.opencms.widgets.CmsInputWidget;
043: import org.opencms.widgets.CmsTextareaWidget;
044: import org.opencms.widgets.CmsVfsFileWidget;
045: import org.opencms.workplace.CmsWidgetDialogParameter;
046:
047: import java.util.ArrayList;
048: import java.util.Iterator;
049: import java.util.List;
050:
051: import javax.servlet.http.HttpServletRequest;
052: import javax.servlet.http.HttpServletResponse;
053: import javax.servlet.jsp.PageContext;
054:
055: /**
056: * Dialog to edit new or existing organizational unit in the administration view.<p>
057: *
058: * @author Raphael Schnuck
059: *
060: * @version $Revision: 1.7 $
061: *
062: * @since 6.5.6
063: */
064: public class CmsOrgUnitEditDialog extends A_CmsOrgUnitDialog {
065:
066: /** Request parameter name for the sub organizational unit fqn. */
067: public static final String PARAM_SUBOUFQN = "suboufqn";
068:
069: /**
070: * Public constructor with JSP action element.<p>
071: *
072: * @param jsp an initialized JSP action element
073: */
074: public CmsOrgUnitEditDialog(CmsJspActionElement jsp) {
075:
076: super (jsp);
077: }
078:
079: /**
080: * Public constructor with JSP variables.<p>
081: *
082: * @param context the JSP page context
083: * @param req the JSP request
084: * @param res the JSP response
085: */
086: public CmsOrgUnitEditDialog(PageContext context,
087: HttpServletRequest req, HttpServletResponse res) {
088:
089: this (new CmsJspActionElement(context, req, res));
090: }
091:
092: /**
093: * @see org.opencms.workplace.CmsWidgetDialog#actionCommit()
094: */
095: public void actionCommit() {
096:
097: List errors = new ArrayList();
098:
099: try {
100: // if new create it first
101: if (isNewOrgUnit()) {
102: List resourceNames = CmsFileUtil
103: .removeRedundancies(m_orgUnitBean
104: .getResources());
105: CmsOrganizationalUnit newOrgUnit = OpenCms
106: .getOrgUnitManager()
107: .createOrganizationalUnit(
108: getCms(),
109: m_orgUnitBean.getFqn(),
110: m_orgUnitBean.getDescription(),
111: m_orgUnitBean.getFlags(),
112: resourceNames.isEmpty() ? null
113: : (String) resourceNames.get(0));
114:
115: if (!resourceNames.isEmpty()) {
116: resourceNames.remove(0);
117: Iterator itResourceNames = CmsFileUtil
118: .removeRedundancies(resourceNames)
119: .iterator();
120: while (itResourceNames.hasNext()) {
121: OpenCms
122: .getOrgUnitManager()
123: .addResourceToOrgUnit(getCms(),
124: newOrgUnit.getName(),
125: (String) itResourceNames.next());
126: }
127: }
128: } else {
129: CmsOrganizationalUnit orgunit = OpenCms
130: .getOrgUnitManager().readOrganizationalUnit(
131: getCms(), m_orgUnitBean.getFqn());
132: orgunit.setDescription(m_orgUnitBean.getDescription());
133: orgunit.setFlags(m_orgUnitBean.getFlags());
134: List resourceNamesNew = CmsFileUtil
135: .removeRedundancies(m_orgUnitBean
136: .getResources());
137: List resourcesOld = OpenCms.getOrgUnitManager()
138: .getResourcesForOrganizationalUnit(getCms(),
139: orgunit.getName());
140: List resourceNamesOld = new ArrayList();
141: Iterator itResourcesOld = resourcesOld.iterator();
142: while (itResourcesOld.hasNext()) {
143: CmsResource resourceOld = (CmsResource) itResourcesOld
144: .next();
145: resourceNamesOld.add(getCms().getSitePath(
146: resourceOld));
147: }
148: Iterator itResourceNamesNew = resourceNamesNew
149: .iterator();
150: // add new resources to ou
151: while (itResourceNamesNew.hasNext()) {
152: String resourceNameNew = (String) itResourceNamesNew
153: .next();
154: if (!resourceNamesOld.contains(resourceNameNew)) {
155: OpenCms.getOrgUnitManager()
156: .addResourceToOrgUnit(getCms(),
157: orgunit.getName(),
158: resourceNameNew);
159: }
160: }
161: Iterator itResourceNamesOld = resourceNamesOld
162: .iterator();
163: // delete old resources from ou
164: while (itResourceNamesOld.hasNext()) {
165: String resourceNameOld = (String) itResourceNamesOld
166: .next();
167: if (!resourceNamesNew.contains(resourceNameOld)) {
168: OpenCms.getOrgUnitManager()
169: .removeResourceFromOrgUnit(getCms(),
170: orgunit.getName(),
171: resourceNameOld);
172: }
173: }
174: // write the edited organizational unit
175: OpenCms.getOrgUnitManager().writeOrganizationalUnit(
176: getCms(), orgunit);
177: }
178: } catch (Throwable t) {
179: errors.add(t);
180: }
181:
182: // set the list of errors to display when saving failed
183: setCommitErrors(errors);
184: }
185:
186: /**
187: * @see org.opencms.workplace.CmsWidgetDialog#createDialogHtml(java.lang.String)
188: */
189: protected String createDialogHtml(String dialog) {
190:
191: StringBuffer result = new StringBuffer(1024);
192:
193: result.append(createWidgetTableStart());
194: // show error header once if there were validation errors
195: result.append(createWidgetErrorHeader());
196:
197: if (dialog.equals(PAGES[0])) {
198: // create the widgets for the first dialog page
199: result
200: .append(dialogBlockStart(key(Messages.GUI_ORGUNIT_EDITOR_LABEL_IDENTIFICATION_BLOCK_0)));
201: result.append(createWidgetTableStart());
202: result.append(createDialogRowsHtml(0, 2));
203: result.append(createWidgetTableEnd());
204: result.append(dialogBlockEnd());
205: result
206: .append(dialogBlockStart(key(Messages.GUI_ORGUNIT_EDITOR_LABEL_FLAGS_BLOCK_0)));
207: result.append(createWidgetTableStart());
208: result.append(createDialogRowsHtml(3, 4));
209: result.append(createWidgetTableEnd());
210: result
211: .append(dialogBlockStart(key(Messages.GUI_ORGUNIT_EDITOR_LABEL_CONTENT_BLOCK_0)));
212: result.append(createWidgetTableStart());
213: result.append(createDialogRowsHtml(5, 5));
214: result.append(createWidgetTableEnd());
215: result.append(dialogBlockEnd());
216: }
217:
218: result.append(createWidgetTableEnd());
219: return result.toString();
220: }
221:
222: /**
223: * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
224: */
225: protected void defineWidgets() {
226:
227: super .defineWidgets();
228:
229: // widgets to display
230: if (isNewOrgUnit()) {
231: addWidget(new CmsWidgetDialogParameter(m_orgUnitBean,
232: "name", PAGES[0], new CmsInputWidget()));
233: } else {
234: addWidget(new CmsWidgetDialogParameter(m_orgUnitBean,
235: "name", PAGES[0], new CmsDisplayWidget()));
236: }
237: addWidget(new CmsWidgetDialogParameter(m_orgUnitBean,
238: "description", PAGES[0], new CmsTextareaWidget()));
239: addWidget(new CmsWidgetDialogParameter(m_orgUnitBean,
240: "parentOuDesc", PAGES[0], new CmsDisplayWidget()));
241:
242: if (isNewOrgUnit()) {
243: addWidget(new CmsWidgetDialogParameter(m_orgUnitBean,
244: "nologin", PAGES[0], new CmsCheckboxWidget()));
245: addWidget(new CmsWidgetDialogParameter(m_orgUnitBean,
246: "webusers", PAGES[0], new CmsCheckboxWidget()));
247: } else {
248: if (m_orgUnitBean.isWebusers()) {
249: addWidget(new CmsWidgetDialogParameter(m_orgUnitBean,
250: "nologin", PAGES[0], new CmsDisplayWidget()));
251: } else {
252: addWidget(new CmsWidgetDialogParameter(m_orgUnitBean,
253: "nologin", PAGES[0], new CmsCheckboxWidget()));
254: }
255: addWidget(new CmsWidgetDialogParameter(m_orgUnitBean,
256: "webusers", PAGES[0], new CmsDisplayWidget()));
257: }
258: addWidget(new CmsWidgetDialogParameter(m_orgUnitBean,
259: "resources", PAGES[0], new CmsVfsFileWidget(false,
260: getCms().getRequestContext().getSiteRoot(),
261: false)));
262: }
263:
264: /**
265: * @see org.opencms.workplace.CmsWidgetDialog#validateParamaters()
266: */
267: protected void validateParamaters() throws Exception {
268:
269: OpenCms.getRoleManager().checkRole(getCms(),
270: CmsRole.ACCOUNT_MANAGER.forOrgUnit(getParamOufqn()));
271: if (!isNewOrgUnit()) {
272: // test the needed parameters
273: OpenCms.getOrgUnitManager().readOrganizationalUnit(
274: getCms(), getParamOufqn()).getName();
275: }
276: }
277: }
|