cmsuserdataimportdialog.java
来自「找了很久才找到到源代码」· Java 代码 · 共 426 行 · 第 1/2 页
JAVA
426 行
/*
* File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsUserDataImportDialog.java,v $
* Date : $Date: 2007-08-13 16:29:47 $
* Version: $Revision: 1.3 $
*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) 2002 - 2007 Alkacon Software GmbH (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software GmbH, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.workplace.tools.accounts;
import org.opencms.i18n.CmsEncoder;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsIllegalArgumentException;
import org.opencms.main.CmsRuntimeException;
import org.opencms.util.CmsRequestUtil;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsXsltUtil;
import org.opencms.widgets.CmsGroupWidget;
import org.opencms.widgets.CmsHttpUploadWidget;
import org.opencms.widgets.CmsInputWidget;
import org.opencms.widgets.CmsSelectWidget;
import org.opencms.workplace.CmsDialog;
import org.opencms.workplace.CmsWidgetDialogParameter;
import org.opencms.workplace.CmsWorkplaceSettings;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
import org.apache.commons.fileupload.FileItem;
/**
* Dialog to import user data.<p>
*
* @author Raphael Schnuck
*
* @version $Revision: 1.3 $
*
* @since 6.5.6
*/
public class CmsUserDataImportDialog extends A_CmsUserDataImexportDialog {
/** localized messages Keys prefix. */
public static final String KEY_PREFIX = "userdata.import";
/** The path to the file to import. */
private String m_importFile;
/** The password to use in the import. */
private String m_password;
/**
* Public constructor with JSP action element.<p>
*
* @param jsp an initialized JSP action element
*/
public CmsUserDataImportDialog(CmsJspActionElement jsp) {
super(jsp);
}
/**
* Public constructor with JSP variables.<p>
*
* @param context the JSP page context
* @param req the JSP request
* @param res the JSP response
*/
public CmsUserDataImportDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) {
this(new CmsJspActionElement(context, req, res));
}
/**
* @see org.opencms.workplace.tools.accounts.A_CmsUserDataImexportDialog#actionCommit()
*/
public void actionCommit() throws IOException, ServletException {
List errors = new ArrayList();
// get the file item from the multipart request
Iterator it = getMultiPartFileItems().iterator();
FileItem fi = null;
while (it.hasNext()) {
fi = (FileItem)it.next();
if (fi.getName() != null) {
// found the file object, leave iteration
break;
} else {
// this is no file object, check next item
continue;
}
}
if (fi != null && CmsStringUtil.isNotEmptyOrWhitespaceOnly(fi.getName())) {
byte[] content = fi.get();
File importFile = File.createTempFile("import_users", ".csv");
m_importFile = importFile.getAbsolutePath();
FileOutputStream fileOutput = new FileOutputStream(importFile);
fileOutput.write(content);
fileOutput.close();
fi.delete();
FileReader fileReader = new FileReader(importFile);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String line = bufferedReader.readLine();
if (line != null) {
List colDefs = CmsStringUtil.splitAsList(line, CmsXsltUtil.getPreferredDelimiter(line));
if (!colDefs.contains("name")) {
errors.add(new CmsRuntimeException(Messages.get().container(
Messages.ERR_USERDATA_IMPORT_CSV_MISSING_NAME_0)));
}
if ((line.indexOf("password") == -1) && CmsStringUtil.isEmptyOrWhitespaceOnly(m_password)) {
errors.add(new CmsRuntimeException(Messages.get().container(
Messages.ERR_USERDATA_IMPORT_CSV_MISSING_PASSWORD_0)));
}
}
bufferedReader.close();
} else {
errors.add(new CmsIllegalArgumentException(Messages.get().container(
Messages.ERR_USERDATA_IMPORT_NO_CONTENT_0)));
}
if (errors.isEmpty()) {
Map params = new HashMap();
params.put("groups", CmsStringUtil.collectionAsString(getGroups(), ","));
params.put("roles", CmsStringUtil.collectionAsString(getRoles(), ","));
params.put("importfile", m_importFile);
params.put("password", m_password);
params.put(A_CmsOrgUnitDialog.PARAM_OUFQN, getParamOufqn());
// set action parameter to initial dialog call
params.put(CmsDialog.PARAM_ACTION, CmsDialog.DIALOG_INITIAL);
getToolManager().jspForwardTool(this, getCurrentToolPath() + "/list", params);
}
// set the list of errors to display when something goes wrong
setCommitErrors(errors);
}
/**
* @see org.opencms.workplace.CmsWidgetDialog#dialogButtonsCustom()
*/
public String dialogButtonsCustom() {
StringBuffer result = new StringBuffer(256);
result.append(dialogButtonRow(HTML_START));
result.append("<input name=\"ok\" value=\"");
result.append(key(org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_CONTINUE_0) + "\"");
result.append(" type=\"submit\"");
result.append(" class=\"dialogbutton\"");
result.append(">\n");
dialogButtonsHtml(result, BUTTON_CANCEL, "");
result.append(dialogButtonRow(HTML_END));
return result.toString();
}
/**
* Returns the path of the file to import.<p>
*
* @return the path of the file to import
*/
public String getImportFile() {
return m_importFile;
}
/**
* Returns the password to set during import.<p>
*
* @return the password to set during import
*/
public String getPassword() {
return m_password;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?