001package 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
024import org.apache.commons.logging.Log;
025import org.apache.commons.logging.LogFactory;
026import org.apache.turbine.modules.Screen;
027import org.apache.turbine.modules.ScreenLoader;
028import org.apache.turbine.services.TurbineServices;
029import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService;
030import org.apache.turbine.services.template.TemplateService;
031import org.apache.turbine.util.RunData;
032
033/**
034 * Returns output of a Screen module. An instance of this is placed in the
035 * request by the JspLayout. This allows template authors to
036 * place the screen template within the layout.<br>
037 * Here's how it's used in a JSP template:<br>
038 * <code>
039 * &lt;%useBean id="screen_placeholder" class="JspScreenPlaceholder" scope="request" %&gt;
040 * ...
041 * &lt;%= screen_placeholder %&gt;
042 * </code>
043 *
044 * @author <a href="john.mcnally@clearink.com">John D. McNally</a>
045 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
046 * @version $Id: JspScreenPlaceholder.java 1773378 2016-12-09 13:19:59Z tv $
047 */
048public class JspScreenPlaceholder
049{
050    /** Logging */
051    private static Log log = LogFactory.getLog(JspNavigation.class);
052
053    /* The RunData object */
054    private final RunData data;
055
056    private final ScreenLoader screenLoader;
057
058    /**
059     * Constructor
060     *
061     * @param data A Rundata Object
062     */
063    public JspScreenPlaceholder(RunData data)
064    {
065        this.data = data;
066        AssemblerBrokerService abs = (AssemblerBrokerService)TurbineServices.getInstance()
067            .getService(AssemblerBrokerService.SERVICE_NAME);
068        this.screenLoader = (ScreenLoader)abs.getLoader(Screen.class);
069    }
070
071    /**
072     * builds the output of the navigation template
073     */
074    public void exec()
075    {
076        String template = null;
077        String module = null;
078        try
079        {
080            template = data.getTemplateInfo().getScreenTemplate();
081            TemplateService templateService = (TemplateService)TurbineServices.getInstance().getService(TemplateService.SERVICE_NAME);
082            module = templateService.getScreenName(template);
083            screenLoader.exec(data, module);
084        }
085        catch (Exception e)
086        {
087            String message = "Error processing navigation template:" +
088                    template + " using module: " + module;
089            log.error(message, e);
090            try
091            {
092                data.getResponse().getWriter().print("Error processing navigation template: "
093                        + template + " using module: " + module);
094            }
095            catch (java.io.IOException ioe)
096            {
097                // ignore
098            }
099        }
100    }
101}