📄 cmsimportversion2.java
字号:
acentryNodes = currentElement.selectNodes("*/" + CmsImportExportManager.N_ACCESSCONTROL_ENTRY);
// collect all access control entries
for (int j = 0; j < acentryNodes.size(); j++) {
currentEntry = (Element)acentryNodes.get(j);
// get the data of the access control entry
String id = CmsImport.getChildElementTextValue(currentEntry, CmsImportExportManager.N_ID);
String acflags = CmsImport.getChildElementTextValue(
currentEntry,
CmsImportExportManager.N_FLAGS);
String allowed = CmsImport.getChildElementTextValue(
currentEntry,
CmsImportExportManager.N_ACCESSCONTROL_ALLOWEDPERMISSIONS);
String denied = CmsImport.getChildElementTextValue(
currentEntry,
CmsImportExportManager.N_ACCESSCONTROL_DENIEDPERMISSIONS);
// add the entry to the list
aceList.add(getImportAccessControlEntry(res, id, allowed, denied, acflags));
}
importAccessControlEntries(res, aceList);
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(
Messages.LOG_IMPORTING_4,
new Object[] {
String.valueOf(i + 1),
String.valueOf(importSize),
translatedName,
destination}));
}
} else {
// resource import failed, since no CmsResource was created
m_report.print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_OK);
m_report.println(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_ARGUMENT_1,
translatedName));
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(
Messages.LOG_SKIPPING_3,
String.valueOf(i + 1),
String.valueOf(importSize),
translatedName));
}
}
} else {
// skip the file import, just print out the information to the report
m_report.print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE);
m_report.println(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_ARGUMENT_1,
translatedName));
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(
Messages.LOG_SKIPPING_3,
String.valueOf(i + 1),
String.valueOf(importSize),
translatedName));
}
}
}
// now merge the body and page control files. this only has to be done if the import
// version is below version 3
if (getVersion() < 3 && m_convertToXmlPage) {
mergePageFiles();
removeFolders();
}
} catch (Exception e) {
m_report.println(e);
CmsMessageContainer message = Messages.get().container(
Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0);
if (LOG.isDebugEnabled()) {
LOG.debug(message.key(), e);
}
throw new CmsImportExportException(message, e);
} finally {
if (m_importingChannelData) {
m_cms.getRequestContext().restoreSiteRoot();
}
// set the flag to overwrite colliding resources back to its original value
OpenCms.getImportExportManager().setOverwriteCollidingResources(old_overwriteCollidingResources);
}
}
/**
* Imports a resource (file or folder) into the cms.<p>
*
* @param source the path to the source-file
* @param destination the path to the destination-file in the cms
* @param uuid the structure uuid of the resource
* @param uuidresource the resource uuid of the resource
* @param resourceTypeId the ID of the file's resource type
* @param resourceTypeName the name of the file's resource type
* @param lastmodified the timestamp of the file
* @param properties a list with properties for this resource
*
* @return imported resource
*/
private CmsResource importResource(
String source,
String destination,
String uuid,
String uuidresource,
int resourceTypeId,
String resourceTypeName,
long lastmodified,
List properties) {
byte[] content = null;
CmsResource res = null;
String targetName = null;
try {
if (m_importingChannelData) {
// try to read an existing channel to get the channel id
String channelId = null;
try {
if ((resourceTypeName.equalsIgnoreCase(CmsResourceTypeFolder.RESOURCE_TYPE_NAME))
&& (!destination.endsWith("/"))) {
destination += "/";
}
CmsResource channel = m_cms.readResource("/" + destination);
channelId = m_cms.readPropertyObject(
m_cms.getSitePath(channel),
CmsPropertyDefinition.PROPERTY_CHANNELID,
false).getValue();
} catch (Exception e) {
// ignore the exception, a new channel id will be generated
}
if (channelId != null) {
properties.add(new CmsProperty(CmsPropertyDefinition.PROPERTY_CHANNELID, channelId, null));
}
}
// get the file content
if (source != null) {
content = getFileBytes(source);
}
content = convertContent(source, destination, content, resourceTypeName);
// get all required information to create a CmsResource
int size = 0;
if (content != null) {
size = content.length;
}
// get the required UUIDs
CmsUUID curUser = m_cms.getRequestContext().currentUser().getId();
CmsUUID newUuidstructure = new CmsUUID();
CmsUUID newUuidresource = new CmsUUID();
if (uuid != null) {
newUuidstructure = new CmsUUID(uuid);
}
if (uuidresource != null) {
newUuidresource = new CmsUUID(uuidresource);
}
// extract the name of the resource form the destination
targetName = destination;
if (targetName.endsWith("/")) {
targetName = targetName.substring(0, targetName.length() - 1);
}
boolean isFolder = false;
try {
isFolder = CmsFolder.isFolderType(resourceTypeId);
} catch (Throwable t) {
// the specified resource type ID might be of an unknown resource type.
// as another option, check the content length and resource type name
// to determine if the resource is a folder or not.
isFolder = ((content.length == 0) && CmsResourceTypeFolder.RESOURCE_TYPE_NAME.equalsIgnoreCase(resourceTypeName));
}
// create a new CmsResource
CmsResource resource = new CmsResource(
newUuidstructure,
newUuidresource,
targetName,
resourceTypeId,
isFolder,
0,
m_cms.getRequestContext().currentProject().getId(),
CmsResource.STATE_NEW,
lastmodified,
curUser,
lastmodified,
curUser,
CmsResource.DATE_RELEASED_DEFAULT,
CmsResource.DATE_EXPIRED_DEFAULT,
1,
size);
if (RESOURCE_TYPE_LINK_ID == resourceTypeId) {
// store links for later conversion
m_report.print(Messages.get().container(Messages.RPT_STORING_LINK_0), I_CmsReport.FORMAT_NOTE);
m_linkStorage.put(m_importPath + destination, new String(content));
m_linkPropertyStorage.put(m_importPath + destination, properties);
res = resource;
} else {
// import this resource in the VFS
String resName = m_importPath + destination;
res = m_cms.importResource(resName, resource, content, properties);
try {
m_cms.unlockResource(resName);
} catch (CmsLockException e) {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_IMPORTEXPORT_UNABLE_TO_UNLOCK_RESOURCE_1,
resName), e);
}
}
}
m_report.println(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
} catch (CmsException exc) {
CmsMessageContainer message = Messages.get().container(
Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCE_1,
targetName);
if (LOG.isDebugEnabled()) {
LOG.debug(message.key(), exc);
}
// an error while importing the file
m_report.println(exc);
try {
// Sleep some time after an error so that the report output has a chance to keep up
Thread.sleep(1000);
} catch (Exception e) {
//
}
}
return res;
}
/**
* Merges a single page.<p>
*
* @param resourcename the resource name of the page
* @throws CmsImportExportException if something goes wrong
* @throws CmsXmlException if the page file could not be unmarshalled
*/
private void mergePageFile(String resourcename) throws CmsXmlException, CmsImportExportException {
try {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_START_MERGING_1, resourcename));
}
// in OpenCms versions <5 node names have not been case sensitive. thus, nodes are read both in upper
// and lower case letters, or have to be tested for equality ignoring upper/lower case...
// get the header file
CmsFile pagefile = m_cms.readFile(resourcename, CmsResourceFilter.ALL);
Document contentXml = CmsXmlUtils.unmarshalHelper(pagefile.getContents(), null);
// get the <masterTemplate> node to check the content. this node contains the name of the template file.
String masterTemplateNodeName = "//masterTemplate";
Node masterTemplateNode = contentXml.selectSingleNode(masterTemplateNodeName);
if (masterTemplateNode == null) {
masterTemplateNode = contentXml.selectSingleNode(masterTemplateNodeName.toLowerCase());
}
if (masterTemplateNode == null) {
masterTemplateNode = contentXml.selectSingleNode(masterTemplateNodeName.toUpperCase());
}
// there is only one <masterTemplate> allowed
String mastertemplate = null;
if (masterTemplateNode != null) {
// get the name of the mastertemplate
mastertemplate = masterTemplateNode.getText().trim();
}
// get the <ELEMENTDEF> nodes to check the content.
// this node contains the information for the body element.
String elementDefNodeName = "//ELEMENTDEF";
Node bodyNode = contentXml.selectSingleNode(elementDefNodeName);
if (bodyNode == null) {
bodyNode = contentXml.selectSingleNode(elementDefNodeName.toLowerCase());
}
// there is only one <ELEMENTDEF> allowed
if (bodyNode != null) {
String bodyclass = null;
String bodyname = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -