source: trunk/gsdl3/src/java/org/greenstone/gsdl3/util/XSLTUtil.java@ 4702

Last change on this file since 4702 was 4702, checked in by kjdon, 21 years ago

added method for retrieving strings from resource bundles, including ones with args

  • Property svn:keywords set to Author Date Id Revision
File size: 1.7 KB
Line 
1package org.greenstone.gsdl3.util;
2
3/** a class to contain various static methods that are used by the xslt
4 * stylesheets
5 */
6public class XSLTUtil {
7
8 public static String toLower(String orig) {
9 return orig.toLowerCase();
10 }
11
12 public static byte[] toUTF8(String orig) {
13
14 try {
15 byte[] utf8 = orig.getBytes("UTF-8");
16 return utf8;
17 }
18 catch (Exception e){
19 System.err.println("XSLTUtil.toUTF8: unsupported encoding");
20 return orig.getBytes();
21 }
22 }
23
24 public static String getNumberedItem(String list, int number) {
25 String [] items = list.split(",", -1);
26 if (items.length > number) {
27 return items[number];
28 }
29 return ""; // index out of bounds
30 }
31
32
33 public static String tidyWhitespace(String original) {
34
35 if (original==null || original.equals("")) {
36 return original;
37 }
38 String new_s = original.replaceAll("\\s+", " ");
39 return new_s;
40 }
41
42
43 public static String getInterfaceText(String interface_name, String lang, String key) {
44 return getInterfaceText(interface_name, lang, key, null);
45 }
46 public static String getInterfaceText(String interface_name, String lang, String key, String args_str) {
47 String [] args = null;
48 if (args_str!=null && !args_str.equals("")) {
49 args = args_str.split(";");
50 }
51 Dictionary dict = new Dictionary("interface_"+interface_name, lang);
52 String result = dict.get(key, args);
53
54 if (result == null && !interface_name.equals("default")) { // not found, try the default interface
55 dict = new Dictionary("interface_default", lang);
56 result = dict.get(key, args);
57 }
58
59 if (result == null) { // not found
60 return "_"+key+"_";
61 }
62 return result;
63 }
64}
65
Note: See TracBrowser for help on using the repository browser.