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: * Refresh all skins.
038: */
039: public static void refresh() {
040: ((UIService) TurbineServices.getInstance().getService(
041: UIService.SERVICE_NAME)).refresh();
042: }
043:
044: /**
045: * Refresh a particular skin.
046: *
047: * @param skinName the name of the skin to clear.
048: */
049: public static void refresh(String skinName) {
050: ((UIService) TurbineServices.getInstance().getService(
051: UIService.SERVICE_NAME)).refresh(skinName);
052: }
053:
054: /**
055: * Provide access to the list of available skin names.
056: *
057: * @return the available skin names.
058: */
059: public static String[] getSkinNames() {
060: return ((UIService) TurbineServices.getInstance().getService(
061: UIService.SERVICE_NAME)).getSkinNames();
062: }
063:
064: /**
065: * Get the name of the default skin name for the web application from the
066: * TurbineResources.properties file. If the property is not present the
067: * name of the default skin will be returned. Note that the web application
068: * skin name may be something other than default, in which case its
069: * properties will default to the skin with the name "default".
070: *
071: * @return the name of the default skin for the web application.
072: */
073: public static String getWebappSkinName() {
074: return ((UIService) TurbineServices.getInstance().getService(
075: UIService.SERVICE_NAME)).getWebappSkinName();
076: }
077:
078: /**
079: * Retrieve a skin property from the named skin. If the property is not
080: * defined in the named skin the value for the default skin will be
081: * provided. If the named skin does not exist then the skin configured for
082: * the webapp will be used. If the webapp skin does not exist the default
083: * skin will be used. If the default skin does not exist then
084: * <code>null</code> will be returned.
085: *
086: * @param skinName the name of the skin to retrieve the property from.
087: * @param key the key to retrieve from the skin.
088: * @return the value of the property for the named skin (defaulting to the
089: * default skin), the webapp skin, the default skin or <code>null</code>,
090: * depending on whether or not the property or skins exist.
091: */
092: public static String get(String skinName, String key) {
093: return ((UIService) TurbineServices.getInstance().getService(
094: UIService.SERVICE_NAME)).get(skinName, key);
095: }
096:
097: /**
098: * Retrieve a skin property from the default skin for the webapp. If the
099: * property is not defined in the webapp skin the value for the default skin
100: * will be provided. If the webapp skin does not exist the default skin
101: * will be used. If the default skin does not exist then <code>null</code>
102: * will be returned.
103: *
104: * @param key the key to retrieve.
105: * @return the value of the property for the webapp skin (defaulting to the
106: * default skin), the default skin or <code>null</code>, depending on
107: * whether or not the property or skins exist.
108: */
109: public static String get(String key) {
110: return ((UIService) TurbineServices.getInstance().getService(
111: UIService.SERVICE_NAME)).get(key);
112: }
113:
114: /**
115: * Retrieve the URL for an image that is part of a skin. The images are
116: * stored in the WEBAPP/resources/ui/skins/[SKIN]/images directory.
117: *
118: * <p>Use this if for some reason your server name, server scheme, or server
119: * port change on a per request basis. I'm not sure if this would happen in
120: * a load balanced situation. I think in most cases the image(String image)
121: * method would probably be enough, but I'm not absolutely positive.
122: *
123: * @param skinName the name of the skin to retrieve the image from.
124: * @param imageId the id of the image whose URL will be generated.
125: * @param data the RunData to use as the source of the ServerData to use as
126: * the basis for the URL.
127: */
128: public static String image(String skinName, String imageId,
129: ServerData serverData) {
130: return ((UIService) TurbineServices.getInstance().getService(
131: UIService.SERVICE_NAME)).image(skinName, imageId,
132: serverData);
133: }
134:
135: /**
136: * Retrieve the URL for an image that is part of a skin. The images are
137: * stored in the WEBAPP/resources/ui/skins/[SKIN]/images directory.
138: *
139: * @param skinName the name of the skin to retrieve the image from.
140: * @param imageId the id of the image whose URL will be generated.
141: */
142: public static String image(String skinName, String imageId) {
143: return ((UIService) TurbineServices.getInstance().getService(
144: UIService.SERVICE_NAME)).image(skinName, imageId);
145: }
146:
147: /**
148: * Retrieve the URL for the style sheet that is part of a skin. The style is
149: * stored in the WEBAPP/resources/ui/skins/[SKIN] directory with the
150: * filename skin.css
151: *
152: * <p>Use this if for some reason your server name, server scheme, or server
153: * port change on a per request basis. I'm not sure if this would happen in
154: * a load balanced situation. I think in most cases the style() method would
155: * probably be enough, but I'm not absolutely positive.
156: *
157: * @param skinName the name of the skin to retrieve the style sheet from.
158: * @param data the RunData to use as the source of the ServerData to use as
159: * the basis for the URL.
160: */
161: public static String getStylecss(String skinName,
162: ServerData serverData) {
163: return ((UIService) TurbineServices.getInstance().getService(
164: UIService.SERVICE_NAME)).getStylecss(skinName,
165: serverData);
166: }
167:
168: /**
169: * Retrieve the URL for the style sheet that is part of a skin. The style is
170: * stored in the WEBAPP/resources/ui/skins/[SKIN] directory with the
171: * filename skin.css
172: *
173: * @param skinName the name of the skin to retrieve the style sheet from.
174: */
175: public static String getStylecss(String skinName) {
176: return ((UIService) TurbineServices.getInstance().getService(
177: UIService.SERVICE_NAME)).getStylecss(skinName);
178: }
179:
180: /**
181: * Retrieve the URL for a given script that is part of the skin. The script
182: * is stored in the WEBAPP/resources/ui/skins/[SKIN] directory.
183: *
184: * <p>Use this if for some reason your server name, server scheme, or server
185: * port change on a per request basis. I'm not sure if this would happen in
186: * a load balanced situation. I think in most cases the image(String image)
187: * method would probably be enough, but I'm not absolutely positive.
188: *
189: * @param skinName the name of the skin to retrieve the image from.
190: * @param filename the name of the script file whose URL will be generated.
191: * @param data the RunData to use as the source of the ServerData to use as
192: * the basis for the URL.
193: */
194: public static String getScript(String skinName, String filename,
195: ServerData serverData) {
196: return ((UIService) TurbineServices.getInstance().getService(
197: UIService.SERVICE_NAME)).getScript(skinName, filename,
198: serverData);
199: }
200:
201: /**
202: * Retrieve the URL for a given script that is part of the skin. The script
203: * is stored in the WEBAPP/resources/ui/skins/[SKIN] directory.
204: *
205: * @param skinName the name of the skin to retrieve the image from.
206: * @param filename the name of the script file whose URL will be generated.
207: */
208: public static String getScript(String skinName, String filename) {
209: return ((UIService) TurbineServices.getInstance().getService(
210: UIService.SERVICE_NAME)).getScript(skinName, filename);
211: }
212:
213: }
|