View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.portals.gems.dojo;
18  
19  import javax.portlet.PortletConfig;
20  import javax.portlet.PortletException;
21  
22  import org.apache.jetspeed.headerresource.HeaderResource;
23  import org.apache.jetspeed.portlet.PortletHeaderRequest;
24  import org.apache.jetspeed.portlet.PortletHeaderResponse;
25  import org.apache.jetspeed.portlet.SupportsHeaderPhase;
26  import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
27  
28  /***
29   * Abstract DOJO portlet for inserting in cross context dojo widget includes
30   * 
31   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
32   * @version $Id: $
33   */
34  public abstract class AbstractDojoVelocityPortlet extends GenericVelocityPortlet implements SupportsHeaderPhase 
35  {    
36      protected String headerPage;
37  
38      /*
39       * Portlet constructor.
40       */
41      public AbstractDojoVelocityPortlet() 
42      {
43          super();
44      }
45  
46      public void init(PortletConfig config) throws PortletException
47      {
48          super.init(config);
49          this.headerPage = this.getInitParameter("HeaderPage");
50      }
51      
52      /*
53       * Include Dojo and Turbo header content using header resource component.
54       *
55       * @param request render request
56       * @param response render response
57       */    
58      public void doHeader( PortletHeaderRequest request, PortletHeaderResponse response )
59      throws PortletException
60      {
61          // use header resource component to ensure header logic is included only once
62          HeaderResource headerResource = response.getHeaderResource();
63  
64          headerResource.dojoEnable();
65          includeHeaderContent( headerResource );
66          
67          if ( this.headerPage != null )
68          {
69              include( request, response, this.headerPage );
70          }
71      }
72      
73      protected void includeHeaderContent( HeaderResource headerResource )
74      {
75          // do nothing - intended for derived classes
76      }
77      
78      protected void include(PortletHeaderRequest request, PortletHeaderResponse response, String headerPagePath, StringBuffer headerText) throws PortletException
79      {
80          response.include(request, response, headerPagePath);
81          headerText.append(response.getContent());
82      }
83      
84      protected void include(PortletHeaderRequest request, PortletHeaderResponse response, String headerPagePath) throws PortletException
85      {
86          response.include(request, response, headerPagePath);
87          response.getHeaderResource().addHeaderInfo(response.getContent());
88      }
89  }