Changeset 24450
- Timestamp:
- 2011-08-23T14:08:19+12:00 (12 years ago)
- Location:
- main/trunk/greenstone3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/XSLTUtil.java
r24393 r24450 26 26 27 27 import org.apache.log4j.*; 28 import org.w3c.dom.Node; 28 import org.w3c.dom.Node; 29 29 30 30 import org.apache.commons.lang3.StringUtils; 31 31 32 /** a class to contain various static methods that are used by the xslt 32 /** 33 * a class to contain various static methods that are used by the xslt 33 34 * stylesheets 34 35 */ 35 public class XSLTUtil { 36 37 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.XSLTUtil.class.getName()); 38 39 /* some tests */ 40 public static boolean equals(String s1, String s2) { 41 return s1.equals(s2); 42 } 43 public static boolean notEquals(String s1, String s2) { 44 return !s1.equals(s2); 45 } 46 public static boolean exists(String s1, String s2) { 47 return !s1.equals(""); 48 } 49 public static boolean contains(String s1, String s2) { 50 return (s1.indexOf(s2) != -1); 51 } 52 public static boolean startsWith(String s1, String s2) { 53 return s1.startsWith(s2); 54 } 55 public static boolean endsWith(String s1, String s2) { 56 return s1.endsWith(s2); 57 } 58 public static boolean lessThan(String s1, String s2) { 59 return (s1.compareTo(s2) < 0); 60 } 61 public static boolean lessThanOrEquals(String s1, String s2) { 62 return (s1.compareTo(s2) <= 0); 63 } 64 public static boolean greaterThan(String s1, String s2) { 65 return (s1.compareTo(s2) > 0); 66 } 67 public static boolean greaterThanOrEquals(String s1, String s2) { 68 return (s1.compareTo(s2) >= 0); 69 } 70 71 /* some preprocessing functions */ 72 public static String toLower(String orig) { 73 return orig.toLowerCase(); 74 } 75 public static String toUpper(String orig) { 76 return orig.toUpperCase(); 77 } 78 79 public static byte[] toUTF8(String orig) { 80 81 try { 82 byte[] utf8 = orig.getBytes("UTF-8"); 83 return utf8; 84 } 85 catch (Exception e){ 86 logger.error("unsupported encoding"); 87 return orig.getBytes(); 88 } 89 } 90 91 public static String getNumberedItem(String list, int number) { 92 String [] items = StringUtils.split(list, ",", -1); 93 if (items.length > number) { 94 return items[number]; 95 } 96 return ""; // index out of bounds 97 } 98 99 /** Generates links to equivalent documents for a document with a default document icon/type. 100 * Links are generated from the parameters: a list of document icons which are each in turn embedded 101 * in the matching starting link tag in the list of docStartLinks (these starting links link to the 102 * equivalent documents in another format). Each link's start tag is closed with the corresponding 103 * closing tag in the docEndLinks list. Parameter token is the list separator. Parameter divider is 104 * the string that should separate each final link generated from the next. 105 * Returns a string that represents a sequence of links to equivalent documents, where the anchor is 106 * a document icon. */ 107 public static String getEquivDocLinks(String token, String docIconsString, String docStartLinksString, 108 String docEndLinksString, String divider) 109 { 110 String [] docIcons = StringUtils.split(docIconsString, token, -1); 111 String [] startLinks = StringUtils.split(docStartLinksString, token, -1); 112 String [] endLinks = StringUtils.split(docEndLinksString, token, -1); 113 114 StringBuffer buffer = new StringBuffer(); 115 for(int i = 0; i < docIcons.length; i++) { 116 if(i > 0) { 117 buffer.append(divider); 118 } 119 buffer.append(startLinks[i]+docIcons[i]+endLinks[i]); 120 } 121 122 return buffer.toString(); 123 } 124 125 126 public static String tidyWhitespace(String original) { 127 128 if (original==null || original.equals("")) { 129 return original; 130 } 131 String new_s = original.replaceAll("\\s+", " "); 132 return new_s; 133 } 134 135 136 public static String getInterfaceText(String interface_name, String lang, String key) { 137 return getInterfaceText(interface_name, lang, key, null); 138 } 139 public static String getInterfaceText(String interface_name, String lang, String key, String args_str) { 140 141 key = key.replaceAll("__INTERFACE_NAME__", interface_name); 142 143 String [] args = null; 144 if (args_str!=null && !args_str.equals("")) { 145 args = StringUtils.split(args_str, ";"); 146 } 147 Dictionary dict = new Dictionary("interface_"+interface_name, lang); 148 String result = dict.get(key, args); 149 if (result == null) { // not found 150 //if not found, search a separate subdirectory named by the interface name 151 String sep_interface_dir = interface_name + File.separatorChar + lang + File.separatorChar + "interface"; 152 dict = new Dictionary(sep_interface_dir, lang); 153 result = dict.get(key, args); 154 if(result != null) { 155 return result; 156 } 157 } 158 159 if (result == null && !interface_name.equals("default")) { // not found, try the default interface 160 dict = new Dictionary("interface_default", lang); 161 result = dict.get(key, args); 162 } 163 164 if (result == null) { // not found 165 return "_"+key+"_"; 166 } 167 return result; 168 } 169 170 public static String getInterfaceTextWithDOM(String interface_name, String lang, String key, Node arg_node) { 171 String [] args = new String [1]; 172 173 String node_str = XMLConverter.getString(arg_node); 174 args[0] = node_str; 175 Dictionary dict = new Dictionary("interface_"+interface_name, lang); 176 String result = dict.get(key, args); 177 if (result == null) { // not found 178 //if not found, search a separate subdirectory named by the interface name 179 String sep_interface_dir = interface_name + File.separatorChar + lang + File.separatorChar + "interface"; 180 dict = new Dictionary(sep_interface_dir, lang); 181 result = dict.get(key, args); 182 if(result != null) { 36 public class XSLTUtil 37 { 38 39 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.XSLTUtil.class.getName()); 40 41 /* some tests */ 42 public static boolean equals(String s1, String s2) 43 { 44 return s1.equals(s2); 45 } 46 47 public static boolean notEquals(String s1, String s2) 48 { 49 return !s1.equals(s2); 50 } 51 52 public static boolean exists(String s1, String s2) 53 { 54 return !s1.equals(""); 55 } 56 57 public static boolean contains(String s1, String s2) 58 { 59 return (s1.indexOf(s2) != -1); 60 } 61 62 public static boolean startsWith(String s1, String s2) 63 { 64 return s1.startsWith(s2); 65 } 66 67 public static boolean endsWith(String s1, String s2) 68 { 69 return s1.endsWith(s2); 70 } 71 72 public static boolean lessThan(String s1, String s2) 73 { 74 return (s1.compareTo(s2) < 0); 75 } 76 77 public static boolean lessThanOrEquals(String s1, String s2) 78 { 79 return (s1.compareTo(s2) <= 0); 80 } 81 82 public static boolean greaterThan(String s1, String s2) 83 { 84 return (s1.compareTo(s2) > 0); 85 } 86 87 public static boolean greaterThanOrEquals(String s1, String s2) 88 { 89 return (s1.compareTo(s2) >= 0); 90 } 91 92 /* some preprocessing functions */ 93 public static String toLower(String orig) 94 { 95 return orig.toLowerCase(); 96 } 97 98 public static String toUpper(String orig) 99 { 100 return orig.toUpperCase(); 101 } 102 103 public static byte[] toUTF8(String orig) 104 { 105 106 try 107 { 108 byte[] utf8 = orig.getBytes("UTF-8"); 109 return utf8; 110 } 111 catch (Exception e) 112 { 113 logger.error("unsupported encoding"); 114 return orig.getBytes(); 115 } 116 } 117 118 public static String getNumberedItem(String list, int number) 119 { 120 String[] items = StringUtils.split(list, ",", -1); 121 if (items.length > number) 122 { 123 return items[number]; 124 } 125 return ""; // index out of bounds 126 } 127 128 /** 129 * Generates links to equivalent documents for a document with a default 130 * document icon/type. Links are generated from the parameters: a list of 131 * document icons which are each in turn embedded in the matching starting 132 * link tag in the list of docStartLinks (these starting links link to the 133 * equivalent documents in another format). Each link's start tag is closed 134 * with the corresponding closing tag in the docEndLinks list. Parameter 135 * token is the list separator. Parameter divider is the string that should 136 * separate each final link generated from the next. Returns a string that 137 * represents a sequence of links to equivalent documents, where the anchor 138 * is a document icon. 139 */ 140 public static String getEquivDocLinks(String token, String docIconsString, String docStartLinksString, String docEndLinksString, String divider) 141 { 142 String[] docIcons = StringUtils.split(docIconsString, token, -1); 143 String[] startLinks = StringUtils.split(docStartLinksString, token, -1); 144 String[] endLinks = StringUtils.split(docEndLinksString, token, -1); 145 146 StringBuffer buffer = new StringBuffer(); 147 for (int i = 0; i < docIcons.length; i++) 148 { 149 if (i > 0) 150 { 151 buffer.append(divider); 152 } 153 buffer.append(startLinks[i] + docIcons[i] + endLinks[i]); 154 } 155 156 return buffer.toString(); 157 } 158 159 public static String tidyWhitespace(String original) 160 { 161 162 if (original == null || original.equals("")) 163 { 164 return original; 165 } 166 String new_s = original.replaceAll("\\s+", " "); 167 return new_s; 168 } 169 170 public static String getInterfaceText(String interface_name, String lang, String key) 171 { 172 return getInterfaceText(interface_name, lang, key, null); 173 } 174 175 public static String getInterfaceText(String interface_name, String lang, String key, String args_str) 176 { 177 key = key.replaceAll("__INTERFACE_NAME__", interface_name); 178 179 String[] args = null; 180 if (args_str != null && !args_str.equals("")) 181 { 182 args = StringUtils.split(args_str, ";"); 183 } 184 Dictionary dict = new Dictionary("interface_" + interface_name, lang); 185 String result = dict.get(key, args); 186 if (result == null) 187 { // not found 188 //if not found, search a separate subdirectory named by the interface name 189 String sep_interface_dir = interface_name + File.separatorChar + lang + File.separatorChar + "interface"; 190 dict = new Dictionary(sep_interface_dir, lang); 191 result = dict.get(key, args); 192 if (result != null) 193 { 194 result = result.replaceAll("__INTERFACE_NAME__", interface_name); 195 return result; 196 } 197 } 198 199 if (result == null && !interface_name.equals("default")) 200 { // not found, try the default interface 201 dict = new Dictionary("interface_default", lang); 202 result = dict.get(key, args); 203 } 204 205 if (result == null) 206 { // not found 207 return "_" + key + "_"; 208 } 209 result = result.replaceAll("__INTERFACE_NAME__", interface_name); 183 210 return result; 184 } 185 } 186 187 if (result == null && !interface_name.equals("default")) { // not found, try the default interface 188 dict = new Dictionary("interface_default", lang); 189 result = dict.get(key, args); 190 } 191 192 if (result == null) { // not found 193 return "_"+key+"_"; 194 } 195 196 return result; 197 } 198 public static String getInterfaceTextWithDOM(String interface_name, String lang, String key, Node arg1_node, Node arg2_node) { 199 String [] args = new String [2]; 200 201 String node_str = XMLConverter.getString(arg1_node); 202 args[0] = node_str; 203 node_str = XMLConverter.getString(arg2_node); 204 args[1] = node_str; 205 Dictionary dict = new Dictionary("interface_"+interface_name, lang); 206 String result = dict.get(key, args); 207 if (result == null) { // not found 208 //if not found, search a separate subdirectory named by the interface name 209 String sep_interface_dir = interface_name + File.separatorChar + lang + File.separatorChar + "interface"; 210 dict = new Dictionary(sep_interface_dir, lang); 211 result = dict.get(key, args); 212 if(result != null) { 211 } 212 213 public static String getInterfaceTextWithDOM(String interface_name, String lang, String key, Node arg_node) 214 { 215 String[] args = new String[1]; 216 217 String node_str = XMLConverter.getString(arg_node); 218 args[0] = node_str; 219 Dictionary dict = new Dictionary("interface_" + interface_name, lang); 220 String result = dict.get(key, args); 221 if (result == null) 222 { // not found 223 //if not found, search a separate subdirectory named by the interface name 224 String sep_interface_dir = interface_name + File.separatorChar + lang + File.separatorChar + "interface"; 225 dict = new Dictionary(sep_interface_dir, lang); 226 result = dict.get(key, args); 227 if (result != null) 228 { 229 return result; 230 } 231 } 232 233 if (result == null && !interface_name.equals("default")) 234 { // not found, try the default interface 235 dict = new Dictionary("interface_default", lang); 236 result = dict.get(key, args); 237 } 238 239 if (result == null) 240 { // not found 241 return "_" + key + "_"; 242 } 243 213 244 return result; 214 } 215 } 216 217 if (result == null && !interface_name.equals("default")) { // not found, try the default interface 218 dict = new Dictionary("interface_default", lang); 219 result = dict.get(key, args); 220 } 221 222 if (result == null) { // not found 223 return "_"+key+"_"; 224 } 225 226 return result; 227 } 228 229 public static boolean isImage(String mimetype) { 230 if (mimetype.startsWith("image/")) { 231 return true; 232 } 233 return false; 234 } 235 236 public static String formatDate(String date, String lang) { 237 238 String in_pattern = "yyyyMMdd"; 239 String out_pattern = "dd MMMM yyyy"; 240 if (date.length()==6) { 241 in_pattern = "yyyyMM"; 242 } 243 244 SimpleDateFormat formatter = new SimpleDateFormat(in_pattern, new Locale(lang)); 245 try { 246 Date d = formatter.parse(date); 247 formatter.applyPattern(out_pattern); 248 String new_date = formatter.format(d); 249 return new_date; 250 } catch (Exception e) { 251 return date; 252 } 253 254 } 255 256 public static String formatLanguage(String display_lang, String lang) { 257 258 return new Locale(display_lang).getDisplayLanguage(new Locale(lang)); 259 } 260 261 public static String cgiSafe(String original, String lang) { 262 263 original = original.replace('&', ' '); 264 original = original.replaceAll(" ", "%20"); 265 return original; 266 } 267 268 public static String formatBigNumber(String num){ 269 270 String num_str = num; 271 char[] num_chars = num_str.toCharArray(); 272 String zero_str = ""; 273 String formatted_str = ""; 274 275 for(int i = num_chars.length-4; i >=0; i--){ 276 zero_str += '0'; 277 } 278 279 String sig_str = ""; 280 for(int i = 0; i<3 && i < num_chars.length; i++){ 281 sig_str = sig_str + num_chars[i]; 282 if(i == 1 && i+1 < num_chars.length){ 283 sig_str = sig_str + "."; 284 } 285 } 286 287 int sig_int = Math.round(Float.parseFloat(sig_str)); 288 String new_sig_str = sig_int +""; 289 if(sig_str.length() > 2){ 290 new_sig_str = sig_int + "0"; 291 } 292 293 char[] final_chars = (new_sig_str+zero_str).toCharArray(); 294 int count = 1; 295 for(int i=final_chars.length -1 ; i>=0; i-- ){ 296 formatted_str = final_chars[i] + formatted_str ; 297 if(count == 3 && i !=0){ 298 formatted_str = "," +formatted_str; 299 count = 1; 300 } 301 else{ 302 count++; 303 } 304 } 305 return formatted_str; 306 } 307 245 } 246 247 public static String getInterfaceTextWithDOM(String interface_name, String lang, String key, Node arg1_node, Node arg2_node) 248 { 249 String[] args = new String[2]; 250 251 String node_str = XMLConverter.getString(arg1_node); 252 args[0] = node_str; 253 node_str = XMLConverter.getString(arg2_node); 254 args[1] = node_str; 255 Dictionary dict = new Dictionary("interface_" + interface_name, lang); 256 String result = dict.get(key, args); 257 if (result == null) 258 { // not found 259 //if not found, search a separate subdirectory named by the interface name 260 String sep_interface_dir = interface_name + File.separatorChar + lang + File.separatorChar + "interface"; 261 dict = new Dictionary(sep_interface_dir, lang); 262 result = dict.get(key, args); 263 if (result != null) 264 { 265 return result; 266 } 267 } 268 269 if (result == null && !interface_name.equals("default")) 270 { // not found, try the default interface 271 dict = new Dictionary("interface_default", lang); 272 result = dict.get(key, args); 273 } 274 275 if (result == null) 276 { // not found 277 return "_" + key + "_"; 278 } 279 280 return result; 281 } 282 283 public static boolean isImage(String mimetype) 284 { 285 if (mimetype.startsWith("image/")) 286 { 287 return true; 288 } 289 return false; 290 } 291 292 public static String formatDate(String date, String lang) 293 { 294 295 String in_pattern = "yyyyMMdd"; 296 String out_pattern = "dd MMMM yyyy"; 297 if (date.length() == 6) 298 { 299 in_pattern = "yyyyMM"; 300 } 301 302 SimpleDateFormat formatter = new SimpleDateFormat(in_pattern, new Locale(lang)); 303 try 304 { 305 Date d = formatter.parse(date); 306 formatter.applyPattern(out_pattern); 307 String new_date = formatter.format(d); 308 return new_date; 309 } 310 catch (Exception e) 311 { 312 return date; 313 } 314 315 } 316 317 public static String formatLanguage(String display_lang, String lang) 318 { 319 320 return new Locale(display_lang).getDisplayLanguage(new Locale(lang)); 321 } 322 323 public static String cgiSafe(String original, String lang) 324 { 325 326 original = original.replace('&', ' '); 327 original = original.replaceAll(" ", "%20"); 328 return original; 329 } 330 331 public static String formatBigNumber(String num) 332 { 333 334 String num_str = num; 335 char[] num_chars = num_str.toCharArray(); 336 String zero_str = ""; 337 String formatted_str = ""; 338 339 for (int i = num_chars.length - 4; i >= 0; i--) 340 { 341 zero_str += '0'; 342 } 343 344 String sig_str = ""; 345 for (int i = 0; i < 3 && i < num_chars.length; i++) 346 { 347 sig_str = sig_str + num_chars[i]; 348 if (i == 1 && i + 1 < num_chars.length) 349 { 350 sig_str = sig_str + "."; 351 } 352 } 353 354 int sig_int = Math.round(Float.parseFloat(sig_str)); 355 String new_sig_str = sig_int + ""; 356 if (sig_str.length() > 2) 357 { 358 new_sig_str = sig_int + "0"; 359 } 360 361 char[] final_chars = (new_sig_str + zero_str).toCharArray(); 362 int count = 1; 363 for (int i = final_chars.length - 1; i >= 0; i--) 364 { 365 formatted_str = final_chars[i] + formatted_str; 366 if (count == 3 && i != 0) 367 { 368 formatted_str = "," + formatted_str; 369 count = 1; 370 } 371 else 372 { 373 count++; 374 } 375 } 376 return formatted_str; 377 } 378 308 379 public static String hashToSectionId(String hashString) 309 380 { 310 if(hashString == null || hashString.length() == 0) {return "";} 311 381 if (hashString == null || hashString.length() == 0) 382 { 383 return ""; 384 } 385 312 386 int firstDotIndex = hashString.indexOf("."); 313 if (firstDotIndex == -1)314 { 387 if (firstDotIndex == -1) 388 { 315 389 return ""; 316 390 } 317 391 318 392 String sectionString = hashString.substring(firstDotIndex + 1); 319 393 320 394 return sectionString; 321 395 } 322 396 323 397 public static String hashToDepthClass(String hashString) 324 398 { 325 if(hashString == null || hashString.length() == 0) {return "";} 326 399 if (hashString == null || hashString.length() == 0) 400 { 401 return ""; 402 } 403 327 404 String sectionString = hashToSectionId(hashString); 328 405 329 406 int count = sectionString.split("\\.").length; 330 407 331 408 if (sectionString.equals("")) 332 409 { 333 410 return "sectionHeaderDepthTitle"; 334 411 } 335 else 412 else 336 413 { 337 414 return "sectionHeaderDepth" + count; … … 339 416 } 340 417 } 341 -
main/trunk/greenstone3/web/WEB-INF/classes/interface_default.properties
r24244 r24450 1 1 #***** IMAGE URLS ***** 2 expand_image=interfaces/oran/images/expand.png 3 collapse_image=interfaces/oran/images/collapse.png 4 page_image=interfaces/oran/images/page.png 5 chapter_image=interfaces/oran/images/chapter.png 6 realistic_books_image=interfaces/oran/images/rbook.png 7 highlight_image=interfaces/oran/images/hl.png 8 bookshelf_image=interfaces/oran/images/bookshelf.png 9 book_image=interfaces/oran/images/book.png 10 loading_image=interfaces/oran/images/loading.gif 2 expand_image=interfaces/__INTERFACE_NAME__/images/expand.png 3 collapse_image=interfaces/__INTERFACE_NAME__/images/collapse.png 4 page_image=interfaces/__INTERFACE_NAME__/images/page.png 5 chapter_image=interfaces/__INTERFACE_NAME__/images/chapter.png 6 realistic_books_image=interfaces/__INTERFACE_NAME__/images/rbook.png 7 highlight_image=interfaces/__INTERFACE_NAME__/images/hl.png 8 bookshelf_image=interfaces/__INTERFACE_NAME__/images/bookshelf.png 9 book_image=interfaces/__INTERFACE_NAME__/images/book.png 10 loading_image=interfaces/__INTERFACE_NAME__/images/loading.gif 11 page_icon_image=interfaces/__INTERFACE_NAME__/images/itext.gif 11 12 12 13 #***** TEXT FRAGMENTS *****
Note:
See TracChangeset
for help on using the changeset viewer.