cmsadmindatabase.java
来自「java 编写的程序」· Java 代码 · 共 441 行 · 第 1/2 页
JAVA
441 行
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/workplace/CmsAdminDatabase.java,v $
* Date : $Date: 2002/04/12 12:07:17 $
* Version: $Revision: 1.23 $
*
* 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.*;
import com.opencms.file.*;
import com.opencms.core.*;
import com.opencms.util.*;
import com.opencms.template.*;
import java.util.*;
import java.io.*;
import javax.servlet.http.*;
/**
* Template class for displaying OpenCms workplace task head screens.
* <P>
*
* @author Andreas Schouten
* @version $Revision: 1.23 $ $Date: 2002/04/12 12:07:17 $
* @see com.opencms.workplace.CmsXmlWpTemplateFile
*/
public class CmsAdminDatabase extends CmsWorkplaceDefault implements I_CmsConstants {
private static String C_DATABASE_THREAD = "databse_im_export_thread";
/**
* Gets a database importfile from the client and copys it to the server.
*
* @param cms The CmsObject.
* @param session The session.
*
* @return the name of the file.
*/
private String copyFileToServer(CmsObject cms, I_CmsSession session) throws CmsException{
// get the filename
String filename = null;
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
byte[] filecontent = new byte[0];
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);
// first create the folder if it doesnt exists
File discFolder = new File(com.opencms.boot.CmsBase.getAbsolutePath(cms.readExportPath()) + "/");
if(!discFolder.exists()) {
boolean success = discFolder.mkdir();
if(com.opencms.boot.I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() && (!success)) {
A_OpenCms.log(com.opencms.boot.I_CmsLogChannels.C_OPENCMS_INFO, "[CmsAccessFilesystem] Couldn't create folder " + com.opencms.boot.CmsBase.getAbsolutePath(cms.readExportPath()) + "/"+ ".");
}
}
// now write the file into the modules dierectory in the exportpaht
File discFile = new File(com.opencms.boot.CmsBase.getAbsolutePath(cms.readExportPath()) + "/" + filename);
try {
// write the new file to disk
OutputStream s = new FileOutputStream(discFile);
s.write(filecontent);
s.close();
}
catch(Exception e) {
throw new CmsException("[" + this.getClass().getName() + "] " + e.getMessage());
}
return filename;
}
/**
* Gets the content of a defined section in a given template file and its subtemplates
* with the given parameters.
*
* @see getContent(CmsObject cms, String templateFile, String elementName, Hashtable parameters)
* @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(com.opencms.boot.I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && C_DEBUG && A_OpenCms.isLogging()) {
A_OpenCms.log(C_OPENCMS_DEBUG, this.getClassName()
+ "getting content of element "
+ ((elementName == null) ? "<root>" : elementName));
A_OpenCms.log(C_OPENCMS_DEBUG, this.getClassName()
+ "template file is: " + templateFile);
A_OpenCms.log(C_OPENCMS_DEBUG, this.getClassName()
+ "selected template section is: "
+ ((templateSelector == null) ? "<default>" : templateSelector));
}
//CmsXmlTemplateFile xmlTemplateDocument = getOwnTemplateFile(cms, templateFile, elementName, parameters, templateSelector);
CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
I_CmsSession session = cms.getRequestContext().getSession(true);
// get the parameters
// String folder = (String)parameters.get("selectallfolders");
String fileName = (String)parameters.get("filename");
String existingFile = (String)parameters.get("existingfile");
String action = (String)parameters.get("action");
String allResources = (String)parameters.get("ALLRES");
String allModules = (String)parameters.get("ALLMOD");
String step = (String)parameters.get("step");
if(action == null) {
// This is an initial request of the database administration page
// Generate datablocks for checkboxes in the HTML form
if(!cms.getRequestContext().currentProject().equals(cms.onlineProject())) {
xmlTemplateDocument.setData("nounchanged",
xmlTemplateDocument.getProcessedDataValue("nounchangedbox", this, parameters));
}
if(cms.isAdmin()) {
xmlTemplateDocument.setData("userdata",
xmlTemplateDocument.getProcessedDataValue("userdatabox", this, parameters));
}
xmlTemplateDocument.setData("moduleselect", this.getModuleSelectbox(cms, xmlTemplateDocument));
}
// first we look if the thread is allready running
if((action != null) && ("working".equals(action))) {
// still working?
Thread doTheWork = (Thread)session.getValue(C_DATABASE_THREAD);
if(doTheWork.isAlive()) {
String time = (String)parameters.get("time");
int wert = Integer.parseInt(time);
wert += 20;
xmlTemplateDocument.setData("time", "" + wert);
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, "wait");
}else {
// thread has come to an end, was there an error?
String errordetails = (String)session.getValue(C_SESSION_THREAD_ERROR);
if(errordetails == null) {
// im/export ready
session.removeValue(C_PARA_FILE);
session.removeValue(C_PARA_FILECONTENT);
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, "done");
}else {
// get errorpage:
xmlTemplateDocument.setData("details", errordetails);
session.removeValue(C_SESSION_THREAD_ERROR);
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, "error");
}
}
}
try {
if("export".equals(action)) {
// export the database
Vector resourceNames = parseResources(allResources);
String[] exportPaths = new String[resourceNames.size()];
CmsXmlLanguageFile lang = xmlTemplateDocument.getLanguageFile();
for(int i = 0;i < resourceNames.size();i++) {
// modify the foldername if nescessary (the root folder is always given
// as a nice name)
if(lang.getLanguageValue("title.rootfolder").equals(resourceNames.elementAt(i))) {
resourceNames.setElementAt("/", i);
}
exportPaths[i] = (String)resourceNames.elementAt(i);
}
boolean excludeSystem = false;
if(parameters.get("nosystem") != null) {
excludeSystem = true;
}
boolean excludeUnchanged = false;
if(parameters.get("nounchanged") != null) {
excludeUnchanged = true;
}
boolean exportUserdata = false;
if(parameters.get("userdata") != null) {
exportUserdata = true;
}
// start the thread for: export
// first clear the session entry if necessary
if(session.getValue(C_SESSION_THREAD_ERROR) != null) {
session.removeValue(C_SESSION_THREAD_ERROR);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?