001package org.apache.turbine.services.ui; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.turbine.services.TurbineServices; 023import org.apache.turbine.services.pull.tools.UITool; 024import org.apache.turbine.util.ServerData; 025 026/** 027 * This is a convenience class provided to allow access to the UIService 028 * through static methods. The {@link UIService} should ALWAYS be accessed via 029 * either this class or {@link UITool}. 030 * 031 * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a> 032 */ 033public class TurbineUI 034{ 035 /** 036 * Refresh all skins. 037 */ 038 public static void refresh() 039 { 040 getService().refresh(); 041 } 042 043 /** 044 * Get the service instance 045 * @return the {@link UIService} instance 046 */ 047 protected static UIService getService() 048 { 049 return (UIService) TurbineServices.getInstance() 050 .getService(UIService.SERVICE_NAME); 051 } 052 053 /** 054 * Refresh a particular skin. 055 * 056 * @param skinName the name of the skin to clear. 057 */ 058 public static void refresh(String skinName) 059 { 060 getService().refresh(skinName); 061 } 062 063 /** 064 * Provide access to the list of available skin names. 065 * 066 * @return the available skin names. 067 */ 068 public static String[] getSkinNames() 069 { 070 return getService().getSkinNames(); 071 } 072 073 /** 074 * Get the name of the default skin name for the web application from the 075 * TurbineResources.properties file. If the property is not present the 076 * name of the default skin will be returned. Note that the web application 077 * skin name may be something other than default, in which case its 078 * properties will default to the skin with the name "default". 079 * 080 * @return the name of the default skin for the web application. 081 */ 082 public static String getWebappSkinName() 083 { 084 return getService().getWebappSkinName(); 085 } 086 087 /** 088 * Retrieve a skin property from the named skin. If the property is not 089 * defined in the named skin the value for the default skin will be 090 * provided. If the named skin does not exist then the skin configured for 091 * the webapp will be used. If the webapp skin does not exist the default 092 * skin will be used. If the default skin does not exist then 093 * <code>null</code> will be returned. 094 * 095 * @param skinName the name of the skin to retrieve the property from. 096 * @param key the key to retrieve from the skin. 097 * @return the value of the property for the named skin (defaulting to the 098 * default skin), the webapp skin, the default skin or <code>null</code>, 099 * depending on whether or not the property or skins exist. 100 */ 101 public static String get(String skinName, String key) 102 { 103 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 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 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 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 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 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 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 return getService().getScript(skinName, filename); 222 } 223}