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

📄 aggregatedlayoutmanager.java

📁 uPortal是开放源码的Portal门户产品
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/** * Copyright (c) 2002 The JA-SIG Collaborative.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. * * 3. Redistributions of any form whatsoever must retain the following *    acknowledgment: *    "This product includes software developed by the JA-SIG Collaborative *    (http://www.jasig.org/)." * * THIS SOFTWARE IS PROVIDED BY THE JA-SIG COLLABORATIVE "AS IS" AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE JA-SIG COLLABORATIVE OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * */package org.jasig.portal.layout;import java.util.Collection;import java.util.Enumeration;import java.util.HashSet;import java.util.Hashtable;import java.util.Iterator;import java.util.Set;import java.util.Vector;import org.jasig.portal.IUserLayoutStore;import org.jasig.portal.PortalException;import org.jasig.portal.UserProfile;import org.jasig.portal.groups.IGroupMember;import org.jasig.portal.layout.restrictions.IUserLayoutRestriction;import org.jasig.portal.layout.restrictions.PriorityRestriction;import org.jasig.portal.layout.restrictions.RestrictionTypes;import org.jasig.portal.layout.restrictions.UserLayoutRestriction;import org.jasig.portal.layout.restrictions.UserLayoutRestrictionFactory;import org.jasig.portal.security.IPerson;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.jasig.portal.utils.CommonUtils;import org.jasig.portal.utils.DocumentFactory;import org.jasig.portal.utils.GuidGenerator;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.xml.sax.ContentHandler;/** * An implementation of Aggregated User Layout Manager Interface defining common operations on user layout nodes, * that is channels and folders * * @author <a href="mailto:mvi@immagic.com">Michael Ivanov</a> * @version $Revision: 1.48.2.1 $ */public class AggregatedLayoutManager implements IAggregatedUserLayoutManager {    private static final Log log = LogFactory.getLog(AggregatedLayoutManager.class);      private AggregatedUserLayoutStore layoutStore;  private AggregatedLayout layout;  private UserProfile userProfile;  private IPerson person;  private Set listeners = new HashSet();  // Boolean flags for marking nodes  //private boolean addTargetsAllowed = false;  //private boolean moveTargetsAllowed = false;  private IALNodeDescription addTargetsNodeDesc;  private String moveTargetsNodeId;  private int restrictionMask = 0;  private boolean autoCommit = false;  // The ID of the current loaded fragment  private String fragmentId;  // The IDs and names of the fragments which a user is owner of  //private Hashtable fragments;  // GUID generator  private static GuidGenerator guid = null;  private String cacheKey = null;  public AggregatedLayoutManager( IPerson person, UserProfile userProfile ) throws Exception {    this.person = person;    this.userProfile = userProfile;    layout = new AggregatedLayout ( String.valueOf(getLayoutId()), this );    autoCommit = false;    if ( guid == null )      guid = new GuidGenerator();      updateCacheKey();  }  public AggregatedLayoutManager( IPerson person, UserProfile userProfile, IUserLayoutStore layoutStore ) throws Exception {    this ( person, userProfile );    this.layoutStore = (AggregatedUserLayoutStore) layoutStore;    this.loadUserLayout();  }  private void updateCacheKey() {     cacheKey = guid.getNewGuid();  }  public IUserLayout getUserLayout() throws PortalException {      return layout;  }  public void setUserLayout(IUserLayout userLayout) throws PortalException {   if ( !(layout instanceof AggregatedLayout) )    throw new PortalException ( "The user layout instance must have AggregatedLayout type!" );    this.layout = (AggregatedLayout) layout;    updateCacheKey();  }  /**     * A factory method to create an empty <code>IUserLayoutNodeDescription</code> instance     *     * @param nodeType a node type value     * @return an <code>IUserLayoutNodeDescription</code> instance     * @exception PortalException if the error occurs.     */    public IUserLayoutNodeDescription createNodeDescription( int nodeType ) throws PortalException {    	    IALNodeDescription nodeDesc = null;            switch ( nodeType ) {              case IUserLayoutNodeDescription.FOLDER:                nodeDesc = new ALFolderDescription();                break;              case IUserLayoutNodeDescription.CHANNEL:                nodeDesc = new ALChannelDescription();                break;            }              // Adding the user priority restriction              if ( nodeDesc != null ) {               int[] priorityRange = UserPriorityManager.getPriorityRange(person);	  				   PriorityRestriction restriction = new PriorityRestriction(); 			   restriction.setRestriction(priorityRange[0],priorityRange[1]);               nodeDesc.addRestriction(restriction);              }             return nodeDesc;  	    }    /**     * Sets a layout manager to auto-commit mode that allows to update the database immediately     * @param autoCommit a boolean value     */    public void setAutoCommit (boolean  autoCommit) {      this.autoCommit = autoCommit;    }    /**     * Returns an Id of the current user layout.     *     * @return a <code>int</code> value     */     public int getLayoutId() {       return userProfile.getLayoutId();     }  /**     * Returns an Id of a parent user layout node.     * The user layout root node always has ID="root"     *     * @param nodeId a <code>String</code> value     * @return a <code>String</code> value     * @exception PortalException if an error occurs     */  public String getParentId(String nodeId) throws PortalException {    return layout.getParentId(nodeId);  }    /**     * Returns a list of child node Ids for a given node.     *     * @param nodeId a <code>String</code> value     * @return a <code>Enumeration</code> of <code>String</code> child node Ids.     * @exception PortalException if an error occurs     */    public Enumeration getChildIds(String nodeId) throws PortalException {      return layout.getChildIds(nodeId);    }  /**     * Determine an Id of a previous sibling node.     *     * @param nodeId a <code>String</code> node ID     * @return a <code>String</code> Id value of a previous sibling node, or <code>null</code> if this is the first sibling.     * @exception PortalException if an error occurs     */  public String getPreviousSiblingId(String nodeId) throws PortalException {    return layout.getPreviousSiblingId(nodeId);  }  /**     * Determine an Id of a next sibling node.     *     * @param nodeId a <code>String</code> node ID     * @return a <code>String</code> Id value of a next sibling node, or <code>null</code> if this is the last sibling.     * @exception PortalException if an error occurs     */  public String getNextSiblingId(String nodeId) throws PortalException {    return layout.getNextSiblingId(nodeId);  }   /**     * Checks the restriction specified by the parameters below     * @param nodeId a <code>String</code> node ID     * @param restrictionType a restriction type     * @param restrictionPath a <code>String</code> restriction path     * @param propertyValue a <code>String</code> property value to be checked     * @return a boolean value     * @exception PortalException if an error occurs     */  protected boolean checkRestriction(String nodeId, int restrictionType, String restrictionPath, String propertyValue) throws PortalException {    ALNode node = getLayoutNode(nodeId);    return (node!=null)?checkRestriction(node,restrictionType,restrictionPath,propertyValue):true;  }  /**     * Checks the local restriction specified by the parameters below     * @param nodeId a <code>String</code> node ID     * @param restrictionType a restriction type     * @param propertyValue a <code>String</code> property value to be checked     * @return a boolean value     * @exception PortalException if an error occurs     */  protected boolean checkRestriction(String nodeId, int restrictionType, String propertyValue ) throws PortalException {    return (nodeId!=null)?checkRestriction(nodeId, restrictionType, UserLayoutRestriction.LOCAL_RESTRICTION, propertyValue):true;  }  /**     * Checks the restriction specified by the parameters below     * @param node a <code>ALNode</code> node to be checked     * @param restrictionType a restriction type     * @param restrictionPath a <code>String</code> restriction path     * @param propertyValue a <code>String</code> property value to be checked     * @return a boolean value     * @exception PortalException if an error occurs     */  protected boolean checkRestriction(ALNode node, int restrictionType, String restrictionPath, String propertyValue) throws PortalException {    IUserLayoutRestriction restriction = node.getRestriction(UserLayoutRestriction.getRestrictionName(restrictionType,restrictionPath));    if ( restriction != null )     return restriction.checkRestriction(propertyValue);     return true;  } private void moveWrongFragmentsToLostFolder() throws PortalException {  Collection nodes = layoutStore.getIncorrectPushedFragmentNodes(person,userProfile);  for ( Iterator i = nodes.iterator(); i.hasNext(); ) {    String nodeId = (String) i.next();    ALNode node = getLayoutNode(nodeId);    if ( node != null && nodeId != null ) {     if ( !moveNodeToLostFolder(nodeId) )      log.info( "Unable to move the pushed fragment with ID="+node.getFragmentId()+" to the lost folder");    }  } }  /**     * Moves the nodes to the lost folder if they don't satisfy their restrictions     * @exception PortalException if an error occurs     */  protected void moveWrongNodesToLostFolder() throws PortalException {    moveWrongNodesToLostFolder(getRootFolderId(),0);  }   /**     * Moves the nodes to the lost folder if they don't satisfy their restrictions     * @param nodeId a <code>String</code> node ID     * @param depth a depth of the given node     * @exception PortalException if an error occurs     */  private void moveWrongNodesToLostFolder(String nodeId, int depth) throws PortalException {      ALNode node = getLayoutNode(nodeId);      // Checking restrictions on the node      Vector restrictions = node.getRestrictionsByPath(UserLayoutRestriction.LOCAL_RESTRICTION);      for ( int i = 0; i < restrictions.size(); i++ ) {         IUserLayoutRestriction restriction = (IUserLayoutRestriction)restrictions.get(i);         // check other restrictions except priority and depth         if ( ( restriction.getRestrictionType() & (RestrictionTypes.DEPTH_RESTRICTION | RestrictionTypes.PRIORITY_RESTRICTION )) == 0                && !restriction.checkRestriction(node) ) {            moveNodeToLostFolder(nodeId);            break;         }      }      // Checking the depth restriction      if ( !checkRestriction(nodeId,RestrictionTypes.DEPTH_RESTRICTION,depth+"") ) {          moveNodeToLostFolder(nodeId);      }      // Checking children related restrictions on the children if they exist

⌨️ 快捷键说明

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