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.file.CmsGroup; 031import org.opencms.jsp.CmsJspActionElement; 032import org.opencms.security.CmsRole; 033import org.opencms.util.CmsStringUtil; 034import org.opencms.widgets.CmsGroupWidget; 035import org.opencms.widgets.CmsSelectWidget; 036import org.opencms.workplace.CmsDialog; 037import org.opencms.workplace.CmsWidgetDialogParameter; 038import org.opencms.workplace.CmsWorkplaceSettings; 039import org.opencms.workplace.tools.CmsToolDialog; 040 041import java.io.IOException; 042import java.util.ArrayList; 043import java.util.HashMap; 044import java.util.List; 045import java.util.Map; 046 047import javax.servlet.ServletException; 048import javax.servlet.http.HttpServletRequest; 049import javax.servlet.http.HttpServletResponse; 050import javax.servlet.jsp.PageContext; 051 052/** 053 * Dialog to export user data.<p> 054 * 055 * @since 6.7.1 056 */ 057public class CmsUserDataExportDialog extends A_CmsUserDataImexportDialog { 058 059 /** localized messages Keys prefix. */ 060 public static final String KEY_PREFIX = "userdata.export"; 061 062 /** 063 * Public constructor with JSP action element.<p> 064 * 065 * @param jsp an initialized JSP action element 066 */ 067 public CmsUserDataExportDialog(CmsJspActionElement jsp) { 068 069 super(jsp); 070 } 071 072 /** 073 * Public constructor with JSP variables.<p> 074 * 075 * @param context the JSP page context 076 * @param req the JSP request 077 * @param res the JSP response 078 */ 079 public CmsUserDataExportDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) { 080 081 this(new CmsJspActionElement(context, req, res)); 082 } 083 084 /** 085 * @see org.opencms.workplace.tools.accounts.A_CmsUserDataImexportDialog#actionCommit() 086 */ 087 @Override 088 public void actionCommit() throws IOException, ServletException { 089 090 List<Throwable> errors = new ArrayList<Throwable>(); 091 092 Map<String, String[]> params = new HashMap<String, String[]>(); 093 params.put(A_CmsOrgUnitDialog.PARAM_OUFQN, new String[] {getParamOufqn()}); 094 params.put(CmsDialog.PARAM_CLOSELINK, new String[] {getParamCloseLink()}); 095 params.put(CmsToolDialog.PARAM_STYLE, new String[] {CmsToolDialog.STYLE_NEW}); 096 getToolManager().jspForwardPage(this, getDownloadPath(), params); 097 setCommitErrors(errors); 098 } 099 100 /** 101 * Creates the dialog HTML for all defined widgets of the named dialog (page).<p> 102 * 103 * This overwrites the method from the super class to create a layout variation for the widgets.<p> 104 * 105 * @param dialog the dialog (page) to get the HTML for 106 * @return the dialog HTML for all defined widgets of the named dialog (page) 107 */ 108 @Override 109 protected String createDialogHtml(String dialog) { 110 111 StringBuffer result = new StringBuffer(1024); 112 113 result.append(createWidgetTableStart()); 114 // show error header once if there were validation errors 115 result.append(createWidgetErrorHeader()); 116 117 if (dialog.equals(PAGES[0])) { 118 // create the widgets for the first dialog page 119 result.append(dialogBlockStart(key(Messages.GUI_USERDATA_EXPORT_LABEL_HINT_BLOCK_0))); 120 result.append(key(Messages.GUI_USERDATA_EXPORT_LABEL_HINT_TEXT_0)); 121 result.append(dialogBlockEnd()); 122 result.append(dialogBlockStart(key(Messages.GUI_USERDATA_EXPORT_LABEL_GROUPS_BLOCK_0))); 123 result.append(createWidgetTableStart()); 124 result.append(createDialogRowsHtml(0, 0)); 125 result.append(createWidgetTableEnd()); 126 result.append(dialogBlockEnd()); 127 result.append(dialogBlockStart(key(Messages.GUI_USERDATA_EXPORT_LABEL_ROLES_BLOCK_0))); 128 result.append(createWidgetTableStart()); 129 result.append(createDialogRowsHtml(1, 1)); 130 result.append(createWidgetTableEnd()); 131 result.append(dialogBlockEnd()); 132 } 133 134 result.append(createWidgetTableEnd()); 135 return result.toString(); 136 } 137 138 /** 139 * @see org.opencms.workplace.tools.accounts.A_CmsUserDataImexportDialog#defineWidgets() 140 */ 141 @Override 142 protected void defineWidgets() { 143 144 initExportObject(); 145 setKeyPrefix(KEY_PREFIX); 146 147 addWidget( 148 new CmsWidgetDialogParameter(this, "groups", PAGES[0], new CmsGroupWidget(null, null, getParamOufqn()))); 149 addWidget(new CmsWidgetDialogParameter(this, "roles", PAGES[0], new CmsSelectWidget(getSelectRoles()))); 150 } 151 152 /** 153 * Returns the download path.<p> 154 * 155 * @return the download path 156 */ 157 protected String getDownloadPath() { 158 159 return "/system/workplace/admin/accounts/imexport_user_data/dodownload.jsp"; 160 } 161 162 /** 163 * @see org.opencms.workplace.tools.accounts.A_CmsUserDataImexportDialog#getPageArray() 164 */ 165 @Override 166 protected String[] getPageArray() { 167 168 return PAGES; 169 } 170 171 /** 172 * Initializes the message info object to work with depending on the dialog state and request parameters.<p> 173 */ 174 @SuppressWarnings("unchecked") 175 protected void initExportObject() { 176 177 try { 178 if (CmsStringUtil.isEmpty(getParamAction()) || CmsDialog.DIALOG_INITIAL.equals(getParamAction())) { 179 // create a new list 180 setGroups(new ArrayList<CmsGroup>()); 181 setRoles(new ArrayList<CmsRole>()); 182 } else { 183 // this is not the initial call, get the message info object from session 184 setGroups((List<CmsGroup>)((Map<?, ?>)getDialogObject()).get("groups")); 185 setRoles((List<CmsRole>)((Map<?, ?>)getDialogObject()).get("roles")); 186 } 187 } catch (Exception e) { 188 // create a new list 189 setGroups(new ArrayList<CmsGroup>()); 190 setRoles(new ArrayList<CmsRole>()); 191 } 192 } 193 194 /** 195 * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest) 196 */ 197 @Override 198 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 199 200 // initialize parameters and dialog actions in super implementation 201 super.initWorkplaceRequestValues(settings, request); 202 203 HashMap<String, List<?>> objectsMap = new HashMap<String, List<?>>(); 204 objectsMap.put("groups", getGroups()); 205 objectsMap.put("roles", getRoles()); 206 207 // save the current state of the message (may be changed because of the widget values) 208 setDialogObject(objectsMap); 209 } 210}