portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/aggregator/impl PageAggregator.java PortletAggregator.java BasicAggregator.java
Date Tue, 16 Mar 2004 20:21:06 GMT
taylor      2004/03/16 12:21:06

  Added:       portal/src/java/org/apache/jetspeed/aggregator/impl
                        PageAggregator.java PortletAggregator.java
                        BasicAggregator.java
  Removed:     portal/src/java/org/apache/jetspeed/aggregator
                        PageAggregator.java BasicAggregator.java
                        PortletAggregator.java
  Log:
  Moving Aggregator implementations under impl directory
  
  PR:
  Obtained from:
  Submitted by:	
  Reviewed by:	
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/aggregator/impl/PageAggregator.java
  
  Index: PageAggregator.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.aggregator.impl;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Stack;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.jetspeed.Jetspeed;
  import org.apache.jetspeed.aggregator.Aggregator;
  import org.apache.jetspeed.aggregator.ContentDispatcher;
  import org.apache.jetspeed.aggregator.PortletRenderer;
  import org.apache.jetspeed.contentserver.ContentFilter;
  import org.apache.jetspeed.cps.BaseCommonService;
  import org.apache.jetspeed.cps.CommonPortletServices;
  import org.apache.jetspeed.cps.CPSInitializationException;
  import org.apache.jetspeed.exception.JetspeedException;
  import org.apache.jetspeed.profiler.Profiler;
  import org.apache.jetspeed.profiler.ProfileLocator;
  import org.apache.jetspeed.om.page.Page;
  import org.apache.jetspeed.om.page.Fragment;
  import org.apache.jetspeed.request.RequestContext;
  
  /**
   * Single-step multi-thread aggregation valve. Not very efficient because, hidden
   * portlets may be sent to rendering but useful for testing
   *
   * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
   * @version $Id: PageAggregator.java,v 1.1 2004/03/16 20:21:06 taylor Exp $
   */
  public class PageAggregator extends BaseCommonService implements Aggregator
  {
      private final static Log log = LogFactory.getLog(PageAggregator.class);
      private final static String DEFAULT_STRATEGY = "strategy.default";
  
      public final static int STRATEGY_SEQUENTIAL = 0;
      public final static int STRATEGY_PARALLEL = 1;
      private final static String CONFIG_STRATEGY_SEQUENTIAL = "sequential";
      private final static String CONFIG_STRATEGY_PARALLEL = "parallel";
      private int strategy = STRATEGY_SEQUENTIAL;
  
      /**
       */
      public void init() throws CPSInitializationException
      {
          if (isInitialized())
          {
              return;
          }
  
          try
          {
              initConfiguration();
          }
          catch (Exception e)
          {
              log.error("Aggregator: Failed to load Service: " + e);
              e.printStackTrace();
          }
  
          setInit(true);
      }
  
      /**
       */
      public void shutdown()
      {
      }
  
      private void initConfiguration() throws CPSInitializationException
      {
          String defaultStrategy = getConfiguration().getString(DEFAULT_STRATEGY, CONFIG_STRATEGY_SEQUENTIAL);
          if (defaultStrategy.equals(CONFIG_STRATEGY_SEQUENTIAL))
          {
              strategy = STRATEGY_SEQUENTIAL;
          }
          else if (defaultStrategy.equals(CONFIG_STRATEGY_PARALLEL))
          {
              strategy = STRATEGY_PARALLEL;
          }
      }
  
      /**
       * Builds the portlet set defined in the context into a portlet tree.
       *
       * @return Unique Portlet Entity ID
       */
      public void build(RequestContext context)
          throws JetspeedException
      {
  
          PortletRenderer renderer = (PortletRenderer)CommonPortletServices.getPortalService(PortletRenderer.SERVICE_NAME);
          Profiler profiler = (Profiler)Jetspeed.getComponentManager().getComponent(Profiler.class);
          
          ProfileLocator locator = context.getProfileLocator();
          if (null == locator)
          {
              throw new JetspeedException("Failed to find ProfileLocator in BasicAggregator.build");
          }
          Page page = profiler.getPage(locator);
          if (null == page)
          {
              throw new JetspeedException("Failed to find PSML Pin BasicAggregator.build");
          }
          context.setPage(page);
  
          //Set default acl
          String acl = page.getAcl();
          if (acl == null)
          {
              //TBD get system default acl;
          }
  
          // Initialize fragment
          Stack stack = new Stack();
          Fragment currentFragment = page.getRootFragment();
  
          if (currentFragment == null)
          {
              throw new JetspeedException("No root Fragment found in Page");
          }
          
          String layoutDecorator = currentFragment.getDecorator();
          if(layoutDecorator == null)
          {
              layoutDecorator = page.getDefaultDecorator(currentFragment.getType());
          }
          
          //TODO: Remove hard coding of locations and use CM + TL
          List contentPathes = (List) context.getSessionAttribute(ContentFilter.SESSION_CONTENT_PATH_ATTR);
          
          if(contentPathes == null)
          {
              contentPathes = new ArrayList(2);
              context.setSessionAttribute(ContentFilter.SESSION_CONTENT_PATH_ATTR, contentPathes);
          }
          
          if(contentPathes.size() < 1)
          {
              // define the lookup order
              contentPathes.add(currentFragment.getType()+"/html/"+layoutDecorator);
              contentPathes.add("portlet/html");
              contentPathes.add("generic/html");
              contentPathes.add("/html");
          }
          else
          {
              contentPathes.set(0, currentFragment.getType()+"/html/"+layoutDecorator);
          }
          
  
          if (checkAccess(context,(currentFragment.getAcl()!=null)?currentFragment.getAcl():acl,
"render"))
          {
              if (strategy == STRATEGY_PARALLEL)
              {
                  // initializes the rendering stack with root children
                  // root fragement is always treated synchronously
                  for(Iterator i = currentFragment.getFragments().iterator(); i.hasNext();)
                  {
                      Fragment f = (Fragment)i.next();
  
                      if (!"hidden".equals(f.getState()))
                      {
                          stack.push(f);
                      }
                  }
  
                  // Walk through the Fragment tree, and start rendering "portlet" type
                  // fragment
                  while (!stack.isEmpty())
                  {
                      currentFragment = (Fragment)stack.pop();
  
                      if (checkAccess(context,
                                      ((currentFragment.getAcl()!=null)?currentFragment.getAcl():acl),
                                      "render"))
                      {
                          if (currentFragment.getType().equals("portlet"))
                          {
                          	// make the page aggreator less fragile
                          	// by preventing failed rendering from screwing up the
                          	// whole process
                             try
                              {
                                   renderer.render(currentFragment,context);
                              }
                              catch (Exception e)
                              {
                                  log.error("Failed to render portlet \""+currentFragment+"\":
"+e.toString());
                              }
                          }
  
                          // push the children frgaments on the rendering stack
                          for(Iterator i = currentFragment.getFragments().iterator(); i.hasNext();)
                          {
                              Fragment f = (Fragment)i.next();
  
                              if (!"hidden".equals(f.getState()))
                              {
                                  stack.push(f);
                              }
                          }
                      }
                      else
                      {
                          log.warn("Access denied RENDER fragment "+currentFragment);
                      }
                  }
              }
  
              // Retrieves the content dispatcher appropriate for sequential
              // or parallel rendering
  
              ContentDispatcher dispatcher = renderer.getDispatcher(context,(strategy==STRATEGY_PARALLEL));
  
  
              // Now synchronously trigger the rendering of the whole page
              renderer.renderNow(page.getRootFragment(), context);
  
              // DEBUG Testing: Use ContentDispatcher to display all children
              // of root fragment
  /*
              for(Iterator i = page.getRootFragment().getFragments().iterator(); i.hasNext();)
              {
                  Fragment fragment = (Fragment)i.next();
  
                  if (!"hidden".equals(fragment.getState()))
                  {
                      dispatcher.include(fragment, context.getRequest(), context.getResponse());
                  }
              }
  */            
          }
          else
          {
              log.warn("Access denied RENDER page "+page);
          }
          
      }
  
      public boolean checkAccess(RequestContext context, String acl, String action)
      {
          // This methid needs to be moved a secuity module.
          // Does nothing right now
          return true;
      }
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletAggregator.java
  
  Index: PortletAggregator.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.aggregator.impl;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.fulcrum.InitializationException;
  import org.apache.jetspeed.PortalReservedParameters;
  import org.apache.jetspeed.aggregator.Aggregator;
  import org.apache.jetspeed.aggregator.PortletRenderer;
  import org.apache.jetspeed.cps.BaseCommonService;
  import org.apache.jetspeed.cps.CommonPortletServices;
  import org.apache.jetspeed.exception.JetspeedException;
  import org.apache.jetspeed.om.page.Fragment;
  import org.apache.jetspeed.om.page.psml.FragmentImpl;
  import org.apache.jetspeed.request.RequestContext;
  
  /**
   * PortletAggregator is used to produce the content of a single portlet.
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: PortletAggregator.java,v 1.1 2004/03/16 20:21:06 taylor Exp $
   */
  public class PortletAggregator extends BaseCommonService implements Aggregator
  {
      private final static Log log = LogFactory.getLog(PortletAggregator.class);
      
      /* (non-Javadoc)
       * @see org.apache.fulcrum.Service#init()
       */
      public void init() throws InitializationException
      {
          if (isInitialized())
          {
              return;
          }
  
          setInit(true);
      }
  
      
      /* (non-Javadoc)
       * @see org.apache.jetspeed.aggregator.Aggregator#build(org.apache.jetspeed.request.RequestContext)
       */
      public void build(RequestContext context) throws JetspeedException
      {
          PortletRenderer renderer = (PortletRenderer)CommonPortletServices.getPortalService(PortletRenderer.SERVICE_NAME);
          Fragment fragment = new FragmentImpl(); // TODO: fragment factory
          fragment.setType(Fragment.PORTLET);
          fragment.setName(context.getRequestParameter(PortalReservedParameters.PORTLET));
          fragment.setId(context.getRequestParameter(PortalReservedParameters.PORTLET_ENTITY));
           
          renderer.renderNow(fragment, context);
      }
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/aggregator/impl/BasicAggregator.java
  
  Index: BasicAggregator.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.aggregator.impl;
  
  import java.util.Iterator;
  
  import javax.portlet.WindowState;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.jetspeed.Jetspeed;
  import org.apache.jetspeed.aggregator.Aggregator;
  import org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
  import org.apache.jetspeed.container.PortletContainerFactory;
  import org.apache.jetspeed.container.window.PortletWindowAccessor;
  import org.apache.jetspeed.cps.BaseCommonService;
  import org.apache.jetspeed.cps.CPSInitializationException;
  import org.apache.jetspeed.engine.core.PortalControlParameter;
  import org.apache.jetspeed.exception.JetspeedException;
  import org.apache.jetspeed.om.page.Fragment;
  import org.apache.jetspeed.om.page.Page;
  import org.apache.jetspeed.profiler.ProfileLocator;
  import org.apache.jetspeed.profiler.Profiler;
  import org.apache.jetspeed.request.RequestContext;
  import org.apache.pluto.PortletContainer;
  import org.apache.pluto.PortletContainerException;
  import org.apache.pluto.om.portlet.PortletDefinition;
  import org.apache.pluto.om.window.PortletWindow;
  
  /**
   * Basic Aggregator, nothing complicated. 
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: BasicAggregator.java,v 1.1 2004/03/16 20:21:06 taylor Exp $
   */
  public class BasicAggregator extends BaseCommonService implements Aggregator
  {
      private final static Log log = LogFactory.getLog(BasicAggregator.class);
      private final static String DEFAULT_STRATEGY = "strategy.default";
  
      public final static int STRATEGY_SEQUENTIAL = 0;
      public final static int STRATEGY_PARALLEL = 1;
      private final static String CONFIG_STRATEGY_SEQUENTIAL = "sequential";
      private final static String CONFIG_STRATEGY_PARALLEL = "parallel";
      private int strategy = STRATEGY_SEQUENTIAL;
  
      /**
       * This is the early initialization method called by the
       * Turbine <code>Service</code> framework
       * @param conf The <code>ServletConfig</code>
       * @exception throws a <code>InitializationException</code> if the service
       * fails to initialize
       */
      public void init() throws CPSInitializationException
      {
          if (isInitialized())
          {
              return;
          }
  
          try
          {
              initConfiguration();
          }
          catch (Exception e)
          {
              log.error("Aggregator: Failed to load Service: " + e);
              e.printStackTrace();
          }
  
          // initialization done
          setInit(true);
  
      }
  
      private void initConfiguration() throws CPSInitializationException
      {
          String defaultStrategy = getConfiguration().getString(DEFAULT_STRATEGY, CONFIG_STRATEGY_SEQUENTIAL);
          if (defaultStrategy.equals(CONFIG_STRATEGY_SEQUENTIAL))
          {
              strategy = STRATEGY_SEQUENTIAL;
          }
          else if (defaultStrategy.equals(CONFIG_STRATEGY_PARALLEL))
          {
              strategy = STRATEGY_PARALLEL;
          }
      }
  
      /**
       * This is the shutdown method called by the
       * Turbine <code>Service</code> framework
       */
      public void shutdown()
      {
      }
  
      /**
       * Builds the portlet set defined in the context into a portlet tree.
       *
       * @return Unique Portlet Entity ID
       */
      public void build(RequestContext request) throws JetspeedException
      {
          ProfileLocator locator = request.getProfileLocator();
          if (null == locator)
          {
              throw new JetspeedException("Failed to find ProfileLocator in BasicAggregator.build");
          }
  
          Profiler profiler = (Profiler)Jetspeed.getComponentManager().getComponent(Profiler.class);
       
          Page page = profiler.getPage(locator);
          if (null == page)
          {
              throw new JetspeedException("Failed to find PSML Pin BasicAggregator.build");
          }
  
          PortletContainer container;
          try
          {
              container = PortletContainerFactory.getPortletContainer();
          }
          catch (PortletContainerException e)
          {
              throw new JetspeedException("Failed to get PortletContainer: " + e);
          }
  
          Fragment root = page.getRootFragment();
          render(container, root, request);
          
          for (Iterator fit = root.getFragments().iterator(); fit.hasNext();)
          {
              Fragment fragment = (Fragment)fit.next();
              
              if (fragment.getType().equals(Fragment.LAYOUT))
              {
                  // skip layouts for now
                  // continue;
              }
              render(container, fragment, request);
          }
      }
  
      /**
       * Render a portlet by calling the container's renderPortlet.
       * 
       * @param container
       * @param fragment
       * @param request
       */
      private void render(PortletContainer container, Fragment fragment, RequestContext request)
      {
  
          //
          // create the portlet window and render the portlet
          //
          try
          {
              // 
              // Load Portlet from registry
              // 
              System.out.println("*** Getting portlet from registry: " + fragment.getName());
  			PortletRegistryComponent regsitry = (PortletRegistryComponent) Jetspeed.getComponentManager().getComponent(PortletRegistryComponent.class);
              PortletDefinition portletDefinition = regsitry.getPortletDefinitionByUniqueName(fragment.getName());
              if (portletDefinition == null)
              {
                  throw new JetspeedException("Failed to load: " + fragment.getName() + "
from registry");
              }
              
              // TODO: make renderer a component, assemble window accessor in constructor
              PortletWindowAccessor windowAccess = (PortletWindowAccessor)Jetspeed.getComponentManager().getComponent(PortletWindowAccessor.class);
              
              PortletWindow portletWindow = windowAccess.getPortletWindow(fragment);
  
              HttpServletRequest servletRequest = request.getRequestForWindow(portletWindow);
              HttpServletResponse servletResponse = request.getResponseForWindow(portletWindow);
  
              PortalControlParameter control = new PortalControlParameter(request.getRequestedPortalURL());
              WindowState windowState = control.getState(portletWindow);
  
              container.renderPortlet(portletWindow, servletRequest, servletResponse);
          }
          catch (Throwable t)
          {
              t.printStackTrace();
              log.error("Failed to service portlet, portlet exception: " + t);
          }
          
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message