📄 cmsimportmoduledata.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/file/CmsImportModuledata.java,v $
* Date : $Date: 2002/02/18 09:48:25 $
* Version: $Revision: 1.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.file;
import java.io.*;
import java.util.*;
import java.util.zip.*;
import java.lang.reflect.*;
import java.security.*;
import java.text.*;
import com.opencms.boot.*;
import com.opencms.core.*;
import com.opencms.file.*;
import com.opencms.template.*;
import com.opencms.defaults.master.*;
import org.w3c.dom.*;
import source.org.apache.java.util.*;
/**
* This class holds the functionaility to import resources from the filesystem
* into the cms.
*
* @author Edna Falkenhan
* @version $Revision: 1.2 $ $Date: 2002/02/18 09:48:25 $
*/
public class CmsImportModuledata implements I_CmsConstants, Serializable {
/**
* The algorithm for the message digest
*/
public static final String C_IMPORT_DIGEST="MD5";
/**
* The import-file to load resources from
*/
private String m_importFile;
/**
* The import-resource (folder) to load resources from
*/
private File m_importResource = null;
/**
* The version of this import, noted in the info tag of the manifest.xml.
* 0 if the import file dosent have a version nummber (that is befor version
* 4.3.23 of OpenCms).
*/
private int m_importVersion = 0;
/**
* The import-resource (zip) to load resources from
*/
private ZipFile m_importZip = null;
/**
* The import-path to write resources into the cms.
*/
private String m_importPath;
/**
* The cms-object to do the operations.
*/
private CmsObject m_cms;
/**
* The xml manifest-file.
*/
private Document m_docXml;
/**
* This constructs a new CmsImportModuledata-object which imports the moduledata.
*
* @param importFile the file or folder to import from.
* @param importPath the path to the cms to import into.
* @exception CmsException the CmsException is thrown if something goes wrong.
*/
public CmsImportModuledata(String importFile, String importPath, CmsObject cms)
throws CmsException {
m_importFile = importFile;
m_importPath = importPath;
m_cms = cms;
// open the import resource
getImportResource();
// read the xml-config file
getXmlConfigFile();
// try to read the export version nummber
try{
m_importVersion = Integer.parseInt(
getTextNodeValue((Element)m_docXml.getElementsByTagName(
C_EXPORT_TAG_INFO).item(0) , C_EXPORT_TAG_VERSION));
}catch(Exception e){
//ignore the exception, the export file has no version number (version 0).
}
}
/**
* Imports the moduledata and writes them to the cms even if there already exist conflicting files
*/
public void importModuledata() throws CmsException {
try{
// first import the channels
importChannels(null, null, null, null, null);
// now import the moduledata
importModuleMasters();
} catch (CmsException e){
throw e;
} finally {
if (m_importZip != null){
try{
m_importZip.close();
} catch (IOException exc) {
throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
}
}
}
}
/**
* Imports the resources and writes them to the cms.
* param excludeList filenames of files and folders which should not be (over) written in the virtual file system
* param writtenFilenames filenames of the files and folder which have actually been successfully written
* not used when null
* param fileCodes code of the written files (for the registry)
* not used when null
* param propertyName name of a property to be added to all resources
* param propertyValue value of that property
*/
public void importChannels(Vector excludeList, Vector writtenFilenames, Vector fileCodes, String propertyName, String propertyValue) throws CmsException {
NodeList fileNodes, propertyNodes;
Element currentElement, currentProperty;
String destination, type, user, group, access;
Hashtable properties;
Vector types = new Vector(); // stores the file types for which the property already exists
// first lock the resource to import
try {
// get all file-nodes
fileNodes = m_docXml.getElementsByTagName(CmsExportModuledata.C_EXPORT_TAG_FILE);
// walk through all files in manifest
for (int i = 0; i < fileNodes.getLength(); i++) {
currentElement = (Element) fileNodes.item(i);
// get all information for a file-import
destination = getTextNodeValue(currentElement, C_EXPORT_TAG_DESTINATION);
type = getTextNodeValue(currentElement, C_EXPORT_TAG_TYPE);
user = getTextNodeValue(currentElement, C_EXPORT_TAG_USER);
group = getTextNodeValue(currentElement, C_EXPORT_TAG_GROUP);
access = getTextNodeValue(currentElement, C_EXPORT_TAG_ACCESS);
if (!inExcludeList(excludeList, m_importPath + destination)) {
// get all properties for this file
propertyNodes = currentElement.getElementsByTagName(C_EXPORT_TAG_PROPERTY);
// clear all stores for property information
properties = new Hashtable();
// add the module property to properties
if (propertyName != null && propertyValue != null && !"".equals(propertyName)) {
if (!types.contains(type)) {
types.addElement(type);
createPropertydefinition(propertyName, type);
}
properties.put(propertyName, propertyValue);
}
// walk through all properties
for (int j = 0; j < propertyNodes.getLength(); j++) {
currentProperty = (Element) propertyNodes.item(j);
// get all information for this property
String name = getTextNodeValue(currentProperty, C_EXPORT_TAG_NAME);
String value = getTextNodeValue(currentProperty, C_EXPORT_TAG_VALUE);
if(value == null) {
// create an empty property
value = "";
}
// store these informations
if ((name != null) && (value != null)) {
properties.put(name, value);
createPropertydefinition(name, type);
}
}
// import the specified file and write maybe put it on the lists writtenFilenames,fileCodes
importChannel(destination, type, user, group, access, properties, writtenFilenames, fileCodes);
} else {
System.out.print("skipping " + destination);
}
}
} catch (Exception exc) {
throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
}
}
/**
* Gets the available modules in the current system
* and imports the data for existing modules
*/
public void importModuleMasters() throws CmsException{
// get all available modules in this system
Hashtable moduleExportables = new Hashtable();
m_cms.getRegistry().getModuleExportables(moduleExportables);
// now get the subIds of each module
Hashtable availableModules = new Hashtable();
Enumeration modElements = moduleExportables.elements();
while(modElements.hasMoreElements()){
String classname = (String)modElements.nextElement();
// get the subId of the module
try{
int subId = getContentDefinition(classname, new Class[]{CmsObject.class}, new Object[]{m_cms}).getSubId();
// put the subid and the classname into the hashtable of available modules
availableModules.put(""+subId, classname);
} catch (Exception e){
// do nothing
}
}
// now get the moduledata for import
NodeList masterNodes;
Element currentElement;
String subid;
try {
// get all master-nodes
masterNodes = m_docXml.getElementsByTagName(CmsExportModuledata.C_EXPORT_TAG_MASTER);
// walk through all files in manifest
for (int i = 0; i < masterNodes.getLength(); i++) {
currentElement = (Element) masterNodes.item(i);
// get the subid of the modulemaster
subid = getTextNodeValue(currentElement, CmsExportModuledata.C_EXPORT_TAG_MASTER_SUBID);
// check if there exists a module with this subid
String classname = (String)availableModules.get(subid);
if((classname != null) && !("".equals(classname.trim()))){
// import the dataset, the channelrelation and the media
importMaster(subid, classname, currentElement);
}
}
} catch (Exception exc) {
throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
}
}
/**
* This method returns the resource-names that are needed to create a project for this import.
* It calls the method getConflictingFileNames if needed, to calculate these resources.
*/
public Vector getResourcesForProject() throws CmsException {
NodeList fileNodes;
Element currentElement, currentProperty;
String destination, path;
Vector resources = new Vector();
try {
// get all file-nodes
fileNodes = m_docXml.getElementsByTagName(C_EXPORT_TAG_FILE);
// walk through all files in manifest
for (int i = 0; i < fileNodes.getLength(); i++) {
currentElement = (Element) fileNodes.item(i);
destination = getTextNodeValue(currentElement, C_EXPORT_TAG_DESTINATION);
path = m_importPath + destination;
// get the resources for a project
try {
String resource = destination.substring(0, destination.indexOf("/",1) + 1);
resource = m_importPath + resource;
// add the resource, if it dosen't already exist
if((!resources.contains(resource)) && (!resource.equals(m_importPath))) {
try {
m_cms.setContextToCos();
m_cms.readFolder(resource);
m_cms.setContextToVfs();
// this resource exists in the current project -> add it
resources.addElement(resource);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -