cmsexplorer.java
来自「找了很久才找到到源代码」· Java 代码 · 共 786 行 · 第 1/2 页
JAVA
786 行
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/CmsExplorer.java,v $
* Date : $Date: 2007-08-13 16:29:41 $
* Version: $Revision: 1.37 $
*
* 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.explorer;
import org.opencms.db.CmsUserSettings;
import org.opencms.file.CmsFolder;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsProject;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.file.collectors.I_CmsResourceCollector;
import org.opencms.file.types.CmsResourceTypePlain;
import org.opencms.i18n.CmsEncoder;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.CmsRuntimeException;
import org.opencms.main.OpenCms;
import org.opencms.util.CmsRequestUtil;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.CmsWorkplaceSettings;
import org.opencms.workplace.galleries.A_CmsGallery;
import org.opencms.workplace.list.I_CmsListResourceCollector;
import org.opencms.workplace.tools.CmsToolManager;
import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
/**
* Provides methods for building the main framesets of the OpenCms Workplace.<p>
*
* The following files use this class:
* <ul>
* <li>/views/explorer/explorer_fs.jsp
* <li>/views/explorer/explorer_files.jsp
* <li>/views/explorer/explorer_body_fs.jsp
* </ul>
* <p>
*
* @author Alexander Kandzior
*
* @version $Revision: 1.37 $
*
* @since 6.0.0
*/
public class CmsExplorer extends CmsWorkplace {
/** The "mode" parameter. */
public static final String PARAMETER_MODE = "mode";
/** The "explorerview" view selection. */
public static final String VIEW_EXPLORER = "explorerview";
/** The "galleryview" view selection. */
public static final String VIEW_GALLERY = "galleryview";
/** The "list" view selection. */
public static final String VIEW_LIST = "listview";
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsExplorer.class);
/** The "flaturl" parameter. */
private static final String PARAMETER_FLATURL = "flaturl";
/** The "page" parameter. */
private static final String PARAMETER_PAGE = "page";
/** The "resource" parameter. */
private static final String PARAMETER_RESOURCE = "resource";
/** The "uri" parameter. */
private static final String PARAMETER_URI = "uri";
/** The 'uri' parameter value. */
private String m_uri;
/**
* Public constructor.<p>
*
* @param jsp an initialized JSP action element
*/
public CmsExplorer(CmsJspActionElement jsp) {
super(jsp);
}
/**
* Returns the explorer body frame content uri.<p>
*
* Used by the explorer_fs.jsp.<p>
*
* @return the explorer body frame content uri
*/
public String getExplorerBodyUri() {
String body = "explorer_body_fs.jsp";
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_uri)) {
body += "?" + PARAMETER_URI + "=" + m_uri;
}
return getJsp().link(body);
}
/**
* Returns the explorer files frame content uri.<p>
*
* Used by the explorer_body_fs.jsp.<p>
*
* @return the explorer files frame content uri
*/
public String getExplorerFilesUri() {
String body = "explorer_files.jsp?mode=explorerview";
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_uri)) {
body = m_uri;
}
return getJsp().link(body);
}
/**
* Returns the html for the explorer file list.<p>
*
* @return the html for the explorer file list
*/
public String getFileList() {
// if mode is "listonly", only the list will be shown
boolean galleryView = VIEW_GALLERY.equals(getSettings().getExplorerMode());
// if mode is "listview", all file in the set collector will be shown
boolean listView = VIEW_LIST.equals(getSettings().getExplorerMode());
String currentFolder = getSettings().getExplorerResource();
try {
getCms().readResource(currentFolder, CmsResourceFilter.ALL);
} catch (CmsException e) {
// file was not readable
currentFolder = "/";
}
// start creating content
StringBuffer content = new StringBuffer(2048);
content.append(getInitializationHeader());
// now get the entries for the filelist
List resources = getResources(getSettings().getExplorerResource());
// if a folder contains to much entrys we split them to pages of C_ENTRYS_PER_PAGE length
int startat = 0;
int stopat = resources.size();
int selectedPage = 1;
int numberOfPages = 0;
int maxEntrys = getSettings().getUserSettings().getExplorerFileEntries();
if (!galleryView) {
selectedPage = getSettings().getExplorerPage();
if (stopat > maxEntrys) {
// we have to split
numberOfPages = (stopat / maxEntrys) + 1;
if (selectedPage > numberOfPages) {
// the user has changed the folder and then selected a page for the old folder
selectedPage = 1;
}
startat = (selectedPage - 1) * maxEntrys;
if ((startat + maxEntrys) < stopat) {
stopat = startat + maxEntrys;
}
}
}
// now check which filelist colums we want to show
int preferences = getUserPreferences();
boolean showTitle = (preferences & CmsUserSettings.FILELIST_TITLE) > 0;
boolean showNavText = (preferences & CmsUserSettings.FILELIST_NAVTEXT) > 0;
boolean showPermissions = (preferences & CmsUserSettings.FILELIST_PERMISSIONS) > 0;
boolean showDateLastModified = (preferences & CmsUserSettings.FILELIST_DATE_LASTMODIFIED) > 0;
boolean showUserWhoLastModified = (preferences & CmsUserSettings.FILELIST_USER_LASTMODIFIED) > 0;
boolean showDateCreated = (preferences & CmsUserSettings.FILELIST_DATE_CREATED) > 0;
boolean showUserWhoCreated = (preferences & CmsUserSettings.FILELIST_USER_CREATED) > 0;
boolean showDateReleased = (preferences & CmsUserSettings.FILELIST_DATE_RELEASED) > 0;
boolean showDateExpired = (preferences & CmsUserSettings.FILELIST_DATE_EXPIRED) > 0;
boolean fullPath = galleryView || listView;
// set the right reference project
CmsProject referenceProject;
try {
if (!listView) {
referenceProject = getCms().readProject(getSettings().getProject());
} else {
referenceProject = getCms().readProject(getSettings().getExplorerProjectId());
}
} catch (CmsException ex) {
referenceProject = getCms().getRequestContext().currentProject();
}
CmsResourceUtil resUtil = new CmsResourceUtil(getCms());
resUtil.setReferenceProject(referenceProject);
for (int i = startat; i < stopat; i++) {
CmsResource res = (CmsResource)resources.get(i);
resUtil.setResource(res);
content.append(getInitializationEntry(
resUtil,
fullPath,
showTitle,
showNavText,
showPermissions,
showDateLastModified,
showUserWhoLastModified,
showDateCreated,
showUserWhoCreated,
showDateReleased,
showDateExpired));
}
content.append(getInitializationFooter(numberOfPages, selectedPage));
return content.toString();
}
/**
* Generates a resource entry for the explorer initialization code.<p>
*
* @param resUtil the resource util object to generate the entry for
* @param showPath if the path should be given or taken from <code>top.setDirectory</code>
* @param showTitle if the title should be shown
* @param showNavText if the navtext should be shown
* @param showPermissions if the permissions should be shown
* @param showDateLastModified if the date of modification should be shown
* @param showUserWhoLastModified if the user who last modified the resource should be shown
* @param showDateCreated if the date of creation should be shown
* @param showUserWhoCreated if the user who created the resource should be shown
* @param showDateReleased if the date of release should be shown
* @param showDateExpired if the date of expiration should be shown
*
* @return js code for intializing the explorer view
*
* @see #getInitializationHeader()
* @see #getInitializationFooter(int, int)
*/
public String getInitializationEntry(
CmsResourceUtil resUtil,
boolean showPath,
boolean showTitle,
boolean showNavText,
boolean showPermissions,
boolean showDateLastModified,
boolean showUserWhoLastModified,
boolean showDateCreated,
boolean showUserWhoCreated,
boolean showDateReleased,
boolean showDateExpired) {
CmsResource resource = resUtil.getResource();
String path = getCms().getSitePath(resource);
StringBuffer content = new StringBuffer(2048);
content.append("top.aF(");
// position 1: name
content.append("\"");
content.append(resource.getName());
content.append("\",");
// position 2: path
if (showPath) {
content.append("\"");
content.append(path);
content.append("\",");
} else {
//is taken from top.setDirectory
content.append("\"\",");
}
// position 3: title
if (showTitle) {
String title = resUtil.getTitle();
content.append("\"");
content.append(CmsEncoder.escapeWBlanks(title, CmsEncoder.ENCODING_UTF_8));
content.append("\",");
} else {
content.append("\"\",");
}
// position 4: navtext
if (showNavText) {
String navText = resUtil.getNavText();
content.append("\"");
content.append(CmsEncoder.escapeWBlanks(navText, CmsEncoder.ENCODING_UTF_8));
content.append("\",");
} else {
content.append("\"\",");
}
// position 5: type
content.append(resUtil.getResourceTypeId());
content.append(",");
// position 6: link type
content.append(resUtil.getLinkType());
content.append(",");
// position 7: size
content.append(resource.getLength());
content.append(",");
// position 8: state
content.append(resource.getState());
content.append(",");
// position 9: layoutstyle
content.append(resUtil.getTimeWindowLayoutType());
content.append(',');
// position 10: date of last modification
if (showDateLastModified) {
content.append("\"");
content.append(getMessages().getDateTime(resource.getDateLastModified()));
content.append("\",");
} else {
content.append("\"\",");
}
// position 11: user who last modified the resource
if (showUserWhoLastModified) {
content.append("\"");
content.append(resUtil.getUserLastModified());
content.append("\",");
} else {
content.append("\"\",");
}
// position 12: date of creation
if (showDateCreated) {
content.append("\"");
content.append(getMessages().getDateTime(resource.getDateCreated()));
content.append("\",");
} else {
content.append("\"\",");
}
// position 13: user who created the resource
if (showUserWhoCreated) {
content.append("\"");
content.append(resUtil.getUserCreated());
content.append("\",");
} else {
content.append("\"\",");
}
// position 14: date of release
if (showDateReleased) {
content.append("\"");
content.append(resUtil.getDateReleased());
content.append("\",");
} else {
content.append("\"\",");
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?