📄 cmsnewresourcefolder.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/workplace/CmsNewResourceFolder.java,v $
* Date : $Date: 2004/01/07 10:57:09 $
* Version: $Revision: 1.39.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.CmsException;
import com.opencms.core.I_CmsConstants;
import com.opencms.core.I_CmsSession;
import com.opencms.file.CmsFile;
import com.opencms.file.CmsFolder;
import com.opencms.file.CmsObject;
import com.opencms.file.CmsResource;
import com.opencms.file.I_CmsRegistry;
import com.opencms.util.Encoder;
import com.opencms.util.Utils;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
/**
* Template class for displaying the new resource screen for a new folder
* of the OpenCms workplace.<P>
* Reads template files of the content type <code>CmsXmlWpTemplateFile</code>.
*
* @author Michael Emmerich
* @version $Revision: 1.39.2.1 $ $Date: 2004/01/07 10:57:09 $
*/
public class CmsNewResourceFolder extends CmsWorkplaceDefault implements I_CmsWpConstants,I_CmsConstants {
final static String C_SESSIONHEADER = "CmsNewResourceFolder_";
/**
* Overwrites the getContent method of the CmsWorkplaceDefault.<br>
* Gets the content of the new resource page template and processed the data input.
* @param cms The CmsObject.
* @param templateFile The new folder 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;
// get the document to display
CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
CmsXmlLanguageFile lang = xmlTemplateDocument.getLanguageFile();
I_CmsSession session = cms.getRequestContext().getSession(true);
I_CmsRegistry registry = cms.getRegistry();
boolean extendedNavigation = "on".equals(registry.getSystemValue("extendedNavigation"));
// clear the session on first call
String initial = (String)parameters.get("initial");
if (initial != null){
clearSession(session);
xmlTemplateDocument.setData("name", "");
xmlTemplateDocument.setData("title", "");
}
xmlTemplateDocument.setData("navtext", "");
xmlTemplateDocument.setData("doOnload", "");
//get the current filelist
String currentFilelist = (String)session.getValue(C_PARA_FILELIST);
if(currentFilelist == null) {
currentFilelist = cms.rootFolder().getAbsolutePath();
}
// set the title
if ((extendedNavigation) && (cms.rootFolder().getAbsolutePath().equals(currentFilelist))){
xmlTemplateDocument.setData("frameTitle", lang.getLanguageValue("label.ebtitle"));
}else{
xmlTemplateDocument.setData("frameTitle", lang.getLanguageValue("title.newfolder"));
}
// set the right endbutton lable
if(extendedNavigation){
xmlTemplateDocument.setData("endbutton", lang.getLanguageValue("button.nextscreen"));
}else{
xmlTemplateDocument.setData("endbutton", lang.getLanguageValue("button.endwizard"));
}
// get request parameters
String newFolder = (String)parameters.get(C_PARA_NEWFOLDER);
String title = Encoder.redecodeUriComponent((String)parameters.get(C_PARA_TITLE));
String navtitle = Encoder.redecodeUriComponent((String)parameters.get(C_PARA_NAVTEXT));
String navpos = (String)parameters.get(C_PARA_NAVPOS);
if (newFolder != null) {
newFolder = newFolder.trim();
}
// get the current phase of this wizard
String step = (String)parameters.get("step");
if(step != null) {
// test if we come from the extended Nav errorpages
if(step.equals("extNavError")){
step = "1";
newFolder = (String)session.getValue(C_SESSIONHEADER + C_PARA_NEWFOLDER);
title = (String)session.getValue(C_SESSIONHEADER + C_PARA_TITLE);
navtitle = (String)session.getValue(C_SESSIONHEADER + C_PARA_NAVTEXT);
navpos = (String)session.getValue(C_SESSIONHEADER + C_PARA_NAVPOS);
}
if(step.equals("1")) {
// store all data in session for ext nav or in case of an error
session.putValue(C_SESSIONHEADER + C_PARA_NEWFOLDER, newFolder.trim());
session.putValue(C_SESSIONHEADER + C_PARA_TITLE, title);
if(navtitle != null) {
session.putValue(C_SESSIONHEADER + C_PARA_NAVTEXT, navtitle);
session.putValue(C_SESSIONHEADER + C_PARA_NAVPOS, navpos);
}else{
session.removeValue(C_SESSIONHEADER + C_PARA_NAVTEXT);
session.removeValue(C_SESSIONHEADER + C_PARA_NAVPOS);
}
if(extendedNavigation){
// display the extended navigation
// look if there are allready values to display (if user used the backbutton)
Hashtable preprops = (Hashtable)session.getValue(C_SESSIONHEADER + "extendedProperties");
//set the default values or the before selected values in the template
setNavDefault(xmlTemplateDocument, preprops, newFolder);
// now we decide if we should show the sectionLogo entry (only in root)
if (cms.rootFolder().getAbsolutePath().equals(currentFilelist)){
//display it
xmlTemplateDocument.setData("displaySektLogo", xmlTemplateDocument.getProcessedDataValue("SektLogo", this));
xmlTemplateDocument.setData("displayFolderLogo", xmlTemplateDocument.getProcessedDataValue("folderLogo", this));
}else{
xmlTemplateDocument.setData("displayFolderLogo", xmlTemplateDocument.getProcessedDataValue("folderLogo", this));
xmlTemplateDocument.setData("displaySektLogo", "");
}
template = "extendedNav";
}else{
try {
// create the folder
CmsFolder folder = (CmsFolder)cms.createResource(currentFilelist, newFolder, "folder");
//cms.lockResource(folder.getAbsolutePath());
cms.writeProperty(folder.getAbsolutePath(), C_PROPERTY_TITLE, title);
// create the folder in content bodys
try{
CmsFolder bodyFolder = (CmsFolder)cms.createResource(C_VFS_PATH_BODIES.substring(0, C_VFS_PATH_BODIES.length()-1)+currentFilelist, newFolder, "folder");
//cms.lockResource(bodyFolder.getAbsolutePath());
cms.writeProperty(bodyFolder.getAbsolutePath(), C_PROPERTY_TITLE, title);
} catch (CmsException ce){
//throw ce;
}
// now check if navigation informations have to be added to the new page.
if(navtitle != null) {
cms.writeProperty(folder.getAbsolutePath(), C_PROPERTY_NAVTEXT, navtitle);
// update the navposition.
if(navpos != null) {
updateNavPos(cms, folder, navpos);
// ednfal(20.06.01) new projectmechanism: do not unlock the new folder
// try to unlock the folder, ignore the Exception (the parent folder is looked)
//try{
// cms.unlockResource(folder.getAbsolutePath());
//}catch(CmsException e){
//}
// prepare to call the dialog for creating the index.html page
session.putValue(C_PARA_FILELIST, folder.getAbsolutePath());
xmlTemplateDocument.setData("indexlocation", folder.getAbsolutePath());
}
template = "update2";
}else{
template = "update";
}
// all done, now we have to clean up our mess
clearSession(session);
}catch(CmsException ex) {
xmlTemplateDocument.setData("details", Utils.getStackTrace(ex));
return startProcessing(cms, xmlTemplateDocument, "", parameters, "error_system");
}
}
}else if("2".equals(step)){
// get all the usefull parameters and the session stuff
String back = (String)parameters.get("back");
newFolder = (String)session.getValue(C_SESSIONHEADER + C_PARA_NEWFOLDER);
title = (String)session.getValue(C_SESSIONHEADER + C_PARA_TITLE);
navtitle = (String)session.getValue(C_SESSIONHEADER + C_PARA_NAVTEXT);
navpos = (String)session.getValue(C_SESSIONHEADER + C_PARA_NAVPOS);
// generate a Hashtable for all properties for createFolder and for saving all data in the session
Hashtable allProperties = new Hashtable();
insertProperty(allProperties, C_PROPERTY_TITLE, title);
insertProperty(allProperties, C_PROPERTY_NAVTEXT, navtitle);
fillProperties(allProperties, parameters);
session.putValue(C_SESSIONHEADER + "extendedProperties", allProperties);
// check the backbutton
if (back == null){
// fast forward
try {
// first check if everything is ok
boolean checkFileLogo = ! cms.rootFolder().getAbsolutePath().equals(currentFilelist);
int propError = checkProperties(cms, allProperties, checkFileLogo);
if (propError > 0){
// error by user get the correct error template
template = "error_" + propError;
return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
}
// create the folder
CmsFolder folder = (CmsFolder)cms.createResource(currentFilelist, newFolder, C_TYPE_FOLDER_NAME);
try{
cms.lockResource(folder.getAbsolutePath());
}catch(CmsException e){
//folder is already locked, do nothing
}
cms.writeProperties(folder.getAbsolutePath(), allProperties);
// create the folder in content bodys
try{
CmsFolder bodyFolder = (CmsFolder)cms.createResource(C_VFS_PATH_BODIES.substring(0, C_VFS_PATH_BODIES.length()-1)+currentFilelist, newFolder, C_TYPE_FOLDER_NAME);
cms.lockResource(bodyFolder.getAbsolutePath());
cms.writeProperty(bodyFolder.getAbsolutePath(), C_PROPERTY_TITLE, title);
} catch (CmsException ce){
//throw ce;
}
// update the navposition.
if ((navtitle != null) && (navpos != null)){
updateNavPos(cms, folder, navpos);
// ednfal(20.06.01) new projectmechanism: do not unlock the new folder
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -