View Javadoc

1   package org.apache.turbine.services.jsp.util;
2   
3   
4   /*
5    * Licensed to the Apache Software Foundation (ASF) under one
6    * or more contributor license agreements.  See the NOTICE file
7    * distributed with this work for additional information
8    * regarding copyright ownership.  The ASF licenses this file
9    * to you under the Apache License, Version 2.0 (the
10   * "License"); you may not use this file except in compliance
11   * with the License.  You may obtain a copy of the License at
12   *
13   *   http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing,
16   * software distributed under the License is distributed on an
17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18   * KIND, either express or implied.  See the License for the
19   * specific language governing permissions and limitations
20   * under the License.
21   */
22  
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.apache.turbine.modules.Screen;
27  import org.apache.turbine.modules.ScreenLoader;
28  import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker;
29  import org.apache.turbine.services.template.TurbineTemplate;
30  import org.apache.turbine.util.RunData;
31  
32  /**
33   * Returns output of a Screen module. An instance of this is placed in the
34   * request by the JspLayout. This allows template authors to
35   * place the screen template within the layout.<br>
36   * Here's how it's used in a JSP template:<br>
37   * <code>
38   * <%useBean id="screen_placeholder" class="JspScreenPlaceholder" scope="request"/%>
39   * ...
40   * <%= screen_placeholder %>
41   *</code>
42   *
43   * @author <a href="john.mcnally@clearink.com">John D. McNally</a>
44   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
45   * @version $Id: JspScreenPlaceholder.java 1199089 2011-11-08 03:14:28Z tv $
46   */
47  public class JspScreenPlaceholder
48  {
49      /** Logging */
50      private static Log log = LogFactory.getLog(JspNavigation.class);
51  
52      /* The RunData object */
53      private final RunData data;
54  
55      private final ScreenLoader screenLoader;
56  
57      /**
58       * Constructor
59       *
60       * @param data A Rundata Object
61       */
62      public JspScreenPlaceholder(RunData data)
63      {
64          this.data = data;
65          this.screenLoader = (ScreenLoader)TurbineAssemblerBroker.getLoader(Screen.class);
66      }
67  
68      /**
69       * builds the output of the navigation template
70       */
71      public void exec()
72      {
73          String template = null;
74          String module = null;
75          try
76          {
77              template = data.getTemplateInfo().getScreenTemplate();
78              module = TurbineTemplate.getScreenName(template);
79              screenLoader.exec(data, module);
80          }
81          catch (Exception e)
82          {
83              String message = "Error processing navigation template:" +
84                      template + " using module: " + module;
85              log.error(message, e);
86              try
87              {
88                  data.getResponse().getWriter().print("Error processing navigation template: "
89                          + template + " using module: " + module);
90              }
91              catch (java.io.IOException ioe)
92              {
93                  // ignore
94              }
95          }
96      }
97  }