📄 cmsnewresourceupload.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/workplace/CmsNewResourceUpload.java,v $
* Date : $Date: 2004/01/07 10:57:09 $
* Version: $Revision: 1.37.2.1 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001 The OpenCms Group
*
* 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 OpenCms, please see the
* OpenCms 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 com.opencms.workplace;
import com.opencms.core.A_OpenCms;
import com.opencms.core.CmsException;
import com.opencms.core.I_CmsConstants;
import com.opencms.core.I_CmsSession;
import com.opencms.file.CmsImportFolder;
import com.opencms.file.CmsObject;
import com.opencms.file.I_CmsResourceType;
import com.opencms.util.Encoder;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
/**
* Template class for displaying the new resource upload screen
* of the OpenCms workplace.<P>
* Reads template files of the content type <code>CmsXmlWpTemplateFile</code>.
*
* @author Michael Emmerich
* @version $Revision: 1.37.2.1 $ $Date: 2004/01/07 10:57:09 $
*/
public class CmsNewResourceUpload extends CmsWorkplaceDefault implements I_CmsWpConstants,I_CmsConstants {
private static final String C_PARAM_OVERWRITE = "overwrite";
private static final String C_PARAM_CANCEL = "cancel";
private static final int DEBUG = 0;
/** Vector containing all names of the radiobuttons */
private Vector m_names = null;
/** Vector containing all links attached to the radiobuttons */
private Vector m_values = null;
/**
* Overwrites the getContent method of the CmsWorkplaceDefault.<br>
* Gets the content of the new resource upload page template and processed the data input.
* @param cms The CmsObject.
* @param templateFile The upload template file
* @param elementName not used
* @param parameters Parameters of the request and the template.
* @param templateSelector Selector of the template tag to be displayed.
* @return Bytearry containing the processed data of the template.
* @throws Throws CmsException if something goes wrong.
*/
public byte[] getContent(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) throws CmsException {
// the template to be displayed
String template = null;
I_CmsSession session = cms.getRequestContext().getSession(true);
// get the file size upload limitation value (value is in kB)
int maxFileSize = ((Integer)A_OpenCms.getRuntimeProperty("workplace.file.maxuploadsize")).intValue();
// check if current user belongs to Admin group, if so no file upload limit
if ((maxFileSize <= 0) || cms.userInGroup(cms.getRequestContext().currentUser().getName(), C_GROUP_ADMIN)) {
maxFileSize = -1;
}
// clear session values on first load
String initial = (String)parameters.get(C_PARA_INITIAL);
if (initial != null) {
// remove all session values
session.removeValue(C_PARA_FILE);
session.removeValue(C_PARA_FILECONTENT);
session.removeValue(C_PARA_NEWTYPE);
session.removeValue(C_PARA_TITLE);
session.removeValue(CmsNewResourceUpload.C_PARAM_OVERWRITE);
session.removeValue("lasturl");
}
String lastUrl = getLastUrl(cms, parameters);
// get the parameters from the request and session
String step = (String)parameters.get("STEP");
String unzip = (String) parameters.get("unzip");
String nofolder = (String) parameters.get("NOFOLDER");
String currentFolder = (String)parameters.get(C_PARA_FILELIST);
if(currentFolder != null) {
session.putValue(C_PARA_FILELIST, currentFolder);
}
currentFolder = (String)session.getValue(C_PARA_FILELIST);
if(currentFolder == null) {
currentFolder = cms.rootFolder().getAbsolutePath();
}
String title = (String) parameters.get(C_PARA_TITLE);
if (title!=null && !"".equals(title.trim())) {
session.putValue(C_PARA_TITLE, title);
}
else {
title = (String)session.getValue(C_PARA_TITLE);
}
String newname = (String)parameters.get(C_PARA_NAME);
// get filename and file content if available
String filename = null;
byte[] filecontent = new byte[0];
// get the filename
Enumeration files = cms.getRequestContext().getRequest().getFileNames();
while(files.hasMoreElements()) {
filename = (String)files.nextElement();
}
if(filename != null) {
session.putValue(C_PARA_FILE, filename.trim());
}
filename = (String)session.getValue(C_PARA_FILE);
// get the filecontent
if(filename != null) {
filecontent = cms.getRequestContext().getRequest().getFile(filename);
}
if(filecontent != null) {
session.putValue(C_PARA_FILECONTENT, filecontent);
}
filecontent = (byte[])session.getValue(C_PARA_FILECONTENT);
//get the filetype
String newtype = (String)parameters.get(C_PARA_NEWTYPE);
if(newtype != null) {
session.putValue(C_PARA_NEWTYPE, newtype);
}
newtype = (String)session.getValue(C_PARA_NEWTYPE);
// get the document to display
CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
xmlTemplateDocument.setData("lasturl", lastUrl);
// get the overwrite parameter
String dummy = (String) parameters.get(CmsNewResourceUpload.C_PARAM_OVERWRITE);
boolean replaceResource = false;
if (dummy != null) {
replaceResource = "yes".equals(dummy);
session.putValue(CmsNewResourceUpload.C_PARAM_OVERWRITE, dummy);
}
else {
replaceResource = "yes".equals((String) session.getValue(CmsNewResourceUpload.C_PARAM_OVERWRITE));
}
// get the cancel parameter
boolean cancelUpload = "yes".equals((String) parameters.get(CmsNewResourceUpload.C_PARAM_CANCEL));
if (cancelUpload) {
// the resource to upload exists, the user choosed
// cancel in the warning dialogue... clear the session
// values now.
session.removeValue(C_PARA_FILE);
session.removeValue(C_PARA_FILECONTENT);
session.removeValue(C_PARA_NEWTYPE);
session.removeValue(C_PARA_TITLE);
session.removeValue(CmsNewResourceUpload.C_PARAM_OVERWRITE);
}
if (DEBUG > 0) {
System.out.println("\nstep: " + step);
System.out.println("filename: " + filename);
System.out.println("currentFolder: " + currentFolder);
System.out.println("title: " + title);
System.out.println("newtype: " + newtype);
System.out.println("overwrite: " + replaceResource);
System.out.println("cancel: " + cancelUpload);
}
// there was a file uploaded, so select its type
if(step != null) {
if(step.equals("1")) {
// display the select filetype screen
if(filename != null) {
// check if the file size is 0
if(filecontent.length == 0) {
template = "error";
xmlTemplateDocument.setData("details", filename);
}
// check if the file size is larger than the maximum allowed upload size
else if ((maxFileSize > 0) && (filecontent.length > (maxFileSize * 1024))) {
template = "errorfilesize";
xmlTemplateDocument.setData("details", filename+": "+(filecontent.length/1024)+" kb, max. "+maxFileSize+" kb.");
}
else {
if(unzip != null) {
// try to unzip the file here ...
boolean noSubFolder = (nofolder != null ? true : false);
CmsImportFolder zip = new CmsImportFolder(
filecontent, currentFolder, cms, noSubFolder);
if( zip.isValidZipFile() ) {
// remove the values form the session
session.removeValue(C_PARA_FILE);
session.removeValue(C_PARA_FILECONTENT);
session.removeValue(C_PARA_NEWTYPE);
session.removeValue(C_PARA_TITLE);
session.removeValue(CmsNewResourceUpload.C_PARAM_OVERWRITE);
// return to the filelist
try {
//cms.getRequestContext().getResponse().sendCmsRedirect( getConfigFile(cms).getWorkplaceActionPath()+C_WP_EXPLORER_FILELIST);
if((lastUrl != null) && (lastUrl != "")) {
cms.getRequestContext().getResponse().sendRedirect(lastUrl);
}
else {
cms.getRequestContext().getResponse().sendCmsRedirect(
getConfigFile(cms).getWorkplaceActionPath() + C_WP_EXPLORER_FILELIST);
}
} catch(Exception ex) {
throw new CmsException(
"Redirect fails :" + getConfigFile(cms).getWorkplaceActionPath()
+ C_WP_EXPLORER_FILELIST, CmsException.C_UNKNOWN_EXCEPTION, ex);
}
return null;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -