View Javadoc

1   package org.apache.jetspeed.services.jsp.tags;
2   
3   /*
4    * Copyright 2000-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 javax.servlet.jsp.JspException;
20  import javax.servlet.jsp.PageContext;
21  import javax.servlet.jsp.tagext.TagSupport;
22  
23  // Turbine Classes 
24  import org.apache.turbine.modules.ScreenLoader;
25  import org.apache.turbine.util.RunData;
26  import org.apache.turbine.services.jsp.JspService;
27  import org.apache.turbine.services.resources.TurbineResources;
28  import org.apache.ecs.ConcreteElement;
29  
30  // Jetspeed classes
31  import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
32  import org.apache.jetspeed.services.logging.JetspeedLogger;
33  
34  /***
35   * Supporting class for the ecsscreen tag.
36   * Sends the screens ecs element's content to the output stream.  
37   * RunData's screen value is expected to be set!
38   *
39   * @author <a href="mailto:ingo@raleigh.ibm.com">Ingo Schuster</a>
40   * @version $Id: EcsScreenTag.java,v 1.12 2004/02/23 03:59:40 jford Exp $
41   */
42  public class EcsScreenTag extends TagSupport 
43  {
44      /***
45       * Static initialization of the logger for this class
46       */    
47      private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(EcsScreenTag.class.getName());
48      
49      /***
50       * Method called when the tag is encountered to send attributes to the
51       * output stream
52       *
53       * @return SKIP_BODY, as it is intended to be a single tag.
54       */
55      public int doStartTag() throws JspException 
56      {
57          RunData data = (RunData)pageContext.getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE);
58          String screenName = data.getScreen();
59  
60          // make sure that not the BaseJspScreen is called 
61          // as this would result in an endless loop...
62          if ( screenName.equals( "BaseJspScreen" ) )
63          {
64              screenName = TurbineResources.getString("screen.homepage");
65          }
66  
67          try
68          {  
69              pageContext.getOut().flush();
70  
71              ConcreteElement screenElement = ScreenLoader.getInstance().eval( data, screenName );
72  
73              // Check whether this is an "old" screen (that returns a ConcreteElement)
74              // or a "new" one that returns null.
75              if ( screenElement != null )
76              {
77                  //The ECS element must serialize in the character encoding
78                  // of the response
79                  screenElement.setCodeSet( data.getResponse().getCharacterEncoding() );
80  
81                  screenElement.output( data.getResponse().getWriter() );
82              }
83  
84          }
85      catch (Exception e)
86          {
87              String message = "Error processing ecs screen '" + screenName + "'.";
88              logger.error(message, e);
89              try
90              {
91                  data.getOut().print("Error processing ecs screen '" + screenName + "'. See log for more information.");
92              }
93              catch(java.io.IOException ioe) {}    
94          }
95          return SKIP_BODY;
96      }
97  }