001 package 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
022 import org.apache.turbine.services.TurbineServices;
023 import org.apache.turbine.util.ServerData;
024
025 /**
026 * This is a convenience class provided to allow access to the UIService
027 * through static methods. The UIService should ALWAYS be accessed via
028 * either this class or UITool.
029 *
030 * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
031 * @version $Id$
032 * @see UIService
033 * @see UITool
034 */
035 public class TurbineUI
036 {
037 /**
038 * Refresh all skins.
039 */
040 public static void refresh()
041 {
042 ((UIService) TurbineServices.getInstance()
043 .getService(UIService.SERVICE_NAME)).refresh();
044 }
045
046 /**
047 * Refresh a particular skin.
048 *
049 * @param skinName the name of the skin to clear.
050 */
051 public static void refresh(String skinName)
052 {
053 ((UIService) TurbineServices.getInstance()
054 .getService(UIService.SERVICE_NAME)).refresh(skinName);
055 }
056
057 /**
058 * Provide access to the list of available skin names.
059 *
060 * @return the available skin names.
061 */
062 public static String[] getSkinNames()
063 {
064 return ((UIService) TurbineServices.getInstance()
065 .getService(UIService.SERVICE_NAME)).getSkinNames();
066 }
067
068 /**
069 * Get the name of the default skin name for the web application from the
070 * TurbineResources.properties file. If the property is not present the
071 * name of the default skin will be returned. Note that the web application
072 * skin name may be something other than default, in which case its
073 * properties will default to the skin with the name "default".
074 *
075 * @return the name of the default skin for the web application.
076 */
077 public static String getWebappSkinName()
078 {
079 return ((UIService) TurbineServices.getInstance()
080 .getService(UIService.SERVICE_NAME)).getWebappSkinName();
081 }
082
083 /**
084 * Retrieve a skin property from the named skin. If the property is not
085 * defined in the named skin the value for the default skin will be
086 * provided. If the named skin does not exist then the skin configured for
087 * the webapp will be used. If the webapp skin does not exist the default
088 * skin will be used. If the default skin does not exist then
089 * <code>null</code> will be returned.
090 *
091 * @param skinName the name of the skin to retrieve the property from.
092 * @param key the key to retrieve from the skin.
093 * @return the value of the property for the named skin (defaulting to the
094 * default skin), the webapp skin, the default skin or <code>null</code>,
095 * depending on whether or not the property or skins exist.
096 */
097 public static String get(String skinName, String key)
098 {
099 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 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 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 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 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 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 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 return ((UIService) TurbineServices.getInstance()
222 .getService(UIService.SERVICE_NAME)).getScript(skinName, filename);
223 }
224
225 }