cmsnewresourceupload.java
来自「java 编写的程序」· Java 代码 · 共 377 行 · 第 1/2 页
JAVA
377 行
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/workplace/CmsNewResourceUpload.java,v $
* Date : $Date: 2001/07/31 15:50:19 $
* Version: $Revision: 1.29 $
*
* 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.file.*;
import com.opencms.core.*;
import com.opencms.util.*;
import com.opencms.template.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
/**
* 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.29 $ $Date: 2001/07/31 15:50:19 $
*/
public class CmsNewResourceUpload extends CmsWorkplaceDefault implements I_CmsWpConstants,I_CmsConstants {
/** 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.
* @exception 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);
// 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("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);
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);
}
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);
// 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);
}
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);
// 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;
}
} // else, zip was not valid, so continue ...
template = "step1";
}
}
}
else {
if(step.equals("2")) {
// get the selected resource and check if it is an image
I_CmsResourceType type = cms.getResourceType(newtype);
if(newtype.equals(C_TYPE_IMAGE_NAME)) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?