📄 cmsexportmoduledata.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/file/Attic/CmsExportModuledata.java,v $
* Date : $Date: 2003/04/01 15:20:18 $
* Version: $Revision: 1.17 $
*
* 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 com.opencms.boot.I_CmsLogChannels;
import com.opencms.core.A_OpenCms;
import com.opencms.core.CmsException;
import com.opencms.core.I_CmsConstants;
import com.opencms.defaults.master.CmsMasterContent;
import com.opencms.defaults.master.CmsMasterDataSet;
import com.opencms.defaults.master.CmsMasterMedia;
import com.opencms.report.I_CmsReport;
import com.opencms.template.A_CmsXmlContent;
import com.opencms.util.Utils;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import java.util.zip.ZipEntry;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* Holds the functionaility to export channels and modulemasters from the cms
* to the filesystem.
*
* @author Edna Falkenhan
* @author Alexander Kandzior (a.kandzior@alkacon.com)
*
* @version $Revision: 1.17 $ $Date: 2003/04/01 15:20:18 $
*/
public class CmsExportModuledata extends CmsExport implements I_CmsConstants, Serializable{
// the tags for the manifest or dataset xml files
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";
/** Holds information about contents that have already been exported */
private Vector m_exportedMasters = new Vector();
/**
* This constructs a new CmsExportModuledata-object which exports the channels and modulemasters.
*
* @param cms the cms-object to work with
* @param exportFile the filename of the zip to export to
* @param resourcesToExport the cos folders (channels) to export
* @param modulesToExport the modules to export
* @param report to write the progress information to
*
* @throws CmsException if something goes wrong
*/
public CmsExportModuledata(
CmsObject cms,
String exportFile,
String[] resourcesToExport,
String[] modulesToExport,
I_CmsReport report
) throws CmsException {
m_cms = cms;
m_exportFile = exportFile;
m_cms = cms;
m_report = report;
// indicate that module date is exported to the export super class
m_exportingModuleData = true;
// open the export file
openExportFile(null);
// export the cos folders (ie. channels)
m_report.println(m_report.key("report.export_channels_begin"), I_CmsReport.C_FORMAT_HEADLINE);
try {
m_cms.setContextToCos();
// export all the resources
exportAllResources(resourcesToExport);
} catch (Exception e) {
throw new CmsException("Error exporting COS channels", e);
} finally {
m_cms.setContextToVfs();
}
m_report.println(m_report.key("report.export_channels_end"), I_CmsReport.C_FORMAT_HEADLINE);
// get the modules to export
Vector modules = new Vector();
Vector moduleNames = new Vector();
for (int i=0; i<modulesToExport.length; i++) {
String modName = modulesToExport[i];
if(modName != null && !"".equals(modName)){
moduleNames.addElement(modulesToExport[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(resourcesToExport.length > 0){
Enumeration modElements = moduleExportables.elements();
while(modElements.hasMoreElements()){
modules.add(modElements.nextElement());
}
}
} else {
modules = moduleNames;
}
// 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_exportedChannelIds);
}
// close the export file
closeExportFile();
}
/**
* Exports the content definition data,
* only content definition data from selected channels will be exported.<p>
*
* @param classname name of the content definition class
* @param exportedChannelIds set of channels that have been exported
*
*/
private void exportData(
String classname,
Set exportedChannelIds
) throws CmsException {
// output something to the report for the data
m_report.print(m_report.key("report.export_moduledata_begin"), I_CmsReport.C_FORMAT_HEADLINE);
m_report.print("<i>" + classname + "</i>", I_CmsReport.C_FORMAT_HEADLINE);
m_report.println(m_report.key("report.dots"), I_CmsReport.C_FORMAT_HEADLINE);
Iterator keys = exportedChannelIds.iterator();
// get the subId of the module
int subId = getContentDefinition(classname, new Class[]{CmsObject.class}, new Object[]{m_cms}).getSubId();
// the number for identifying each master
int masterNr = 1;
while(keys.hasNext()){
int channelId;
String key = (String)keys.next();
try {
channelId = Integer.parseInt(key);
} catch (NumberFormatException nfe) {
m_report.println(nfe);
continue;
}
try{
Vector allDatasets = new Vector();
// execute the static method readAllByChannel of the content definition class
allDatasets = (Vector)Class.forName(classname).getMethod("readAllByChannel",
new Class[] {CmsObject.class, Integer.class, Integer.class}).invoke(null,
new Object[] {m_cms, new Integer(channelId), new Integer(subId)});
for(int i=0; i<allDatasets.size(); i++){
CmsMasterDataSet curDataset = (CmsMasterDataSet)allDatasets.elementAt(i);
if(!m_exportedMasters.contains(""+curDataset.m_masterId)){
writeExportManifestEntries(classname, curDataset, masterNr, subId);
m_exportedMasters.add(""+curDataset.m_masterId);
masterNr++;
}
}
} catch (InvocationTargetException ite) {
m_report.println(ite);
if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, "[CmsExportModuledata] "+classname + ".readAllByChannel: Invocation target exception!");
}
} catch (NoSuchMethodException nsm) {
m_report.println(nsm);
if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, "[CmsExportModuledata] "+classname + ".readAllByChannel: Requested method was not found!");
}
} catch (Exception e) {
m_report.println(e);
if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, "[CmsExportModuledata] "+classname + ".readAllByChannel: Other exception! "+e);
A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, e.getMessage() );
}
}
}
m_report.println(m_report.key("report.export_moduledata_end"), I_CmsReport.C_FORMAT_HEADLINE);
}
/**
* Export a single content definition.<P>
*
* @param classname name of the content definition class
* @param dataset data for the content definition object instance
* @param masterNr id of master
* @param subId id of content definition
*
* @throws CmsException if something goes wrong
*/
private void writeExportManifestEntries(
String classname,
CmsMasterDataSet dataset,
int masterNr,
int subId
) throws CmsException{
// output something to the report for the resource
m_report.print(m_report.key("report.exporting"), I_CmsReport.C_FORMAT_NOTE);
m_report.print("'" + dataset.m_title + "' (id: " + dataset.m_masterId + ")");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -