📄 cmsexport.java
字号:
// 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_GROUP) > 0) {
// the principal is a group
acePrincipalName = getCms().readGroup(acePrincipal).getPrefixedName();
} else {
// the principal is a user
acePrincipalName = getCms().readUser(acePrincipal).getPrefixedName();
}
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)));
}
/**
* Exports one single file with all its data and content.<p>
*
* @param file the file to be exported
* @throws CmsImportExportException if something goes wrong
* @throws SAXException if something goes wrong procesing the manifest.xml
* @throws CmsLoaderException if an "old style" XML page could be exported
* @throws IOException if the ZIP entry for the file could be appended to the ZIP archive
*/
private void exportFile(CmsFile file)
throws CmsImportExportException, SAXException, CmsLoaderException, IOException {
String source = trimResourceName(getCms().getSitePath(file));
I_CmsReport report = getReport();
m_exportCount++;
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(file)));
report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
// store content in zip-file
// check if the content of this resource was not already exported
if (!m_exportedResources.contains(file.getResourceId())) {
ZipEntry entry = new ZipEntry(source);
// save the time of the last modification in the zip
entry.setTime(file.getDateLastModified());
getExportZipStream().putNextEntry(entry);
getExportZipStream().write(file.getContents());
getExportZipStream().closeEntry();
// add the resource id to the storage to mark that this resource was already exported
m_exportedResources.add(file.getResourceId());
// create the manifest-entrys
appendResourceToManifest(file, true);
} else {
// only create the manifest-entrys
appendResourceToManifest(file, false);
}
// check if the resource is a page of the old style. if so, export the body as well
if (OpenCms.getResourceManager().getResourceType(file.getTypeId()).getTypeName().equals("page")) {
m_exportedPageFiles.add("/" + source);
}
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(Messages.LOG_EXPORTING_OK_2, String.valueOf(m_exportCount), source));
}
report.println(
org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
I_CmsReport.FORMAT_OK);
}
/**
* Exports one single group with all it's data.<p>
*
* @param parent the parent node to add the groups to
* @param group the group to be exported
* @throws CmsImportExportException if something goes wrong
* @throws SAXException if something goes wrong procesing the manifest.xml
*/
private void exportGroup(Element parent, CmsGroup group) throws CmsImportExportException, SAXException {
try {
String parentgroup;
if (group.getParentId().isNullUUID()) {
parentgroup = "";
} else {
parentgroup = getCms().getParent(group.getName()).getName();
}
Element e = parent.addElement(CmsImportExportManager.N_GROUPDATA);
e.addElement(CmsImportExportManager.N_NAME).addText(group.getName());
e.addElement(CmsImportExportManager.N_DESCRIPTION).addCDATA(group.getDescription());
e.addElement(CmsImportExportManager.N_FLAGS).addText(Integer.toString(group.getFlags()));
e.addElement(CmsImportExportManager.N_PARENTGROUP).addText(parentgroup);
// write the XML
digestElement(parent, e);
} catch (CmsException e) {
CmsMessageContainer message = org.opencms.db.Messages.get().container(
org.opencms.db.Messages.ERR_GET_PARENT_GROUP_1,
group.getName());
if (LOG.isDebugEnabled()) {
LOG.debug(message.key(), e);
}
throw new CmsImportExportException(message, e);
}
}
/**
* Exports all groups with all data.<p>
*
* @param parent the parent node to add the groups to
* @throws CmsImportExportException if something goes wrong
* @throws SAXException if something goes wrong procesing the manifest.xml
*/
private void exportGroups(Element parent) throws CmsImportExportException, SAXException {
try {
I_CmsReport report = getReport();
List allGroups = getCms().getGroups();
for (int i = 0, l = allGroups.size(); i < l; i++) {
CmsGroup group = (CmsGroup)allGroups.get(i);
report.print(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_SUCCESSION_2,
String.valueOf(i + 1),
String.valueOf(l)), I_CmsReport.FORMAT_NOTE);
report.print(Messages.get().container(Messages.RPT_EXPORT_GROUP_0), I_CmsReport.FORMAT_NOTE);
report.print(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_ARGUMENT_1,
group.getName()));
report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
exportGroup(parent, group);
report.println(
org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
I_CmsReport.FORMAT_OK);
}
} catch (CmsImportExportException e) {
throw e;
} catch (CmsException e) {
CmsMessageContainer message = org.opencms.db.Messages.get().container(
org.opencms.db.Messages.ERR_GET_GROUPS_0);
if (LOG.isDebugEnabled()) {
LOG.debug(message.key(), e);
}
throw new CmsImportExportException(message, e);
}
}
/**
* Exports one single user with all its data.<p>
*
* @param parent the parent node to add the users to
* @param user the user to be exported
* @throws CmsImportExportException if something goes wrong
* @throws SAXException if something goes wrong procesing the manifest.xml
*/
private void exportUser(Element parent, CmsUser user) throws CmsImportExportException, SAXException {
try {
// add user node to the manifest.xml
Element e = parent.addElement(CmsImportExportManager.N_USERDATA);
e.addElement(CmsImportExportManager.N_NAME).addText(user.getName());
// encode the password, using a base 64 decoder
String passwd = new String(Base64.encodeBase64(user.getPassword().getBytes()));
e.addElement(CmsImportExportManager.N_PASSWORD).addCDATA(passwd);
e.addElement(CmsImportExportManager.N_DESCRIPTION).addCDATA(user.getDescription());
e.addElement(CmsImportExportManager.N_FIRSTNAME).addText(user.getFirstname());
e.addElement(CmsImportExportManager.N_LASTNAME).addText(user.getLastname());
e.addElement(CmsImportExportManager.N_EMAIL).addText(user.getEmail());
e.addElement(CmsImportExportManager.N_FLAGS).addText(Integer.toString(user.getFlags()));
e.addElement(CmsImportExportManager.N_TAG_ADDRESS).addCDATA(user.getAddress());
e.addElement(CmsImportExportManager.N_TYPE).addText(Integer.toString(user.getType()));
// serialize the user info and write it into a file
try {
String datfileName = "/~" + CmsImportExportManager.N_USERINFO + "/" + user.getName() + ".dat";
// create tag for userinfo
e.addElement(CmsImportExportManager.N_USERINFO).addText(datfileName);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream oout = new ObjectOutputStream(bout);
oout.writeObject(user.getAdditionalInfo());
oout.close();
byte[] serializedInfo = bout.toByteArray();
// store the serialized user info in the zip-file
ZipEntry entry = new ZipEntry(datfileName);
getExportZipStream().putNextEntry(entry);
getExportZipStream().write(serializedInfo);
getExportZipStream().closeEntry();
} catch (IOException ioe) {
getReport().println(ioe);
if (LOG.isErrorEnabled()) {
LOG.error(Messages.get().getBundle().key(
Messages.ERR_IMPORTEXPORT_ERROR_EXPORTING_USER_1,
user.getName()), ioe);
}
}
// append the node for groups of user
List userGroups = getCms().getDirectGroupsOfUser(user.getName());
Element g = e.addElement(CmsImportExportManager.N_USERGROUPS);
for (int i = 0; i < userGroups.size(); i++) {
String groupName = ((CmsGroup)userGroups.get(i)).getName();
g.addElement(CmsImportExportManager.N_GROUPNAME).addElement(CmsImportExportManager.N_NAME).addText(
groupName);
}
// write the XML
digestElement(parent, e);
} catch (CmsException e) {
CmsMessageContainer message = org.opencms.db.Messages.get().container(
org.opencms.db.Messages.ERR_GET_GROUPS_OF_USER_1,
user.getName());
if (LOG.isDebugEnabled()) {
LOG.debug(message.key(), e);
}
throw new CmsImportExportException(message, e);
}
}
/**
* Exports all users with all data.<p>
*
* @param parent the parent node to add the users to
* @throws CmsImportExportException if something goes wrong
* @throws SAXException if something goes wrong procesing the manifest.xml
*/
private void exportUsers(Element parent) throws CmsImportExportException, SAXException {
try {
I_CmsReport report = getReport();
List allUsers = new ArrayList();
if (m_exportUserdata) {
// add system users
allUsers.addAll(getCms().getUsers());
}
if (m_exportWebusers) {
// add webusers
allUsers.addAll(getCms().getUsers(CmsUser.USER_TYPE_WEBUSER));
}
for (int i = 0, l = allUsers.size(); i < l; i++) {
CmsUser user = (CmsUser)allUsers.get(i);
report.print(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_SUCCESSION_2,
String.valueOf(i + 1),
String.valueOf(l)), I_CmsReport.FORMAT_NOTE);
report.print(Messages.get().container(Messages.RPT_EXPORT_USER_0), I_CmsReport.FORMAT_NOTE);
report.print(org.opencms.report.Messages.get().container(
org.opencms.report.Messages.RPT_ARGUMENT_1,
user.getName()));
report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
exportUser(parent, user);
report.println(
org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
I_CmsReport.FORMAT_OK);
}
} catch (CmsImportExportException e) {
throw e;
} catch (CmsException e) {
CmsMessageContainer message = org.opencms.db.Messages.get().container(
org.opencms.db.Messages.ERR_GET_USERS_0);
if (LOG.isDebugEnabled()) {
LOG.debug(message.key(), e);
}
throw new CmsImportExportException(message, e);
}
}
/**
* Cuts leading and trailing '/' from the given resource name.<p>
*
* @param resourceName the absolute path of a resource
* @return the trimmed resource name
*/
private String trimResourceName(String resourceName) {
if (resourceName.startsWith("/")) {
resourceName = resourceName.substring(1);
}
if (resourceName.endsWith("/")) {
resourceName = resourceName.substring(0, resourceName.length() - 1);
}
return resourceName;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -