📄 cmsdownloadbrowser.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/workplace/CmsDownloadBrowser.java,v $
* Date : $Date: 2004/01/07 16:44:15 $
* Version: $Revision: 1.22.2.2 $
*
* 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.boot.I_CmsLogChannels;
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.CmsFile;
import com.opencms.file.CmsObject;
import com.opencms.file.CmsResource;
import com.opencms.util.Encoder;
import com.opencms.util.Utils;
import java.util.Hashtable;
import java.util.Vector;
/**
* Template class for displaying OpenCms download browser.
* <P>
*
* @author Mario Stanke
* @version $Revision: 1.22.2.2 $ $Date: 2004/01/07 16:44:15 $
* @see com.opencms.workplace.CmsXmlWpTemplateFile
*/
public class CmsDownloadBrowser extends A_CmsGalleryBrowser implements I_CmsFileListUsers {
/**
* Gets the content of a defined section in a given template file and its subtemplates
* with the given parameters.
*
* @see #getContent(CmsObject, String, String, Hashtable, String)
* @param cms CmsObject Object for accessing system resources.
* @param templateFile Filename of the template file.
* @param elementName Element name of this template in our parent template.
* @param parameters Hashtable with all template class parameters.
* @param templateSelector template section that should be processed.
*/
public byte[] getContent(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) throws CmsException {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() && C_DEBUG) {
A_OpenCms.log(C_OPENCMS_DEBUG, getClassName() + "getting content of element "
+ ((elementName == null) ? "<root>" : elementName));
A_OpenCms.log(C_OPENCMS_DEBUG, getClassName() + "template file is: "
+ templateFile);
A_OpenCms.log(C_OPENCMS_DEBUG, getClassName() + "selected template section is: "
+ ((templateSelector == null) ? "<default>" : templateSelector));
}
I_CmsSession session = cms.getRequestContext().getSession(true);
CmsXmlWpTemplateFile xmlTemplateDocument = (CmsXmlWpTemplateFile)getOwnTemplateFile(cms,
templateFile, elementName, parameters, templateSelector);
// test whether the download folder exists at all
try {
cms.readFileHeader(getConfigFile(cms).getDownGalleryPath());
}
catch(CmsException e) {
xmlTemplateDocument.setData("ERRORDETAILS", Utils.getStackTrace(e));
templateSelector = "error";
}
if(!"error".equals(templateSelector)) {
// clear session parameters of first load
if(parameters.get(C_PARA_INITIAL) != null) {
session.removeValue(C_PARA_FOLDER);
session.removeValue(C_PARA_PAGE);
session.removeValue("_DOWNLIST_");
session.removeValue(C_PARA_FILTER);
session.removeValue("numfiles");
session.removeValue("lasturl");
}
// most parameters have to be stored in the session because 'getFiles' needs them
String folder = (String)parameters.get(C_PARA_FOLDER);
if(folder != null) {
session.putValue(C_PARA_FOLDER, folder);
}
folder = (String)session.getValue(C_PARA_FOLDER);
if(folder == null || "".equals(folder)) {
folder = getConfigFile(cms).getDownGalleryPath();
Vector galleries = cms.getSubFolders(folder);
if(galleries.size() > 0) {
// take the first gallery
folder = ((CmsResource)galleries.elementAt(0)).getAbsolutePath();
session.putValue(C_PARA_FOLDER, folder);
}
else {
// there was a C_VFS_GALLERY_DOWNLOAD - folder but no gallery in it
templateSelector = "error_no_gallery";
}
}
if(!"error_no_gallery".equals(templateSelector)) {
String pageText = (String)parameters.get(C_PARA_PAGE);
String filter = (String)parameters.get(C_PARA_FILTER);
// check if the user requested a file deletion
String deleteAction = (String)parameters.get("action");
if ("delete".equals(deleteAction)) {
String deleteResource = (String)parameters.get("resource");
if (deleteResource != null && !"".equals(deleteResource)) {
try {
// lock and delete the resource
CmsResource res = cms.readFileHeader(deleteResource);
if (!res.isLocked()) {
cms.lockResource(deleteResource, true);
}
cms.deleteResource(deleteResource);
} catch (CmsException e) {
xmlTemplateDocument.setData("ERRORDETAILS", Utils.getStackTrace(e));
templateSelector = "error";
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
}
}
}
// Check if the user requested a certain page number
if(pageText == null || "".equals(pageText)) {
pageText = "1";
parameters.put(C_PARA_PAGE, pageText);
}
session.putValue(C_PARA_PAGE, pageText);
// Check if the user requested a filter
if(filter == null) {
filter = "";
session.putValue(C_PARA_FILTER, filter);
parameters.put(C_PARA_FILTER, filter);
}
// Compute the maximum page number
Vector filteredFiles = getFilteredDownList(cms, folder, filter);
int maxpage = ((filteredFiles.size() - 1) / C_DOWNBROWSER_MAXENTRIES) + 1;
// Now set the appropriate datablocks
xmlTemplateDocument.setData(C_PARA_FOLDER, Encoder.escape(folder,
cms.getRequestContext().getEncoding()));
xmlTemplateDocument.setData(C_PARA_PAGE, pageText);
xmlTemplateDocument.setData(C_PARA_FILTER, filter);
xmlTemplateDocument.setData(C_PARA_MAXPAGE, "" + maxpage);
session.putValue("_DOWNLIST_", filteredFiles);
session.putValue("numfiles", new Integer(filteredFiles.size())); // for 'showNextButton'
}
}
// Start the processing
return startProcessing(cms, xmlTemplateDocument, elementName, parameters,
templateSelector);
}
/**
* From interface <code>I_CmsFileListUsers</code>.
* <P>
* Fills all customized columns with the appropriate settings for the given file
* list entry. Any column filled by this method may be used in the customized template
* for the file list.
* @param cms Cms object for accessing system resources.
* @param filelist Template file containing the definitions for the file list together with
* the included customized defintions.
* @param res CmsResource Object of the current file list entry.
* @param lang Current language file.
* @throws CmsException if access to system resources failed.
* @see I_CmsFileListUsers
*/
public void getCustomizedColumnValues(CmsObject cms, CmsXmlWpTemplateFile filelistTemplate,
CmsResource res, CmsXmlLanguageFile lang) throws CmsException {
String servletPath = cms.getRequestContext().getRequest().getServletUrl();
String downloadPath = servletPath + res.getAbsolutePath();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -