Coverage Report - org.apache.turbine.services.ui.TurbineUI
 
Classes in this File Line Coverage Branch Coverage Complexity
TurbineUI
46%
7/15
N/A
1
 
 1  
 package org.apache.turbine.services.ui;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.apache.turbine.services.TurbineServices;
 23  
 import org.apache.turbine.util.ServerData;
 24  
 
 25  
 /** 
 26  
  * This is a convenience class provided to allow access to the UIService
 27  
  * through static methods.  The UIService should ALWAYS be accessed via
 28  
  * either this class or UITool.
 29  
  *
 30  
  * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
 31  
  * @version $Id$
 32  
  * @see UIService
 33  
  * @see UITool
 34  
  */
 35  0
 public class TurbineUI
 36  
 {
 37  
     /**
 38  
      * Refresh all skins.
 39  
      */
 40  
     public static void refresh()
 41  
     {
 42  0
         ((UIService) TurbineServices.getInstance()
 43  
                 .getService(UIService.SERVICE_NAME)).refresh();
 44  0
     }
 45  
 
 46  
     /**
 47  
      * Refresh a particular skin.
 48  
      * 
 49  
      * @param skinName the name of the skin to clear.
 50  
      */
 51  
     public static void refresh(String skinName)
 52  
     {
 53  28
         ((UIService) TurbineServices.getInstance()
 54  
                 .getService(UIService.SERVICE_NAME)).refresh(skinName);
 55  28
     }
 56  
 
 57  
     /**
 58  
      * Provide access to the list of available skin names.
 59  
      * 
 60  
      * @return the available skin names.
 61  
      */
 62  
     public static String[] getSkinNames()
 63  
     {
 64  2
         return ((UIService) TurbineServices.getInstance()
 65  
                 .getService(UIService.SERVICE_NAME)).getSkinNames();
 66  
     }
 67  
 
 68  
     /**
 69  
      * Get the name of the default skin name for the web application from the 
 70  
      * TurbineResources.properties file. If the property is not present the 
 71  
      * name of the default skin will be returned.  Note that the web application
 72  
      * skin name may be something other than default, in which case its 
 73  
      * properties will default to the skin with the name "default".
 74  
      * 
 75  
      * @return the name of the default skin for the web application.
 76  
      */
 77  
     public static String getWebappSkinName()
 78  
     {
 79  46
         return ((UIService) TurbineServices.getInstance()
 80  
                 .getService(UIService.SERVICE_NAME)).getWebappSkinName();
 81  
     }
 82  
 
 83  
     /**
 84  
      * Retrieve a skin property from the named skin.  If the property is not 
 85  
      * defined in the named skin the value for the default skin will be 
 86  
      * provided.  If the named skin does not exist then the skin configured for 
 87  
      * the webapp will be used.  If the webapp skin does not exist the default
 88  
      * skin will be used.  If the default skin does not exist then 
 89  
      * <code>null</code> will be returned.
 90  
      * 
 91  
      * @param skinName the name of the skin to retrieve the property from.
 92  
      * @param key the key to retrieve from the skin.
 93  
      * @return the value of the property for the named skin (defaulting to the 
 94  
      * default skin), the webapp skin, the default skin or <code>null</code>,
 95  
      * depending on whether or not the property or skins exist.
 96  
      */
 97  
     public static String get(String skinName, String key)
 98  
     {
 99  4
         return ((UIService) TurbineServices.getInstance()
 100  
                 .getService(UIService.SERVICE_NAME)).get(skinName, key);
 101  
     }
 102  
 
 103  
     /**
 104  
      * Retrieve a skin property from the default skin for the webapp.  If the 
 105  
      * property is not defined in the webapp skin the value for the default skin 
 106  
      * will be provided.  If the webapp skin does not exist the default skin 
 107  
      * will be used.  If the default skin does not exist then <code>null</code> 
 108  
      * will be returned.
 109  
      * 
 110  
      * @param key the key to retrieve.
 111  
      * @return the value of the property for the webapp skin (defaulting to the 
 112  
      * default skin), the default skin or <code>null</code>, depending on 
 113  
      * whether or not the property or skins exist.
 114  
      */
 115  
     public static String get(String key)
 116  
     {
 117  0
         return ((UIService) TurbineServices.getInstance()
 118  
             .getService(UIService.SERVICE_NAME)).get(key);
 119  
     }
 120  
 
 121  
     /**
 122  
      * Retrieve the URL for an image that is part of a skin. The images are 
 123  
      * stored in the WEBAPP/resources/ui/skins/[SKIN]/images directory.
 124  
      *
 125  
      * <p>Use this if for some reason your server name, server scheme, or server 
 126  
      * port change on a per request basis. I'm not sure if this would happen in 
 127  
      * a load balanced situation. I think in most cases the image(String image)
 128  
      * method would probably be enough, but I'm not absolutely positive.
 129  
      * 
 130  
      * @param skinName the name of the skin to retrieve the image from.
 131  
      * @param imageId the id of the image whose URL will be generated.
 132  
      * @param data the RunData to use as the source of the ServerData to use as 
 133  
      * the basis for the URL.
 134  
      */
 135  
     public static String image(String skinName, String imageId, 
 136  
             ServerData serverData)
 137  
     {
 138  0
         return ((UIService) TurbineServices.getInstance()
 139  
                 .getService(UIService.SERVICE_NAME))
 140  
                         .image(skinName, imageId, serverData);
 141  
     }
 142  
 
 143  
     /**
 144  
      * Retrieve the URL for an image that is part of a skin. The images are 
 145  
      * stored in the WEBAPP/resources/ui/skins/[SKIN]/images directory.
 146  
      * 
 147  
      * @param skinName the name of the skin to retrieve the image from.
 148  
      * @param imageId the id of the image whose URL will be generated.
 149  
      */
 150  
     public static String image(String skinName, String imageId)
 151  
     {
 152  12
         return ((UIService) TurbineServices.getInstance()
 153  
                 .getService(UIService.SERVICE_NAME)).image(skinName, imageId);
 154  
     }
 155  
 
 156  
     /**
 157  
      * Retrieve the URL for the style sheet that is part of a skin. The style is 
 158  
      * stored in the WEBAPP/resources/ui/skins/[SKIN] directory with the 
 159  
      * filename skin.css
 160  
      *
 161  
      * <p>Use this if for some reason your server name, server scheme, or server 
 162  
      * port change on a per request basis. I'm not sure if this would happen in 
 163  
      * a load balanced situation. I think in most cases the style() method would 
 164  
      * probably be enough, but I'm not absolutely positive.
 165  
      * 
 166  
      * @param skinName the name of the skin to retrieve the style sheet from.
 167  
      * @param data the RunData to use as the source of the ServerData to use as 
 168  
      * the basis for the URL.
 169  
      */
 170  
     public static String getStylecss(String skinName, ServerData serverData)
 171  
     {
 172  0
         return ((UIService) TurbineServices.getInstance()
 173  
                 .getService(UIService.SERVICE_NAME))
 174  
                         .getStylecss(skinName, serverData);
 175  
     }
 176  
 
 177  
     /**
 178  
      * Retrieve the URL for the style sheet that is part of a skin. The style is 
 179  
      * stored in the WEBAPP/resources/ui/skins/[SKIN] directory with the 
 180  
      * filename skin.css
 181  
      * 
 182  
      * @param skinName the name of the skin to retrieve the style sheet from.
 183  
      */
 184  
     public static String getStylecss(String skinName)
 185  
     {
 186  2
         return ((UIService) TurbineServices.getInstance()
 187  
                 .getService(UIService.SERVICE_NAME)).getStylecss(skinName);
 188  
     }
 189  
 
 190  
     /**
 191  
      * Retrieve the URL for a given script that is part of the skin. The script
 192  
      * is stored in the WEBAPP/resources/ui/skins/[SKIN] directory.
 193  
      *
 194  
      * <p>Use this if for some reason your server name, server scheme, or server 
 195  
      * port change on a per request basis. I'm not sure if this would happen in 
 196  
      * a load balanced situation. I think in most cases the image(String image)
 197  
      * method would probably be enough, but I'm not absolutely positive.
 198  
      * 
 199  
      * @param skinName the name of the skin to retrieve the image from.
 200  
      * @param filename the name of the script file whose URL will be generated.
 201  
      * @param data the RunData to use as the source of the ServerData to use as 
 202  
      * the basis for the URL.
 203  
      */
 204  
     public static String getScript(String skinName, String filename, 
 205  
             ServerData serverData)
 206  
     {
 207  0
         return ((UIService) TurbineServices.getInstance()
 208  
                 .getService(UIService.SERVICE_NAME))
 209  
                         .getScript(skinName, filename, serverData);
 210  
     }
 211  
 
 212  
     /**
 213  
      * Retrieve the URL for a given script that is part of the skin. The script
 214  
      * is stored in the WEBAPP/resources/ui/skins/[SKIN] directory.
 215  
      *
 216  
      * @param skinName the name of the skin to retrieve the image from.
 217  
      * @param filename the name of the script file whose URL will be generated.
 218  
      */
 219  
     public static String getScript(String skinName, String filename)
 220  
     {
 221  0
         return ((UIService) TurbineServices.getInstance()
 222  
                 .getService(UIService.SERVICE_NAME)).getScript(skinName, filename);
 223  
     }
 224  
 
 225  
 }