001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/A_CmsOrgUnitDialog.java,v $
003: * Date : $Date: 2008-02-27 12:05:26 $
004: * Version: $Revision: 1.6 $
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.util.CmsStringUtil;
039: import org.opencms.workplace.CmsDialog;
040: import org.opencms.workplace.CmsWidgetDialog;
041: import org.opencms.workplace.CmsWorkplaceSettings;
042:
043: import java.util.ArrayList;
044: import java.util.Iterator;
045: import java.util.List;
046:
047: import javax.servlet.http.HttpServletRequest;
048: import javax.servlet.http.HttpServletResponse;
049: import javax.servlet.jsp.PageContext;
050:
051: /**
052: * Dialog to edit new or existing organizational unit in the administration view.<p>
053: *
054: * @author Raphael Schnuck
055: *
056: * @version $Revision: 1.6 $
057: *
058: * @since 6.5.6
059: */
060: public abstract class A_CmsOrgUnitDialog extends CmsWidgetDialog {
061:
062: /** localized messages Keys prefix. */
063: public static final String KEY_PREFIX = "orgunit";
064:
065: /** Defines which pages are valid for this dialog. */
066: public static final String[] PAGES = { "page1" };
067:
068: /** Request parameter name for the organizational unit fqn. */
069: public static final String PARAM_OUFQN = "oufqn";
070:
071: /** The organizational unit bean object to work with in this dialog. */
072: protected CmsOrgUnitBean m_orgUnitBean;
073:
074: /** Stores the value of the request parameter for the organizational unit fqn. */
075: private String m_paramOufqn;
076:
077: /**
078: * Public constructor with JSP action element.<p>
079: *
080: * @param jsp an initialized JSP action element
081: */
082: public A_CmsOrgUnitDialog(CmsJspActionElement jsp) {
083:
084: super (jsp);
085: }
086:
087: /**
088: * Public constructor with JSP variables.<p>
089: *
090: * @param context the JSP page context
091: * @param req the JSP request
092: * @param res the JSP response
093: */
094: public A_CmsOrgUnitDialog(PageContext context,
095: HttpServletRequest req, HttpServletResponse res) {
096:
097: this (new CmsJspActionElement(context, req, res));
098: }
099:
100: /**
101: * Returns the organizational unit fqn parameter value.<p>
102: *
103: * @return the organizational unit fqn parameter value
104: */
105: public String getParamOufqn() {
106:
107: return m_paramOufqn;
108: }
109:
110: /**
111: * Sets the organizational unit fqn parameter value.<p>
112: *
113: * @param ouFqn the organizational unit fqn parameter value
114: */
115: public void setParamOufqn(String ouFqn) {
116:
117: if (ouFqn == null) {
118: ouFqn = "";
119: }
120: m_paramOufqn = ouFqn;
121: }
122:
123: /**
124: * Sets the resources for the given orgUnitBean.<p>
125: *
126: * @param orgUnitBean the <code>CmsOrgUnitBean</code> object
127: * @param resources the list of resources
128: */
129: public void setResourcesInBean(CmsOrgUnitBean orgUnitBean,
130: List resources) {
131:
132: List resourceNames = new ArrayList();
133: Iterator itResources = resources.iterator();
134: while (itResources.hasNext()) {
135: CmsResource resource = (CmsResource) itResources.next();
136: resourceNames.add(getCms().getSitePath(resource));
137: }
138: orgUnitBean.setResources(resourceNames);
139: }
140:
141: /**
142: *
143: * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
144: */
145: protected void defineWidgets() {
146:
147: initOrgUnitObject();
148: setKeyPrefix(KEY_PREFIX);
149: }
150:
151: /**
152: * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
153: */
154: protected String[] getPageArray() {
155:
156: return PAGES;
157: }
158:
159: /**
160: * Initializes the organizational unit object to work with depending
161: * on the dialog state and request parameters.<p>
162: */
163: protected void initOrgUnitObject() {
164:
165: try {
166: if (CmsStringUtil.isEmpty(getParamAction())
167: || CmsDialog.DIALOG_INITIAL
168: .equals(getParamAction())) {
169: // edit an existing ou, get the ou object from database
170: CmsOrganizationalUnit orgunit = OpenCms
171: .getOrgUnitManager().readOrganizationalUnit(
172: getCms(), getParamOufqn());
173: m_orgUnitBean = new CmsOrgUnitBean();
174: if (!isNewOrgUnit()) {
175: m_orgUnitBean.setName(orgunit.getName());
176: m_orgUnitBean.setDescription(orgunit
177: .getDescription(getLocale()));
178: m_orgUnitBean.setParentOu(orgunit.getParentFqn());
179: m_orgUnitBean.setFqn(orgunit.getName());
180: m_orgUnitBean
181: .setNologin(orgunit.hasFlagHideLogin());
182: m_orgUnitBean.setWebusers(orgunit.hasFlagWebuser());
183: if (orgunit.getParentFqn() != null) {
184: m_orgUnitBean.setParentOuDesc(OpenCms
185: .getOrgUnitManager()
186: .readOrganizationalUnit(getCms(),
187: orgunit.getParentFqn())
188: .getDescription(getLocale())
189: + " ("
190: + CmsOrganizationalUnit.SEPARATOR
191: + orgunit.getParentFqn() + ")");
192: }
193: } else {
194: m_orgUnitBean.setParentOu(orgunit.getName());
195: m_orgUnitBean.setParentOuDesc(orgunit
196: .getDescription(getLocale())
197: + " ("
198: + CmsOrganizationalUnit.SEPARATOR
199: + orgunit.getName() + ")");
200: }
201: List resources = OpenCms.getOrgUnitManager()
202: .getResourcesForOrganizationalUnit(getCms(),
203: orgunit.getName());
204: setResourcesInBean(m_orgUnitBean, resources);
205: } else {
206: // this is not the initial call, get the ou object from session
207: m_orgUnitBean = (CmsOrgUnitBean) getDialogObject();
208: // test
209: m_orgUnitBean.getName();
210: }
211: } catch (Exception e) {
212: // create a new ou object
213: m_orgUnitBean = new CmsOrgUnitBean();
214: m_orgUnitBean.setParentOu(getParamOufqn());
215: }
216: }
217:
218: /**
219: * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
220: */
221: protected void initWorkplaceRequestValues(
222: CmsWorkplaceSettings settings, HttpServletRequest request) {
223:
224: // initialize parameters and dialog actions in super implementation
225: super .initWorkplaceRequestValues(settings, request);
226:
227: // save the current state of the ou (may be changed because of the widget values)
228: setDialogObject(m_orgUnitBean);
229: }
230:
231: /**
232: * Checks if the new organizational unit dialog has to be displayed.<p>
233: *
234: * @return <code>true</code> if the new organizational unit dialog has to be displayed
235: */
236: protected boolean isNewOrgUnit() {
237:
238: return getCurrentToolPath().endsWith("/orgunit/mgmt/new");
239: }
240: }
|