📄 cmsimportmoduledata.java
字号:
// set the purge date
purgeDate = getTextNodeValue(dataset, CmsExportModuledata.C_EXPORT_TAG_MASTER_PURGEDATE);
try{
newDataset.m_purgeDate = convertDate(purgeDate);
} catch (Exception e){
}
// set the flags
flags = getTextNodeValue(dataset, CmsExportModuledata.C_EXPORT_TAG_MASTER_FLAGS);
try{
newDataset.m_flags = Integer.parseInt(flags);
} catch (Exception e){
}
// set the feedid
feedId = getTextNodeValue(dataset, CmsExportModuledata.C_EXPORT_TAG_MASTER_FEEDID);
try{
newDataset.m_feedId = Integer.parseInt(feedId);
} catch (Exception e){
}
// set the feedreference
feedReference = getTextNodeValue(dataset, CmsExportModuledata.C_EXPORT_TAG_MASTER_FEEDREFERENCE);
try{
newDataset.m_feedReference = Integer.parseInt(feedReference);
} catch (Exception e){
}
// set the feedfilenam
feedFilename = getTextNodeValue(dataset, CmsExportModuledata.C_EXPORT_TAG_MASTER_FEEDFILENAME);
newDataset.m_feedFilename = feedFilename;
// set the masters title
title = getTextNodeValue(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 = getTextNodeValue(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 = getTextNodeValue(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 = getTextNodeValue(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 = getTextNodeValue(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 = getTextNodeValue(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 = getTextNodeValue(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 channel relations for the master from the xml file.<p>
*
* @param currentElement the current element of the xml file
* @return vector containing the ids of all channels of the master
*/
private Vector getMasterChannelRelation(Element currentElement){
Vector channelRelations = new Vector();
// get the channelnames of the master
NodeList channelNodes = currentElement.getElementsByTagName(CmsExportModuledata.C_EXPORT_TAG_MASTER_CHANNELNAME);
// walk through all channelrelations
for (int j = 0; j < channelNodes.getLength(); j++) {
// get the name of the channel
String channelName = ((Element)channelNodes.item(j)).getFirstChild().getNodeValue();
// try to read the channel and get its channelid
if ((channelName != null) && !("".equals(channelName.trim()))) {
channelRelations.addElement(channelName);
}
}
return channelRelations;
}
/**
* Gets the media of the master from the xml file.<p>
*
* @param currentElement The current element of the xml file
* @return vector containing the media (CmsMasterMedia object) of the master
* @throws CmsException in case something goes wrong
*/
private Vector getMasterMedia(Element currentElement) throws CmsException{
Vector masterMedia = new Vector();
// get the mediafiles of the master
NodeList mediaNodes = currentElement.getElementsByTagName(CmsExportModuledata.C_EXPORT_TAG_MASTER_MEDIA);
// walk through all media
for (int j = 0; j < mediaNodes.getLength(); j++) {
// get the name of the file where the mediadata is stored
String mediaFilename = ((Element) mediaNodes.item(j)).getFirstChild().getNodeValue();
// try to get the information of the media
if ((mediaFilename != null) && !("".equals(mediaFilename.trim()))) {
CmsMasterMedia newMedia = getMediaData(mediaFilename);
masterMedia.add(newMedia);
}
}
return masterMedia;
}
/**
* 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, width, height, size, mimetype, type, title, name, description, contentfile;
// get the new media object
CmsMasterMedia newMedia = new CmsMasterMedia();
// get the file with the data of the media
Document mediaXml = this.getXmlFile(mediaFilename);
Element media = (Element)mediaXml.getDocumentElement();
position = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_POSITION);
try{
newMedia.setPosition(Integer.parseInt(position));
} catch (Exception e){
}
width = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_WIDTH);
try{
newMedia.setWidth(Integer.parseInt(width));
} catch (Exception e){
}
height = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_HEIGHT);
try{
newMedia.setHeight(Integer.parseInt(height));
} catch (Exception e){
}
size = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_SIZE);
try{
newMedia.setSize(Integer.parseInt(size));
} catch (Exception e){
}
mimetype = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_MIMETYPE);
newMedia.setMimetype(mimetype);
type = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_TYPE);
try{
newMedia.setType(Integer.parseInt(type));
} catch (Exception e){
}
title = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_TITLE);
newMedia.setTitle(title);
name = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_NAME);
newMedia.setName(name);
description = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_DESCRIPTION);
newMedia.setDescription(description);
// get the content of the media
contentfile = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_CONTENT);
byte[] mediacontent = null;
try {
mediacontent = getFileBytes(contentfile);
} catch (Exception e) {
m_report.println(e);
}
newMedia.setMedia(mediacontent);
return newMedia;
}
/**
* 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 BufferedReader getFileReader(String filename) throws Exception{
// is this a zip-file?
if(m_importZip != null) {
// yes
ZipEntry entry = m_importZip.getEntry(filename);
InputStream stream = m_importZip.getInputStream(entry);
return new BufferedReader( new InputStreamReader(stream));
} else {
// no - use directory
File xmlFile = new File(m_importResource, filename);
return new BufferedReader(new FileReader(xmlFile));
}
}
/**
* Gets a xml file from the import resource.<p>
*
* @param filename the name of the file to read
* @return the xml document
* @throws CmsException in case something goes wrong
*/
private Document getXmlFile(String filename) throws CmsException {
Document xmlDoc;
try {
BufferedReader xmlReader = getFileReader(filename);
xmlDoc = A_CmsXmlContent.getXmlParser().parse(xmlReader);
xmlReader.close();
} catch(Exception exc) {
throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
}
return xmlDoc;
}
/**
* 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("dd.MM.yyyy HH:mm");
long adate=0;
try{
adate=formatterFullTime.parse(date).getTime();
}catch(ParseException e){
}
return adate;
}
/**
* Gets the content definition class method constructor.<p>
*
* @return content definition object
*/
protected CmsMasterContent getContentDefinition(String classname, Class[] classes, Object[] objects) {
CmsMasterContent cd = null;
try {
Class cdClass = Class.forName(classname);
Constructor co = cdClass.getConstructor(classes);
cd = (CmsMasterContent)co.newInstance(objects);
} catch (InvocationTargetException ite) {
if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, "[CmsImportModuledata] "+classname + " contentDefinitionConstructor: Invocation target exception!");
}
} catch (NoSuchMethodException nsm) {
if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, "[CmsImportModuledata] "+classname + " contentDefinitionConstructor: Requested method was not found!");
}
} catch (InstantiationException ie) {
if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, "[CmsImportModuledata] "+classname + " contentDefinitionConstructor: the reflected class is abstract!");
}
} catch (Exception e) {
if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, "[CmsImportModuledata] "+classname + " contentDefinitionConstructor: Other exception! "+e);
}
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, e.getMessage() );
}
}
return cd;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -