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

Last change on this file since 6232 was 6232, checked in by kjdon, 20 years ago

added some string handling methods

  • Property svn:keywords set to Author Date Id Revision
File size: 2.1 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 boolean equals(String s1, String s2) {
9 return s1.equals(s2);
10 }
11
12 public static boolean contains(String s1, String s2) {
13 return (s1.indexOf(s2) != -1);
14 }
15 public static boolean startsWith(String s1, String s2) {
16 return s1.startsWith(s2);
17 }
18 public static boolean endsWith(String s1, String s2) {
19 return s1.endsWith(s2);
20 }
21
22 public static String toLower(String orig) {
23 return orig.toLowerCase();
24 }
25 public static String toUpper(String orig) {
26 return orig.toUpperCase();
27 }
28
29 public static byte[] toUTF8(String orig) {
30
31 try {
32 byte[] utf8 = orig.getBytes("UTF-8");
33 return utf8;
34 }
35 catch (Exception e){
36 System.err.println("XSLTUtil.toUTF8: unsupported encoding");
37 return orig.getBytes();
38 }
39 }
40
41 public static String getNumberedItem(String list, int number) {
42 String [] items = list.split(",", -1);
43 if (items.length > number) {
44 return items[number];
45 }
46 return ""; // index out of bounds
47 }
48
49
50 public static String tidyWhitespace(String original) {
51
52 if (original==null || original.equals("")) {
53 return original;
54 }
55 String new_s = original.replaceAll("\\s+", " ");
56 return new_s;
57 }
58
59
60 public static String getInterfaceText(String interface_name, String lang, String key) {
61 return getInterfaceText(interface_name, lang, key, null);
62 }
63 public static String getInterfaceText(String interface_name, String lang, String key, String args_str) {
64 String [] args = null;
65 if (args_str!=null && !args_str.equals("")) {
66 args = args_str.split(";");
67 }
68 Dictionary dict = new Dictionary("interface_"+interface_name, lang);
69 String result = dict.get(key, args);
70
71 if (result == null && !interface_name.equals("default")) { // not found, try the default interface
72 dict = new Dictionary("interface_default", lang);
73 result = dict.get(key, args);
74 }
75
76 if (result == null) { // not found
77 return "_"+key+"_";
78 }
79 return result;
80 }
81}
82
Note: See TracBrowser for help on using the repository browser.