| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| TurbineUI |
|
| 1.0;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.services.pull.tools.UITool; | |
| 24 | import org.apache.turbine.util.ServerData; | |
| 25 | ||
| 26 | /** | |
| 27 | * This is a convenience class provided to allow access to the UIService | |
| 28 | * through static methods. The {@link UIService} should ALWAYS be accessed via | |
| 29 | * either this class or {@link UITool}. | |
| 30 | * | |
| 31 | * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a> | |
| 32 | */ | |
| 33 | 0 | public class TurbineUI |
| 34 | { | |
| 35 | /** | |
| 36 | * Refresh all skins. | |
| 37 | */ | |
| 38 | public static void refresh() | |
| 39 | { | |
| 40 | 0 | getService().refresh(); |
| 41 | 0 | } |
| 42 | ||
| 43 | /** | |
| 44 | * Get the service instance | |
| 45 | * @return the {@link UIService} instance | |
| 46 | */ | |
| 47 | protected static UIService getService() | |
| 48 | { | |
| 49 | 27 | return (UIService) TurbineServices.getInstance() |
| 50 | .getService(UIService.SERVICE_NAME); | |
| 51 | } | |
| 52 | ||
| 53 | /** | |
| 54 | * Refresh a particular skin. | |
| 55 | * | |
| 56 | * @param skinName the name of the skin to clear. | |
| 57 | */ | |
| 58 | public static void refresh(String skinName) | |
| 59 | { | |
| 60 | 10 | getService().refresh(skinName); |
| 61 | 10 | } |
| 62 | ||
| 63 | /** | |
| 64 | * Provide access to the list of available skin names. | |
| 65 | * | |
| 66 | * @return the available skin names. | |
| 67 | */ | |
| 68 | public static String[] getSkinNames() | |
| 69 | { | |
| 70 | 0 | return getService().getSkinNames(); |
| 71 | } | |
| 72 | ||
| 73 | /** | |
| 74 | * Get the name of the default skin name for the web application from the | |
| 75 | * TurbineResources.properties file. If the property is not present the | |
| 76 | * name of the default skin will be returned. Note that the web application | |
| 77 | * skin name may be something other than default, in which case its | |
| 78 | * properties will default to the skin with the name "default". | |
| 79 | * | |
| 80 | * @return the name of the default skin for the web application. | |
| 81 | */ | |
| 82 | public static String getWebappSkinName() | |
| 83 | { | |
| 84 | 17 | return getService().getWebappSkinName(); |
| 85 | } | |
| 86 | ||
| 87 | /** | |
| 88 | * Retrieve a skin property from the named skin. If the property is not | |
| 89 | * defined in the named skin the value for the default skin will be | |
| 90 | * provided. If the named skin does not exist then the skin configured for | |
| 91 | * the webapp will be used. If the webapp skin does not exist the default | |
| 92 | * skin will be used. If the default skin does not exist then | |
| 93 | * <code>null</code> will be returned. | |
| 94 | * | |
| 95 | * @param skinName the name of the skin to retrieve the property from. | |
| 96 | * @param key the key to retrieve from the skin. | |
| 97 | * @return the value of the property for the named skin (defaulting to the | |
| 98 | * default skin), the webapp skin, the default skin or <code>null</code>, | |
| 99 | * depending on whether or not the property or skins exist. | |
| 100 | */ | |
| 101 | public static String get(String skinName, String key) | |
| 102 | { | |
| 103 | 0 | return getService().get(skinName, key); |
| 104 | } | |
| 105 | ||
| 106 | /** | |
| 107 | * Retrieve a skin property from the default skin for the webapp. If the | |
| 108 | * property is not defined in the webapp skin the value for the default skin | |
| 109 | * will be provided. If the webapp skin does not exist the default skin | |
| 110 | * will be used. If the default skin does not exist then <code>null</code> | |
| 111 | * will be returned. | |
| 112 | * | |
| 113 | * @param key the key to retrieve. | |
| 114 | * @return the value of the property for the webapp skin (defaulting to the | |
| 115 | * default skin), the default skin or <code>null</code>, depending on | |
| 116 | * whether or not the property or skins exist. | |
| 117 | */ | |
| 118 | public static String get(String key) | |
| 119 | { | |
| 120 | 0 | return getService().get(key); |
| 121 | } | |
| 122 | ||
| 123 | /** | |
| 124 | * Retrieve the URL for an image that is part of a skin. The images are | |
| 125 | * stored in the WEBAPP/resources/ui/skins/[SKIN]/images directory. | |
| 126 | * | |
| 127 | * <p>Use this if for some reason your server name, server scheme, or server | |
| 128 | * port change on a per request basis. I'm not sure if this would happen in | |
| 129 | * a load balanced situation. I think in most cases the image(String image) | |
| 130 | * method would probably be enough, but I'm not absolutely positive. | |
| 131 | * | |
| 132 | * @param skinName the name of the skin to retrieve the image from. | |
| 133 | * @param imageId the id of the image whose URL will be generated. | |
| 134 | * @param serverData the ServerData to use as | |
| 135 | * the basis for the URL. | |
| 136 | * @return the image URL | |
| 137 | */ | |
| 138 | public static String image(String skinName, String imageId, | |
| 139 | ServerData serverData) | |
| 140 | { | |
| 141 | 0 | return getService().image(skinName, imageId, serverData); |
| 142 | } | |
| 143 | ||
| 144 | /** | |
| 145 | * Retrieve the URL for an image that is part of a skin. The images are | |
| 146 | * stored in the WEBAPP/resources/ui/skins/[SKIN]/images directory. | |
| 147 | * | |
| 148 | * @param skinName the name of the skin to retrieve the image from. | |
| 149 | * @param imageId the id of the image whose URL will be generated. | |
| 150 | * @return the image URL | |
| 151 | */ | |
| 152 | public static String image(String skinName, String imageId) | |
| 153 | { | |
| 154 | 0 | return getService().image(skinName, imageId); |
| 155 | } | |
| 156 | ||
| 157 | /** | |
| 158 | * Retrieve the URL for the style sheet that is part of a skin. The style is | |
| 159 | * stored in the WEBAPP/resources/ui/skins/[SKIN] directory with the | |
| 160 | * filename skin.css | |
| 161 | * | |
| 162 | * <p>Use this if for some reason your server name, server scheme, or server | |
| 163 | * port change on a per request basis. I'm not sure if this would happen in | |
| 164 | * a load balanced situation. I think in most cases the style() method would | |
| 165 | * probably be enough, but I'm not absolutely positive. | |
| 166 | * | |
| 167 | * @param skinName the name of the skin to retrieve the style sheet from. | |
| 168 | * @param serverData the ServerData to use as | |
| 169 | * the basis for the URL. | |
| 170 | * @return the CSS URL | |
| 171 | */ | |
| 172 | public static String getStylecss(String skinName, ServerData serverData) | |
| 173 | { | |
| 174 | 0 | return getService().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 | * @return the CSS URL | |
| 184 | */ | |
| 185 | public static String getStylecss(String skinName) | |
| 186 | { | |
| 187 | 0 | return getService().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 serverData the ServerData to use as | |
| 202 | * the basis for the URL. | |
| 203 | * @return the script URL | |
| 204 | */ | |
| 205 | public static String getScript(String skinName, String filename, | |
| 206 | ServerData serverData) | |
| 207 | { | |
| 208 | 0 | return getService().getScript(skinName, filename, serverData); |
| 209 | } | |
| 210 | ||
| 211 | /** | |
| 212 | * Retrieve the URL for a given script that is part of the skin. The script | |
| 213 | * is stored in the WEBAPP/resources/ui/skins/[SKIN] directory. | |
| 214 | * | |
| 215 | * @param skinName the name of the skin to retrieve the image from. | |
| 216 | * @param filename the name of the script file whose URL will be generated. | |
| 217 | * @return the script URL | |
| 218 | */ | |
| 219 | public static String getScript(String skinName, String filename) | |
| 220 | { | |
| 221 | 0 | return getService().getScript(skinName, filename); |
| 222 | } | |
| 223 | } |