001: /*
002: * File : $Source: /usr/local/cvs/alkacon/com.alkacon.opencms.newsletter/src/com/alkacon/opencms/newsletter/admin/CmsMailinglistDeleteDialog.java,v $
003: * Date : $Date: 2007-11-30 11:57:27 $
004: * Version: $Revision: 1.6 $
005: *
006: * This file is part of the Alkacon OpenCms Add-On Module Package
007: *
008: * Copyright (c) 2007 Alkacon Software GmbH (http://www.alkacon.com)
009: *
010: * The Alkacon OpenCms Add-On Module Package is free software:
011: * you can redistribute it and/or modify
012: * it under the terms of the GNU General Public License as published by
013: * the Free Software Foundation, either version 3 of the License, or
014: * (at your option) any later version.
015: *
016: * The Alkacon OpenCms Add-On Module Package is distributed
017: * in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with the Alkacon OpenCms Add-On Module Package.
024: * If not, see http://www.gnu.org/licenses/.
025: *
026: * For further information about Alkacon Software GmbH, please see the
027: * company website: http://www.alkacon.com.
028: *
029: * For further information about OpenCms, please see the
030: * project website: http://www.opencms.org.
031: */
032:
033: package com.alkacon.opencms.newsletter.admin;
034:
035: import org.opencms.file.CmsObject;
036: import org.opencms.file.CmsUser;
037: import org.opencms.jsp.CmsJspActionElement;
038: import org.opencms.main.CmsException;
039: import org.opencms.main.CmsRuntimeException;
040: import org.opencms.util.CmsStringUtil;
041: import org.opencms.workplace.list.CmsHtmlList;
042:
043: import java.io.IOException;
044: import java.util.ArrayList;
045: import java.util.Iterator;
046: import java.util.List;
047:
048: import javax.servlet.ServletException;
049: import javax.servlet.http.HttpServletRequest;
050: import javax.servlet.http.HttpServletResponse;
051: import javax.servlet.jsp.JspException;
052: import javax.servlet.jsp.PageContext;
053:
054: /**
055: * Mailing list delete dialog.<p>
056: *
057: * @author Michael Moossen
058: * @author Andreas Zahner
059: *
060: * @version $Revision: 1.6 $
061: *
062: * @since 7.0.3
063: */
064: public class CmsMailinglistDeleteDialog extends
065: org.opencms.workplace.tools.accounts.CmsGroupDependenciesList {
066:
067: /**
068: * Public constructor.<p>
069: *
070: * @param jsp an initialized JSP action element
071: */
072: public CmsMailinglistDeleteDialog(CmsJspActionElement jsp) {
073:
074: super (LIST_ID + "l", jsp);
075: }
076:
077: /**
078: * Public constructor with JSP variables.<p>
079: *
080: * @param context the JSP page context
081: * @param req the JSP request
082: * @param res the JSP response
083: */
084: public CmsMailinglistDeleteDialog(PageContext context,
085: HttpServletRequest req, HttpServletResponse res) {
086:
087: this (new CmsJspActionElement(context, req, res));
088: }
089:
090: /**
091: * @see org.opencms.workplace.list.A_CmsListDialog#actionDialog()
092: */
093: public void actionDialog() throws JspException, ServletException,
094: IOException {
095:
096: switch (getAction()) {
097: case ACTION_DELETE:
098: Iterator it = CmsStringUtil.splitAsList(getGroupName(),
099: CmsHtmlList.ITEM_SEPARATOR, true).iterator();
100: CmsObject cms = getCms();
101: while (it.hasNext()) {
102: String name = (String) it.next();
103: try {
104: List users = cms.getUsersOfGroup(name);
105: cms.deleteGroup(name);
106: Iterator itUsers = users.iterator();
107: while (itUsers.hasNext()) {
108: CmsUser user = (CmsUser) itUsers.next();
109: if (cms.getGroupsOfUser(user.getName(), true)
110: .isEmpty()) {
111: cms.deleteUser(user.getId());
112: }
113: }
114: } catch (CmsException e) {
115: throw new CmsRuntimeException(e
116: .getMessageContainer(), e);
117: }
118: }
119: setAction(ACTION_CANCEL);
120: actionCloseDialog();
121: break;
122: default:
123: super .actionDialog();
124: }
125: }
126:
127: /**
128: * @see org.opencms.workplace.tools.accounts.CmsGroupDependenciesList#customHtmlStart()
129: */
130: protected String customHtmlStart() {
131:
132: StringBuffer result = new StringBuffer(512);
133: result
134: .append(dialogBlockStart(org.opencms.workplace.tools.accounts.Messages
135: .get()
136: .container(
137: org.opencms.workplace.tools.accounts.Messages.GUI_GROUP_DEPENDENCIES_NOTICE_0)
138: .key(getLocale())));
139: result.append(key(Messages.GUI_MAILINGLIST_DELETE_0));
140: result.append(dialogBlockEnd());
141: return result.toString();
142: }
143:
144: /**
145: * @see org.opencms.workplace.tools.accounts.CmsGroupDependenciesList#getListItems()
146: */
147: protected List getListItems() {
148:
149: // the list should never appear
150: return new ArrayList();
151: }
152:
153: /**
154: * @see org.opencms.workplace.CmsWorkplace#initMessages()
155: */
156: protected void initMessages() {
157:
158: // add specific dialog resource bundle
159: addMessages(Messages.get().getBundleName());
160: // add default resource bundles
161: super.initMessages();
162: }
163: }
|