View Javadoc

1   package org.apache.jetspeed.services.jsp.tags;
2   
3   /*
4    * Copyright 2000-2001,2004 The Apache Software Foundation.
5    * 
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * 
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   * 
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  //import java.util.*;
20  import javax.servlet.jsp.JspException;
21  import javax.servlet.jsp.PageContext;
22  import javax.servlet.jsp.tagext.TagSupport;
23  
24  // Turbine Classes 
25  import org.apache.turbine.services.jsp.JspService;
26  
27  import org.apache.ecs.ConcreteElement;
28  
29  // Jetspeed classes
30  import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
31  import org.apache.jetspeed.services.logging.JetspeedLogger;
32  import org.apache.jetspeed.services.resources.JetspeedResources;
33  import org.apache.jetspeed.services.rundata.JetspeedRunData;
34  import org.apache.jetspeed.util.template.JetspeedTool;
35  
36  /***
37   * Supporting class for the pane tag.
38   * Builds the output of a PSML config file and insert it within the 
39   * current JSP page
40   *
41   * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
42   * @author <a href="mailto:morciuch@apache.org">Mark Orciuch</a> 
43   * @version $Id: JetspeedPaneTag.java,v 1.6 2004/02/23 03:59:40 jford Exp $
44   */
45  public class JetspeedPaneTag extends TagSupport 
46  {
47      /***
48       * Static initialization of the logger for this class
49       */    
50      private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedPaneTag.class.getName());
51      
52      private String name = null;
53  
54      public void setName(String name)
55      {
56          this.name = name;
57      }
58      
59      public String getName()
60      {
61          return this.name;
62      }
63     
64      /***
65       * Method called when the tag is encountered to send attributes to the
66       * output stream
67       *
68       * @return SKIP_BODY, as it is intended to be a single tag.
69       */
70      public int doStartTag() throws JspException                   
71      {
72          JetspeedRunData data = (JetspeedRunData) pageContext.getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE);
73          
74          // retrieve the name attribute val
75          if (this.name == null)
76          {
77              this.name = JetspeedResources.getString("screen.homepage");
78          }
79              
80          try
81          {  
82              pageContext.getOut().flush();
83  
84              ConcreteElement result = new ConcreteElement();
85  
86              if (data != null && data.getUser() != null)
87              {
88                  JetspeedTool jt = new JetspeedTool(data);
89                  String jspeid = (String) data.getUser().getTemp("js_peid");
90                  if (jspeid != null)
91                  {
92                      data.setMode(JetspeedRunData.MAXIMIZE);
93                      result = jt.getPortletById(jspeid);
94                  }
95                  else 
96                  {
97                      result = jt.getPane(this.name);
98                  }
99              }
100         
101             // Check whether this is an "old" screen (that returns a ConcreteElement)
102             // or a "new" one that returns null.
103             if (result != null)
104             {
105                 //The ECS element must serialize in the character encoding
106                 // of the response
107                 result.setCodeSet(data.getResponse().getCharacterEncoding());
108 
109                 result.output(data.getResponse().getWriter());
110             }
111 
112         }
113         catch (Exception e)
114         {
115             String message = "Error processing name '" + name + "'.";
116             logger.error(message, e);
117             try
118             {
119                 data.getOut().print("Error processing ecs screen '" + name + "'. See log for more information.");
120             }
121             catch (java.io.IOException ioe) 
122             {
123             }    
124         }
125         return SKIP_BODY;
126     }
127 }