All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.tinygroup.menutree.fileresolver.ManageUserConfigLoaderFileProcessor Maven / Gradle / Ivy

The newest version!
package org.tinygroup.menutree.fileresolver;

import com.thoughtworks.xstream.XStream;
import org.tinygroup.fileresolver.impl.AbstractFileProcessor;
import org.tinygroup.logger.LogLevel;
import org.tinygroup.menutree.config.UserConfigs;
import org.tinygroup.menutree.manager.UserAuthManager;
import org.tinygroup.vfs.FileObject;
import org.tinygroup.xstream.XStreamFactory;

import java.io.InputStream;

/**
 * Created by wangwy11342 on 2016/10/18.
 */
public class ManageUserConfigLoaderFileProcessor extends AbstractFileProcessor {
    private static final String USER_LOAD_FILE_NAME = "manage.users.xml";
    private static final String USER_XSTEAM_PACKAGE_NAME = "manage_user";

    private UserAuthManager userAuthManager;

    public UserAuthManager getUserAuthManager() {
        return userAuthManager;
    }

    public void setUserAuthManager(UserAuthManager userAuthManager) {
        this.userAuthManager = userAuthManager;
    }

    protected boolean checkMatch(FileObject fileObject) {
        return fileObject.getFileName().equals(USER_LOAD_FILE_NAME);
    }

    public void process() {
        XStream stream = XStreamFactory
                .getXStream(USER_XSTEAM_PACKAGE_NAME);
        LOGGER.logMessage(LogLevel.INFO, "用户管理配置文件加载开始");
        for (FileObject fileObject : fileObjects) {
            LOGGER.logMessage(LogLevel.INFO, "找到用户管理配置文件:[{}]",
                    fileObject.getAbsolutePath());
            InputStream inputStream = fileObject.getInputStream();
            UserConfigs configs = (UserConfigs) stream
                    .fromXML(inputStream);
            try {
                inputStream.close();
            } catch (Exception e) {
                LOGGER.errorMessage("关闭文件流时出错,文件路径:{}", e, fileObject.getAbsolutePath());
            }
            userAuthManager.load(configs.getUserList());
        }
        // manager.load();
        LOGGER.logMessage(LogLevel.INFO, "用户管理配置文件加载结束");
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy