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

📄 physicaltreeview.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.service.services.views.plugins;

import opiam.admin.faare.config.javabeans.JBObjectView;
import opiam.admin.faare.config.javabeans.JBRessource;
import opiam.admin.faare.config.javabeans.JBViewDef;
import opiam.admin.faare.persistence.PersistenceLDAP;
import opiam.admin.faare.persistence.javabeans.JBTop;
import opiam.admin.faare.service.UserContext;
import opiam.admin.faare.service.javabeans.SearchArgument;
import opiam.admin.faare.service.services.SortService;
import opiam.admin.faare.service.services.views.JBTreeNode;
import opiam.admin.faare.service.services.views.TreeView;
import opiam.admin.faare.service.services.views.ViewGenerator;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.apache.log4j.Logger;

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


/**
 * View plugin allowing to generate the physical views.<br>
 * To use this plugin, you must declare it in the view configuration in the
 * <i>views.xml</i> file.
 *
 * Example:
 * <code>&lt;viewdef name="Hierarchy" label="Hierarchical view"</code>
 * <code>  dynamic="false" </code>
 * <code>  plugin="opiam.admin.faare.service.services.views.plugins.PhysicalTreeView"</code>
 * <code>  expandUrl="" icon=""&gt;</code>
 */
public class PhysicalTreeView implements TreeView
{
    /** Instance of logger. */
    private static Logger _logger = Logger.getLogger(PhysicalTreeView.class.getName());

    /** View definition. */
    private JBViewDef jbViewDef;

    /** User context. */
    private UserContext userContext;

    /**
     * Creates a new PhysicalTreeView object.
     */
    public PhysicalTreeView()
    {
    }

    /**
     * Gets the root node of the view.
     *
     * @return The root node.
     */
    public JBTreeNode getRoot()
    {
        _logger.debug("getRoot");

        JBTreeNode jbTreeNode = new JBTreeNode();
        jbTreeNode.setIcon(jbViewDef.getIcon());
        jbTreeNode.setLabel(jbViewDef.getLabel());

        return jbTreeNode;
    }

    /**
     * Gets the children (list of JBTreeNode objects) of the given node.
     *
     * @param jbTreeNode  Node on which JBTop objects have to be created.
     * @param level  Current view level.
     *
     * @return The list of JBTreeNode objects.
     */
    public List getChildrenByJBTreeNode(JBTreeNode jbTreeNode, int level)
    {
        List returnedList = new ArrayList();
        _logger.debug("getChildrenByJBTreeNode level : " + level);

        try
        {
            //R閏up閞ation de tous les objectView de cette vue physique
            Map objectViewMap = jbViewDef.getObjectviewMap();
            _logger.debug("getChildrenByJBTreeNode objectViewMap.size() : " +
                objectViewMap.size());

            JBTop jbTop = jbTreeNode.getJbTop();
            _logger.debug("getChildrenByJBTreeNode jbTop : " + jbTop);

            Iterator objectViewIterator = objectViewMap.values().iterator();

            JBObjectView jbObjectView = null;
            String ressourceName = null;
            JBRessource jbRessource = null;

            while (objectViewIterator.hasNext())
            {
                ArrayList lJbTop = new ArrayList();
                jbObjectView = (JBObjectView) objectViewIterator.next();
                ressourceName = jbObjectView.getRessourceName();
                _logger.debug("getChildrenByJBTreeNode ressourceName : " +
                    ressourceName);

                jbRessource = userContext.findJBRessourceByName(ressourceName);

                SearchArgument arg = new SearchArgument(jbRessource, userContext);
                List arguments = new ArrayList();
                arguments.add(arg);

                if (jbTop == null)
                {
                    _logger.debug("getChildrenByJBTreeNode jbTop == null  ");

                    String base = jbViewDef.getLdapBaseParam();

                    if (base == null)
                    {
                        base = userContext.getLdapConfig().getBaseDN();
                    }
                    List tempList =
                        (PersistenceLDAP.searchOneLevel(arguments, base,
                            userContext)).getLResults();

                    lJbTop.addAll(tempList);
                }
                else
                {
                    lJbTop.addAll((PersistenceLDAP.searchOneLevel(arguments,
                            jbTop.getDn(), userContext)).getLResults());
                }

                SortService.sort(lJbTop, Class.forName(jbRessource.getType()),
                    jbObjectView.getOrderBy(), userContext);

                JBTop jbTopTemp = null;
                Object value = null;

                for (int i = 0; i < lJbTop.size(); i++)
                {
                    jbTopTemp = (JBTop) lJbTop.get(i);
                    _logger.debug(
                        "getChildrenByJBTreeNode jbTopTemp.getDn() : " +
                        jbTopTemp.getDn());

                    JBTreeNode jbTreeNodeTemp = new JBTreeNode();

                    jbTreeNodeTemp.setIcon(jbObjectView.getIcon());
                    _logger.debug(
                        "getChildrenByJBTreeNode jbObjectView.getIcon() : " +
                        jbObjectView.getIcon());

                    //jbTreeNodeTemp.setOpenUrl(jbObjectView.getLabelUrl());
                    jbTreeNodeTemp.setOpenUrl(ViewGenerator.constructOpenUrl(
                            jbObjectView.getLabelUrl(), jbTopTemp));

                    // DW/2667/BeginPatch
                    jbTreeNodeTemp.setTarget(jbObjectView.getTarget());
                    // DW/2667/EndPatch
                    
                    _logger.debug(
                        "getChildrenByJBTreeNode jbObjectView.getLabelAtt() : " +
                        jbObjectView.getLabelAtt());

                    value = PropertyUtils.getProperty(jbTopTemp,
                            jbObjectView.getLabelAtt());

                    //On enl鑦e les guillemets: PB dans l'affichage sinon
                    value =
                        (String) StringUtils.replace((String) value, "'", " ");

                    //((String) value)..replace('',' ');
                    _logger.debug("getChildrenByJBTreeNode value : " + value);

                    _logger.debug(
                        "getChildrenByJBTreeNode jbTopTemp.toString()  : " +
                        jbTopTemp.toString());

                    jbTreeNodeTemp.setLabel((String) value);
                    jbTreeNodeTemp.setJbTop(jbTopTemp);
                    returnedList.add(jbTreeNodeTemp);
                }
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

        return returnedList;
    }

    /**
     * Gets the definition of the view.
     *
     * @return View definition.
     */
    public JBViewDef getJBViewDef()
    {
        return jbViewDef;
    }

    /**
    * Gets the user context.
    *
    * @return The context of the user.
     */
    public UserContext getUserContext()
    {
        return userContext;
    }

    /**
     * Sets the definition of the view.
     *
     * @param ajbViewDef  View definition to set.
     */
    public void setJBViewDef(JBViewDef ajbViewDef)
    {
        this.jbViewDef = ajbViewDef;
    }

    /**
     * Sets the user context.
     *
     * @param auserContext The user context to set.
     */
    public void setUserContext(UserContext auserContext)
    {
        this.userContext = auserContext;
    }
}

⌨️ 快捷键说明

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