blob: d392c0d0cb962d93ee4a7caa7407d0a09bfb6ce4 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang=""><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>TemplateScreen.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Turbine</a> &gt; <a href="index.source.html" class="el_package">org.apache.turbine.modules.screens</a> &gt; <span class="el_source">TemplateScreen.java</span></div><h1>TemplateScreen.java</h1><pre class="source lang-java linenums">package org.apache.turbine.modules.screens;
import org.apache.logging.log4j.LogManager;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* &quot;License&quot;); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.logging.log4j.Logger;
import org.apache.turbine.annotation.TurbineLoader;
import org.apache.turbine.annotation.TurbineService;
import org.apache.turbine.modules.Screen;
import org.apache.turbine.modules.ScreenLoader;
import org.apache.turbine.pipeline.PipelineData;
import org.apache.turbine.services.TurbineServices;
import org.apache.turbine.services.template.TemplateService;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.template.TemplateInfo;
/**
* Template Screen.
*
* Base Template Screens should extend this class and override the
* buildTemplate() method. Users of the particular service can then
* override the doBuildTemplate() for any specific pre-processing.
* You can also override the doBuild() method in order to add extra
* functionality to your system, but you need to make sure to at least
* duplicate the existing functionality in order for things to work.
* Look at the code for the doBuild() method to get an idea of what is
* going on there (it is quite simple really).
*
* @author &lt;a href=&quot;mailto:mbryson@mont.mindspring.com&quot;&gt;Dave Bryson&lt;/a&gt;
* @author &lt;a href=&quot;mailto:hps@intermeta.de&quot;&gt;Henning P. Schmiedehausen&lt;/a&gt;
* @author &lt;a href=&quot;mailto:peter@courcoux.biz&quot;&gt;Peter Courcoux&lt;/a&gt;
* @version $Id$
*/
<span class="nc" id="L52">public abstract class TemplateScreen implements Screen</span>
{
/** Logging */
<span class="nc" id="L55"> protected Logger log = LogManager.getLogger(this.getClass());</span>
/** Injected service instance */
@TurbineService
private TemplateService templateService;
/** Injected loader instance */
@TurbineLoader( Screen.class )
private ScreenLoader screenLoader;
/**
* This method should be overridden by subclasses that wish to add
* specific business logic.
* @param pipelineData Turbine information.
* @throws Exception A generic exception.
*/
protected abstract void doBuildTemplate(PipelineData pipelineData)
throws Exception;
/**
* This method should be implemented by Base template classes. It
* should contain the specific template service code to generate
* the template.
* @param pipelineData Turbine information.
* @return the content of the screen
* @throws Exception A generic exception.
*/
public abstract String buildTemplate(PipelineData pipelineData)
throws Exception;
/**
* This method can be overridden to write code that executes when
* the template has been built (called from a finally clause, so
* executes regardless of whether an exception is thrown or not)
*
* @param pipelineData Turbine information
*/
protected void doPostBuildTemplate(PipelineData pipelineData)
{
// empty
<span class="nc" id="L95"> }</span>
/**
* This method is called by the Screenloader to construct the
* Screen.
*
* @param pipelineData Turbine information.
* @return the content of the screen
* @throws Exception A generic exception.
*/
@Override
public String doBuild(PipelineData pipelineData)
throws Exception
{
<span class="nc" id="L109"> String out = null;</span>
try
{
<span class="nc" id="L113"> doBuildTemplate(pipelineData);</span>
<span class="nc" id="L114"> out = buildTemplate(pipelineData);</span>
}
finally
{
<span class="nc" id="L118"> doPostBuildTemplate(pipelineData);</span>
}
<span class="nc" id="L121"> return out;</span>
}
/**
* This method is used when you want to short circuit a Screen and
* change the template that will be executed next. &lt;b&gt;Note that the current
* context will be applied to the next template that is executed.
* If you want to have the context executed for the next screen,
* to be the same one as the next screen, then you should use the
* TemplateScreen.doRedirect() method.&lt;/b&gt;
*
* @param pipelineData Turbine information.
* @param template The name of the next template.
*/
public static void setTemplate(PipelineData pipelineData, String template)
{
<span class="nc" id="L137"> RunData data = (RunData)pipelineData;</span>
<span class="nc" id="L138"> TemplateInfo ti = data.getTemplateInfo();</span>
<span class="nc" id="L139"> TemplateService templateService = (TemplateService)TurbineServices.getInstance().getService(TemplateService.SERVICE_NAME);</span>
<span class="nc" id="L141"> ti.setScreenTemplate(template);</span>
try
{
// We have do call getScreenTemplate because of the path
// separator.
<span class="nc" id="L146"> ti.setLayoutTemplate(templateService.getLayoutTemplateName(ti.getScreenTemplate()));</span>
}
<span class="nc" id="L148"> catch (Exception e)</span>
{
// Nothing to do.
<span class="nc" id="L151"> }</span>
<span class="nc" id="L152"> }</span>
/**
* You can call this within a Screen to cause an internal redirect
* to happen. It essentially allows you to stop execution in one
* Screen and instantly execute another Screen. Don't worry, this
* does not do a HTTP redirect and also if you have anything added
* in the Context, it will get carried over.
*
* &lt;p&gt;
*
* This class is useful if you have a Screen that submits to
* another Screen and you want it to do error validation before
* executing the other Screen. If there is an error, you can
* doRedirect() back to the original Screen.
*
* @param pipelineData Turbine information.
* @param screen Name of screen to redirect to.
* @param template Name of template.
* @throws Exception A generic exception.
*/
public void doRedirect(PipelineData pipelineData, String screen, String template)
throws Exception
{
<span class="nc" id="L176"> log.debug(&quot;doRedirect(data, {}, {})&quot;, screen, template);</span>
<span class="nc" id="L177"> setTemplate(pipelineData, template);</span>
<span class="nc" id="L178"> screenLoader.exec(pipelineData, screen);</span>
<span class="nc" id="L179"> }</span>
/**
* You can call this within a Screen to cause an internal redirect
* to happen. It essentially allows you to stop execution in one
* Screen and instantly execute another Screen. Don't worry, this
* does not do a HTTP redirect and also if you have anything added
* in the Context, it will get carried over.
*
* &lt;p&gt;
*
* This class is useful if you have a Screen that submits to
* another Screen and you want it to do error validation before
* executing the other Screen. If there is an error, you can
* doRedirect() back to the original Screen.
*
* @param pipelineData Turbine information.
* @param template Name of template.
* @throws Exception A generic exception.
*/
public void doRedirect(PipelineData pipelineData, String template)
throws Exception
{
<span class="nc" id="L202"> doRedirect(pipelineData, templateService.getScreenName(template), template);</span>
<span class="nc" id="L203"> }</span>
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.12.202403310830</span></div></body></html>