📄 cmsimportmoduledata.java
字号:
accessFlags = CmsImport.getChildElementTextValue(dataset, CmsExportModuledata.C_EXPORT_TAG_MASTER_ACCESSFLAGS);
try {
newDataset.m_accessFlags = Integer.parseInt(accessFlags);
} catch (Exception e) {
newDataset.m_accessFlags = com.opencms.core.I_CmsConstants.C_ACCESS_DEFAULT_FLAGS;
}
// set the publication date
publicationDate = CmsImport.getChildElementTextValue(
dataset,
CmsExportModuledata.C_EXPORT_TAG_MASTER_PUBLICATIONDATE);
try {
newDataset.m_publicationDate = convertDate(publicationDate);
} catch (Exception e) {
// ignore
}
// set the purge date
purgeDate = CmsImport.getChildElementTextValue(dataset, CmsExportModuledata.C_EXPORT_TAG_MASTER_PURGEDATE);
try {
newDataset.m_purgeDate = convertDate(purgeDate);
} catch (Exception e) {
// ignore
}
// set the creation date if possible
try {
creationDate = CmsImport.getChildElementTextValue(
dataset,
CmsExportModuledata.C_EXPORT_TAG_MASTER_CREATEDATE);
newDataset.m_dateCreated = convertDate(creationDate);
} catch (Exception e) {
// ignore
}
// set the flags
flags = CmsImport.getChildElementTextValue(dataset, CmsExportModuledata.C_EXPORT_TAG_MASTER_FLAGS);
try {
newDataset.m_flags = Integer.parseInt(flags);
} catch (Exception e) {
// ignore
}
// set the feedid
feedId = CmsImport.getChildElementTextValue(dataset, CmsExportModuledata.C_EXPORT_TAG_MASTER_FEEDID);
try {
newDataset.m_feedId = Integer.parseInt(feedId);
} catch (Exception e) {
// ignore
}
// set the feedreference
feedReference = CmsImport.getChildElementTextValue(
dataset,
CmsExportModuledata.C_EXPORT_TAG_MASTER_FEEDREFERENCE);
try {
newDataset.m_feedReference = Integer.parseInt(feedReference);
} catch (Exception e) {
// ignore
}
// set the feedfilenam
feedFilename = CmsImport.getChildElementTextValue(dataset, CmsExportModuledata.C_EXPORT_TAG_MASTER_FEEDFILENAME);
newDataset.m_feedFilename = feedFilename;
// set the masters title
title = CmsImport.getChildElementTextValue(dataset, CmsExportModuledata.C_EXPORT_TAG_MASTER_TITLE);
newDataset.m_title = title;
// set the values of data_big
for (int i = 0; i < newDataset.m_dataBig.length; i++) {
String filename = CmsImport.getChildElementTextValue(
dataset,
CmsExportModuledata.C_EXPORT_TAG_MASTER_DATABIG + i);
String value = new String();
if (filename != null && !"".equals(filename.trim())) {
// get the value from the file
value = new String(getFileBytes(filename));
}
newDataset.m_dataBig[i] = value;
}
// get the values of data_medium
for (int i = 0; i < newDataset.m_dataMedium.length; i++) {
String filename = CmsImport.getChildElementTextValue(
dataset,
CmsExportModuledata.C_EXPORT_TAG_MASTER_DATAMEDIUM + i);
String value = new String();
if (filename != null && !"".equals(filename.trim())) {
// get the value from the file
value = new String(getFileBytes(filename));
}
newDataset.m_dataMedium[i] = value;
}
// get the values of data_small
for (int i = 0; i < newDataset.m_dataSmall.length; i++) {
String filename = CmsImport.getChildElementTextValue(
dataset,
CmsExportModuledata.C_EXPORT_TAG_MASTER_DATASMALL + i);
String value = new String();
if (filename != null && !"".equals(filename.trim())) {
// get the value from the file
value = new String(getFileBytes(filename));
}
newDataset.m_dataSmall[i] = value;
}
// get the values of data_int
for (int i = 0; i < newDataset.m_dataInt.length; i++) {
String value = CmsImport.getChildElementTextValue(dataset, CmsExportModuledata.C_EXPORT_TAG_MASTER_DATAINT
+ i);
try {
newDataset.m_dataInt[i] = new Integer(value).intValue();
} catch (Exception e) {
newDataset.m_dataInt[i] = 0;
}
}
// get the values of data_reference
for (int i = 0; i < newDataset.m_dataReference.length; i++) {
String value = CmsImport.getChildElementTextValue(
dataset,
CmsExportModuledata.C_EXPORT_TAG_MASTER_DATAREFERENCE + i);
try {
newDataset.m_dataReference[i] = new Integer(value).intValue();
} catch (Exception e) {
newDataset.m_dataReference[i] = 0;
}
}
// get the values of data_date
for (int i = 0; i < newDataset.m_dataDate.length; i++) {
String value = CmsImport.getChildElementTextValue(dataset, CmsExportModuledata.C_EXPORT_TAG_MASTER_DATADATE
+ i);
try {
newDataset.m_dataDate[i] = convertDate(value);
} catch (Exception e) {
newDataset.m_dataDate[i] = 0;
}
}
return newDataset;
}
/**
* Gets the media of the master from the xml file.<p>
*
* @param masterElement The current element of the xml file
* @return vector containing the media (CmsMasterMedia object) of the master
* @throws CmsException in case something goes wrong
*/
protected Vector getMasterMedia(Element masterElement) throws CmsException {
Vector masterMedia = new Vector();
// get the mediafiles of the master
List mediaNodes = masterElement.selectNodes("*/" + CmsExportModuledata.C_EXPORT_TAG_MASTER_MEDIA);
// walk through all media
for (int j = 0; j < mediaNodes.size(); j++) {
// get the name of the file where the mediadata is stored
String mediaFilename = ((Element)mediaNodes.get(j)).getTextTrim();
// try to get the information of the media
if ((mediaFilename != null) && !("".equals(mediaFilename.trim()))) {
CmsMasterMedia newMedia = getMediaData(mediaFilename);
masterMedia.add(newMedia);
}
}
return masterMedia;
}
/**
* Imports a single master.<p>
*
* @param subId the subid of the module
* @param classname the name of the module class
* @param masterElement the current element of the xml file
* @throws CmsException in case something goes wrong
*/
protected void importMaster(String subId, String classname, Element masterElement) throws CmsException {
CmsMasterDataSet newDataset = new CmsMasterDataSet();
Vector channelRelations = new Vector();
Vector masterMedia = new Vector();
m_report.print(org.opencms.importexport.Messages.get().container(
org.opencms.importexport.Messages.RPT_IMPORTING_0), I_CmsReport.FORMAT_NOTE);
// try to get the dataset
try {
int subIdInt = Integer.parseInt(subId);
newDataset = getMasterDataSet(subIdInt, masterElement);
} catch (Exception e) {
m_report.println(e);
throw new CmsLegacyException("Cannot get dataset ", e);
}
m_report.print(Messages.get().container(
Messages.RPT_ARGUMENT_2,
CmsEncoder.escapeHtml(newDataset.m_title),
classname));
m_report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
// try to get the channelrelations
try {
channelRelations = getMasterChannelRelation(masterElement);
} catch (Exception e) {
m_report.println(e);
throw new CmsLegacyException("Cannot get channelrelations ", e);
}
// try to get the media
try {
masterMedia = getMasterMedia(masterElement);
} catch (Exception e) {
m_report.println(e);
throw new CmsLegacyException("Cannot get media ", e);
}
// add the channels and media to the dataset
newDataset.m_channelToAdd = channelRelations;
newDataset.m_mediaToAdd = masterMedia;
// create the new content definition
CmsMasterContent newMaster = getContentDefinition(classname, new Class[] {
CmsObject.class,
CmsMasterDataSet.class}, new Object[] {m_cms, newDataset});
try {
CmsUUID userId = newMaster.getOwner();
CmsUUID groupId = newMaster.getGroupId();
// first insert the new master
newMaster.importMaster();
// now update the master because user and group might be changed
newMaster.chown(m_cms, userId);
newMaster.chgrp(m_cms, groupId);
} catch (Exception e) {
m_report.println(e);
throw new CmsLegacyException("Cannot write master ", e);
}
m_report.println(
org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
I_CmsReport.FORMAT_OK);
}
/**
* Coverts a String Date in long.<p>
*
* @param date String
* @return long converted date
*/
private long convertDate(String date) {
java.text.SimpleDateFormat formatterFullTime = new SimpleDateFormat("M/d/yy h:mm a");
long adate = 0;
try {
adate = formatterFullTime.parse(date).getTime();
} catch (ParseException e) {
java.text.SimpleDateFormat formatterFullTimeDe = new SimpleDateFormat("dd.MM.yyyy HH:mm");
try {
adate = formatterFullTimeDe.parse(date).getTime();
} catch (ParseException e2) {
// ignore
}
}
return adate;
}
/**
* Returns a buffered reader for this resource using the importFile as root.<p>
*
* @param filename the name of the file to read
* @return the file reader for this file
* @throws CmsException in case something goes wrong
*/
private InputStream getFileInputStream(String filename) throws CmsException {
try {
// is this a zip-file?
if (m_importZip != null) {
// yes
ZipEntry entry = m_importZip.getEntry(filename);
return m_importZip.getInputStream(entry);
} else {
// no - use directory
File xmlFile = new File(m_importResource, filename);
return new FileInputStream(xmlFile);
}
} catch (Exception e) {
throw new CmsLegacyException(CmsLegacyException.C_UNKNOWN_EXCEPTION, e);
}
}
/**
* Gets the information for a single media from the media file.<p>
*
* @param mediaFilename the name of the xml file that contains the media information
* @return the media information from the media file
* @throws CmsException in case something goes wrong
*/
private CmsMasterMedia getMediaData(String mediaFilename) throws CmsException {
String position = null, width = null, height = null, size = null, mimetype = null, type = null, title = null, name = null, description = null, contentfile = null;
CmsMasterMedia newMedia = null;
Document mediaXml = null;
Element rootElement = null;
byte[] mediacontent = null;
newMedia = new CmsMasterMedia();
mediaXml = CmsImportVersion1.getXmlDocument(getFileInputStream(mediaFilename));
rootElement = mediaXml.getRootElement();
position = ((Element)rootElement.selectNodes("./media/" + CmsExportModuledata.C_EXPORT_TAG_MEDIA_POSITION).get(
0)).getTextTrim();
try {
newMedia.setPosition(Integer.parseInt(position));
} catch (Exception e) {
// ignore
}
width = ((Element)rootElement.selectNodes("./media/" + CmsExportModuledata.C_EXPORT_TAG_MEDIA_WIDTH).get(0)).getTextTrim();
try {
newMedia.setWidth(Integer.parseInt(width));
} catch (Exception e) {
// ignore
}
height = ((Element)rootElement.selectNodes("./media/" + CmsExportModuledata.C_EXPORT_TAG_MEDIA_HEIGHT).get(0)).getTextTrim();
try {
newMedia.setHeight(Integer.parseInt(height));
} catch (Exception e) {
// ignore
}
size = ((Element)rootElement.selectNodes("./media/" + CmsExportModuledata.C_EXPORT_TAG_MEDIA_SIZE).get(0)).getTextTrim();
try {
newMedia.setSize(Integer.parseInt(size));
} catch (Exception e) {
// ignore
}
mimetype = ((Element)rootElement.selectNodes("./media/" + CmsExportModuledata.C_EXPORT_TAG_MEDIA_MIMETYPE).get(
0)).getTextTrim();
newMedia.setMimetype(mimetype);
type = ((Element)rootElement.selectNodes("./media/" + CmsExportModuledata.C_EXPORT_TAG_MEDIA_TYPE).get(0)).getTextTrim();
try {
newMedia.setType(Integer.parseInt(type));
} catch (Exception e) {
// ignore
}
title = ((Element)rootElement.selectNodes("./media/" + CmsExportModuledata.C_EXPORT_TAG_MEDIA_TITLE).get(0)).getTextTrim();
newMedia.setTitle(title);
name = ((Element)rootElement.selectNodes("./media/" + CmsExportModuledata.C_EXPORT_TAG_MEDIA_NAME).get(0)).getTextTrim();
newMedia.setName(name);
description = ((Element)rootElement.selectNodes("./media/" + CmsExportModuledata.C_EXPORT_TAG_MEDIA_DESCRIPTION).get(
0)).getTextTrim();
newMedia.setDescription(description);
contentfile = ((Element)rootElement.selectNodes("./media/" + CmsExportModuledata.C_EXPORT_TAG_MEDIA_CONTENT).get(
0)).getTextTrim();
try {
mediacontent = getFileBytes(contentfile);
} catch (Exception e) {
m_report.println(e);
}
newMedia.setMedia(mediacontent);
return newMedia;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -