📄 cmsexportmoduledata.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/file/CmsExportModuledata.java,v $
* Date : $Date: 2002/02/20 11:08:25 $
* Version: $Revision: 1.4 $
*
* 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 org.w3c.dom.*;
import com.opencms.util.*;
import com.opencms.core.*;
import com.opencms.template.*;
import com.opencms.defaults.master.*;
/**
* This class holds the functionaility to export channels and modulemasters from the cms
* to the filesystem.
*
* @author Edna Falkenhan
* @version $Revision: 1.4 $ $Date: 2002/02/20 11:08:25 $
*/
public class CmsExportModuledata implements I_CmsConstants, Serializable{
/**
* The tags for the manifest
*/
public static String C_EXPORT_TAG_CHANNELS = "channels";
public static String C_EXPORT_TAG_MASTERS = "masters";
public static String C_EXPORT_TAG_MASTER = "master";
public static String C_EXPORT_TAG_MASTER_SUBID = "sub_id";
public static String C_EXPORT_TAG_MASTER_DATASET = "dataset";
public static String C_EXPORT_TAG_MASTER_CHANNELREL = "channelrelations";
public static String C_EXPORT_TAG_MASTER_CHANNELNAME = "channelname";
public static String C_EXPORT_TAG_MASTER_MEDIASET = "mediaset";
public static String C_EXPORT_TAG_MASTER_MEDIA = "media";
public static String C_EXPORT_TAG_MASTER_USER = "user_name";
public static String C_EXPORT_TAG_MASTER_GROUP = "group_name";
public static String C_EXPORT_TAG_MASTER_ACCESSFLAGS = "access_flags";
public static String C_EXPORT_TAG_MASTER_PUBLICATIONDATE = "publication_date";
public static String C_EXPORT_TAG_MASTER_PURGEDATE = "purge_date";
public static String C_EXPORT_TAG_MASTER_FLAGS = "flags";
public static String C_EXPORT_TAG_MASTER_FEEDID = "feed_id";
public static String C_EXPORT_TAG_MASTER_FEEDREFERENCE = "feed_reference";
public static String C_EXPORT_TAG_MASTER_FEEDFILENAME = "feed_filename";
public static String C_EXPORT_TAG_MASTER_TITLE = "title";
public static String C_EXPORT_TAG_MASTER_DATABIG = "data_big_";
public static String C_EXPORT_TAG_MASTER_DATAMEDIUM = "data_medium_";
public static String C_EXPORT_TAG_MASTER_DATASMALL = "data_small_";
public static String C_EXPORT_TAG_MASTER_DATAINT = "data_int_";
public static String C_EXPORT_TAG_MASTER_DATAREFERENCE = "data_reference_";
public static String C_EXPORT_TAG_MASTER_DATADATE = "data_date_";
public static String C_EXPORT_TAG_MEDIA_POSITION = "media_position";
public static String C_EXPORT_TAG_MEDIA_WIDTH = "media_width";
public static String C_EXPORT_TAG_MEDIA_HEIGHT = "media_height";
public static String C_EXPORT_TAG_MEDIA_SIZE = "media_size";
public static String C_EXPORT_TAG_MEDIA_MIMETYPE = "media_mimetype";
public static String C_EXPORT_TAG_MEDIA_TYPE = "media_type";
public static String C_EXPORT_TAG_MEDIA_TITLE = "media_title";
public static String C_EXPORT_TAG_MEDIA_NAME = "media_name";
public static String C_EXPORT_TAG_MEDIA_DESCRIPTION = "media_description";
public static String C_EXPORT_TAG_MEDIA_CONTENT = "media_content";
/**
* The export-zipfile to store resources to
*/
private String m_exportFile;
/**
* The export-stream (zip) to store resources to
*/
private ZipOutputStream m_exportZipStream = null;
/**
* The export-path to read resources from the cms.
*/
private String m_exportPath;
/**
* The cms-object to do the operations.
*/
private CmsObject m_cms;
/**
* The xml manifest-file.
*/
private Document m_docXml;
/**
* The xml-element to store fileinformations to.
*/
private Element m_filesElement;
/**
* The xml-element to store mastersinformations to.
*/
private Element m_mastersElement;
/**
* Cache for previously added super folders
*/
private Vector m_superChannels;
/**
* The channelid and the resourceobject of the exported channels
*/
private Hashtable m_channelIds = new Hashtable();
/**
* This constructs a new CmsExportModuledata-object which exports the channels and modulemasters.
*
* @param exportFile the zip-file to export to.
* @param exportModules the modules to write into the exportFile
* @param exportChannels the paths of channels to write into the exportFile
* @param cms the cms-object to work with.
* @exception CmsException the CmsException is thrown if something goes wrong.
*/
public CmsExportModuledata(String exportFile, String[] exportChannels, String[] exportModules, CmsObject cms) throws CmsException {
m_exportFile = exportFile;
m_cms = cms;
// open the import resource
getExportResource();
// create the xml-config file
getXmlConfigFile();
// get the modules to export
Vector modules = new Vector();
Vector moduleNames = new Vector();
for (int i=0; i<exportModules.length; i++) {
String modName = exportModules[i];
if(modName != null && !"".equals(modName)){
moduleNames.addElement(exportModules[i]);
}
}
Hashtable moduleExportables = new Hashtable();
m_cms.getRegistry().getModuleExportables(moduleExportables);
// if there was no module selected then select all exportable modules,
// else get only the modules from Hashtable that were selected
if(moduleNames.size() == 0){
if(exportChannels.length > 0){
Enumeration modElements = moduleExportables.elements();
while(modElements.hasMoreElements()){
modules.add(modElements.nextElement());
}
}
} else {
modules = moduleNames;
}
// get the channels for export
Vector channelNames = new Vector();
for (int i=0; i<exportChannels.length; i++) {
channelNames.addElement(exportChannels[i]);
}
if(channelNames.size() != 0){
// remove the possible redundancies in the list of paths
checkRedundancies(channelNames);
} else {
// select the channels from the selected modules
Enumeration enumModules = modules.elements();
while(enumModules.hasMoreElements()){
String classname = (String)enumModules.nextElement();
CmsMasterContent cd = getContentDefinition(classname, new Class[]{CmsObject.class}, new Object[]{m_cms});
String rootName = cd.getRootChannel();
if(rootName != null && !"".equals(rootName)){
channelNames.add(rootName);
}
}
// remove the possible redundancies in the list of paths
checkRedundancies(channelNames);
}
// export the channels and return a vector with the channel-id
exportAllChannels(channelNames);
// now do the export for all modules with the given channel-ids
Enumeration enumModules = modules.elements();
while(enumModules.hasMoreElements()){
// get the name of the content definition class
String classname = (String)enumModules.nextElement();
this.exportData(classname, m_channelIds);
}
// write the document to the zip-file
writeXmlConfigFile( );
try {
m_exportZipStream.close();
} catch(IOException exc) {
throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
}
}
/** Check whether some of the resources are redundant because a superfolder has also
* been selected and change the parameter Vectors
*
* @param channelNames contains the full pathnames of all channels
*/
private void checkRedundancies(Vector channelNames) {
int i, j;
if (channelNames == null) {
return;
}
Vector redundant = new Vector();
int n = channelNames.size();
if (n > 1) {
// otherwise no check needed, because there is only one resource
for (i = 0; i < n; i++) {
redundant.addElement(new Boolean(false));
}
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
if (((String) channelNames.elementAt(i)).length() < ((String) channelNames.elementAt(j)).length()) {
if (((String) channelNames.elementAt(j)).startsWith((String) channelNames.elementAt(i))) {
redundant.setElementAt(new Boolean(true), j);
}
} else {
if (((String) channelNames.elementAt(i)).startsWith((String) channelNames.elementAt(j))) {
redundant.setElementAt(new Boolean(true), i);
}
}
}
}
for (i = n - 1; i >= 0; i--) {
if (((Boolean) redundant.elementAt(i)).booleanValue()) {
channelNames.removeElementAt(i);
}
}
}
}
/**
* Creates the xml-file and appends the initial tags to it.
*/
private void getXmlConfigFile() throws CmsException {
try {
// creates the document
m_docXml = A_CmsXmlContent.getXmlParser().createEmptyDocument(C_EXPORT_TAG_MODULEXPORT);
// add the info element. it contains all infos for this export
Element info = m_docXml.createElement(C_EXPORT_TAG_INFO);
m_docXml.getDocumentElement().appendChild(info);
addElement(m_docXml, info, C_EXPORT_TAG_CREATOR, m_cms.getRequestContext().currentUser().getName());
addElement(m_docXml, info, C_EXPORT_TAG_OC_VERSION, m_cms.version());
addElement(m_docXml, info, C_EXPORT_TAG_DATE, Utils.getNiceDate(new Date().getTime()));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -