001    package org.apache.turbine.services.jsp.util;
002    
003    
004    /*
005     * Licensed to the Apache Software Foundation (ASF) under one
006     * or more contributor license agreements.  See the NOTICE file
007     * distributed with this work for additional information
008     * regarding copyright ownership.  The ASF licenses this file
009     * to you under the Apache License, Version 2.0 (the
010     * "License"); you may not use this file except in compliance
011     * with the License.  You may obtain a copy of the License at
012     *
013     *   http://www.apache.org/licenses/LICENSE-2.0
014     *
015     * Unless required by applicable law or agreed to in writing,
016     * software distributed under the License is distributed on an
017     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018     * KIND, either express or implied.  See the License for the
019     * specific language governing permissions and limitations
020     * under the License.
021     */
022    
023    
024    import org.apache.commons.logging.Log;
025    import org.apache.commons.logging.LogFactory;
026    import org.apache.turbine.modules.Screen;
027    import org.apache.turbine.modules.ScreenLoader;
028    import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker;
029    import org.apache.turbine.services.template.TurbineTemplate;
030    import org.apache.turbine.util.RunData;
031    
032    /**
033     * Returns output of a Screen module. An instance of this is placed in the
034     * request by the JspLayout. This allows template authors to
035     * place the screen template within the layout.<br>
036     * Here's how it's used in a JSP template:<br>
037     * <code>
038     * <%useBean id="screen_placeholder" class="JspScreenPlaceholder" scope="request"/%>
039     * ...
040     * <%= screen_placeholder %>
041     *</code>
042     *
043     * @author <a href="john.mcnally@clearink.com">John D. McNally</a>
044     * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
045     * @version $Id: JspScreenPlaceholder.java 757213 2009-03-22 16:43:31Z tv $
046     */
047    public class JspScreenPlaceholder
048    {
049        /** Logging */
050        private static Log log = LogFactory.getLog(JspNavigation.class);
051    
052        /* The RunData object */
053        private RunData data;
054    
055        private ScreenLoader screenLoader;
056    
057        /**
058         * Constructor
059         *
060         * @param data A Rundata Object
061         */
062        public JspScreenPlaceholder(RunData data)
063        {
064            this.data = data;
065            this.screenLoader = (ScreenLoader)TurbineAssemblerBroker.getLoader(Screen.NAME);
066        }
067    
068        /**
069         * builds the output of the navigation template
070         */
071        public void exec()
072        {
073            String template = null;
074            String module = null;
075            try
076            {
077                template = data.getTemplateInfo().getScreenTemplate();
078                module = TurbineTemplate.getScreenName(template);
079                screenLoader.exec(data, module);
080            }
081            catch (Exception e)
082            {
083                String message = "Error processing navigation template:" +
084                        template + " using module: " + module;
085                log.error(message, e);
086                try
087                {
088                    data.getResponse().getWriter().print("Error processing navigation template: "
089                            + template + " using module: " + module);
090                }
091                catch (java.io.IOException ioe)
092                {
093                    // ignore
094                }
095            }
096        }
097    }