📄 cmsexportmoduledata.java
字号:
A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, e.getMessage() );
}
}
return cd;
}
/**
* Substrings the source-filename, so it is shrinked to the needed part for
* import/export.
* @param absoluteName The absolute path of the resource.
* @return The shrinked path.
*/
private String getSourceFilename(String absoluteName) {
// String path = absoluteName.substring(m_exportPath.length());
String path = absoluteName; // keep absolute name to distinguish resources
if (path.startsWith("/")) {
path = path.substring(1);
}
if(path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
return path;
}
/**
* Export the content definitions in the specified channels.
* @param cms The CmsObject
* @param zipfile The zip file to store the data
* @param manifest The document where the maindata of the master are stored
* @param channelId The Vector that includes the exported channels
*/
private void exportData(String classname, Hashtable exportedChannels) throws CmsException {
// get the modulemaster for each exported channel
System.out.println("Export Module "+classname);
Enumeration keys = exportedChannels.keys();
// 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.hasMoreElements()){
int channelId = Integer.parseInt((String) keys.nextElement());
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);
writeExportManifestEntries(classname, curDataset, masterNr, subId);
masterNr++;
}
} catch (InvocationTargetException 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) {
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) {
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() );
}
}
}
}
/**
* Write the XML-entries and Documents of a contentdefinition
*/
private void writeExportManifestEntries(String classname, CmsMasterDataSet dataset, int masterNr, int subId)
throws CmsException{
// the name of the XML-file where the dataset is stored
String dataSetFile = "dataset_"+subId+"_"+masterNr+".xml";
// create new mastercontent for getting channels and media
CmsMasterContent content = getContentDefinition(classname, new Class[]{CmsObject.class, CmsMasterDataSet.class}, new Object[]{m_cms, dataset});
// the channels of the master
Vector channels = content.getChannels();
// write these informations to the xml-manifest
Element master = m_docXml.createElement(this.C_EXPORT_TAG_MASTER);
m_mastersElement.appendChild(master);
addElement(m_docXml, master, this.C_EXPORT_TAG_MASTER_SUBID, ""+subId);
// add the name of the datasetfile and create the datasetfile
// with the information from the dataset
addElement(m_docXml, master, this.C_EXPORT_TAG_MASTER_DATASET, dataSetFile);
writeExportDataset(dataset, dataSetFile, masterNr, subId);
// add the channel relation of this master
Element channelrel = m_docXml.createElement(this.C_EXPORT_TAG_MASTER_CHANNELREL);
master.appendChild(channelrel);
Vector moduleChannels = content.getChannels();
for(int i=0; i<moduleChannels.size(); i++){
String channelname = (String)moduleChannels.elementAt(i);
addElement(m_docXml, channelrel, this.C_EXPORT_TAG_MASTER_CHANNELNAME, channelname);
}
// add the mediaset
Element mediaset = m_docXml.createElement(this.C_EXPORT_TAG_MASTER_MEDIASET);
master.appendChild(mediaset);
Vector moduleMedia = content.getMedia();
for(int i=0; i<moduleMedia.size(); i++){
// for each media add the name of the xml-file for the mediadata to the manifest
// and create the files for the media information
String mediaFile = "media_"+subId+"_"+masterNr+"_"+i+".xml";
addElement(m_docXml, mediaset, this.C_EXPORT_TAG_MASTER_MEDIA, mediaFile);
writeExportMediaset((CmsMasterMedia)moduleMedia.elementAt(i), mediaFile, masterNr, subId, i);
}
}
/**
* Write the XML-entries and Documents of the dataset of a contentdefinition
*/
private void writeExportDataset(CmsMasterDataSet dataset, String filename, int masterNr, int subId)
throws CmsException{
// creates the XML-document
Document xmlDoc = null;
try{
xmlDoc = A_CmsXmlContent.getXmlParser().createEmptyDocument(C_EXPORT_TAG_MODULEXPORT);
} catch(Exception exc) {
throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
}
// add the data element
Element elementDataset = xmlDoc.createElement(this.C_EXPORT_TAG_MASTER_DATASET);
xmlDoc.getDocumentElement().appendChild(elementDataset);
// add the data of the contentdefinition
// get the name of the owner
String ownerName = "";
try{
ownerName = m_cms.readUser(dataset.m_userId).getName();
} catch (CmsException e){
}
// get the name of the group
String groupName = "";
try{
groupName = m_cms.readGroup(dataset.m_groupId).getName();
} catch (CmsException e){
}
addElement(xmlDoc, elementDataset, this.C_EXPORT_TAG_MASTER_USER, ownerName);
addElement(xmlDoc, elementDataset, this.C_EXPORT_TAG_MASTER_GROUP, groupName);
addElement(xmlDoc, elementDataset, this.C_EXPORT_TAG_MASTER_ACCESSFLAGS, ""+dataset.m_accessFlags);
addElement(xmlDoc, elementDataset, this.C_EXPORT_TAG_MASTER_PUBLICATIONDATE, Utils.getNiceDate(dataset.m_publicationDate));
addElement(xmlDoc, elementDataset, this.C_EXPORT_TAG_MASTER_PURGEDATE, Utils.getNiceDate(dataset.m_purgeDate));
addElement(xmlDoc, elementDataset, this.C_EXPORT_TAG_MASTER_FLAGS, ""+dataset.m_flags);
addElement(xmlDoc, elementDataset, this.C_EXPORT_TAG_MASTER_FEEDID, ""+dataset.m_feedId);
addElement(xmlDoc, elementDataset, this.C_EXPORT_TAG_MASTER_FEEDREFERENCE, ""+dataset.m_feedReference);
addElement(xmlDoc, elementDataset, this.C_EXPORT_TAG_MASTER_FEEDFILENAME, dataset.m_feedFilename);
addElement(xmlDoc, elementDataset, this.C_EXPORT_TAG_MASTER_TITLE, dataset.m_title);
// get the values of data_big from the string array
for(int i=0; i< dataset.m_dataBig.length; i++){
String value = dataset.m_dataBig[i];
String dataFile = new String();
if(value != null && !"".equals(value)){
// the name of the file where the value of the field is stored
dataFile = "databig_"+subId+"_"+masterNr+"_"+i+".dat";
writeExportContentFile(dataFile, value.getBytes());
}
addElement(xmlDoc, elementDataset, this.C_EXPORT_TAG_MASTER_DATABIG+i, dataFile);
}
// get the values of data_medium from the string array
for(int i=0; i< dataset.m_dataMedium.length; i++){
String value = dataset.m_dataMedium[i];
String dataFile = new String();
if(value != null && !"".equals(value)){
// the name of the file where the value of the field is stored
dataFile = "datamedium_"+subId+"_"+masterNr+"_"+i+".dat";
writeExportContentFile(dataFile, value.getBytes());
}
addElement(xmlDoc, elementDataset, this.C_EXPORT_TAG_MASTER_DATAMEDIUM+i, dataFile);
}
// get the values of data_small from the string array
for(int i=0; i< dataset.m_dataSmall.length; i++){
String value = dataset.m_dataSmall[i];
String dataFile = new String();
if(value != null && !"".equals(value)){
// the name of the file where the value of the field is stored
dataFile = "datasmall_"+subId+"_"+masterNr+"_"+i+".dat";
writeExportContentFile(dataFile, value.getBytes());
}
addElement(xmlDoc, elementDataset, this.C_EXPORT_TAG_MASTER_DATASMALL+i, dataFile);
}
// get the values of data_int from the int array
for(int i=0; i< dataset.m_dataInt.length; i++){
String value = ""+dataset.m_dataInt[i];
addElement(xmlDoc, elementDataset, this.C_EXPORT_TAG_MASTER_DATAINT+i, value);
}
// get the values of data_reference from the int array
for(int i=0; i< dataset.m_dataReference.length; i++){
String value = ""+dataset.m_dataReference[i];
addElement(xmlDoc, elementDataset, this.C_EXPORT_TAG_MASTER_DATAREFERENCE+i, value);
}
// get the values of data_reference from the int array
for(int i=0; i< dataset.m_dataDate.length; i++){
String value = Utils.getNiceDate(dataset.m_dataDate[i]);
addElement(xmlDoc, elementDataset, this.C_EXPORT_TAG_MASTER_DATADATE+i, value);
}
try {
ZipEntry entry = new ZipEntry(filename);
m_exportZipStream.putNextEntry(entry);
A_CmsXmlContent.getXmlParser().getXmlText(xmlDoc, m_exportZipStream);
m_exportZipStream.closeEntry();
} catch(Exception exc) {
throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
}
}
/**
* Write the XML-entries and Documents of the dataset of a contentdefinition
*/
private void writeExportMediaset(CmsMasterMedia media, String filename, int masterNr, int subId, int mediaId)
throws CmsException{
// creates the XML-document
Document xmlDoc = null;
try{
xmlDoc = A_CmsXmlContent.getXmlParser().createEmptyDocument(C_EXPORT_TAG_MODULEXPORT);
} catch(Exception exc) {
throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
}
// add the data element
Element elementMedia = xmlDoc.createElement("media");
xmlDoc.getDocumentElement().appendChild(elementMedia);
// add the data of the contentdefinition
addElement(xmlDoc, elementMedia, this.C_EXPORT_TAG_MEDIA_POSITION, ""+media.getPosition());
addElement(xmlDoc, elementMedia, this.C_EXPORT_TAG_MEDIA_WIDTH, ""+media.getWidth());
addElement(xmlDoc, elementMedia, this.C_EXPORT_TAG_MEDIA_HEIGHT, ""+media.getHeight());
addElement(xmlDoc, elementMedia, this.C_EXPORT_TAG_MEDIA_SIZE, ""+media.getSize());
addElement(xmlDoc, elementMedia, this.C_EXPORT_TAG_MEDIA_MIMETYPE, media.getMimetype());
addElement(xmlDoc, elementMedia, this.C_EXPORT_TAG_MEDIA_TYPE, ""+media.getType());
addElement(xmlDoc, elementMedia, this.C_EXPORT_TAG_MEDIA_TITLE, media.getTitle());
addElement(xmlDoc, elementMedia, this.C_EXPORT_TAG_MEDIA_NAME, media.getName());
addElement(xmlDoc, elementMedia, this.C_EXPORT_TAG_MEDIA_DESCRIPTION, media.getDescription());
// now add the name of the file where the media content is stored and write this file
String contentFilename = "mediacontent_"+subId+"_"+masterNr+"_"+mediaId+".dat";
addElement(xmlDoc, elementMedia, this.C_EXPORT_TAG_MEDIA_CONTENT, contentFilename);
writeExportContentFile(contentFilename, media.getMedia());
// write the media xml-file
try {
ZipEntry entry = new ZipEntry(filename);
m_exportZipStream.putNextEntry(entry);
A_CmsXmlContent.getXmlParser().getXmlText(xmlDoc, m_exportZipStream);
m_exportZipStream.closeEntry();
} catch(Exception exc) {
throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
}
}
/**
* Write the XML-entries and Documents of the media of a contentdefinition
*/
private void writeExportContentFile(String filename, byte[] content){
try{
// store the userinfo in zip-file
ZipEntry entry = new ZipEntry(filename);
m_exportZipStream.putNextEntry(entry);
m_exportZipStream.write(content);
m_exportZipStream.closeEntry();
} catch (IOException ioex){
System.err.println("IOException: "+ioex.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -