📄 cmsexport.java
字号:
}
}
/**
* Writes the xml-config file (manifest) to the zip-file.
*/
private void writeXmlConfigFile()
throws CmsException {
try {
ZipEntry entry = new ZipEntry(C_EXPORT_XMLFILENAME);
m_exportZipStream.putNextEntry(entry);
A_CmsXmlContent.getXmlParser().getXmlText(m_docXml, m_exportZipStream);
m_exportZipStream.closeEntry();
} catch(Exception exc) {
throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
}
}
/**
* Writes the data for a resources (like acces-rights) to the manifest-xml-file.
* @param resource The resource to get the data from.
* @exception throws a CmsException if something goes wrong.
*/
private void writeXmlEntrys(CmsResource resource)
throws CmsException {
String source, type, user, group, access, launcherStartClass;
// get all needed informations from the resource
source = getSourceFilename(resource.getAbsolutePath());
type = m_cms.getResourceType(resource.getType()).getResourceTypeName();
user = m_cms.readOwner(resource).getName();
group = m_cms.readGroup(resource).getName();
access = resource.getAccessFlags() + "";
launcherStartClass = resource.getLauncherClassname();
// write these informations to the xml-manifest
Element file = m_docXml.createElement(C_EXPORT_TAG_FILE);
m_filesElement.appendChild(file);
// only write source if resource is a file
if(resource.isFile()) {
addElement(file, C_EXPORT_TAG_SOURCE, source);
}
addElement(file, C_EXPORT_TAG_DESTINATION, source);
addElement(file, C_EXPORT_TAG_TYPE, type);
addElement(file, C_EXPORT_TAG_USER, user);
addElement(file, C_EXPORT_TAG_GROUP, group);
addElement(file, C_EXPORT_TAG_ACCESS, access);
if(launcherStartClass != null && !"".equals(launcherStartClass) && !C_UNKNOWN_LAUNCHER.equals(launcherStartClass)) {
addElement(file, C_EXPORT_TAG_LAUNCHER_START_CLASS, launcherStartClass);
}
// append the node for properties
Element properties = m_docXml.createElement(C_EXPORT_TAG_PROPERTIES);
file.appendChild(properties);
// read the properties
Hashtable fileProperties = m_cms.readAllProperties(resource.getAbsolutePath());
Enumeration keys = fileProperties.keys();
// create xml-elements for the properties
while(keys.hasMoreElements()) {
// append the node for a property
Element property = m_docXml.createElement(C_EXPORT_TAG_PROPERTY);
properties.appendChild(property);
String key = (String) keys.nextElement();
String value = (String) fileProperties.get(key);
String propertyType = m_cms.readPropertydefinition(key, type).getType() + "";
addElement(property, C_EXPORT_TAG_NAME, key);
addElement(property, C_EXPORT_TAG_TYPE, propertyType);
addCdataElement(property, C_EXPORT_TAG_VALUE, value);
}
}
/**
* Exports groups with all data.
*
* @exception throws a CmsException if something goes wrong.
*/
private void exportGroups()
throws CmsException {
Vector allGroups = m_cms.getGroups();
for (int i = 0; i < allGroups.size(); i++){
exportGroup((CmsGroup)allGroups.elementAt(i));
}
}
/**
* Exports users with all data.
*
* @exception throws a CmsException if something goes wrong.
*/
private void exportUsers()
throws CmsException {
Vector allUsers = m_cms.getUsers();
for (int i = 0; i < allUsers.size(); i++){
exportUser((CmsUser)allUsers.elementAt(i));
}
}
/**
* Exports one single group with all its data.
*
* @param group the group to be exported,
* @exception throws a CmsException if something goes wrong.
*/
private void exportGroup(CmsGroup group)
throws CmsException {
System.out.print("Exporting group "+group.getName()+" ...");
try {
// create the manifest entries
writeXmlGroupEntrys(group);
} catch(Exception e) {
System.out.println("Error");
throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, e);
}
System.out.println("OK");
}
/**
* Exports one single user with all its data.
*
* @param user the user to be exported,
* @exception throws a CmsException if something goes wrong.
*/
private void exportUser(CmsUser user)
throws CmsException {
System.out.print("Exporting user "+user.getName()+" ...");
try {
// create the manifest entries
writeXmlUserEntrys(user);
} catch(Exception e) {
System.out.println("Error");
throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, e);
}
System.out.println("OK");
}
/**
* Writes the data for a group to the manifest-xml-file.
* @param group The group to get the data from.
* @exception throws a CmsException if something goes wrong.
*/
private void writeXmlGroupEntrys(CmsGroup group)
throws CmsException {
String name, description, flags, parentgroup;
// get all needed information from the group
name = group.getName();
description = group.getDescription();
flags = Integer.toString(group.getFlags());
int parentId = group.getParentId();
if (parentId != C_UNKNOWN_ID) {
parentgroup = m_cms.getParent(name).getName();
} else {
parentgroup = "";
}
// write these informations to the xml-manifest
Element groupdata = m_docXml.createElement(C_EXPORT_TAG_GROUPDATA);
m_userdataElement.appendChild(groupdata);
addElement(groupdata, C_EXPORT_TAG_NAME, name);
addCdataElement(groupdata, C_EXPORT_TAG_DESCRIPTION, description);
addElement(groupdata, C_EXPORT_TAG_FLAGS, flags);
addElement(groupdata, C_EXPORT_TAG_PARENTGROUP, parentgroup);
}
/**
* Writes the data for a user to the manifest-xml-file.
* @param group The group to get the data from.
* @exception throws a CmsException if something goes wrong.
*/
private void writeXmlUserEntrys(CmsUser user)
throws CmsException {
String name, password, recoveryPassword, description, firstname;
String lastname, email, flags, defaultGroup, address, section, type;
String datfileName = new String();
String infostr = new String();
Hashtable info = new Hashtable();
Vector userGroups = new Vector();
sun.misc.BASE64Encoder enc;
ObjectOutputStream oout;
// get all needed information from the group
name = user.getName();
password = user.getPassword();
recoveryPassword = user.getRecoveryPassword();
description = user.getDescription();
firstname = user.getFirstname();
lastname = user.getLastname();
email = user.getEmail();
flags = Integer.toString(user.getFlags());
info = user.getAdditionalInfo();
defaultGroup = user.getDefaultGroup().getName();
address = user.getAddress();
section = user.getSection();
type = Integer.toString(user.getType());
userGroups = m_cms.getDirectGroupsOfUser(user.getName());
// write these informations to the xml-manifest
Element userdata = m_docXml.createElement(C_EXPORT_TAG_USERDATA);
m_userdataElement.appendChild(userdata);
addElement(userdata, C_EXPORT_TAG_NAME, name);
//Encode the info value, using any base 64 decoder
enc = new sun.misc.BASE64Encoder();
String passwd = new String(enc.encodeBuffer(password.getBytes()));
addCdataElement(userdata, C_EXPORT_TAG_PASSWORD, passwd);
enc = new sun.misc.BASE64Encoder();
String recPasswd = new String(enc.encodeBuffer(recoveryPassword.getBytes()));
addCdataElement(userdata, C_EXPORT_TAG_RECOVERYPASSWORD, recPasswd);
addCdataElement(userdata, C_EXPORT_TAG_DESCRIPTION, description);
addElement(userdata, C_EXPORT_TAG_FIRSTNAME, firstname);
addElement(userdata, C_EXPORT_TAG_LASTNAME, lastname);
addElement(userdata, C_EXPORT_TAG_EMAIL, email);
addElement(userdata, C_EXPORT_TAG_FLAGS, flags);
addElement(userdata, C_EXPORT_TAG_DEFAULTGROUP, defaultGroup);
addCdataElement(userdata, C_EXPORT_TAG_ADDRESS, address);
addElement(userdata, C_EXPORT_TAG_SECTION, section);
addElement(userdata, C_EXPORT_TAG_TYPE, type);
// serialize the hashtable and write the info into a file
try{
datfileName = "/~"+C_EXPORT_TAG_USERINFO+"/"+name+".dat";
ByteArrayOutputStream bout = new ByteArrayOutputStream();
oout = new ObjectOutputStream(bout);
oout.writeObject(info);
oout.close();
byte[] serializedInfo = bout.toByteArray();
// store the userinfo in zip-file
ZipEntry entry = new ZipEntry(datfileName);
m_exportZipStream.putNextEntry(entry);
m_exportZipStream.write(serializedInfo);
m_exportZipStream.closeEntry();
} catch (IOException ioex){
System.out.println("IOException: "+ioex.getMessage());
}
// create tag for userinfo
addCdataElement(userdata, C_EXPORT_TAG_USERINFO, datfileName);
// append the node for groups of user
Element usergroup = m_docXml.createElement(C_EXPORT_TAG_USERGROUPS);
userdata.appendChild(usergroup);
for (int i = 0; i < userGroups.size(); i++){
String groupName = ((CmsGroup)userGroups.elementAt(i)).getName();
Element group = m_docXml.createElement(C_EXPORT_TAG_GROUPNAME);
usergroup.appendChild(group);
addElement(group, C_EXPORT_TAG_NAME, groupName);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -