pagestandardform.java

来自「开源项目CRM之OpenCustomer」· Java 代码 · 共 225 行

JAVA
225
字号
/*******************************************************************************
 * ***** BEGIN LICENSE BLOCK Version: MPL 1.1
 * 
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * 
 * The Original Code is the OpenCustomer CRM.
 * 
 * The Initial Developer of the Original Code is Thomas Bader (Bader & Jene
 * Software-Ingenieurb黵o). Portions created by the Initial Developer are
 * Copyright (C) 2005 the Initial Developer. All Rights Reserved.
 * 
 * Contributor(s): Thomas Bader <thomas.bader@bader-jene.de>
 * 
 * ***** END LICENSE BLOCK *****
 */

package org.opencustomer.application.web.module.system.user.manage.edit;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.util.ImageButtonBean;
import org.opencustomer.application.db.vo.system.RoleVO;
import org.opencustomer.application.db.vo.system.UserVO;
import org.opencustomer.application.db.vo.system.UsergroupVO;
import org.opencustomer.application.web.module.system.user.manage.Constants;
import org.opencustomer.web.util.FormUtility;
import org.opencustomer.web.util.MessageUtil;
import org.opencustomer.web.util.RequestUtility;

public final class PageStandardForm extends DefaultPageForm
{
    private static final long serialVersionUID = 3257571706599061552L;

    private static Logger log = Logger.getLogger(PageStandardForm.class);

    private String userName;

    private String password;

    private boolean locked;

    private int roleId;

    private int mainUsergroupId;

    private int deleteUsergroupId;

    private ImageButtonBean doAddPerson = new ImageButtonBean();

    private ImageButtonBean doAddUsergroup = new ImageButtonBean();

    public void validate(ActionMapping mapping, ActionMessages errors, HttpServletRequest request)
    {
        if (log.isDebugEnabled())
            log.debug("called form");

        setDoPageStandard(null);

        userName = FormUtility.adjustParameter(userName, 255);
        password = FormUtility.adjustParameter(password, 255);

        deleteUsergroupId = RequestUtility.parseParamId(request, "doDeleteUsergroup_");

        if (isTokenValid(request))
        {
            if (log.isDebugEnabled())
                log.debug("token is not valid");
        }
        else if (this.getDoSave() != null || this.isAnyPage() || this.getDoAddPerson().isSelected() || this.getDoAddUsergroup().isSelected())
        {
            if (userName == null)
            {
                errors.add("userName", new ActionMessage("default.error.missingInput", MessageUtil.message(request, "entity.user.userName")));
            }

            if (roleId == 0)
            {
                errors.add("roleId", new ActionMessage("default.error.missingInput", MessageUtil.message(request, "entity.role")));
            }
            else
            {
                boolean validRole = false;
                Iterator<RoleVO> roles = ((List<RoleVO>) request.getSession().getAttribute(Constants.USER_ROLES)).iterator();
                while (roles.hasNext())
                {
                    if (roles.next().getId() == roleId)
                    {
                        validRole = true;
                        break;
                    }
                }

                if (!validRole)
                    errors.add("roleId", new ActionMessage("default.error.invalidValue", MessageUtil.message(request, "entity.role")));
            }

            if (mainUsergroupId != 0)
            {
                boolean validMainUsergroup = false;
                Iterator<UsergroupVO> usergroups = ((UserVO) request.getSession().getAttribute(Constants.USER_USER)).getUsergroups().iterator();
                while (usergroups.hasNext())
                {
                    if (usergroups.next().getId() == mainUsergroupId)
                    {
                        validMainUsergroup = true;
                        break;
                    }
                }

                if (!validMainUsergroup)
                    errors.add("usergroup", new ActionMessage("default.error.invalidValue", MessageUtil.message(request, "entity.user.usergroup")));
            }
        }
    }

    public void reset()
    {
        userName = null;
    }

    public static Logger getLog()
    {
        return log;
    }

    public static void setLog(Logger log)
    {
        PageStandardForm.log = log;
    }

    public ImageButtonBean getDoAddPerson()
    {
        return doAddPerson;
    }

    public void setDoAddPerson(ImageButtonBean doAddPerson)
    {
        this.doAddPerson = doAddPerson;
    }

    public String getUserName()
    {
        return userName;
    }

    public void setUserName(String userName)
    {
        this.userName = userName;
    }

    public boolean isLocked()
    {
        return locked;
    }

    public void setLocked(boolean locked)
    {
        this.locked = locked;
    }

    public String getPassword()
    {
        return password;
    }

    public void setPassword(String password)
    {
        this.password = password;
    }

    public int getRoleId()
    {
        return roleId;
    }

    public void setRoleId(int roleId)
    {
        this.roleId = roleId;
    }

    public final ImageButtonBean getDoAddUsergroup()
    {
        return doAddUsergroup;
    }

    public final void setDoAddUsergroup(ImageButtonBean doAddUsergroup)
    {
        this.doAddUsergroup = doAddUsergroup;
    }

    public final int getDeleteUsergroupId()
    {
        return deleteUsergroupId;
    }

    public final void setDeleteUsergroupId(int deleteUsergroupId)
    {
        this.deleteUsergroupId = deleteUsergroupId;
    }

    public final int getMainUsergroupId()
    {
        return mainUsergroupId;
    }

    public final void setMainUsergroupId(int mainUsergroupId)
    {
        this.mainUsergroupId = mainUsergroupId;
    }

}

⌨️ 快捷键说明

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