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, 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.ui.apps.user;
029
030import org.opencms.file.CmsObject;
031import org.opencms.file.CmsUser;
032import org.opencms.main.CmsException;
033import org.opencms.main.CmsLog;
034import org.opencms.main.CmsRuntimeException;
035import org.opencms.main.OpenCms;
036import org.opencms.security.CmsRole;
037import org.opencms.security.I_CmsPrincipal;
038import org.opencms.ui.A_CmsUI;
039import org.opencms.ui.CmsVaadinUtils;
040import org.opencms.ui.apps.Messages;
041import org.opencms.ui.components.CmsBasicDialog;
042import org.opencms.ui.components.CmsConfirmationDialog;
043import org.opencms.ui.components.editablegroup.CmsEditableGroup;
044import org.opencms.ui.components.editablegroup.I_CmsEditableGroupRow;
045import org.opencms.ui.dialogs.permissions.CmsPrincipalSelect;
046import org.opencms.ui.dialogs.permissions.CmsPrincipalSelect.WidgetType;
047import org.opencms.util.CmsStringUtil;
048import org.opencms.util.CmsUUID;
049import org.opencms.util.CmsXsltUtil;
050
051import java.io.BufferedReader;
052import java.io.ByteArrayInputStream;
053import java.io.ByteArrayOutputStream;
054import java.io.FileReader;
055import java.io.IOException;
056import java.io.InputStreamReader;
057import java.io.OutputStream;
058import java.lang.reflect.InvocationTargetException;
059import java.lang.reflect.Method;
060import java.util.ArrayList;
061import java.util.HashMap;
062import java.util.Iterator;
063import java.util.List;
064import java.util.Map;
065
066import org.apache.commons.logging.Log;
067
068import com.google.common.base.Supplier;
069import com.vaadin.data.HasValue.ValueChangeEvent;
070import com.vaadin.data.HasValue.ValueChangeListener;
071import com.vaadin.ui.Button;
072import com.vaadin.ui.Button.ClickEvent;
073import com.vaadin.ui.CheckBox;
074import com.vaadin.ui.ComboBox;
075import com.vaadin.ui.Component;
076import com.vaadin.ui.Label;
077import com.vaadin.ui.Panel;
078import com.vaadin.ui.TabSheet;
079import com.vaadin.ui.TextField;
080import com.vaadin.ui.Upload;
081import com.vaadin.ui.Upload.Receiver;
082import com.vaadin.ui.Upload.SucceededEvent;
083import com.vaadin.ui.VerticalLayout;
084import com.vaadin.ui.Window;
085
086/**
087 * Dialog for CSV im- and export.<p>
088 */
089public final class CmsImportExportUserDialog extends A_CmsImportExportUserDialog
090implements Receiver, I_CmsPasswordFetcher {
091
092    /**The dialog height. */
093    public static final String DIALOG_HEIGHT = "650px";
094
095    /** Log instance for this class. */
096    static final Log LOG = CmsLog.getLog(CmsImportExportUserDialog.class);
097
098    /**vaadin serial id. */
099    private static final long serialVersionUID = -2055302491540892101L;
100
101    /**Label to show uploaded file. */
102    protected Label m_uploadname;
103
104    /**Start import button. */
105    Button m_startImport;
106
107    /**Vaadin Component. */
108    private Panel m_includeTechnicalFieldsPanel;
109
110    /**Vaadin Component. */
111    private CheckBox m_includeTechnicalFields;
112
113    /**Cancel button. */
114    private Button m_cancel;
115
116    /**CmsObject. */
117    private CmsObject m_cms;
118
119    /**Download button for export. */
120    private Button m_download;
121
122    /**Layout for groups. */
123    private VerticalLayout m_exportGroups;
124
125    /**Groups. */
126    private CmsEditableGroup m_exportGroupsGroup;
127
128    /**Layout for roles. */
129    private VerticalLayout m_exportRoles;
130
131    /**Roles. */
132    private CmsEditableGroup m_exportRolesGroup;
133
134    /**Generate password button. */
135    private Button m_generateButton;
136
137    /**Should the group field be editable? */
138    private boolean m_groupEditable = true;
139
140    /**ID of group. */
141    private CmsUUID m_groupID;
142
143    /**Stream for upload file. */
144    private ByteArrayOutputStream m_importFileStream;
145
146    /**Layout for groups.*/
147    private VerticalLayout m_importGroups;
148
149    /**Groups. */
150    private CmsEditableGroup m_importGroupsGroup;
151
152    /**Should password be imported? */
153    private CheckBox m_importPasswords;
154
155    /**Layout for roles. */
156    private VerticalLayout m_importRoles;
157
158    /**Roles. */
159    private CmsEditableGroup m_importRolesGroup;
160
161    /**Password for imported user. */
162    private TextField m_password;
163
164    /**List of user to import. */
165    List<CmsUser> m_userImportList;
166
167    /**Should the user get an email? */
168    private CheckBox m_sendMail;
169
170    /**Tab with import and export sheet. */
171    private TabSheet m_tab;
172
173    /**Upload for import. */
174    private Upload m_upload;
175
176    /**
177     * public constructor.<p>
178     *
179     * @param ou ou name
180     * @param groupID id of group
181     * @param window window
182     * @param allowTechnicalFieldsExport flag indicates if technical field export option should be available
183     */
184    private CmsImportExportUserDialog(
185        final String ou,
186        CmsUUID groupID,
187        Window window,
188        boolean allowTechnicalFieldsExport) {
189
190        setHeight(DIALOG_HEIGHT);
191
192        m_groupID = groupID;
193
194        try {
195            m_cms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
196        } catch (CmsException e1) {
197            //
198        }
199        CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null);
200        m_includeTechnicalFieldsPanel.setVisible(allowTechnicalFieldsExport);
201        m_includeTechnicalFields.addValueChangeListener(new ValueChangeListener<Boolean>() {
202
203            public void valueChange(ValueChangeEvent event) {
204
205                initDownloadButton();
206
207            }
208
209        });
210        m_importPasswords.setValue(Boolean.TRUE);
211        m_sendMail.setValue(Boolean.TRUE);
212
213        setButtonVisibility(0);
214
215        m_tab.addSelectedTabChangeListener(
216            event -> setButtonVisibility(m_tab.getTabPosition(m_tab.getTab(m_tab.getSelectedTab()))));
217
218        m_password.setValue(CmsGeneratePasswordDialog.getRandomPassword());
219        m_startImport.setEnabled(false);
220        m_startImport.addClickListener(event -> importUserFromFile());
221
222        m_generateButton.addClickListener(new Button.ClickListener() {
223
224            private static final long serialVersionUID = 4128513094772586752L;
225
226            public void buttonClick(ClickEvent event) {
227
228                final Window windowDialog = CmsBasicDialog.prepareWindow(CmsBasicDialog.DialogWidth.content);
229                windowDialog.setCaption(
230                    CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_GEN_PASSWORD_CAPTION_0));
231                CmsGeneratePasswordDialog dialog = new CmsGeneratePasswordDialog(
232                    CmsImportExportUserDialog.this,
233                    new Runnable() {
234
235                        public void run() {
236
237                            windowDialog.close();
238
239                        }
240                    });
241                windowDialog.setContent(dialog);
242                A_CmsUI.get().addWindow(windowDialog);
243            }
244        });
245
246        m_upload.setReceiver(this);
247
248        m_upload.addSucceededListener(new Upload.SucceededListener() {
249
250            private static final long serialVersionUID = -6865652127878123021L;
251
252            public void uploadSucceeded(SucceededEvent event) {
253
254                if (event.getMIMEType().startsWith("text/")) {
255                    try {
256                        m_userImportList = getUsersFromFile();
257                        m_startImport.setEnabled(true);
258                        m_uploadname.setValue(event.getFilename());
259                    } catch (Exception e) {
260                        //wrong csv columns
261                        m_startImport.setEnabled(false);
262                        m_uploadname.setValue("");
263                        CmsConfirmationDialog.show(
264                            CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_IMEXPORT_INVALID_FILE_0),
265                            CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_IMEXPORT_INVALID_CSV_0),
266                            new Runnable() {
267
268                                public void run() {
269
270                            }
271
272                            });
273
274                    }
275                } else {
276                    //Wrong mime type
277                    m_startImport.setEnabled(false);
278                    m_uploadname.setValue("");
279                    CmsConfirmationDialog.show(
280                        CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_IMEXPORT_INVALID_FILE_0),
281                        CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_IMEXPORT_INVALID_MIMETYPE_0),
282                        new Runnable() {
283
284                            public void run() {
285
286                        }
287
288                        });
289                }
290
291            }
292        });
293
294        if (groupID == null) {
295
296            m_importGroupsGroup = new CmsEditableGroup(m_importGroups, new Supplier<Component>() {
297
298                public Component get() {
299
300                    return getGroupSelect(ou, true, null);
301                }
302
303            }, CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_IMEXPORT_ADD_GROUP_0));
304
305            m_importGroupsGroup.init();
306
307            m_exportGroupsGroup = new CmsEditableGroup(m_exportGroups, new Supplier<Component>() {
308
309                public Component get() {
310
311                    return getGroupSelect(ou, true, null);
312                }
313
314            }, CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_IMEXPORT_ADD_GROUP_0));
315
316            m_exportGroupsGroup.init();
317        } else {
318            m_exportGroups.addComponent(getGroupSelect(ou, false, groupID));
319            m_importGroups.addComponent(getGroupSelect(ou, false, groupID));
320        }
321
322        m_importRolesGroup = new CmsEditableGroup(m_importRoles, new Supplier<Component>() {
323
324            public Component get() {
325
326                return getRoleComboBox(ou);
327            }
328
329        }, CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_IMEXPORT_ADD_ROLE_0));
330
331        m_importRolesGroup.init();
332
333        m_exportRolesGroup = new CmsEditableGroup(m_exportRoles, new Supplier<Component>() {
334
335            public Component get() {
336
337                return getRoleComboBox(ou);
338            }
339
340        }, CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_IMEXPORT_ADD_ROLE_0));
341
342        m_exportRolesGroup.init();
343
344        super.init(ou, window);
345
346    }
347
348    /**
349     * Returns a map with the users to export added.<p>
350     * @param cms CmsObject
351     * @param ou ou name
352     * @param exportUsers the map to add the users
353     * @return a map with the users to export added
354     * @throws CmsException if getting users failed
355     */
356    public static Map<CmsUUID, CmsUser> addExportAllUsers(CmsObject cms, String ou, Map<CmsUUID, CmsUser> exportUsers)
357    throws CmsException {
358
359        List<CmsUser> users = OpenCms.getOrgUnitManager().getUsers(cms, ou, false);
360        if ((users != null) && (users.size() > 0)) {
361            Iterator<CmsUser> itUsers = users.iterator();
362            while (itUsers.hasNext()) {
363                CmsUser user = itUsers.next();
364                if (!exportUsers.containsKey(user.getId())) {
365                    exportUsers.put(user.getId(), user);
366                }
367            }
368        }
369        return exportUsers;
370    }
371
372    /**
373     * Returns a map with the users to export added.<p>
374     * @param cms CmsObject
375     * @param groups the selected groups
376     * @param exportUsers the map to add the users
377     *
378     * @return a map with the users to export added
379     *
380     * @throws CmsException if getting groups or users of group failed
381     */
382    public static Map<CmsUUID, CmsUser> addExportUsersFromGroups(
383        CmsObject cms,
384        List<String> groups,
385        Map<CmsUUID, CmsUser> exportUsers)
386    throws CmsException {
387
388        if ((groups != null) && (groups.size() > 0)) {
389            Iterator<String> itGroups = groups.iterator();
390            while (itGroups.hasNext()) {
391                List<CmsUser> groupUsers = cms.getUsersOfGroup(itGroups.next());
392                Iterator<CmsUser> itGroupUsers = groupUsers.iterator();
393                while (itGroupUsers.hasNext()) {
394                    CmsUser groupUser = itGroupUsers.next();
395                    if (!exportUsers.containsKey(groupUser.getId())) {
396                        exportUsers.put(groupUser.getId(), groupUser);
397                    }
398                }
399            }
400        }
401        return exportUsers;
402    }
403
404    /**
405     * Returns a map with the users to export added.<p>
406     * @param cms CmsObject
407     * @param ou ou name
408     *
409     * @param roles the selected roles
410     * @param exportUsers the map to add the users
411     *
412     * @return a map with the users to export added
413     *
414     * @throws CmsException if getting roles or users of role failed
415     */
416    public static Map<CmsUUID, CmsUser> addExportUsersFromRoles(
417        CmsObject cms,
418        String ou,
419        List<String> roles,
420        Map<CmsUUID, CmsUser> exportUsers)
421    throws CmsException {
422
423        if ((roles != null) && (roles.size() > 0)) {
424            Iterator<String> itRoles = roles.iterator();
425            while (itRoles.hasNext()) {
426                List<CmsUser> roleUsers = OpenCms.getRoleManager().getUsersOfRole(
427                    cms,
428                    CmsRole.valueOfGroupName(itRoles.next()).forOrgUnit(ou),
429                    true,
430                    false);
431                Iterator<CmsUser> itRoleUsers = roleUsers.iterator();
432                while (itRoleUsers.hasNext()) {
433                    CmsUser roleUser = itRoleUsers.next();
434                    // contains
435                    if (exportUsers.get(roleUser.getId()) == null) {
436                        exportUsers.put(roleUser.getId(), roleUser);
437                    }
438                }
439            }
440        }
441        return exportUsers;
442    }
443
444    /**
445     * Gets an dialog instance for fixed group.<p>
446     *
447     * @param groupID id
448     * @param ou ou name
449     * @param window window
450     * @param allowTechnicalFieldsExport flag indicates if technical field export option should be available
451     * @return an instance of this class
452         */
453    public static CmsImportExportUserDialog getExportUserDialogForGroup(
454        CmsUUID groupID,
455        String ou,
456        Window window,
457        boolean allowTechnicalFieldsExport) {
458
459        CmsImportExportUserDialog res = new CmsImportExportUserDialog(ou, groupID, window, allowTechnicalFieldsExport);
460        return res;
461    }
462
463    /**
464     * Gets an dialog instance for fixed group.<p>
465     *
466     * @param ou ou name
467     * @param window window
468     * @param allowTechnicalFieldsExport flag indicates if technical field export option should be available
469     * @return an instance of this class
470     */
471    public static CmsImportExportUserDialog getExportUserDialogForOU(
472        String ou,
473        Window window,
474        boolean allowTechnicalFieldsExport) {
475
476        CmsImportExportUserDialog res = new CmsImportExportUserDialog(ou, null, window, allowTechnicalFieldsExport);
477        return res;
478    }
479
480    /**
481     * @see org.opencms.ui.apps.user.I_CmsPasswordFetcher#fetchPassword(java.lang.String)
482     */
483    public void fetchPassword(String password) {
484
485        m_password.setValue(password);
486
487    }
488
489    /**
490     * @see com.vaadin.ui.Upload.Receiver#receiveUpload(java.lang.String, java.lang.String)
491     */
492    public OutputStream receiveUpload(String filename, String mimeType) {
493
494        m_importFileStream = new ByteArrayOutputStream();
495        return m_importFileStream;
496    }
497
498    /**
499     * Get a principle select for choosing groups.<p>
500     *
501     * @param ou name
502     * @param enabled enabled?
503     * @param groupID default value
504     * @return CmsPrinicpalSelect
505     */
506    protected CmsPrincipalSelect getGroupSelect(String ou, boolean enabled, CmsUUID groupID) {
507
508        CmsPrincipalSelect select = new CmsPrincipalSelect();
509        select.setOU(ou);
510        select.setEnabled(enabled);
511        select.setRealPrincipalsOnly(true);
512        select.setPrincipalType(I_CmsPrincipal.PRINCIPAL_GROUP);
513        select.setWidgetType(WidgetType.groupwidget);
514
515        if (groupID != null) {
516            try {
517                select.setValue(m_cms.readGroup(groupID).getName());
518            } catch (CmsException e) {
519                LOG.error("Unable to read group", e);
520            }
521        }
522
523        //OU Change enabled because ou-user can be part of other ou-groups
524        return select;
525    }
526
527    /**
528     * Get ComboBox for selecting roles.<p>
529     *
530     * @param ou name
531     * @return ComboBox
532     */
533    protected ComboBox<CmsRole> getRoleComboBox(String ou) {
534
535        ComboBox<CmsRole> box = new ComboBox<CmsRole>();
536        CmsUserEditDialog.iniRole(A_CmsUI.getCmsObject(), ou, box, null);
537        box.setSelectedItem(CmsRole.EDITOR.forOrgUnit(ou));
538
539        return box;
540    }
541
542    /**
543     * Reads user from import file.<p>
544     *
545     * @return List of user (with passwords)
546     */
547    protected List<CmsUser> getUsersFromFile() {
548
549        String separator = null;
550        List values = null;
551
552        FileReader fileReader;
553        BufferedReader bufferedReader;
554        List<CmsUser> users = null;
555
556        boolean keepPasswordIfPossible = m_importPasswords.getValue().booleanValue();
557
558        try {
559            bufferedReader = new BufferedReader(
560                new InputStreamReader(new ByteArrayInputStream(m_importFileStream.toByteArray())));
561            String line;
562            boolean headline = true;
563
564            while ((line = bufferedReader.readLine()) != null) {
565                if (users == null) {
566                    users = new ArrayList<CmsUser>();
567                }
568                if (separator == null) {
569                    separator = CmsXsltUtil.getPreferredDelimiter(line);
570                }
571                List lineValues = CmsStringUtil.splitAsList(line, separator);
572                if (headline) {
573                    values = new ArrayList();
574                    Iterator itLineValues = lineValues.iterator();
575                    while (itLineValues.hasNext()) {
576                        values.add(itLineValues.next());
577                    }
578                    headline = false;
579                } else if (values != null) {
580                    CmsUser curUser = new CmsUser();
581                    try {
582                        for (int i = 0; i < values.size(); i++) {
583                            String curValue = (String)values.get(i);
584                            try {
585                                Method method = CmsUser.class.getMethod(
586                                    "set" + curValue.substring(0, 1).toUpperCase() + curValue.substring(1),
587                                    new Class[] {String.class});
588                                String value = "";
589                                if ((lineValues.size() > i) && (lineValues.get(i) != null)) {
590                                    value = (String)lineValues.get(i);
591
592                                }
593                                if (curValue.equals("password")) {
594                                    if (CmsStringUtil.isEmptyOrWhitespaceOnly(value) | !keepPasswordIfPossible) {
595                                        value = m_password.getValue();
596                                    }
597                                }
598                                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(value) && !value.equals("null")) {
599                                    method.invoke(curUser, new Object[] {value});
600                                }
601                            } catch (NoSuchMethodException ne) {
602                                if (!CmsStringUtil.isEmptyOrWhitespaceOnly((String)lineValues.get(i))) {
603                                    curUser.setAdditionalInfo(curValue, lineValues.get(i));
604                                }
605                            } catch (IllegalAccessException le) {
606                                //
607                            } catch (InvocationTargetException te) {
608                                //
609                            }
610                        }
611                    } catch (CmsRuntimeException e) {
612                        //
613                    }
614                    users.add(curUser);
615                }
616            }
617            bufferedReader.close();
618        } catch (IOException e) {
619            //noop
620        }
621
622        return users;
623    }
624
625    /**
626     * Import user from file.
627     */
628    protected void importUserFromFile() {
629
630        CmsImportUserThread thread = new CmsImportUserThread(
631            m_cms,
632            m_ou,
633            m_userImportList,
634            getGroupsList(m_importGroups, true),
635            getRolesList(m_importRoles, true),
636            m_sendMail.getValue().booleanValue());
637        thread.start();
638        CmsShowReportDialog dialog = new CmsShowReportDialog(thread, new Runnable() {
639
640            public void run() {
641
642                m_window.close();
643            }
644        });
645        m_window.setContent(dialog);
646
647    }
648
649    /**
650     * @see org.opencms.ui.apps.user.A_CmsImportExportUserDialog#getCloseButton()
651     */
652    @Override
653    Button getCloseButton() {
654
655        return m_cancel;
656    }
657
658    /**
659     * @see org.opencms.ui.apps.user.A_CmsImportExportUserDialog#getDownloadButton()
660     */
661    @Override
662    Button getDownloadButton() {
663
664        return m_download;
665    }
666
667    /**
668     * @see org.opencms.ui.apps.user.A_CmsImportExportUserDialog#getUserToExport()
669     */
670    @Override
671    Map<CmsUUID, CmsUser> getUserToExport() {
672
673        // get the data object from session
674        List<String> groups = getGroupsList(m_exportGroups, false);
675
676        Iterator<I_CmsEditableGroupRow> it = m_exportRolesGroup.getRows().iterator();
677        List<String> roles = new ArrayList<String>();
678        while (it.hasNext()) {
679            CmsRole role = (CmsRole)((ComboBox)it.next().getComponent()).getValue();
680            roles.add(role.getGroupName());
681        }
682
683        Map<CmsUUID, CmsUser> exportUsers = new HashMap<CmsUUID, CmsUser>();
684        try {
685            if (((groups.size() < 1)) && ((roles.size() < 1))) {
686                exportUsers = CmsImportExportUserDialog.addExportAllUsers(m_cms, m_ou, exportUsers);
687            } else {
688                exportUsers = CmsImportExportUserDialog.addExportUsersFromGroups(m_cms, groups, exportUsers);
689                exportUsers = CmsImportExportUserDialog.addExportUsersFromRoles(m_cms, m_ou, roles, exportUsers);
690            }
691        } catch (CmsException e) {
692            LOG.error("Unable to get export user list.", e);
693        }
694        return exportUsers;
695    }
696
697    /**
698     * @see org.opencms.ui.apps.user.A_CmsImportExportUserDialog#isExportWithTechnicalFields()
699     */
700    @Override
701    boolean isExportWithTechnicalFields() {
702
703        return m_includeTechnicalFields.getValue().booleanValue();
704    }
705
706    /**
707     * Gets selected groups in List.<p>
708     *
709     * @param parent layout
710     * @param importCase boolean
711     * @return List of group names
712     */
713    private List<String> getGroupsList(VerticalLayout parent, boolean importCase) {
714
715        List<String> res = new ArrayList<String>();
716
717        if (m_groupID != null) {
718            try {
719                res.add(m_cms.readGroup(m_groupID).getName());
720            } catch (CmsException e) {
721                LOG.error("Unable to read group", e);
722            }
723            return res;
724        }
725
726        if (m_groupEditable) {
727            CmsEditableGroup editableGroup = importCase ? m_importGroupsGroup : m_exportGroupsGroup;
728            for (I_CmsEditableGroupRow row : editableGroup.getRows()) {
729                String groupName = ((CmsPrincipalSelect)row.getComponent()).getValue();
730                if (!CmsStringUtil.isEmptyOrWhitespaceOnly(groupName)) {
731                    res.add(groupName);
732                }
733            }
734        } else {
735            TextField comp = (TextField)parent.getComponent(0);
736            res.add(comp.getValue());
737        }
738        return res;
739    }
740
741    /**
742     * Get selected roles list.<p>
743     *
744     * @param parent layout
745     * @param importCase boolean
746     * @return List of roles
747     */
748    private List<CmsRole> getRolesList(VerticalLayout parent, boolean importCase) {
749
750        List<CmsRole> res = new ArrayList<CmsRole>();
751
752        CmsEditableGroup editableGroup = importCase ? m_importRolesGroup : m_exportRolesGroup;
753        for (I_CmsEditableGroupRow row : editableGroup.getRows()) {
754            res.add(((ComboBox<CmsRole>)row.getComponent()).getValue());
755        }
756        return res;
757    }
758
759    /**
760     * Set the visibility of the buttons.<p>
761     *
762     * @param tab which is selected.
763     */
764    private void setButtonVisibility(int tab) {
765
766        m_download.setVisible(tab == 1);
767        m_startImport.setVisible(tab == 0);
768
769    }
770}