cmsexplorer.java
来自「找了很久才找到到源代码」· Java 代码 · 共 786 行 · 第 1/2 页
JAVA
786 行
// position 15: date of expiration
if (showDateExpired) {
content.append("\"");
content.append(resUtil.getDateExpired());
content.append("\",");
} else {
content.append("\"\",");
}
// position 16: permissions
if (showPermissions) {
content.append("\"");
content.append(CmsStringUtil.escapeJavaScript(resUtil.getPermissionString()));
content.append("\",");
} else {
content.append("\"\",");
}
// position 17: locked by
content.append("\"");
content.append(CmsStringUtil.escapeJavaScript(resUtil.getLockedByName()));
content.append("\",");
// position 18: name of project where the resource is locked in
content.append("\"");
content.append(resUtil.getLockedInProjectName());
content.append("\",");
// position 19: id of project where resource belongs to
int lockState = resUtil.getLockState();
content.append(lockState);
content.append(",\"");
// position 20: project state, I=resource is inside current project, O=resource is outside current project
if (resUtil.isInsideProject()) {
content.append("I");
} else {
content.append("O");
}
content.append("\",\"");
// position 21: system lock info, used as text for tool tip
content.append(resUtil.getSystemLockInfo(true));
content.append("\", ");
// position 22: project state
content.append(resUtil.getProjectState().getMode());
// finish
content.append(");\n");
return content.toString();
}
/**
* Generates the footer of the explorer initialization code.<p>
*
* @param numberOfPages the number of pages
* @param selectedPage the selected page to display
*
* @return js code for intializing the explorer view
*
* @see #getInitializationHeader()
* @see #getInitializationEntry(CmsResourceUtil, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean)
*/
public String getInitializationFooter(int numberOfPages, int selectedPage) {
StringBuffer content = new StringBuffer(1024);
content.append("top.dU(document,");
content.append(numberOfPages);
content.append(",");
content.append(selectedPage);
content.append("); \n");
// display eventual error message
if (getSettings().getErrorMessage() != null) {
// display error message as JavaScript alert
content.append("alert(\"");
content.append(CmsStringUtil.escapeJavaScript(getSettings().getErrorMessage().key(getLocale())));
content.append("\");\n");
// delete error message container in settings
getSettings().setErrorMessage(null);
}
// display eventual broadcast message(s)
String message = getBroadcastMessageString();
if (CmsStringUtil.isNotEmpty(message)) {
// display broadcast as JavaScript alert
content.append("alert(decodeURIComponent(\"");
// the user has pending messages, display them all
content.append(CmsEncoder.escapeWBlanks(message, CmsEncoder.ENCODING_UTF_8));
content.append("\"));\n");
}
content.append("}\n");
return content.toString();
}
/**
* Generates the header of the initialization code.<p>
*
* @return js code for intializing the explorer view
*
* @see #getInitializationFooter(int, int)
* @see #getInitializationEntry(CmsResourceUtil, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean)
*/
public String getInitializationHeader() {
// if mode is "listview", all file in the set collector will be shown
boolean listView = VIEW_LIST.equals(getSettings().getExplorerMode());
String currentResourceName = getSettings().getExplorerResource();
CmsResource currentResource = null;
try {
currentResource = getCms().readResource(currentResourceName, CmsResourceFilter.ALL);
} catch (CmsException e) {
// file was not readable
}
if (currentResource == null) {
// show the root folder in case of an error and reset the state
currentResourceName = "/";
try {
currentResource = getCms().readResource(currentResourceName, CmsResourceFilter.ALL);
} catch (CmsException e) {
// should usually never happen
LOG.error(e.getLocalizedMessage(), e);
throw new CmsRuntimeException(e.getMessageContainer(), e);
}
}
StringBuffer content = new StringBuffer(1024);
content.append("function initialize() {\n");
content.append("top.setRootFolder(\"");
String rootFolder = getRootFolder();
content.append(rootFolder);
content.append("\");\n");
content.append("top.mode=\"");
content.append(getSettings().getExplorerMode());
content.append("\";\n");
// the resource id of plain resources
content.append("top.plainresid=");
content.append(CmsResourceTypePlain.getStaticTypeId());
content.append(";\n");
// the autolock setting
content.append("top.autolock=");
content.append(OpenCms.getWorkplaceManager().autoLockResources());
content.append(";\n");
// the button type setting
content.append("top.buttonType=");
content.append(getSettings().getUserSettings().getExplorerButtonStyle());
content.append(";\n");
// the help_url
content.append("top.head.helpUrl='explorer/index.html';\n");
// the project
content.append("top.setProject('");
if (!listView) {
content.append(getSettings().getProject());
} else {
content.append(getSettings().getExplorerProjectId());
}
content.append("');\n");
// the onlineProject
content.append("top.setOnlineProject('");
content.append(CmsProject.ONLINE_PROJECT_ID);
content.append("');\n");
// set the writeAccess for the current Folder
boolean writeAccess = VIEW_EXPLORER.equals(getSettings().getExplorerMode());
if (writeAccess) {
writeAccess = getCms().isInsideCurrentProject(currentResourceName);
}
content.append("top.enableNewButton(");
content.append(writeAccess);
content.append(");\n");
// the folder
content.append("top.setDirectory(\"");
content.append(CmsResource.getFolderPath(currentResource.getRootPath()));
content.append("\",\"");
content.append(CmsResource.getFolderPath(getSettings().getExplorerResource()));
content.append("\");\n");
content.append("top.rD();\n");
List reloadTreeFolders = (List)getJsp().getRequest().getAttribute(REQUEST_ATTRIBUTE_RELOADTREE);
if (reloadTreeFolders != null) {
// folder tree has to be reloaded after copy, delete, move, rename operation
String reloadFolder = "";
for (int i = 0; i < reloadTreeFolders.size(); i++) {
reloadFolder = (String)reloadTreeFolders.get(i);
if (getSettings().getUserSettings().getRestrictExplorerView()) {
// in restricted view, adjust folder path to reload: remove restricted folder name
if (reloadFolder.length() >= rootFolder.length()) {
reloadFolder = reloadFolder.substring(rootFolder.length() - 1);
}
}
content.append("top.addNodeToLoad(\"" + reloadFolder + "\");\n");
}
content.append("top.reloadNodeList();\n");
}
content.append("\n");
return content.toString();
}
/**
* Determines the root folder of the current tree dependent on users setting of explorer view restriction.<p>
*
* @return the root folder resource name to display
*/
public String getRootFolder() {
String folder = "/";
if (getSettings().getUserSettings().getRestrictExplorerView()) {
folder = getSettings().getUserSettings().getStartFolder();
}
try {
getCms().readFolder(folder, CmsResourceFilter.IGNORE_EXPIRATION);
return folder;
} catch (CmsException e) {
// should usually never happen
if (LOG.isInfoEnabled()) {
LOG.info(e);
}
return "/";
}
}
/**
* @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
*/
protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
String currentResource = request.getParameter(PARAMETER_RESOURCE);
String mode = request.getParameter(PARAMETER_MODE);
if (CmsStringUtil.isNotEmpty(mode)) {
settings.setExplorerMode(mode);
} else {
// null argument, use explorer view if no other view currently specified
if (!(VIEW_GALLERY.equals(settings.getExplorerMode()) || VIEW_LIST.equals(settings.getExplorerMode()))) {
settings.setExplorerMode(VIEW_EXPLORER);
}
}
m_uri = request.getParameter(PARAMETER_URI);
if (CmsStringUtil.isNotEmpty(currentResource) && folderExists(getCms(), currentResource)) {
// resource is a folder, set resource name
settings.setExplorerResource(currentResource);
} else {
// other cases (resource null, no folder), first get the resource name from settings
currentResource = settings.getExplorerResource();
if (!resourceExists(getCms(), currentResource)) {
// resource does not exist, display root folder
settings.setExplorerResource("/");
}
}
String selectedPage = request.getParameter(PARAMETER_PAGE);
if (selectedPage != null) {
int page = 1;
try {
page = Integer.parseInt(selectedPage);
} catch (NumberFormatException e) {
// default is 1
if (LOG.isInfoEnabled()) {
LOG.info(e);
}
}
settings.setExplorerPage(page);
}
if (getSettings().getExplorerMode().equals(CmsExplorer.VIEW_EXPLORER)) {
// reset the startup URI, so that it is not displayed again on reload of the frameset
getSettings().setViewStartup(null);
}
// if in explorer list view
if (getSettings().getExplorerMode().equals(CmsExplorer.VIEW_LIST)) {
// if no other view startup url has been set
if (getSettings().getViewStartup() == null) {
// if not in the admin view
if (getSettings().getViewUri().indexOf(CmsToolManager.ADMINVIEW_ROOT_LOCATION) < 0) {
// set the view startup url as editor close link!
String uri = CmsToolManager.VIEW_JSPPAGE_LOCATION;
uri = CmsRequestUtil.appendParameter(
CmsWorkplace.VFS_PATH_VIEWS + "explorer/explorer_fs.jsp",
"uri",
CmsEncoder.encode(CmsEncoder.encode(uri)));
getSettings().setViewStartup(getJsp().link(uri));
}
}
}
// the flaturl
settings.setExplorerFlaturl(request.getParameter(PARAMETER_FLATURL));
}
/**
* Checks if a folder with a given name exits in the VFS.<p>
*
* @param cms the current cms context
* @param folder the folder to check for
* @return true if the folder exists in the VFS
*/
private boolean folderExists(CmsObject cms, String folder) {
try {
CmsFolder test = cms.readFolder(folder, CmsResourceFilter.IGNORE_EXPIRATION);
if (test.isFile()) {
return false;
}
return true;
} catch (Exception e) {
return false;
}
}
/**
* Returns a list resources that should be displayed in the
* OpenCms Exlorer.<p>
*
* How the list is build depends on the current Workplace settings
* of the user.
*
* @param resource the resource to read the files from (usually a folder)
* @return a list of resources to display
*/
private List getResources(String resource) {
if (VIEW_LIST.equals(getSettings().getExplorerMode())) {
// check if the list must show the list view or the check content view
I_CmsResourceCollector collector = getSettings().getCollector();
if (collector != null) {
// is this the collector for the list view
if (collector instanceof I_CmsListResourceCollector) {
((I_CmsListResourceCollector)collector).setPage(getSettings().getExplorerPage());
}
try {
return collector.getResults(getCms());
} catch (CmsException e) {
if (LOG.isInfoEnabled()) {
LOG.info(e);
}
}
}
return Collections.EMPTY_LIST;
} else if (VIEW_GALLERY.equals(getSettings().getExplorerMode())) {
// select galleries
A_CmsGallery gallery = A_CmsGallery.createInstance(getSettings().getGalleryType(), getJsp());
return gallery.getGalleries();
} else {
// default is to return a list of all files in the folder
try {
return getCms().getResourcesInFolder(resource, CmsResourceFilter.ONLY_VISIBLE);
} catch (CmsException e) {
// should usually never happen
if (LOG.isInfoEnabled()) {
LOG.info(e);
}
return Collections.EMPTY_LIST;
}
}
}
/**
* Sets the default preferences for the current user if those values are not available.<p>
*
* @return the int value of the default preferences
*/
private int getUserPreferences() {
CmsUserSettings settings = new CmsUserSettings(getCms());
return settings.getExplorerSettings();
}
/**
* Checks if a resource with a given name exits in the VFS.<p>
*
* @param cms the current cms context
* @param resource the resource to check for
* @return true if the resource exists in the VFS
*/
private boolean resourceExists(CmsObject cms, String resource) {
try {
cms.readResource(resource, CmsResourceFilter.ALL);
return true;
} catch (CmsException e) {
return false;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?