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

📄 cmsimport.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            group = getTextNodeValue(currentElement, C_EXPORT_TAG_GROUP);
            access = getTextNodeValue(currentElement, C_EXPORT_TAG_ACCESS);
            launcherStartClass = getTextNodeValue(currentElement, C_EXPORT_TAG_LAUNCHER_START_CLASS);
            // if the type is javascript set it to plain
            if("script".equals(type)){
                type = C_TYPE_PLAIN_NAME;
            }
            if (!inExcludeList(excludeList, m_importPath + destination)) {

                // get all properties for this file
                propertyNodes = currentElement.getElementsByTagName(C_EXPORT_TAG_PROPERTY);
                // clear all stores for property information
                properties = new Hashtable();
                // add the module property to properties
                if (propertyName != null && propertyValue != null && !"".equals(propertyName)) {
                    if (!types.contains(type)) {
                        types.addElement(type);
                        createPropertydefinition(propertyName, type);
                    }
                    properties.put(propertyName, propertyValue);
                }
                // walk through all properties
                for (int j = 0; j < propertyNodes.getLength(); j++) {
                    currentProperty = (Element) propertyNodes.item(j);
                    // get all information for this property
                    String name = getTextNodeValue(currentProperty, C_EXPORT_TAG_NAME);
                    String value = getTextNodeValue(currentProperty, C_EXPORT_TAG_VALUE);
                    if(value == null) {
                        // create an empty property
                        value = "";
                    }
                    // store these informations
                    if ((name != null) && (value != null)) {
                        properties.put(name, value);
                        createPropertydefinition(name, type);
                    }
                }

                // import the specified file and write maybe put it on the lists writtenFilenames,fileCodes
                importResource(source, destination, type, user, group, access, properties, launcherStartClass, writtenFilenames, fileCodes);
            } else {
                System.out.print("skipping " + destination);
            }
        }
    } catch (Exception exc) {
        throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
    }
    if (m_importZip != null)
    {
      try
      {
          m_importZip.close();
      } catch (IOException exc) {
          throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
      }
    }
}
/**
 * Checks whether the path is on the list of files which are excluded from the import
 *
 * @return boolean true if path is on the excludeList
 * @param excludeList list of pathnames which should not be (over) written
 * @param path a complete path of a resource
 */
private boolean inExcludeList(Vector excludeList, String path) {
    boolean onList = false;
    if (excludeList == null) {
        return onList;
    }
    int i=0;
    while (!onList && i<excludeList.size()) {
        onList = (path.equals(excludeList.elementAt(i)));
        i++;
    }
    return onList;
}

    /**
     * Imports the groups and writes them to the cms.
     */
    private void importGroups() throws CmsException{
        NodeList groupNodes;
        Element currentElement;
        String name, description, flags, parentgroup;

        try{
            // getAll group nodes
            groupNodes = m_docXml.getElementsByTagName(C_EXPORT_TAG_GROUPDATA);
            // walk threw all groups in manifest
            for (int i = 0; i < groupNodes.getLength(); i++) {
                currentElement = (Element)groupNodes.item(i);
                name = getTextNodeValue(currentElement, C_EXPORT_TAG_NAME);
                description = getTextNodeValue(currentElement, C_EXPORT_TAG_DESCRIPTION);
                flags = getTextNodeValue(currentElement, C_EXPORT_TAG_FLAGS);
                parentgroup = getTextNodeValue(currentElement, C_EXPORT_TAG_PARENTGROUP);
                // import this group
                importGroup(name, description, flags, parentgroup);
            }

            // now try to import the groups in the stack
            while (!m_groupsToCreate.empty()){
                Stack tempStack = m_groupsToCreate;
                m_groupsToCreate = new Stack();
                while (tempStack.size() > 0){
                    Hashtable groupdata = (Hashtable)tempStack.pop();
                    name = (String)groupdata.get(C_EXPORT_TAG_NAME);
                    description = (String)groupdata.get(C_EXPORT_TAG_DESCRIPTION);
                    flags = (String)groupdata.get(C_EXPORT_TAG_FLAGS);
                    parentgroup = (String)groupdata.get(C_EXPORT_TAG_PARENTGROUP);
                    // try to import the group
                    importGroup(name, description, flags, parentgroup);
                }
            }
        } catch (Exception exc){
            throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
        }
     }

    /**
     * Imports the users and writes them to the cms.
     */
    private void importUsers() throws CmsException{
        NodeList userNodes;
        NodeList groupNodes;
        Element currentElement, currentGroup, currentInfo;
        Vector userGroups;
        Hashtable userInfo = new Hashtable();
        sun.misc.BASE64Decoder dec;
        String name, description, flags, password, recoveryPassword, firstname,
                lastname, email, address, section, defaultGroup, type, pwd, infoNode;
        // try to get the import resource
        getImportResource();
        try{
            // getAll user nodes
            userNodes = m_docXml.getElementsByTagName(C_EXPORT_TAG_USERDATA);
            // walk threw all groups in manifest
            for (int i = 0; i < userNodes.getLength(); i++) {
                currentElement = (Element)userNodes.item(i);
                name = getTextNodeValue(currentElement, C_EXPORT_TAG_NAME);
                // decode passwords using base 64 decoder
                dec = new sun.misc.BASE64Decoder();
                pwd = getTextNodeValue(currentElement, C_EXPORT_TAG_PASSWORD);
                password = new String(dec.decodeBuffer(pwd.trim()));
                dec = new sun.misc.BASE64Decoder();
                pwd = getTextNodeValue(currentElement, C_EXPORT_TAG_RECOVERYPASSWORD);
                recoveryPassword = new String(dec.decodeBuffer(pwd.trim()));

                description = getTextNodeValue(currentElement, C_EXPORT_TAG_DESCRIPTION);
                flags = getTextNodeValue(currentElement, C_EXPORT_TAG_FLAGS);
                firstname = getTextNodeValue(currentElement, C_EXPORT_TAG_FIRSTNAME);
                lastname = getTextNodeValue(currentElement, C_EXPORT_TAG_LASTNAME);
                email = getTextNodeValue(currentElement, C_EXPORT_TAG_EMAIL);
                address = getTextNodeValue(currentElement, C_EXPORT_TAG_ADDRESS);
                section = getTextNodeValue(currentElement, C_EXPORT_TAG_SECTION);
                defaultGroup = getTextNodeValue(currentElement, C_EXPORT_TAG_DEFAULTGROUP);
                type = getTextNodeValue(currentElement, C_EXPORT_TAG_TYPE);
                // get the userinfo and put it into the hashtable
                infoNode = getTextNodeValue(currentElement,C_EXPORT_TAG_USERINFO);
                try{
                    // read the userinfo from the dat-file
                    byte[] value = getFileBytes(infoNode);
                    // deserialize the object
                    ByteArrayInputStream bin= new ByteArrayInputStream(value);
                    ObjectInputStream oin = new ObjectInputStream(bin);
                    userInfo = (Hashtable)oin.readObject();
                } catch (IOException ioex){
                    System.out.println(ioex.getMessage());
                }

                // get the groups of the user and put them into the vector
                groupNodes = currentElement.getElementsByTagName(C_EXPORT_TAG_GROUPNAME);
                userGroups = new Vector();
                for (int j=0; j < groupNodes.getLength(); j++){
                    currentGroup = (Element) groupNodes.item(j);
                    userGroups.addElement(getTextNodeValue(currentGroup, C_EXPORT_TAG_NAME));
                }
                // import this group
                importUser(name, description, flags, password, recoveryPassword, firstname,
                lastname, email, address, section, defaultGroup, type, userInfo, userGroups);
            }
        } catch (Exception exc){
            throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
        }
    }

    /**
     * Writes the group to the cms.
     */
    private void importGroup(String name, String description, String flags, String parentgroupName)
        throws CmsException{
        if(description == null) {
            description = "";
        }
        CmsGroup parentGroup = null;
        try{
            if ((parentgroupName != null) && (!"".equals(parentgroupName))) {
                try{
                    parentGroup = m_cms.readGroup(parentgroupName);
                } catch(CmsException exc){
                }
            }
            if (((parentgroupName != null) && (!"".equals(parentgroupName))) && (parentGroup == null)){
                // cannot create group, put on stack and try to create later
                Hashtable groupData = new Hashtable();
                groupData.put(C_EXPORT_TAG_NAME, name);
                    groupData.put(C_EXPORT_TAG_DESCRIPTION, description);
                groupData.put(C_EXPORT_TAG_FLAGS, flags);
                groupData.put(C_EXPORT_TAG_PARENTGROUP, parentgroupName);
                m_groupsToCreate.push(groupData);
            } else {
                try{
                    System.out.print("Importing Group: "+name+" ...");
                    m_cms.addGroup(name, description, Integer.parseInt(flags), parentgroupName);
                    System.out.println("OK");
                } catch (CmsException exc){
                    System.out.println("not created");
                }
            }
        } catch (Exception exc){
            throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
        }
    }
    /**
     * Writes the group to the cms.
     */
    private void importUser(String name, String description, String flags, String password,
                            String recoveryPassword, String firstname, String lastname,
                            String email, String address, String section, String defaultGroup,
                            String type, Hashtable userInfo, Vector userGroups)
        throws CmsException{
        CmsUser newUser = null;
        int defGroupId = C_UNKNOWN_ID;
        try{
            try{
                System.out.print("Importing User: "+name+" ...");
                newUser = m_cms.addImportUser(name, password, recoveryPassword, description, firstname,
                                    lastname, email, Integer.parseInt(flags), userInfo, defaultGroup, address,
                                    section, Integer.parseInt(type));
                // add user to all groups vector
                for (int i=0; i < userGroups.size(); i++){
                    try{
                        m_cms.addUserToGroup(name, (String)userGroups.elementAt(i));
                    } catch (CmsException exc){
                    }
                }
                System.out.println("OK");
            } catch (CmsException exc){
                System.out.println("not created");
            }
        } catch (Exception exc){
            throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
        }
    }
}

⌨️ 快捷键说明

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