Changeset 33295
- Timestamp:
- 2019-07-04T13:13:04+12:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/XSLTUtil.java
r33278 r33295 222 222 public static String getInterfaceText(String interface_name, String lang, String key) 223 223 { 224 return getInterfaceText (interface_name, lang, key, null);224 return getInterfaceTextWithArgs(interface_name, lang, key, null); 225 225 } 226 226 227 227 public static String getInterfaceText(String interface_name, String lang, String key, String args_str) 228 228 { 229 key = key.replaceAll("__INTERFACE_NAME__", interface_name);230 231 229 String[] args = null; 232 230 if (args_str != null && !args_str.equals("")) … … 234 232 args = StringUtils.split(args_str, ";"); 235 233 } 236 Dictionary dict = new Dictionary("interface_" + interface_name, lang); 237 String result = dict.get(key, args); 238 if (result == null) 239 { // not found 240 //if not found, search a separate subdirectory named by the interface name 241 String sep_interface_dir = interface_name + File.separatorChar + lang + File.separatorChar + "interface"; 242 dict = new Dictionary(sep_interface_dir, lang); 243 result = dict.get(key, args); 244 if (result != null) 245 { 246 result = result.replaceAll("__INTERFACE_NAME__", interface_name); 247 return result; 248 } 249 } 250 251 if (result == null && !interface_name.startsWith("default")) 252 { // not found, try the default interface 253 if (interface_name.endsWith("2")) { // hack for interface_xxx2.properties 254 dict = new Dictionary("interface_default2", lang); 255 } else { 256 dict = new Dictionary("interface_default", lang); 257 258 } 259 result = dict.get(key, args); 260 } 261 262 if (result == null) 263 { // not found 264 return "_" + key + "_"; 265 } 266 result = result.replaceAll("__INTERFACE_NAME__", interface_name); 267 return result; 268 } 269 270 public static String getInterfaceText(String interfaceName, String dictionaryName, String lang, String key, String args_str) 271 { 272 key = key.replaceAll("__INTERFACE_NAME__", interfaceName); 273 234 return getInterfaceTextWithArgs(interface_name, lang, key, args); 235 } 236 237 public static String getInterfaceText(String interface_name, String dictionary_name, String lang, String key, String args_str) 238 { 274 239 String[] args = null; 275 240 if (args_str != null && !args_str.equals("")) … … 277 242 args = StringUtils.split(args_str, ";"); 278 243 } 279 Dictionary dict = new Dictionary(dictionaryName, lang); 280 String result = dict.get(key, args); 281 if (result == null) 282 { // not found 283 //if not found, search a separate subdirectory named by the interface name 284 String sep_interface_dir = interfaceName + File.separatorChar + lang + File.separatorChar + "interface"; 285 dict = new Dictionary(sep_interface_dir, lang); 286 result = dict.get(key, args); 287 if (result != null) 288 { 289 result = result.replaceAll("__INTERFACE_NAME__", interfaceName); 290 return result; 291 } 292 } 293 294 if (result == null && !interfaceName.equals("default")) 295 { // not found, try the default interface 296 dict = new Dictionary("interface_default", lang); 297 result = dict.get(key, args); 298 } 299 300 if (result == null) 301 { // not found 302 return "_" + key + "_"; 303 } 304 result = result.replaceAll("__INTERFACE_NAME__", interfaceName); 244 245 // try the specified dictionary first 246 Dictionary dict = new Dictionary(dictionary_name, lang); 247 String result = dict.get(key, args); 248 if (result == null) { 249 // fall back to a general interface text search 250 return getInterfaceTextWithArgs(interface_name, lang, key, args); 251 } 252 result = result.replaceAll("__INTERFACE_NAME__", interface_name); // do we need to so this here? 305 253 return result; 306 254 } 307 255 308 256 public static String getInterfaceTextWithDOM(String interface_name, String lang, String key, Node arg_node) 309 257 { 310 String[] args = new String[1]; 311 312 String node_str = XMLConverter.getString(arg_node); 313 args[0] = node_str; 314 Dictionary dict = new Dictionary("interface_" + interface_name, lang); 315 String result = dict.get(key, args); 316 if (result == null) 317 { // not found 318 //if not found, search a separate subdirectory named by the interface name 319 String sep_interface_dir = interface_name + File.separatorChar + lang + File.separatorChar + "interface"; 320 dict = new Dictionary(sep_interface_dir, lang); 321 result = dict.get(key, args); 322 if (result != null) 323 { 324 return result; 325 } 326 } 327 328 if (result == null && !interface_name.equals("default")) 329 { // not found, try the default interface 330 dict = new Dictionary("interface_default", lang); 331 result = dict.get(key, args); 332 } 333 334 if (result == null) 335 { // not found 336 return "_" + key + "_"; 337 } 338 339 return result; 258 return getInterfaceTextWithDOMMulti(interface_name, lang, key, arg_node); 340 259 } 341 260 342 261 public static String getInterfaceTextWithDOM(String interface_name, String lang, String key, Node arg1_node, Node arg2_node) 343 262 { 344 String[] args = new String[2]; 345 346 String node_str = XMLConverter.getString(arg1_node); 347 args[0] = node_str; 348 node_str = XMLConverter.getString(arg2_node); 349 args[1] = node_str; 350 Dictionary dict = new Dictionary("interface_" + interface_name, lang); 351 String result = dict.get(key, args); 352 if (result == null) 353 { // not found 354 //if not found, search a separate subdirectory named by the interface name 355 String sep_interface_dir = interface_name + File.separatorChar + lang + File.separatorChar + "interface"; 356 dict = new Dictionary(sep_interface_dir, lang); 357 result = dict.get(key, args); 358 if (result != null) 359 { 360 return result; 361 } 362 } 363 364 if (result == null && !interface_name.equals("default")) 365 { // not found, try the default interface 366 dict = new Dictionary("interface_default", lang); 367 result = dict.get(key, args); 368 } 369 370 if (result == null) 371 { // not found 372 return "_" + key + "_"; 373 } 374 375 return result; 376 } 377 378 263 return getInterfaceTextWithDOMMulti(interface_name, lang, key, arg1_node, arg2_node); 264 } 265 266 public static String getInterfaceTextWithDOMMulti(String interface_name, String lang, String key, Node... nodes) 267 { 268 int num_nodes = nodes.length; 269 String[] args = null; 270 if (num_nodes != 0) 271 { 272 args = new String[num_nodes]; 273 274 for (int i = 0; i < num_nodes; i++) 275 { 276 String node_str = XMLConverter.getString(nodes[i]); 277 args[i] = node_str; 278 } 279 } 280 return getInterfaceTextWithArgs(interface_name, lang, key, args); 281 282 } 283 284 /* This is the base method that actually does the work of looking up the various chain of dictionaries */ 285 public static String getInterfaceTextWithArgs(String interface_name, String lang, String key, String[] args) 286 { 287 Dictionary dict = new Dictionary("interface_" + interface_name, lang); 288 289 // do we need this?? values can have __INTERFACE_NAME__ but would keys ever have it??? 290 key = key.replaceAll("__INTERFACE_NAME__", interface_name); 291 String result = dict.get(key, args); 292 if (result == null) 293 { // not found - TODO delete this??? 294 //if not found, search a separate subdirectory named by the interface name 295 String sep_interface_dir = interface_name + File.separatorChar + lang + File.separatorChar + "interface"; 296 dict = new Dictionary(sep_interface_dir, lang); 297 result = dict.get(key, args); 298 if (result != null) 299 { 300 return result; 301 } 302 } 303 304 if (result == null && !interface_name.startsWith("default")) { 305 // not found, try the default interface 306 if (interface_name.endsWith("2")) { // hack for interface_xxx2.properties 307 dict = new Dictionary("interface_default2", lang); 308 } else { 309 dict = new Dictionary("interface_default", lang); 310 311 } 312 result = dict.get(key, args); 313 } 314 315 if (result == null) 316 { // not found 317 return "?" + key + "?"; 318 } 319 result = result.replaceAll("__INTERFACE_NAME__", interface_name); 320 321 return result; 322 323 324 325 } 379 326 public static String getInterfaceTextSubstituteArgs(String value, String args_str) 380 327 { … … 464 411 465 412 public static String getGenericText(String dictionary_name, String lang, String key) { 466 413 return getGenericTextWithArgs(dictionary_name, lang, key, null); 414 } 415 416 public String getGenericText(String dictionary_name, String lang, String key, String args_str) { 417 String[] args = null; 418 if (args_str != null && !args_str.equals("")) { 419 args = StringUtils.split(args_str, ";"); 420 } 421 return getGenericTextWithArgs(dictionary_name, lang, key, args); 422 } 423 424 public static String getGenericTextWithArgs(String dictionary_name, String lang, String key, String[] args) 425 { 467 426 Dictionary dict = new Dictionary(dictionary_name, lang); 468 String result = dict.get(key );427 String result = dict.get(key, args); 469 428 if (result == null) { 470 429 return "_"+dictionary_name+"_"+key+"_"; … … 472 431 return result; 473 432 } 433 434 435 474 436 public static boolean isImage(String mimetype) 475 437 {
Note:
See TracChangeset
for help on using the changeset viewer.