📄 cmsexport.java
字号:
try {
// this is a resource in /system/ folder and option includeSystem is not true
if (!checkExportResource(resourceName)) {
return;
}
// Initialize the "previously added folder cache"
if (m_superFolders == null) {
m_superFolders = new ArrayList();
}
List superFolders = new ArrayList();
// Check, if the path is really a folder
if (resourceName.lastIndexOf("/") != (resourceName.length() - 1)) {
resourceName = resourceName.substring(0, resourceName.lastIndexOf("/") + 1);
}
while (resourceName.length() > "/".length()) {
superFolders.add(resourceName);
resourceName = resourceName.substring(0, resourceName.length() - 1);
resourceName = resourceName.substring(0, resourceName.lastIndexOf("/") + 1);
}
for (int i = superFolders.size() - 1; i >= 0; i--) {
String addFolder = (String)superFolders.get(i);
if (!m_superFolders.contains(addFolder)) {
// This super folder was NOT added previously. Add it now!
CmsFolder folder = getCms().readFolder(addFolder, CmsResourceFilter.IGNORE_EXPIRATION);
appendResourceToManifest(folder, false);
// Remember that this folder was added
m_superFolders.add(addFolder);
}
}
} catch (CmsImportExportException e) {
throw e;
} catch (CmsException e) {
CmsMessageContainer message = Messages.get().container(
Messages.ERR_IMPORTEXPORT_ERROR_ADDING_PARENT_FOLDERS_1,
resourceName);
if (LOG.isDebugEnabled()) {
LOG.debug(message.key(), e);
}
throw new CmsImportExportException(message, e);
}
}
/**
* Adds a property node to the manifest.xml.<p>
*
* @param propertiesElement the parent element to append the node to
* @param propertyName the name of the property
* @param propertyValue the value of the property
* @param shared if <code>true</code>, add a shared property attribute to the generated property node
*/
private void addPropertyNode(Element propertiesElement, String propertyName, String propertyValue, boolean shared) {
if (propertyValue != null) {
Element propertyElement = propertiesElement.addElement(CmsImportExportManager.N_PROPERTY);
if (shared) {
// add "type" attribute to the property node in case of a shared/resource property value
propertyElement.addAttribute(
CmsImportExportManager.N_PROPERTY_ATTRIB_TYPE,
CmsImportExportManager.N_PROPERTY_ATTRIB_TYPE_SHARED);
}
propertyElement.addElement(CmsImportExportManager.N_NAME).addText(propertyName);
propertyElement.addElement(CmsImportExportManager.N_VALUE).addCDATA(propertyValue);
}
}
/**
* Adds a relation node to the <code>manifest.xml</code>.<p>
*
* @param relationsElement the parent element to append the node to
* @param structureId the structure id of the target relation
* @param sitePath the site path of the target relation
* @param relationType the type of the relation
*/
private void addRelationNode(Element relationsElement, String structureId, String sitePath, String relationType) {
if ((structureId != null) && (sitePath != null) && (relationType != null)) {
Element relationElement = relationsElement.addElement(CmsImportExportManager.N_RELATION);
relationElement.addElement(CmsImportExportManager.N_RELATION_ATTRIBUTE_ID).addText(structureId);
relationElement.addElement(CmsImportExportManager.N_RELATION_ATTRIBUTE_PATH).addText(sitePath);
relationElement.addElement(CmsImportExportManager.N_RELATION_ATTRIBUTE_TYPE).addText(relationType);
}
}
/**
* Writes the data for a resource (like access-rights) to the <code>manifest.xml</code> file.<p>
*
* @param resource the resource to get the data from
* @param source flag to show if the source information in the xml file must be written
* @throws CmsImportExportException if something goes wrong
* @throws SAXException if something goes wrong processing the manifest.xml
*/
private void appendResourceToManifest(CmsResource resource, boolean source)
throws CmsImportExportException, SAXException {
try {
// define the file node
Element fileElement = m_resourceNode.addElement(CmsImportExportManager.N_FILE);
// only write <source> if resource is a file
String fileName = trimResourceName(getCms().getSitePath(resource));
if (resource.isFile()) {
if (source) {
fileElement.addElement(CmsImportExportManager.N_SOURCE).addText(fileName);
}
} else {
m_exportCount++;
I_CmsReport report = getReport();
// output something to the report for the folder
report.print(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_SUCCESSION_1,
String.valueOf(m_exportCount)), I_CmsReport.FORMAT_NOTE);
report.print(Messages.get().container(Messages.RPT_EXPORT_0), I_CmsReport.FORMAT_NOTE);
report.print(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_ARGUMENT_1,
getCms().getSitePath(resource)));
report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
report.println(
org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
I_CmsReport.FORMAT_OK);
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(
Messages.LOG_EXPORTING_OK_2,
String.valueOf(m_exportCount),
getCms().getSitePath(resource)));
}
}
// <destination>
fileElement.addElement(CmsImportExportManager.N_DESTINATION).addText(fileName);
// <type>
fileElement.addElement(CmsImportExportManager.N_TYPE).addText(
OpenCms.getResourceManager().getResourceType(resource.getTypeId()).getTypeName());
// <uuidstructure>
fileElement.addElement(CmsImportExportManager.N_UUIDSTRUCTURE).addText(resource.getStructureId().toString());
if (resource.isFile()) {
// <uuidresource>
fileElement.addElement(CmsImportExportManager.N_UUIDRESOURCE).addText(
resource.getResourceId().toString());
}
// <datelastmodified>
fileElement.addElement(CmsImportExportManager.N_DATELASTMODIFIED).addText(
CmsDateUtil.getHeaderDate(resource.getDateLastModified()));
// <userlastmodified>
String userNameLastModified = null;
try {
userNameLastModified = getCms().readUser(resource.getUserLastModified()).getName();
} catch (CmsException e) {
userNameLastModified = OpenCms.getDefaultUsers().getUserAdmin();
}
fileElement.addElement(CmsImportExportManager.N_USERLASTMODIFIED).addText(userNameLastModified);
// <datecreated>
fileElement.addElement(CmsImportExportManager.N_DATECREATED).addText(
CmsDateUtil.getHeaderDate(resource.getDateCreated()));
// <usercreated>
String userNameCreated = null;
try {
userNameCreated = getCms().readUser(resource.getUserCreated()).getName();
} catch (CmsException e) {
userNameCreated = OpenCms.getDefaultUsers().getUserAdmin();
}
fileElement.addElement(CmsImportExportManager.N_USERCREATED).addText(userNameCreated);
// <release>
if (resource.getDateReleased() != CmsResource.DATE_RELEASED_DEFAULT) {
fileElement.addElement(CmsImportExportManager.N_DATERELEASED).addText(
CmsDateUtil.getHeaderDate(resource.getDateReleased()));
}
// <expire>
if (resource.getDateExpired() != CmsResource.DATE_EXPIRED_DEFAULT) {
fileElement.addElement(CmsImportExportManager.N_DATEEXPIRED).addText(
CmsDateUtil.getHeaderDate(resource.getDateExpired()));
}
// <flags>
int resFlags = resource.getFlags();
resFlags &= ~CmsResource.FLAG_LABELED;
fileElement.addElement(CmsImportExportManager.N_FLAGS).addText(Integer.toString(resFlags));
// write the properties to the manifest
Element propertiesElement = fileElement.addElement(CmsImportExportManager.N_PROPERTIES);
List properties = getCms().readPropertyObjects(getCms().getSitePath(resource), false);
// sort the properties for a well defined output order
Collections.sort(properties);
for (int i = 0, n = properties.size(); i < n; i++) {
CmsProperty property = (CmsProperty)properties.get(i);
if (isIgnoredProperty(property)) {
continue;
}
addPropertyNode(propertiesElement, property.getName(), property.getStructureValue(), false);
addPropertyNode(propertiesElement, property.getName(), property.getResourceValue(), true);
}
// Write the relations to the manifest
List relations = getCms().getRelationsForResource(
getCms().getSitePath(resource),
CmsRelationFilter.TARGETS.filterNotDefinedInContent());
CmsRelation relation = null;
Element relationsElement = fileElement.addElement(CmsImportExportManager.N_RELATIONS);
// iterate over the relations
for (Iterator iter = relations.iterator(); iter.hasNext();) {
relation = (CmsRelation)iter.next();
CmsResource target = relation.getTarget(getCms(), CmsResourceFilter.ALL);
String structureId = target.getStructureId().toString();
String sitePath = getCms().getSitePath(target);
String relationType = relation.getType().getName();
addRelationNode(relationsElement, structureId, sitePath, relationType);
}
// append the nodes for access control entries
Element acl = fileElement.addElement(CmsImportExportManager.N_ACCESSCONTROL_ENTRIES);
// read the access control entries
List fileAcEntries = getCms().getAccessControlEntries(getCms().getSitePath(resource), false);
Iterator i = fileAcEntries.iterator();
// create xml elements for each access control entry
while (i.hasNext()) {
CmsAccessControlEntry ace = (CmsAccessControlEntry)i.next();
Element a = acl.addElement(CmsImportExportManager.N_ACCESSCONTROL_ENTRY);
// now check if the principal is a group or a user
int flags = ace.getFlags();
String acePrincipalName = "";
CmsUUID acePrincipal = ace.getPrincipal();
if ((flags & CmsAccessControlEntry.ACCESS_FLAGS_ALLOTHERS) > 0) {
acePrincipalName = CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME;
} else if ((flags & CmsAccessControlEntry.ACCESS_FLAGS_OVERWRITE_ALL) > 0) {
acePrincipalName = CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME;
} else if ((flags & CmsAccessControlEntry.ACCESS_FLAGS_GROUP) > 0) {
// the principal is a group
acePrincipalName = getCms().readGroup(acePrincipal).getPrefixedName();
} else if ((flags & CmsAccessControlEntry.ACCESS_FLAGS_USER) > 0) {
// the principal is a user
acePrincipalName = getCms().readUser(acePrincipal).getPrefixedName();
} else {
// the principal is a role
acePrincipalName = CmsRole.PRINCIPAL_ROLE + "." + CmsRole.valueOfId(acePrincipal).getRoleName();
}
a.addElement(CmsImportExportManager.N_ACCESSCONTROL_PRINCIPAL).addText(acePrincipalName);
a.addElement(CmsImportExportManager.N_FLAGS).addText(Integer.toString(flags));
Element b = a.addElement(CmsImportExportManager.N_ACCESSCONTROL_PERMISSIONSET);
b.addElement(CmsImportExportManager.N_ACCESSCONTROL_ALLOWEDPERMISSIONS).addText(
Integer.toString(ace.getAllowedPermissions()));
b.addElement(CmsImportExportManager.N_ACCESSCONTROL_DENIEDPERMISSIONS).addText(
Integer.toString(ace.getDeniedPermissions()));
}
// write the XML
digestElement(m_resourceNode, fileElement);
} catch (CmsImportExportException e) {
throw e;
} catch (CmsException e) {
CmsMessageContainer message = Messages.get().container(
Messages.ERR_IMPORTEXPORT_ERROR_APPENDING_RESOURCE_TO_MANIFEST_1,
resource.getRootPath());
if (LOG.isDebugEnabled()) {
LOG.debug(message.key(), e);
}
throw new CmsImportExportException(message, e);
}
}
/**
* Returns true if the checked resource name can be exported depending on the include settings.<p>
*
* @param resourcename the absolute path of the resource
* @return true if the checked resource name can be exported depending on the include settings
*/
private boolean checkExportResource(String resourcename) {
return (// other folder than "/system/" will be exported
!resourcename.startsWith(CmsWorkplace.VFS_PATH_SYSTEM) // OR always export "/system/"
|| resourcename.equalsIgnoreCase(CmsWorkplace.VFS_PATH_SYSTEM) // OR always export "/system/bodies/"
|| resourcename.startsWith(CmsCompatibleCheck.VFS_PATH_BODIES) // OR always export "/system/galleries/"
|| resourcename.startsWith(CmsWorkplace.VFS_PATH_GALLERIES) // OR option "include system folder" selected
|| (m_includeSystem // AND export folder is a system folder
&& resourcename.startsWith(CmsWorkplace.VFS_PATH_SYSTEM)));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -