portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wea...@apache.org
Subject cvs commit: jakarta-jetspeed-2/portal/src/webapp/WEB-INF/templates/decorator/html/portletstd_jsp decorator.properties decorator.jsp
Date Tue, 13 Jan 2004 17:40:56 GMT
weaver      2004/01/13 09:40:56

  Modified:    portal/src/java/org/apache/jetspeed/velocity
                        JetspeedPowerTool.java
  Added:       portal/src/webapp/WEB-INF/templates/layout/html/columns_jsp
                        layout.properties layout.jsp
               portal/src/webapp/WEB-INF/templates/decorator/html/portletstd
                        decorator.properties decorator.vm
               portal/src/webapp/WEB-INF/templates/decorator/html/clear
                        decorator.vm decorator.properties
               portal/src/webapp/WEB-INF/templates/layout/html/columns
                        layout.vm layout.properties
               portal/src/webapp/WEB-INF/templates/decorator/html/portletstd_jsp
                        decorator.properties decorator.jsp
  Removed:     portal/src/webapp/WEB-INF/templates/decorator/portletstd_jsp
                        portletstd-top.jsp portletstd-bottom.jsp
                        decorator.properties
               portal/src/webapp/WEB-INF/templates/layout/columns layout.vm
                        layout.properties
               portal/src/webapp/WEB-INF/templates/decorator/portletstd
                        decorator.vm decorator.properties
  Log:
  Added capability and localiztion to JetspeedPowerTools template
  location algorithm
  
  Adjusted templates to conform to a localized directory structure
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed-2/portal/src/webapp/WEB-INF/templates/layout/html/columns_jsp/layout.properties
  
  Index: layout.properties
  ===================================================================
  id=columns_jsp
  template.type=JSP
  template.extension=.jsp
  
  
  1.1                  jakarta-jetspeed-2/portal/src/webapp/WEB-INF/templates/layout/html/columns_jsp/layout.jsp
  
  Index: layout.jsp
  ===================================================================
  <%@ page language="java" 
           import="javax.portlet.*, java.util.*, org.apache.jetspeed.aggregator.*, org.apache.jetspeed.om.page.*,org.apache.jetspeed.velocity.JetspeedPowerTool"
           session="false" %>
  <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
  <%@ taglib uri='/WEB-INF/portlet.tld' prefix='portlet'%>
  <portlet:defineObjects/>
  
  <% 
  JetspeedPowerTool jetspeed = new JetspeedPowerTool(pageContext);
  List[] table = jetpseed.getColumns();
  Page myPage = jetspeed.getPage();
  Fragment myFragment = jetspeed.getCurrentFragment();
  org.apache.pluto.om.entity.PortletEntity portletEntity =jetspeed.getCurrentPortletEntity();
  %>
  
  <%
    String decorator = myPage.getDefaultDecorator(myFragment.getType());
    String decoTop = null;
    String decoBottom = null;
    
    if (myFragment.getDecorator()!=null)
    {
          decorator = myFragment.getDecorator();
    }
  
    if (decorator != null)
    {
          decoTop = decorator+"-top.jsp";
          decoBottom = decorator+"-bottom.jsp";
    }
  %>
  <!-- Decorator <%= decorator %>  <%=decoTop%>-<%=decoBottom%>-->
  <%
    if ((decoTop != null) && (myFragment == myPage.getRootFragment()))
    {
  %>
  <jsp:include page="<%=decoTop%>" />
  <%
    }
  %>
  <table width="100%" cellspacing="0" cellpadding="0">
    <tr>
    <%
       for(int i=0; i < table.length; i++)
       {
    %>
      <td valign="top"><table width="100%">
      <%
          for(Iterator it=table[i].iterator(); it.hasNext();)
          {
             Fragment f = (Fragment)it.next();
       %>
       <tr><td width="100%">
       <%
           jetspeed.decorateAndInclude(f);
        %>
  
       </td></tr>
       <%
          }
       %>
       </table></td>
    <%
       }
    %>
    </tr>
  </table>
  <%
  
    if ((decoBottom != null) && (myFragment == myPage.getRootFragment()))
    {
  %>
  <jsp:include page="<%=decoBottom%>" />
  <%
    }
  %>
  
  
  
  1.4       +103 -18   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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JetspeedPowerTool.java	12 Jan 2004 22:50:32 -0000	1.3
  +++ JetspeedPowerTool.java	13 Jan 2004 17:40:55 -0000	1.4
  @@ -54,22 +54,27 @@
   package org.apache.jetspeed.velocity;
   
   import java.io.IOException;
  +import java.io.PrintWriter;
  +import java.io.Writer;
   import java.util.List;
  +import java.util.Locale;
   import java.util.Stack;
   
   import javax.portlet.PortletConfig;
   import javax.portlet.PortletException;
   import javax.portlet.PortletRequest;
   import javax.portlet.PortletRequestDispatcher;
  -import javax.portlet.PortletResponse;
   import javax.portlet.RenderRequest;
   import javax.portlet.RenderResponse;
  +import javax.servlet.jsp.PageContext;
   
   import org.apache.commons.configuration.Configuration;
   import org.apache.commons.configuration.PropertiesConfiguration;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.apache.jetspeed.Jetspeed;
   import org.apache.jetspeed.aggregator.ContentDispatcher;
  +import org.apache.jetspeed.capability.CapabilityMap;
   import org.apache.jetspeed.cps.CommonPortletServices;
   import org.apache.jetspeed.cps.template.Template;
   import org.apache.jetspeed.cps.template.TemplateLocator;
  @@ -78,7 +83,7 @@
   import org.apache.jetspeed.entity.PortletEntityAccess;
   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.Constants;
   import org.apache.pluto.om.entity.PortletEntity;
  @@ -119,6 +124,9 @@
    */
   public class JetspeedPowerTool implements ViewTool
   {
  +    protected static final String PORTLET_CONFIG_ATTR = "portletConfig";
  +    protected static final String RENDER_RESPONSE_ATTR = "renderResponse";
  +    protected static final String RENDER_REQUEST_ATTR = "renderRequest";
       public static final String DISPATCHER_ATTR = "dispatcher";
       private static final String COLUMNS_ATTR = "columns";
       public static final String PAGE_ATTR = "page";
  @@ -137,10 +145,16 @@
   
       private ViewContext viewCtx;
   
  +    private Writer templateWriter;
  +
       private Stack fragmentStack;
   
       private static final Log log = LogFactory.getLog(JetspeedPowerTool.class);
   
  +    private CapabilityMap capabilityMap;
  +    private Locale locale;
  +    private TemplateLocator templateLocator;
  +    private TemplateLocatorService locatorService;
       /**
        * Empty constructor DO NOT USE!!!!  This is only here to allow creation of the
        * via the Velocity Tool Box.  For proper use out side the tool box use @see #JetspeedPowerTool(javax.portlet.RenderRequest,
javax.portlet.RenderResponse, javax.portlet.PortletConfig)
  @@ -152,9 +166,11 @@
       }
   
       /**
  -     * This is here to make this tool easily useable in any
  -     * templating environment including JSPs
  -     * @param request Current PortletRequest
  +      * This is here to make this tool easily useable in 
  +      * within standard java classes.
  +     * @param request
  +     * @param resp
  +     * @param config
        */
       public JetspeedPowerTool(RenderRequest request, RenderResponse resp, PortletConfig
config)
       {
  @@ -162,7 +178,33 @@
           renderRequest = request;
           renderResponse = resp;
           portletConfig = config;
  +        try
  +        {
  +            // I am not sure that this will produce the required result.
  +            templateWriter = renderResponse.getWriter();
  +        }
  +        catch (IOException e)
  +        {
  +            log.error("Unable to retreive Writer from the RenderResponse: " + e.toString(),
e);
  +        }
  +        fragmentStack = new Stack();
  +		clientSetup(Jetspeed.getCurrentRequestContext());
  +    }
  +
  +    /**
  +     * Use this constructor when using the JetspeedPowerTool within JSP
  +     * pages or custom tags.
  +     * @param jspContext
  +     */
  +    public JetspeedPowerTool(PageContext jspContext)
  +    {
  +        this();
  +        renderRequest = (RenderRequest) jspContext.getAttribute(RENDER_REQUEST_ATTR);
  +        renderResponse = (RenderResponse) jspContext.getAttribute(RENDER_RESPONSE_ATTR);
  +        portletConfig = (PortletConfig) jspContext.getAttribute(PORTLET_CONFIG_ATTR);
  +        templateWriter = jspContext.getOut();
           fragmentStack = new Stack();
  +		clientSetup(Jetspeed.getCurrentRequestContext());
       }
   
       /**
  @@ -176,7 +218,8 @@
               ViewContext viewContext = (ViewContext) obj;
               this.viewCtx = viewContext;
               ctx = viewContext.getVelocityContext();
  -            setRequest((RenderRequest) ctx.get("renderRequest"));
  +            setRequest((RenderRequest) ctx.get(RENDER_REQUEST_ATTR));
  +           
           }
           else if (obj instanceof PortletRequest)
           {
  @@ -193,6 +236,7 @@
           renderResponse = (RenderResponse) ctx.get(Constants.PORTLET_RESPONSE);
           portletConfig = (PortletConfig) ctx.get(Constants.PORTLET_CONFIG);
           fragmentStack = new Stack();
  +        clientSetup(Jetspeed.getCurrentRequestContext());
   
       }
   
  @@ -320,11 +364,11 @@
           }
           try
           {
  -            TemplateLocatorService tls =
  -                (TemplateLocatorService) CommonPortletServices.getPortalService(TemplateLocatorService.SERVICE_NAME);
  -            TemplateLocator locator = tls.createLocator(templateType);
  -            locator.setName(path);
  -            Template template = tls.locateTemplate(locator);
  +        	
  +			templateLocator.setName(path);
  +			templateLocator.setType(templateType);
  +			
  +            Template template = locatorService.locateTemplate(templateLocator);
               return template;
           }
           catch (TemplateLocatorException e)
  @@ -359,6 +403,26 @@
           getContentDispatcher().include(f, renderRequest, renderResponse);
   
       }
  +    
  +    public void  includeTemplate(String template, String templateType) throws IOException
  +    {
  +    	checkState();    	
  +    	try
  +        {
  +			flush();
  +            PortletRequestDispatcher pDispatcher = portletConfig.getPortletContext().getRequestDispatcher(getTemplate(template,
templateType).getAppRelativePath());
  +            pDispatcher.include(renderRequest, renderResponse);
  +        }
  +        catch (Exception e)
  +        {            
  +            PrintWriter directError = new PrintWriter(renderResponse.getWriter());
  +			directError.write("Error occured process includeTemplate(): "+e.toString()+"\n\n");
  +            e.printStackTrace(directError);
  +            directError.close();            
  +        }    	
  +    }
  +    
  +
   
       /**
        * 
  @@ -366,10 +430,14 @@
       public void flush() throws IOException
       {
           checkState();
  -        if (viewCtx != null)
  +        if (templateWriter != null)
           {
  -            VelocityWriter vw = (VelocityWriter) viewCtx.getVelocityContext().get(JetspeedVelocityViewServlet.VELOCITY_WRITER_ATTR);
  -            vw.flush();
  +            templateWriter.flush();
  +        }
  +        else if(viewCtx != null)
  +        {
  +			templateWriter = (VelocityWriter) viewCtx.getVelocityContext().get(JetspeedVelocityViewServlet.VELOCITY_WRITER_ATTR);
  +			templateWriter.flush();
           }
       }
   
  @@ -443,15 +511,13 @@
           }
       }
   
  -   
  -
       /**
        * 
        * 
        * @throws java.lang.IllegalStateException if the <code>PortletConfig</code>,
<code>RenderRequest</code> or
        * <code>RenderReponse</code> is null.
        */
  -    private void checkState()
  +    protected void checkState()
       {
           if (portletConfig == null || renderRequest == null || renderResponse == null)
           {
  @@ -460,6 +526,25 @@
                       + ""
                       + "The JetspeedPowerTool generally only usuable during the rendering
phase of  "
                       + "internal portlet applications.");
  +        }
  +    }
  +
  +    protected void clientSetup(RequestContext requestContext) 
  +    {
  +        locatorService = (TemplateLocatorService) CommonPortletServices.getPortalService(TemplateLocatorService.SERVICE_NAME);
  +        // By using null, we create a re-useable locator    
  +        try
  +        {
  +            templateLocator = locatorService.createLocator(null);        
  +            capabilityMap = requestContext.getCapabilityMap();
  +            templateLocator.setMediaType(capabilityMap.getPreferredMediaType().getName());
  +            locale = requestContext.getLocale();
  +            templateLocator.setCountry(locale.getCountry());
  +            templateLocator.setLanguage(locale.getLanguage());       
  +        }
  +        catch (Exception e)
  +        {
  +           log.error("Unable to perform client setup: "+e.toString(), e);
           }
       }
   
  
  
  
  1.1                  jakarta-jetspeed-2/portal/src/webapp/WEB-INF/templates/decorator/html/portletstd/decorator.properties
  
  Index: decorator.properties
  ===================================================================
  id=portletstd
  template.type=velocity
  template.extension=.vm
  
  
  1.1                  jakarta-jetspeed-2/portal/src/webapp/WEB-INF/templates/decorator/html/portletstd/decorator.vm
  
  Index: decorator.vm
  ===================================================================
  #set($myPage = $jetspeed.page)
  
  #set($myF = $jetspeed.currentFragment)
  
  #set($myPE = $jetspeed.currentPortletEntity)
  <!-- Begin portletstd.vm -->
  <table width="100%" cellspacing"0" cellpadding="0">
  <tr>
    <td bgcolor="${myPage.defaultSkin}">
    <table width="100%">
    <tr>
      <td>
        ${myPE.portletDefinition.name}
      </td>
      <td>
      </td>
    </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td width="100%" valign="top">
      #if (!$jetspeed.isHidden($myF))
        $jetspeed.include($myF)
      #end
    </td>
  </tr>
  </table>
  <!--  End portletstd.vm -->
  
  
  1.1                  jakarta-jetspeed-2/portal/src/webapp/WEB-INF/templates/decorator/html/clear/decorator.vm
  
  Index: decorator.vm
  ===================================================================
  <!--  BEGIN: clear/decorator.vm -->
  
  $jetspeed.include($jetspeed.currentFragment)
  
  <!--  END: clear/decorator.vm -->
  
  
  1.1                  jakarta-jetspeed-2/portal/src/webapp/WEB-INF/templates/decorator/html/clear/decorator.properties
  
  Index: decorator.properties
  ===================================================================
  id=clear
  template.type=velocity
  template.extension=.vm
  
  
  1.1                  jakarta-jetspeed-2/portal/src/webapp/WEB-INF/templates/layout/html/columns/layout.vm
  
  Index: layout.vm
  ===================================================================
  #set($table = $jetspeed.columns)
  
  #set($myPage = $jetspeed.page)
  
  #set($myFragment = $jetspeed.currentFragment)
  
  #set($decorator = $myPage.getDefaultDecorator($myFragment.getType()))
  
    
   #if($myFragment.getDecorator())
          #set($decorator = $myFragment.getDecorator())
    #end
  
    #if ($decorator)
          #set($decoTop = "${decorator}-top.vm")
          #set($decoBottom = "${decorator}-bottom.vm")
    #end
  
  <!-- Decorator  $decorator  ${decoTop}.vm-${decoBottom}.vm-->
  
    #if (($decoTop) && ($myFragment == $myPage.getRootFragment()))
        #parse($jetspeed.getTemplate($decoTop).appRelativePath)
    #end
  
  <table width="100%" cellspacing="0" cellpadding="0">
    <tr>
  
       #foreach($entry in $table)
      <td valign="top">
         <table width="100%">
         #foreach($f in $entry)       
          <tr>
         	   	<td width="100%">
                  ## get the decorated Portlet content
                 $jetspeed.decorateAndInclude($f)                
       </td></tr>
        #end
       </table></td>
     #end
    </tr>
  </table>
  
  #if (($decoBottom ) && ($myFragment == $myPage.getRootFragment()))
     #parse($jetspeed.getTemplate($decoBottom).appRelativePath)
  #end
  
  
  
  1.1                  jakarta-jetspeed-2/portal/src/webapp/WEB-INF/templates/layout/html/columns/layout.properties
  
  Index: layout.properties
  ===================================================================
  id=columns
  template.type=velocity
  template.extension=.vm
  
  
  1.1                  jakarta-jetspeed-2/portal/src/webapp/WEB-INF/templates/decorator/html/portletstd_jsp/decorator.properties
  
  Index: decorator.properties
  ===================================================================
  id=portletstd_jsp
  template.type=JSP
  template.extension=.jsp
  
  
  1.1                  jakarta-jetspeed-2/portal/src/webapp/WEB-INF/templates/decorator/html/portletstd_jsp/decorator.jsp
  
  Index: decorator.jsp
  ===================================================================
  <%@ page language="java" import="org.apache.jetspeed.om.page.*,org.apache.pluto.om.entity.*,
org.apache.jetspeed.velocity.JetspeedPowerTool" session="false" %>
  <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
  <%@ taglib uri='/WEB-INF/portlet.tld' prefix='portlet'%>
  <portlet:defineObjects/>
  <% 
  JetspeedPowerTool jetspeed = new JetspeedPowerTool(pageContext);
  Page myPage = jetspeed.getPage();
  Fragment myF = jetspeed.getCurrentFragment();
  PortletEntity myPE = jetspeed.getCurrentPortletEntity();
  
  %>
  <!-- BEGIN: portletstd_jsp -->
  <table width="100%" cellspacing"0" cellpadding="0">
  <tr>
    <td bgcolor="<%=myPage.getDefaultSkin()%>">
    <table width="100%">
    <tr>
      <td><% if (myPE!=null) out.write(myPE.getPortletDefinition().getName());%></td>
      <td>
      </td>
    </tr>
    </table>
    </td>
  </tr>
  <tr><td width="100%" valign="top">
       <%
         if (!jetspeed.isHidden(myF))
         {
            jetspeed.include(myF);
         }
       %>
  </td>
  </tr>
  </table>
  <!-- END: portletstd_jsp -->
  
  

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