⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmsexport.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

            if (m_isOnlineProject || (!m_excludeUnchanged) || state == C_STATE_NEW || state == C_STATE_CHANGED) {
                if ((state != C_STATE_DELETED) && (!file.getName().startsWith("~")) && (age >= m_contentAge)) {
                    exportResource(m_cms.readFile(file.getAbsolutePath()));
                }
            }
            // release file header memory
            subFiles.set(i, null);
        }
        // all files are exported, release memory
        subFiles = null;

        // walk through all subfolders and export them
        for (int i = 0; i < subFolders.size(); i++) {
            CmsResource folder = (CmsResource)subFolders.elementAt(i);
            if (folder.getState() != C_STATE_DELETED) {
                // check if this is a system-folder and if it should be included.
                String export = folder.getAbsolutePath();
                if (// new VFS, always export "/system/" OR
                 (I_CmsWpConstants.C_VFS_NEW_STRUCTURE
                    && export.equalsIgnoreCase(I_CmsWpConstants.C_VFS_PATH_SYSTEM))
                    || // new VFS, always export "/system/bodies/" OR
                 (
                        I_CmsWpConstants.C_VFS_NEW_STRUCTURE && export.startsWith(I_CmsWpConstants.C_VFS_PATH_BODIES))
                    || // new VFS, always export "/system/galleries/" OR
                 (
                        I_CmsWpConstants.C_VFS_NEW_STRUCTURE
                            && export.startsWith(I_CmsWpConstants.C_VFS_PATH_GALLERIES))
                    || // option "exclude system folder" selected AND
                !(
                        m_excludeSystem
                    && // export folder is a system folder 
                 (
                        export.startsWith(I_CmsWpConstants.C_VFS_PATH_SYSTEM)
                    || // if new VFS, ignore old system folders (are below "/system" in new VFS)
                 (
                        (!I_CmsWpConstants.C_VFS_NEW_STRUCTURE) && export.startsWith("/pics/system/"))
                            || ((!I_CmsWpConstants.C_VFS_NEW_STRUCTURE) && export.startsWith("/moduledemos/"))))) {
                    // export this folder
                    if (folder.getDateLastModified() >= m_contentAge) {
                        // only export folder data to manifest.xml if it has changed
                        writeXmlEntrys(folder);
                    }
                    // export all resources in this folder
                    exportResources(folder.getAbsolutePath());
                }
            }
            // release folder memory
            subFolders.set(i, null);
        }
    }
        
    /**
     * Substrings the source filename, so it is shrinked to the needed part for export.<p>
     * 
     * @param absoluteName the absolute path of the resource
     * @return the shrinked path
     */
    private String getSourceFilename(String absoluteName) {
        String path = absoluteName; // keep absolute name to distinguish resources
        if (path.startsWith("/")) {
            path = path.substring(1);
        }
        if (path.endsWith("/")) {
            path = path.substring(0, path.length() - 1);
        }
        return path;
    }
    
    /**
     * 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
     * @throws CmsException if something goes wrong
     */
    private void writeXmlEntrys(CmsResource resource) throws CmsException {
        String source, type, user, group, access, launcherStartClass, lastModified;

        // 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();
        lastModified = String.valueOf(resource.getDateLastModified()); 

        // 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(m_docXml, file, C_EXPORT_TAG_SOURCE, source);
        } else {
            // output something to the report for the folder
            m_report.print(m_report.key("report.exporting"), I_CmsReport.C_FORMAT_NOTE);
            m_report.print(resource.getAbsolutePath());
            m_report.print(m_report.key("report.dots"), I_CmsReport.C_FORMAT_NOTE);
            m_report.println(m_report.key("report.ok"), I_CmsReport.C_FORMAT_OK);
        }
        addElement(m_docXml, file, C_EXPORT_TAG_DESTINATION, source);
        addElement(m_docXml, file, C_EXPORT_TAG_TYPE, type);
        addElement(m_docXml, file, C_EXPORT_TAG_USER, user);
        addElement(m_docXml, file, C_EXPORT_TAG_GROUP, group);
        addElement(m_docXml, file, C_EXPORT_TAG_ACCESS, access);
        addElement(m_docXml, file, C_EXPORT_TAG_LASTMODIFIED, lastModified);
        if (launcherStartClass != null
            && !"".equals(launcherStartClass)
            && !C_UNKNOWN_LAUNCHER.equals(launcherStartClass)) {
            addElement(m_docXml, 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
        Map fileProperties = m_cms.readProperties(resource.getAbsolutePath());
        Iterator i = fileProperties.keySet().iterator();

        // create xml-elements for the properties
        while (i.hasNext()) {
            String key = (String)i.next();
            // make sure channel id property is not exported with module data
            if ((! m_exportingModuleData) || (! I_CmsConstants.C_PROPERTY_CHANNELID.equals(key))) {            
                // append the node for a property
                Element property = m_docXml.createElement(C_EXPORT_TAG_PROPERTY);
                properties.appendChild(property);
    
                String value = (String)fileProperties.get(key);
                String propertyType = m_cms.readPropertydefinition(key, type).getType() + "";
    
                addElement(m_docXml, property, C_EXPORT_TAG_NAME, key);
                addElement(m_docXml, property, C_EXPORT_TAG_TYPE, propertyType);
                addCdataElement(m_docXml, property, C_EXPORT_TAG_VALUE, value);
            }
        }
    }

    /**
     * Exports all groups with all data.<p>
     *
     * @throws 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 all users with all data.<p>
     *
     * @throws 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 it's data.<p>
     *
     * @param group the group to be exported
     * @throws CmsException if something goes wrong
     */
    private void exportGroup(CmsGroup group) throws CmsException {
        m_report.print(m_report.key("report.exporting_group"), I_CmsReport.C_FORMAT_NOTE);
        m_report.print(group.getName());
        m_report.print(m_report.key("report.dots"), I_CmsReport.C_FORMAT_NOTE);
        try {
            // create the manifest entries
            writeXmlGroupEntrys(group);
        } catch (Exception e) {
            m_report.println(e);
            throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, e);
        }
        m_report.println(m_report.key("report.ok"), I_CmsReport.C_FORMAT_OK);
    }

    /**
     * Exports one single user with all its data.<p>
     *
     * @param user the user to be exported
     * @throws CmsException if something goes wrong
     */
    private void exportUser(CmsUser user) throws CmsException {
        m_report.print(m_report.key("report.exporting_user"), I_CmsReport.C_FORMAT_NOTE);
        m_report.print(user.getName());
        m_report.print(m_report.key("report.dots"), I_CmsReport.C_FORMAT_NOTE);
        try {
            // create the manifest entries
            writeXmlUserEntrys(user);
        } catch (Exception e) {
            m_report.println(e);
            throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, e);
        }
        m_report.println(m_report.key("report.ok"), I_CmsReport.C_FORMAT_OK);
    }

    /**
     * Writes the data for a group to the <code>manifest.xml</code> file.<p>
     * 
     * @param group the group to get the data from
     * @throws 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(m_docXml, groupdata, C_EXPORT_TAG_NAME, name);
        addCdataElement(m_docXml, groupdata, C_EXPORT_TAG_DESCRIPTION, description);
        addElement(m_docXml, groupdata, C_EXPORT_TAG_FLAGS, flags);
        addElement(m_docXml, groupdata, C_EXPORT_TAG_PARENTGROUP, parentgroup);
    }

    /**
     * Writes the data for a user to the <code>manifest.xml</code> file.<p>
     * 
     * @param group The group to get the data from.
     * @throws 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();
        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(m_docXml, 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(m_docXml, userdata, C_EXPORT_TAG_PASSWORD, passwd);
        enc = new sun.misc.BASE64Encoder();
        String recPasswd = new String(enc.encodeBuffer(recoveryPassword.getBytes()));
        addCdataElement(m_docXml, userdata, C_EXPORT_TAG_RECOVERYPASSWORD, recPasswd);

        addCdataElement(m_docXml, userdata, C_EXPORT_TAG_DESCRIPTION, description);
        addElement(m_docXml, userdata, C_EXPORT_TAG_FIRSTNAME, firstname);
        addElement(m_docXml, userdata, C_EXPORT_TAG_LASTNAME, lastname);
        addElement(m_docXml, userdata, C_EXPORT_TAG_EMAIL, email);
        addElement(m_docXml, userdata, C_EXPORT_TAG_FLAGS, flags);
        addElement(m_docXml, userdata, C_EXPORT_TAG_DEFAULTGROUP, defaultGroup);
        addCdataElement(m_docXml, userdata, C_EXPORT_TAG_ADDRESS, address);
        addElement(m_docXml, userdata, C_EXPORT_TAG_SECTION, section);
        addElement(m_docXml, 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) {
            m_report.println(ioex);
        }
        // create tag for userinfo
        addCdataElement(m_docXml, 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(m_docXml, group, C_EXPORT_TAG_NAME, groupName);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -