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 ContentDispatcherImpl.java PortletRendererImpl.java
Date Thu, 23 Sep 2004 03:30:52 GMT
taylor      2004/09/22 20:30:52

  Modified:    portal/src/java/org/apache/jetspeed/velocity
                        JetspeedVelocityViewServlet.java
                        JetspeedPowerTool.java
               portal/src/java/org/apache/jetspeed/aggregator/impl
                        ContentDispatcherImpl.java PortletRendererImpl.java
  Log:
  Support for nested fragments!
  Contribution from Randy Watler
  Layout fragments can now be nested inside other fragments such as:
  
  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.6       +11 -2     jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/velocity/JetspeedVelocityViewServlet.java
  
  Index: JetspeedVelocityViewServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/velocity/JetspeedVelocityViewServlet.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JetspeedVelocityViewServlet.java	24 Aug 2004 14:28:17 -0000	1.5
  +++ JetspeedVelocityViewServlet.java	23 Sep 2004 03:30:52 -0000	1.6
  @@ -18,6 +18,8 @@
   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.request.RequestContext;
   import org.apache.pluto.Constants;
   import org.apache.velocity.Template;
  @@ -45,8 +47,9 @@
   	
   	public static final String VELOCITY_WRITER_ATTR = "org.apache.velocity.io.VelocityWriter";
       /** Cache of writers */
  -   private static SimplePool writerPool = new SimplePool(40);
  +    private static SimplePool writerPool = new SimplePool(40);
   	
  +    private static final Log log = LogFactory.getLog(JetspeedVelocityViewServlet.class);
   
       public static final String VELOCITY_CONTEXT_ATTR = "org.apache.velocity.Context";
       /**
  @@ -111,6 +114,12 @@
   			// Place the VelocityWriter into the Context
   			context.put(VELOCITY_WRITER_ATTR, vw);
               template.merge(context, vw);
  +        }
  +        catch (Exception e)
  +        {
  +            // log and rethrow exception
  +            log.error("Exception occured during merge template: " + e.toString(), e);
  +            throw e;
           }
           finally
           {
  
  
  
  1.29      +87 -67    jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/velocity/JetspeedPowerTool.java
  
  Index: JetspeedPowerTool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/velocity/JetspeedPowerTool.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- JetspeedPowerTool.java	20 Sep 2004 19:26:01 -0000	1.28
  +++ JetspeedPowerTool.java	23 Sep 2004 03:30:52 -0000	1.29
  @@ -631,12 +631,80 @@
   
       /**
        * <p>
  +     * Decorate and include fragment content.
  +     * </p>
  +     * 
  +     * @param f Fragment to include and decorate
  +     * @throws Exception
  +     */
  +    public void decorateAndInclude(Fragment f) throws Exception
  +    {
  +        // makes sure that any previous content has been written to
  +        // preserve natural HTML rendering order
  +        flush();
  +
  +        // Set current fragment and layout, making sure
  +        // the last currentFragment goes on to the fragmentStack
  +        if (getCurrentFragment() != null)
  +        {
  +            fragmentStack.push(getCurrentFragment());
  +        }
  +        setCurrentFragment(f);
  +        setCurrentLayout();
  +
  +        // include decorated layout or portlet fragment
  +        try
  +        {
  +            String fragmentType = f.getType();
  +            if (fragmentType.equals(Fragment.PORTLET))
  +            {
  +                decorateAndIncludePortlet(f);
  +            }
  +            else if (fragmentType.equals(Fragment.LAYOUT))
  +            {
  +                decorateAndIncludeLayout(f);
  +            }
  +        }
  +        catch (Exception e)
  +        {
  +            // include stack trace on exception
  +            renderResponse.getWriter().write(e.toString());          
  +        }
  +        finally
  +        {
  +            // Now that were are done with this fragment reset to the last
  +            // "current" fragment
  +            Fragment lastFragment = (Fragment) fragmentStack.pop();
  +            if (lastFragment != null)
  +            {
  +                setCurrentFragment(lastFragment);
  +            }
  +        }
  +    }
  +
  +    /**
  +     * <p>
  +     * Invoke nested layout portlet by including per the ContentDispatcher.
  +     * </p>
  +     * <p>
  +     * 
  +     * @param f Layout fragment to include
  +     * @throws Exception
  +     */
  +    private void decorateAndIncludeLayout(Fragment f) throws Exception
  +    {
  +        // include current layout fragment which includes layout template 
  +        include(f);
  +    }
  +
  +    /**
  +     * <p>
        * This does not actaully "include()" as per the ContentDispatcher, instead,
        * it locates the decorator for this Fragment or, if none has been defined
        * the default decorator for this Fragment type from the parent Page.
        * </p>
        * <p>
  -     * The decorator template itself is responsible for inlcluding the content
  +     * The decorator template itself is responsible for including the content
        * of the target Fragment which is easily acheived like so: <br />
        * in Velocity:
        * 
  @@ -650,69 +718,42 @@
        * 
        * <pre>
        *   <code>
  -     * 
  -     *  
  -     *   
  -     *    
  -     *     
  -     *      
  -     *       
  -     *        
        *            &lt;% 
        *             JetspeedPowerTool jetspeed = new JetspeedPowerTool(renderRequest, renderResponse,
portletConfig);
        *             jetspeed.include(jetspeed.getCurrentFragment());
        *            %&gt;
  -     *          
  -     *        
  -     *       
  -     *      
  -     *     
  -     *    
  -     *   
  -     *  
        * </code>
        * </pre>
        * 
        * 
  -     * @param f
  -     *            Fragment to "decorate"
  -     * @throws IOException
  -     * @throws TemplateLocatorException
  +     * @param f Portlet fragment to "decorate"
  +     * @throws Exception
        */
  -    public void decorateAndInclude(Fragment f) throws Exception
  +    private void decorateAndIncludePortlet(Fragment f) throws Exception
       {
  -        // makes sure that any previous content has been written to
  +        // make sure that any previous content has been written to
           // preserve natural HTML rendering order
           flush();
  -        String decorator = f.getDecorator();
  +
  +        // get fragment decorator; fallback to the default decorator
  +        // if the current fragment is not specifically decorated
           String fragmentType = f.getType();
  -        // Fallback to the default decorator if the current fragment is not
  -        // specifically decorated
  +        String decorator = f.getDecorator();
           if (decorator == null)
           {
  -            decorator = getPage().getDefaultDecorator(f.getType());
  +            decorator = getPage().getDefaultDecorator(fragmentType);
           }
   
  +        // get fragment properties for fragmentType or generic
           TemplateDescriptor propsTemp = getTemplate(decorator + "/" + DECORATOR_TYPE + ".properties",
fragmentType, decorationLocator, decorationLocatorDescriptor);
  -        // Not found specifcally for the fragmentType, then try the generic type
           if(propsTemp == null)
           {
               propsTemp = getTemplate(decorator + "/" + DECORATOR_TYPE + ".properties", GENERIC_TEMPLATE_TYPE,
decorationLocator, decorationLocatorDescriptor);
           }
  -        
   
  +        // get decorator template
           Configuration decoConf = new PropertiesConfiguration(propsTemp.getAbsolutePath());
           String ext = decoConf.getString("template.extension");
  -
  -        // Set this fragment as the current fragment, making sure
  -        // the last currentFragment goes on to the fragmentStack
  -        if (getCurrentFragment() != null)
  -        {
  -            fragmentStack.push(getCurrentFragment());
  -        }
  -        setCurrentFragment(f);
  -        setCurrentLayout();
  -        
           String decoratorPath = decorator + "/" + DECORATOR_TYPE + ext;
           TemplateDescriptor template = null;
           try
  @@ -727,31 +768,10 @@
                   template = getDecoration(parent + "/" + DECORATOR_TYPE + ext, fragmentType);
               }
           }
  -        PortletRequestDispatcher prd = portletConfig.getPortletContext().getRequestDispatcher(template.getAppRelativePath());
  -        try
  -        {
  -            
  -            prd.include(renderRequest, renderResponse);
  -            
  -        }
  -        catch (Exception e1)
  -        {
  -            renderResponse.getWriter().write(e1.toString());          
  -            
  -        }
  -        finally
  -        {
   
  -            // Now that were are done with this fragment reset to the last
  -            // "current" fragment
  -            Fragment lastFragment = (Fragment) fragmentStack.pop();
  -        	if (lastFragment != null)
  -        	{
  -        	    setCurrentFragment(lastFragment);
  -        	}
  -        	
  -        	
  -        }
  +        // include decorator which includes current portlet fragment
  +        PortletRequestDispatcher prd = portletConfig.getPortletContext().getRequestDispatcher(template.getAppRelativePath());
  +        prd.include(renderRequest, renderResponse);
       }
   
       /**
  @@ -970,8 +990,8 @@
   
       /**
        * Gets the list of decorator actions for a page.
  -     * Each page has its own collection of actions associated with it.
  -     * The creation of the decorator action list per page will only be called once per
session.
  +     * Each layout fragment on a page has its own collection of actions associated with
it.
  +     * The creation of the layout decorator action list per page will only be called once
per session.
        * This optimization is to avoid the expensive operation of security checks and action
object creation and logic
        * on a per request basis. 
        * 
  @@ -981,7 +1001,7 @@
       public List getPageDecoratorActions() throws Exception
       {
           RequestContext context = Jetspeed.getCurrentRequestContext();
  -        String key = getPage().getId();
  +        String key = "PAGE" + getPage().getId() + ":" + this.getCurrentFragment().getId()
;
           Map sessionActions = (Map)context.getSessionAttribute(POWER_TOOL_SESSION_ACTIONS);
           if (null == sessionActions)
           {
  
  
  
  1.7       +30 -2     jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/aggregator/impl/ContentDispatcherImpl.java
  
  Index: ContentDispatcherImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/aggregator/impl/ContentDispatcherImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ContentDispatcherImpl.java	28 Jul 2004 13:23:09 -0000	1.6
  +++ ContentDispatcherImpl.java	23 Sep 2004 03:30:52 -0000	1.7
  @@ -86,6 +86,16 @@
               {
                   log.debug("Synchronous rendering for OID "+ oid);
               }
  +
  +            // access servlet request to determine request context in order
  +            // to render inner layout fragment with appropriate request attributes
  +            if (fragment.getType().equals(Fragment.LAYOUT))
  +            {
  +                RequestContext context = (RequestContext) req.getAttribute("org.apache.jetspeed.request.RequestContext");
  +                renderer.renderNow(fragment, context);
  +                return;
  +            }
  +            // render synchronously
               renderer.renderNow(fragment,req,rsp);
               return;
           }
  @@ -160,6 +170,15 @@
                   log.debug("Content is null for OID "+oid);
               }
   
  +            // access servlet request to determine request context in order
  +            // to render inner layout fragment with appropriate request attributes
  +            if (fragment.getType().equals(Fragment.LAYOUT))
  +            {
  +                RequestContext context = (RequestContext) req.getAttribute("org.apache.jetspeed.request.RequestContext");
  +                renderer.renderNow(fragment, context);
  +                return;
  +            }
  +            // render synchronously
               renderer.renderNow(fragment,req,rsp);
               return;
           }
  @@ -251,7 +270,16 @@
                   log.debug("Content is null for OID "+oid);
               }
   
  -            //unwrap the RenderRequest and RenderResponse to avoid having to cascade several
  +            // access servlet request to determine request context in order
  +            // to render inner layout fragment with appropriate request attributes
  +            if (fragment.getType().equals(Fragment.LAYOUT))
  +            {
  +                HttpServletRequest request = (HttpServletRequest)((HttpServletRequestWrapper)req).getRequest();
  +                RequestContext context = (RequestContext) request.getAttribute("org.apache.jetspeed.request.RequestContext");
  +                renderer.renderNow(fragment, context);
  +                return;
  +            }
  +            // unwrap the RenderRequest and RenderResponse to avoid having to cascade several
               // portlet requests/responses
               HttpServletRequest request = (HttpServletRequest)((HttpServletRequestWrapper)req).getRequest();
               HttpServletResponse response = (HttpServletResponse)((HttpServletResponseWrapper)rsp).getResponse();
  
  
  
  1.23      +38 -7     jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletRendererImpl.java
  
  Index: PortletRendererImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletRendererImpl.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- PortletRendererImpl.java	3 Sep 2004 20:17:33 -0000	1.22
  +++ PortletRendererImpl.java	23 Sep 2004 03:30:52 -0000	1.23
  @@ -29,6 +29,7 @@
   import org.apache.jetspeed.container.window.FailedToRetrievePortletWindow;
   import org.apache.jetspeed.container.window.PortletWindowAccessor;
   import org.apache.jetspeed.om.page.Fragment;
  +import org.apache.jetspeed.om.page.Page;
   import org.apache.jetspeed.request.RequestContext;
   import org.apache.jetspeed.util.JetspeedObjectID;
   import org.apache.pluto.PortletContainer;
  @@ -85,6 +86,9 @@
           // create the portlet window and render the portlet
           //
           HttpServletRequest servletRequest = null;
  +        Page outerPage = null;
  +        Fragment outerFragment = null;
  +        ContentDispatcher outerFragmentDispatcher = null;
           try
           {
               PortletContainerServices.prepare("jetspeed");
  @@ -94,9 +98,14 @@
               servletRequest = request.getRequestForWindow(portletWindow);
               HttpServletResponse servletResponse = request.getResponseForWindow(portletWindow);
   
  -            servletRequest.setAttribute("org.apache.jetspeed.ContentDispatcher",getDispatcher(request,true));
  -            servletRequest.setAttribute("org.apache.jetspeed.Fragment",fragment);
  +            // save and set servlet request attributes required
  +            // for rendering layout portlets
  +            outerPage = (Page) servletRequest.getAttribute(PortalReservedParameters.PAGE_ATTRIBUTE_KEY);
  +            outerFragment = (Fragment) servletRequest.getAttribute("org.apache.jetspeed.Fragment");
  +            outerFragmentDispatcher = (ContentDispatcher) servletRequest.getAttribute("org.apache.jetspeed.ContentDispatcher");
               servletRequest.setAttribute(PortalReservedParameters.PAGE_ATTRIBUTE_KEY,request.getPage());
  +            servletRequest.setAttribute("org.apache.jetspeed.Fragment",fragment);
  +            servletRequest.setAttribute("org.apache.jetspeed.ContentDispatcher",getDispatcher(request,true));
   
               // should we decorate here instead of rendering Portlet ?
               container.renderPortlet(portletWindow, servletRequest, servletResponse);
  @@ -109,9 +118,31 @@
           {
               if (servletRequest!=null)
               {
  -                servletRequest.removeAttribute("org.apache.jetspeed.ContentDispatcher");
  -                servletRequest.removeAttribute("org.apache.jetspeed.Fragment");
  -                servletRequest.removeAttribute(PortalReservedParameters.PAGE_ATTRIBUTE_KEY);
  +                // restore servlet request attributes
  +                if (outerFragmentDispatcher == null)
  +                {
  +                    servletRequest.removeAttribute("org.apache.jetspeed.ContentDispatcher");
  +                }
  +                else
  +                {
  +                    servletRequest.setAttribute("org.apache.jetspeed.ContentDispatcher",outerFragmentDispatcher);
  +                }
  +                if (outerFragment == null)
  +                {
  +                    servletRequest.removeAttribute("org.apache.jetspeed.Fragment");
  +                }
  +                else
  +                {
  +                    servletRequest.setAttribute("org.apache.jetspeed.Fragment",outerFragment);
  +                }
  +                if (outerPage == null)
  +                {
  +                    servletRequest.removeAttribute(PortalReservedParameters.PAGE_ATTRIBUTE_KEY);
  +                }
  +                else
  +                {
  +                    servletRequest.setAttribute(PortalReservedParameters.PAGE_ATTRIBUTE_KEY,outerPage);
  +                }
               }
           }
       }
  @@ -210,4 +241,4 @@
   
           return portletWindow;
       }
  -}
  \ No newline at end of file
  +}
  
  
  

---------------------------------------------------------------------
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