blob: 7e79c8a18151eba98d5009c72e946e888ffd8609 [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="de"><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>UITool.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.services.pull.tools</a> &gt; <span class="el_source">UITool.java</span></div><h1>UITool.java</h1><pre class="source lang-java linenums">package org.apache.turbine.services.pull.tools;
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.TurbineService;
import org.apache.turbine.om.security.User;
import org.apache.turbine.pipeline.PipelineData;
import org.apache.turbine.services.pull.ApplicationTool;
import org.apache.turbine.services.ui.UIService;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.ServerData;
/**
* Manages all UI elements for a Turbine Application. Any UI element can be
* accessed in any template using the $ui handle (assuming you use the default
* PullService configuration). So, for example, you could access the background
* color for your pages by using $ui.bgcolor
* &lt;p&gt;
* This implementation provides a single level of inheritance in that if a
* property does not exist in a non-default skin, the value from the default
* skin will be used. By only requiring values different to those stored in
* the default skin to appear in the non-default skins the amount of memory
* consumed in cases where the UserManager instance is used at a non-global
* scope will potentially be reduced due to the fact that a shared instance of
* the default skin properties can be used. Note that this inheritance only
* applies to property values - it does not apply to any images or stylesheets
* that may form part of your skins.
* &lt;p&gt;
* This is an application pull tool for the template system. You should not
* use it in a normal application! Within Java code you should use TurbineUI.
* &lt;p&gt;
*
* This is an application pull tool for the template system. You should
* &lt;strong&gt;only&lt;/strong&gt; use it in a normal application to set the skin
* attribute for a user (setSkin(User user, String skin)) and to initialize it
* for the user, otherwise use TurbineUI is probably the way to go.
*
* @author &lt;a href=&quot;mailto:jvanzyl@periapt.com&quot;&gt;Jason van Zyl&lt;/a&gt;
* @author &lt;a href=&quot;mailto:james_coltman@majorband.co.uk&quot;&gt;James Coltman&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:seade@backstagetech.com.au&quot;&gt;Scott Eade&lt;/a&gt;
* @version $Id$
* @see UIService
*/
<span class="fc" id="L65">public class UITool implements ApplicationTool</span>
{
/** Logging */
<span class="fc" id="L68"> private static final Logger log = LogManager.getLogger(UITool.class);</span>
/**
* Attribute name of skinName value in User's temp hashmap.
*/
<span class="fc" id="L73"> public static final String SKIN_ATTRIBUTE = UITool.class.getName()+ &quot;.skin&quot;;</span>
/**
* The actual skin being used for the webapp.
*/
private String skinName;
/**
* The UI service.
*/
@TurbineService
private UIService uiService;
/**
* Refresh the tool.
*/
@Override
public void refresh()
{
<span class="fc" id="L92"> uiService.refresh(getSkin());</span>
<span class="fc" id="L93"> log.debug(&quot;UITool refreshed for skin: {}&quot;, this::getSkin);</span>
<span class="fc" id="L94"> }</span>
/**
* Provide access to the list of available skin names.
*
* @return the available skin names.
*/
public String[] getSkinNames()
{
<span class="nc" id="L103"> return uiService.getSkinNames();</span>
}
/**
* Get the name of the default skin name for the web application from the
* TurbineResources.properties file. If the property is not present the
* name of the default skin will be returned. Note that the web application
* skin name may be something other than default, in which case its
* properties will default to the skin with the name &quot;default&quot;.
*
* @return the name of the default skin for the web application.
*/
public String getWebappSkinName()
{
<span class="nc" id="L117"> return uiService.getWebappSkinName();</span>
}
/**
* Retrieve a skin property. If the property is not defined in the current
* skin the value for the default skin will be provided. If the current
* skin does not exist then the skin configured for the webapp will be used.
* If the webapp skin does not exist the default skin will be used. If the
* default skin does not exist then &lt;code&gt;null&lt;/code&gt; will be returned.
*
* @param key the key to retrieve from the skin.
* @return the value of the property for the named skin (defaulting to the
* default skin), the webapp skin, the default skin or &lt;code&gt;null&lt;/code&gt;,
* depending on whether or not the property or skins exist.
*/
public String get(String key)
{
<span class="nc" id="L134"> return uiService.get(getSkin(), key);</span>
}
/**
* Retrieve the skin name.
* @return the selected skin name
*/
public String getSkin()
{
<span class="fc" id="L143"> return skinName;</span>
}
/**
* Set the skin name to the skin from the TurbineResources.properties file.
* If the property is not present use the &quot;default&quot; skin.
*/
public void setSkin()
{
<span class="fc" id="L152"> skinName = uiService.getWebappSkinName();</span>
<span class="fc" id="L153"> }</span>
/**
* Set the skin name to the specified skin.
*
* @param skinName the skin name to use.
*/
public void setSkin(String skinName)
{
<span class="nc" id="L162"> this.skinName = skinName;</span>
<span class="nc" id="L163"> }</span>
/**
* Set the skin name when the tool is configured to be loaded on a
* per-request basis. By default it calls getSkin to return the skin
* specified in TurbineResources.properties. Developers can write a subclass
* of UITool that overrides this method to determine the skin to use based
* on information held in the request.
*
* @param data a RunData instance
*/
protected void setSkin(RunData data)
{
<span class="nc" id="L176"> setSkin();</span>
<span class="nc" id="L177"> }</span>
/**
* Set the skin name when the tool is configured to be loaded on a
* per-session basis. If the user's temp hashmap contains a value in the
* attribute specified by the String constant SKIN_ATTRIBUTE then that is
* returned. Otherwise it calls getSkin to return the skin specified in
* TurbineResources.properties.
*
* @param user a User instance
*/
protected void setSkin(User user)
{
<span class="nc bnc" id="L190" title="All 2 branches missed."> if (user.getTemp(SKIN_ATTRIBUTE) == null)</span>
{
<span class="nc" id="L192"> setSkin();</span>
}
else
{
<span class="nc" id="L196"> setSkin((String) user.getTemp(SKIN_ATTRIBUTE));</span>
}
<span class="nc" id="L198"> }</span>
/**
* Set the skin name in the user's temp hashmap for the current session.
*
* @param user a User instance
* @param skin the skin name for the session
*/
public static void setSkin(User user, String skin)
{
<span class="nc" id="L208"> user.setTemp(SKIN_ATTRIBUTE, skin);</span>
<span class="nc" id="L209"> }</span>
/**
* Retrieve the URL for an image that is part of the skin. The images are
* stored in the WEBAPP/resources/ui/skins/[SKIN]/images directory.
*
* &lt;p&gt;Use this if for some reason your server name, server scheme, or server
* port change on a per request basis. I'm not sure if this would happen in
* a load balanced situation. I think in most cases the image(String image)
* method would probably be enough, but I'm not absolutely positive.
*
* @param imageId the id of the image whose URL will be generated.
* @param data the RunData to use as the source of the ServerData to use as
* the basis for the URL.
* @return the image URL
*/
public String image(String imageId, RunData data)
{
<span class="nc" id="L227"> return image(imageId, data.getServerData());</span>
}
/**
* Retrieve the URL for an image that is part of the skin. The images are
* stored in the WEBAPP/resources/ui/skins/[SKIN]/images directory.
*
* &lt;p&gt;Use this if for some reason your server name, server scheme, or server
* port change on a per request basis. I'm not sure if this would happen in
* a load balanced situation. I think in most cases the image(String image)
* method would probably be enough, but I'm not absolutely positive.
*
* @param imageId the id of the image whose URL will be generated.
* @param serverData the serverData to use as the basis for the URL.
* @return the image URL
*/
public String image(String imageId, ServerData serverData)
{
<span class="nc" id="L245"> return uiService.image(getSkin(), imageId, serverData);</span>
}
/**
* Retrieve the URL for an image that is part of the skin. The images are
* stored in the WEBAPP/resources/ui/skins/[SKIN]/images directory.
*
* @param imageId the id of the image whose URL will be generated.
* @return the image URL
*/
public String image(String imageId)
{
<span class="nc" id="L257"> return uiService.image(getSkin(), imageId);</span>
}
/**
* Retrieve the URL for the style sheet that is part of the skin. The style
* is stored in the WEBAPP/resources/ui/skins/[SKIN] directory with the
* filename skin.css
*
* &lt;p&gt;Use this if for some reason your server name, server scheme, or server
* port change on a per request basis. I'm not sure if this would happen in
* a load balanced situation. I think in most cases the style() method would
* probably be enough, but I'm not absolutely positive.
*
* @param data the RunData to use as the source of the ServerData to use as
* the basis for the URL.
* @return the CSS URL
*/
public String getStylecss(RunData data)
{
<span class="nc" id="L276"> return getStylecss(data.getServerData());</span>
}
/**
* Retrieve the URL for the style sheet that is part of the skin. The style
* is stored in the WEBAPP/resources/ui/skins/[SKIN] directory with the
* filename skin.css
*
* &lt;p&gt;Use this if for some reason your server name, server scheme, or server
* port change on a per request basis. I'm not sure if this would happen in
* a load balanced situation. I think in most cases the style() method would
* probably be enough, but I'm not absolutely positive.
*
* @param serverData the serverData to use as the basis for the URL.
* @return the CSS URL
*/
public String getStylecss(ServerData serverData)
{
<span class="nc" id="L294"> return uiService.getStylecss(getSkin(), serverData);</span>
}
/**
* Retrieve the URL for the style sheet that is part of the skin. The style
* is stored in the WEBAPP/resources/ui/skins/[SKIN] directory with the
* filename skin.css
* @return the CSS URL
*/
public String getStylecss()
{
<span class="nc" id="L305"> return uiService.getStylecss(getSkin());</span>
}
/**
* Retrieve the URL for a given script that is part of the skin. The script
* is stored in the WEBAPP/resources/ui/skins/[SKIN] directory.
*
* &lt;p&gt;Use this if for some reason your server name, server scheme, or server
* port change on a per request basis. I'm not sure if this would happen in
* a load balanced situation. I think in most cases the image(String image)
* method would probably be enough, but I'm not absolutely positive.
*
* @param filename the name of the script file whose URL will be generated.
* @param data the RunDate to use as the source of the ServerData to use as
* the basis for the URL.
* @return the script URL
*/
public String getScript(String filename, RunData data)
{
<span class="nc" id="L324"> return getScript(filename, data.getServerData());</span>
}
/**
* Retrieve the URL for a given script that is part of the skin. The script
* is stored in the WEBAPP/resources/ui/skins/[SKIN] directory.
*
* &lt;p&gt;Use this if for some reason your server name, server scheme, or server
* port change on a per request basis. I'm not sure if this would happen in
* a load balanced situation. I think in most cases the image(String image)
* method would probably be enough, but I'm not absolutely positive.
*
* @param filename the name of the script file whose URL will be generated.
* @param serverData the serverData to use as the basis for the URL.
* @return the script URL
*/
public String getScript(String filename, ServerData serverData)
{
<span class="nc" id="L342"> return uiService.getScript(getSkin(), filename, serverData);</span>
}
/**
* Retrieve the URL for a given script that is part of the skin. The script
* is stored in the WEBAPP/resources/ui/skins/[SKIN] directory.
*
* @param filename the name of the script file whose URL will be generated.
* @return the script URL
*/
public String getScript(String filename)
{
<span class="nc" id="L354"> return uiService.getScript(getSkin(), filename);</span>
}
/**
* Initialize the UITool object.
*
* @param data This is null, RunData or User depending upon specified tool
* scope.
*/
@Override
public void init(Object data)
{
<span class="pc bpc" id="L366" title="1 of 2 branches missed."> if (data == null)</span>
{
<span class="fc" id="L368"> log.debug(&quot;UITool scope is global&quot;);</span>
<span class="fc" id="L369"> setSkin();</span>
}
<span class="nc bnc" id="L371" title="All 2 branches missed."> else if (data instanceof RunData)</span>
{
<span class="nc" id="L373"> log.debug(&quot;UITool scope is request&quot;);</span>
<span class="nc" id="L374"> setSkin((RunData) data);</span>
}
<span class="nc bnc" id="L376" title="All 2 branches missed."> else if (data instanceof PipelineData)</span>
{
<span class="nc" id="L378"> PipelineData pipelineData = (PipelineData) data;</span>
<span class="nc" id="L379"> RunData runData = (RunData)pipelineData;</span>
<span class="nc" id="L380"> log.debug(&quot;UITool scope is request&quot;);</span>
<span class="nc" id="L381"> setSkin(runData);</span>
<span class="nc" id="L382"> }</span>
<span class="nc bnc" id="L383" title="All 2 branches missed."> else if (data instanceof User)</span>
{
<span class="nc" id="L385"> log.debug(&quot;UITool scope is session&quot;);</span>
<span class="nc" id="L386"> setSkin((User) data);</span>
}
<span class="fc" id="L388"> }</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>