Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6fd6b3887f67e55940cede5a8a08c5b100382e9e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*******************************************************************************
 * Copyright (c) 2000, 2015 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.help.internal.webapp.data;

import java.util.*;

import javax.servlet.http.*;

import org.eclipse.help.internal.base.HelpBasePlugin;
import org.eclipse.help.internal.webapp.*;

/**
 * Uses a resource bundle to load images and strings from a property file in a
 * documentation plugin
 */
public class ServletResources {

	/**
	 * Resources constructor.
	 */
	protected ServletResources() {
		super();
	}

	public static String getConfirmShowAllExplanation(HttpServletRequest request) {
		String  message = HelpBasePlugin.getActivitySupport().getShowAllMessage();
		if (message==null)
			message = getString("confirmShowAllExplanation", request); //$NON-NLS-1$
		return message;
	}

	/**
	 * Returns a string from a property file. It uses 'name' as a the key to
	 * retrieve from the webapp.properties file.
	 *
	 * @param request
	 *            HttpServletRequest or null; default locale will be used if
	 *            null passed
	 */
	public static String getString(String name, HttpServletRequest request) {
		String property = WebappResources.getString(name, UrlUtil.getLocaleObj(
				request, null));
		if (property == null || property.length() <= 0) {
			return property;
		}
		int amp = property.indexOf('&');
		if (amp <0 || amp >= property.length() - 1) {
			return property;
		}
		return property.substring(0, amp)
				+ property.substring(amp + 1, property.length());
	}

	/**
	 * Returns a string from a property file. It uses 'name' as a the key to
	 * retrieve from the webapp.properties file.
	 *
	 * @param request
	 *            HttpServletRequest or null; default locale will be used if
	 *            null passed
	 */
	public static String getString(String name, String replace0,
			HttpServletRequest request) {
		String property = WebappResources.getString(name, UrlUtil.getLocaleObj(
				request, null), replace0);
		return property;
	}

	/**
	 * Returns a string from a property file. It uses 'name' as a the key to
	 * retrieve from the webapp.properties file. 'args[]' is used to replace
	 * the variables in property string.
	 *
	 * @param request
	 *            HttpServletRequest or null; default locale will be used if
	 *            null passed
	 */
	public static String getString(String name, String[] args,
			HttpServletRequest request) {
		String property = WebappResources.getString(name, UrlUtil.getLocaleObj(
				request, null), args);
		return property;
	}

	/**
	 * Returns a string from a property file, with underlined access key. Access
	 * key can be specified in the label by &amp: character following character
	 * in the label that is to serve as access key It uses 'name' as a the key
	 * to retrieve from the webapp.properties file.
	 *
	 * @param request
	 *            HttpServletRequest or null; default locale will be used if
	 *            null passed
	 */
	public static String getLabel(String name, HttpServletRequest request) {
		String property = WebappResources.getString(name, UrlUtil.getLocaleObj(
				request, null));
		if (property == null || property.length() <= 0) {
			return property;
		}
		int amp = property.indexOf('&');
		if (amp <0 || amp >= property.length() - 1) {
			return property;
		}
		boolean isIE = UrlUtil.isIE(request);
		String acceleratorPrefix = isIE ? "<u STYLE=\"ACCELERATOR:true\">" : ""; //$NON-NLS-1$ //$NON-NLS-2$
		String acceleratorSuffix = isIE ? "</u>" : ""; //$NON-NLS-1$ //$NON-NLS-2$
		return property.substring(0, amp)
				+ acceleratorPrefix
				+ property.charAt(amp+1) + acceleratorSuffix
				+ property.substring(amp + 2, property.length());
	}

	/**
	 * Returns access key for a named label from property file. It uses 'name'
	 * as a the key to retrieve from the webapp.properties file.
	 *
	 * @param request
	 *            HttpServletRequest or null; default locale will be used if
	 *            null passed
	 */
	public static String getAccessKey(String name, HttpServletRequest request) {
		String property = WebappResources.getString(name, UrlUtil.getLocaleObj(
				request, null));
		if (property == null || property.length() <= 0) {
			return null;
		}
		int amp = property.indexOf('&');
		if (amp <0 || amp >= property.length() - 1) {
            return null;
        }
		return ("" + property.charAt(amp +1)).toLowerCase(Locale.ENGLISH); //$NON-NLS-1$
	}

}

Back to the top