Package org.olat.core.gui.control.generic.portal

Source Code of org.olat.core.gui.control.generic.portal.PortletFactory

/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) 1999-2007 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/

package org.olat.core.gui.control.generic.portal;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.olat.core.extensions.ExtensionManager;
import org.olat.core.extensions.OLATExtension;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.logging.AssertException;
import org.olat.core.logging.StartupException;
import org.olat.core.logging.Tracing;

/**
* Description:<br>
* Factory to create instances of portlets defined in the
* WEB-INF/olat_portals.xml
* <P>
* Initial Date:  08.07.2005 <br>
* @author gnaegi
*/
public class PortletFactory {
 
  private static final PortletFactory INSTANCE = new PortletFactory();
  private static Map<String, Portlet> portlets = new HashMap<String, Portlet>();
 
  /**
   * Singleton
   */
  private PortletFactory() {
    // singleton
  }
 
  /**
   * @return The portlet factory
   */
  public static final PortletFactory getInstance() {
    return INSTANCE;
  }

  /**
   * Bean setter method used by spring. Takes all portlets defined in
   * WEB-INF/olat_extensions.xml and adds them to the portlets map
   * @param portletList
   */
  public void setPortletList(List portletList) {
    if (portletList == null)
      throw new AssertException("null value for portletList not allowed.");

    // check beans
    ExtensionManager extMgr = ExtensionManager.getInstance();
    try {
      for (Iterator iter = portletList.iterator(); iter.hasNext();) {
        Portlet portlet = (Portlet) iter.next();
        portlets.put(portlet.getName(), portlet);
        Tracing.logInfo("Adding portlet from configuraton:: " + portlet.getName(), PortletFactory.class);
       
        if (portlet instanceof OLATExtension) {
          try {
            extMgr.deployExtension((OLATExtension)portlet);
          } catch (IOException ioe) {
            throw new StartupException("Error deploying bean '" + portlet + "'.", ioe);
          }
        }
      }
    }
    catch (ClassCastException cce) {
        throw new StartupException("Configured portlet is not of type portlet", cce);
    }
   
  }
 
  /**
   * Factory method to create a portled wrapped in a portlet container.
   * @param defaultConfiguration The default configuration map
   * @param wControl
   * @param ureq
   * @return The portlet container that contains the portlet
   */
  public static PortletContainer getPortletContainerFor(Map portletConfiguration, WindowControl wControl, UserRequest ureq) {   
    String name = (String) portletConfiguration.get("portletName");
   
    // create portlet controller
    Portlet portlet = portlets.get(name);
    // wrap with container
    if (portlet == null) {
      Tracing.logWarn("Could not create portlet with name::" + name, PortletFactory.class);
      return null;
    }    // create an instance using the configuration and wrap portlet in container
    return new PortletContainer(wControl, ureq, portlet.createInstance(wControl, ureq, portletConfiguration));
  }
 
  /**
   * @param beanName : The bean name to check for
   * @return true if such a bean does exist in the config, false
   *         otherwhise
   */
  public boolean containsPortlet(String beanName) {
    return portlets.containsKey(beanName);
  }
}
TOP

Related Classes of org.olat.core.gui.control.generic.portal.PortletFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.