001package org.apache.turbine.services.jsp;
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.turbine.pipeline.PipelineData;
025import org.apache.turbine.services.TurbineServices;
026import org.apache.turbine.util.TurbineException;
027
028/**
029 * Facade class for the Jsp Service.
030 *
031 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
032 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
033 */
034public abstract class TurbineJsp
035{
036    /**
037     * Utility method for accessing the service
038     * implementation
039     *
040     * @return a JspService implementation instance
041     */
042    protected static JspService getService()
043    {
044        return (JspService) TurbineServices
045            .getInstance().getService(JspService.SERVICE_NAME);
046    }
047
048    /**
049     * Adds some convenience objects to the request.  For example an instance
050     * of JspLink which can be used to generate links to other templates.
051     *
052     * @param pipelineData the Turbine PipelineData object
053     */
054    public static void addDefaultObjects(PipelineData pipelineData)
055    {
056        getService().addDefaultObjects(pipelineData);
057    }
058
059    /**
060     * executes the JSP given by templateName.
061     *
062     * @param pipelineData A PipelineData Object
063     * @param templateName The template to execute
064     * @param isForward whether to perform a forward or include.
065     *
066     * @throws TurbineException If a problem occurred while executing the JSP
067     */
068    public static void handleRequest(PipelineData pipelineData, String templateName, boolean isForward)
069        throws TurbineException
070    {
071        getService().handleRequest(pipelineData, templateName, isForward);
072    }
073
074    /**
075     * executes the JSP given by templateName.
076     *
077     * @param pipelineData A PipelineData Object
078     * @param templateName The template to execute
079     *
080     * @throws TurbineException If a problem occurred while executing the JSP
081     */
082    public static void handleRequest(PipelineData pipelineData, String templateName)
083        throws TurbineException
084    {
085        getService().handleRequest(pipelineData, templateName);
086    }
087
088    /**
089     * Returns the default buffer size of the JspService
090     *
091     * @return The default buffer size.
092     */
093    public static int getDefaultBufferSize()
094    {
095        return getService().getDefaultBufferSize();
096    }
097
098    /**
099     * Searches for a template in the default.template path[s] and
100     * returns the template name with a relative path which is required
101     * by <a href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContext.html#getRequestDispatcher(java.lang.String)">javax.servlet.RequestDispatcher</a>
102     *
103     * @param template The name of the template to search for.
104     *
105     * @return the template with a relative path
106     */
107    public static String getRelativeTemplateName(String template)
108    {
109        return getService().getRelativeTemplateName(template);
110    }
111}