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

📄 deleteattributeaction.java

📁 OPIAM stands for Open Identity and Access Management. This Suite will provide modules for user & rig
💻 JAVA
字号:
/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.struts.actions;

//DW/2621/BeginPatch
import opiam.admin.faare.MessageUtil;
//DW/2621/EndPatch

import org.apache.commons.beanutils.PropertyUtils;

import org.apache.log4j.Logger;

import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import java.io.IOException;

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

import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * This action allows to remove some elements from a list contained in an object.
 *<br>
 * HTTP PARAMETERS :<br>
 * <li>objname : name of the object to be modified</li>
 * <li>attname : name of the attribute containing the elements to be removed (java.util.List typed)</li>
 * <li>eltindex : multivalued indexes of elements to remove, or not set to remove all elements</li>
 */
public class DeleteAttributeAction extends SecureAction
{
    /** Logger de log4j. */
    private static Logger _logger = Logger.getLogger(DeleteAttributeAction.class);

    /**
     * Struts Action method.
     * See SecureAction
     *
     * @param mapping Struts mapping data.
     * @param actionForm Input form.
     * @param request HTTP request.
     * @param httpServletResponse HTTP response.
     *
     * @return forward to success or to service_error
     *
     * @throws java.io.IOException see Action.execute()
     * @throws javax.servlet.ServletException see Action.execute()
     */
    public ActionForward secureExecute(
        ActionMapping mapping,
        ActionForm actionForm,
        HttpServletRequest request,
        HttpServletResponse httpServletResponse)
        throws IOException, ServletException
    {
        String objname = request.getParameter("objname");
        String attname = request.getParameter("attname");
        String[] elements = request.getParameterValues("eltindex");
        _logger.debug("objname = " + objname);
        _logger.debug("attname = " + attname);

        ActionMessages errors = new ActionMessages();

//DW/????/BeginPatch
        if ((objname == null) || objname.trim().equals("") ||
            (attname == null) || attname.trim().equals(""))
        {
            _logger.error(MessageUtil.getMessageString("MSG_ARGUMENT_NULL"));
            errors.add(ActionMessages.GLOBAL_MESSAGE,
                new ActionMessage("error.service.unknown"));
            saveErrors(request, errors);

            return (mapping.findForward("service_error"));
        }
//DW/????/EndPatch

        try
        {
            //R閏up閞ation de la session
            HttpSession session = request.getSession();
            Object obj = session.getAttribute(objname);
            Object att = PropertyUtils.getProperty(obj, attname);

            if (att instanceof List)
            {
                List attList = (List) att;

                if (elements == null)
                {
                    // supprimer tout
                    attList.clear();
                }
                else
                {
                    // save elements to remove, since when we delete, the index change !
                    List toRemove = new ArrayList();

                    for (int i = 0; i < elements.length; i++)
                    {
                        toRemove.add(attList.get(Integer.parseInt(elements[i])));
                    }

                    // now delete
                    Iterator it = toRemove.iterator();

                    while (it.hasNext())
                    {
                        attList.remove(it.next());
                    }
                }
            }

            return (mapping.findForward("success"));
        }
        catch (Exception se)
        {
            _logger.error(se.getMessage());
            errors.add(ActionMessages.GLOBAL_MESSAGE,
                new ActionMessage("error.service.unknown"));
            saveErrors(request, errors);

            return (mapping.findForward("service_error"));
        }
    }
}

⌨️ 快捷键说明

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