KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > webapp > data > ServletResources


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.internal.webapp.data;
12
13 import java.util.*;
14
15 import javax.servlet.http.*;
16
17 import org.eclipse.help.internal.base.HelpBasePlugin;
18 import org.eclipse.help.internal.webapp.*;
19
20 /**
21  * Uses a resource bundle to load images and strings from a property file in a
22  * documentation plugin
23  */

24 public class ServletResources {
25
26     /**
27      * Resources constructor.
28      */

29     protected ServletResources() {
30         super();
31     }
32
33     public static String JavaDoc getConfirmShowAllExplanation(HttpServletRequest request) {
34         String JavaDoc message = HelpBasePlugin.getActivitySupport().getShowAllMessage();
35         if (message==null)
36             message = getString("confirmShowAllExplanation", request); //$NON-NLS-1$
37
return message;
38     }
39
40     /**
41      * Returns a string from a property file. It uses 'name' as a the key to
42      * retrieve from the webapp.properties file.
43      *
44      * @param request
45      * HttpServletRequest or null; default locale will be used if
46      * null passed
47      */

48     public static String JavaDoc getString(String JavaDoc name, HttpServletRequest request) {
49         String JavaDoc property = WebappResources.getString(name, UrlUtil.getLocaleObj(
50                 request, null));
51         if (property == null || property.length() <= 0) {
52             return property;
53         }
54         int amp = property.indexOf('&');
55         if (amp <0 || amp >= property.length() - 1) {
56             return property;
57         }
58         return property.substring(0, amp)
59                 + property.substring(amp + 1, property.length());
60     }
61
62     /**
63      * Returns a string from a property file. It uses 'name' as a the key to
64      * retrieve from the webapp.properties file.
65      *
66      * @param request
67      * HttpServletRequest or null; default locale will be used if
68      * null passed
69      */

70     public static String JavaDoc getString(String JavaDoc name, String JavaDoc replace0,
71             HttpServletRequest request) {
72         String JavaDoc property = WebappResources.getString(name, UrlUtil.getLocaleObj(
73                 request, null), replace0);
74         if (property == null || property.length() <= 0) {
75             return property;
76         }
77         int amp = property.indexOf('&');
78         if (amp <0 || amp >= property.length() - 1) {
79             return property;
80         }
81         return property.substring(0, amp - 1)
82                 + property.substring(amp + 1, property.length());
83     }
84     /**
85      * Returns a string from a property file, with underlined access key. Access
86      * key can be specified in the label by &amp: character following character
87      * in the label that is to serve as access key It uses 'name' as a the key
88      * to retrieve from the webapp.properties file.
89      *
90      * @param request
91      * HttpServletRequest or null; default locale will be used if
92      * null passed
93      */

94     public static String JavaDoc getLabel(String JavaDoc name, HttpServletRequest request) {
95         String JavaDoc property = WebappResources.getString(name, UrlUtil.getLocaleObj(
96                 request, null));
97         if (property == null || property.length() <= 0) {
98             return property;
99         }
100         int amp = property.indexOf('&');
101         if (amp <0 || amp >= property.length() - 1) {
102             return property;
103         }
104         return property.substring(0, amp)
105                 + "<u STYLE=\"ACCELERATOR:true\">" //$NON-NLS-1$
106
+ property.charAt(amp+1) + "</u>" //$NON-NLS-1$
107
+ property.substring(amp + 2, property.length());
108     }
109
110     /**
111      * Returns access key for a named label from property file. It uses 'name'
112      * as a the key to retrieve from the webapp.properties file.
113      *
114      * @param request
115      * HttpServletRequest or null; default locale will be used if
116      * null passed
117      */

118     public static String JavaDoc getAccessKey(String JavaDoc name, HttpServletRequest request) {
119         String JavaDoc property = WebappResources.getString(name, UrlUtil.getLocaleObj(
120                 request, null));
121         if (property == null || property.length() <= 0) {
122             return null;
123         }
124         int amp = property.indexOf('&');
125         if (amp <0 || amp >= property.length() - 1) {
126             return null;
127         }
128         return ("" + property.charAt(amp +1)).toLowerCase(Locale.ENGLISH); //$NON-NLS-1$
129
}
130
131 }
132
Popular Tags