- Timestamp:
- 2012-05-10T15:57:02+12:00 (12 years ago)
- Location:
- main/trunk/greenstone3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/resources/java/global.properties.in
r24201 r25567 5 5 gsdl3.home=@gsdl3home@ 6 6 gsdl3.version=@gsdl3version@ 7 8 [email protected]@ 7 9 8 10 # for collection building -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/XSLTUtil.java
r25378 r25567 35 35 36 36 import org.apache.commons.lang3.StringUtils; 37 import org.greenstone.util.GlobalProperties; 37 38 38 39 /** … … 48 49 public static boolean equals(String s1, String s2) 49 50 { 51 System.err.println("COMPARING " + s1 + " AND " + s2 + " = " + s1.equals(s2)); 50 52 return s1.equals(s2); 51 53 } … … 478 480 return escapeNewLines(escapeQuotes(str)); 479 481 } 482 483 public static String getGlobalProperty(String name) 484 { 485 System.err.println("AWAY TO RETURN " + GlobalProperties.getProperty(name)); 486 return GlobalProperties.getProperty(name); 487 } 480 488 481 489 public static void clearMetadataStorage() … … 513 521 } 514 522 515 public static String getInterfaceStringsAsJavascript(String interface_name, String lang, String prefix) { 516 String prependToPrefix = "gs.text"; 517 return XSLTUtil.getInterfaceStringsAsJavascript(interface_name, lang, prefix, prependToPrefix); 518 } 519 520 // generates javascript: 2 arrays are declared and populated with strings that declare variables and assign their values 521 // to be strings loaded from the interface_name.properties file for the language. 522 public static String getInterfaceStringsAsJavascript(String interface_name, String lang, String prefix, String prependToPrefix) { 523 // 1. Generating Javascript of the form: 524 // if(!gs.text) { gs.text = new Array(); } 525 // if(!gs.text.dse) { gs.text.dse = new Array(); } 526 StringBuffer outputStr = new StringBuffer(); 527 outputStr.append("if(!gs.text) { "); 528 outputStr.append(prependToPrefix + " = new Array(); "); 529 outputStr.append("}\n"); 530 outputStr.append("if(!gs.text." + prefix + ") { "); 531 outputStr.append(prependToPrefix + "." + prefix + " = new Array(); "); 532 outputStr.append("}\n"); 533 534 Dictionary dict = new Dictionary("interface_" + interface_name, lang); 535 Enumeration keys = dict.getKeys(); 536 if(keys == null) { // try default interface 537 //logger.debug("****** Interface name: " + interface_name + " does not have any keys. Trying interface_default."); 538 dict = new Dictionary("interface_default", lang); 539 keys = dict.getKeys(); 540 } 541 542 // Get all properties in the language-specific dictionary with the given key prefix 543 // Create Javascript strings of the form: 544 // prependToPrefix.key= "value";\n 545 while(keys.hasMoreElements()) { 546 String key = (String)keys.nextElement(); 547 if(key.startsWith(prefix)) { 548 String value = getInterfaceText(interface_name, lang, key); 549 550 outputStr.append(prependToPrefix); 551 outputStr.append("."); 552 outputStr.append(key); 553 outputStr.append("=\""); 554 outputStr.append(value); 555 outputStr.append("\";\n"); 556 } 557 } 558 559 return outputStr.toString(); 560 561 } 562 563 // Test from cmdline with: 564 // java -classpath /research/ak19/gs3-svn/web/WEB-INF/lib/gsdl3.jar:/research/ak19/gs3-svn/web/WEB-INF/lib/log4j-1.2.8.jar:/research/ak19/gs3-svn/web/WEB-INF/classes/ org.greenstone.gsdl3.util.XSLTUtil 565 public static void main(String args[]) { 566 System.out.println("\n@@@@@\n" + XSLTUtil.getInterfaceStringsAsJavascript("default", "en", "dse", "gs.text") + "@@@@@\n"); 567 } 523 public static String getInterfaceStringsAsJavascript(String interface_name, String lang, String prefix) 524 { 525 String prependToPrefix = "gs.text"; 526 return XSLTUtil.getInterfaceStringsAsJavascript(interface_name, lang, prefix, prependToPrefix); 527 } 528 529 // generates javascript: 2 arrays are declared and populated with strings that declare variables and assign their values 530 // to be strings loaded from the interface_name.properties file for the language. 531 public static String getInterfaceStringsAsJavascript(String interface_name, String lang, String prefix, String prependToPrefix) 532 { 533 // 1. Generating Javascript of the form: 534 // if(!gs.text) { gs.text = new Array(); } 535 // if(!gs.text.dse) { gs.text.dse = new Array(); } 536 StringBuffer outputStr = new StringBuffer(); 537 outputStr.append("if(!gs.text) { "); 538 outputStr.append(prependToPrefix + " = new Array(); "); 539 outputStr.append("}\n"); 540 outputStr.append("if(!gs.text." + prefix + ") { "); 541 outputStr.append(prependToPrefix + "." + prefix + " = new Array(); "); 542 outputStr.append("}\n"); 543 544 Dictionary dict = new Dictionary("interface_" + interface_name, lang); 545 Enumeration keys = dict.getKeys(); 546 if (keys == null) 547 { // try default interface 548 //logger.debug("****** Interface name: " + interface_name + " does not have any keys. Trying interface_default."); 549 dict = new Dictionary("interface_default", lang); 550 keys = dict.getKeys(); 551 } 552 553 // Get all properties in the language-specific dictionary with the given key prefix 554 // Create Javascript strings of the form: 555 // prependToPrefix.key= "value";\n 556 while (keys.hasMoreElements()) 557 { 558 String key = (String) keys.nextElement(); 559 if (key.startsWith(prefix)) 560 { 561 String value = getInterfaceText(interface_name, lang, key); 562 563 outputStr.append(prependToPrefix); 564 outputStr.append("."); 565 outputStr.append(key); 566 outputStr.append("=\""); 567 outputStr.append(value); 568 outputStr.append("\";\n"); 569 } 570 } 571 572 return outputStr.toString(); 573 574 } 575 576 // Test from cmdline with: 577 // java -classpath /research/ak19/gs3-svn/web/WEB-INF/lib/gsdl3.jar:/research/ak19/gs3-svn/web/WEB-INF/lib/log4j-1.2.8.jar:/research/ak19/gs3-svn/web/WEB-INF/classes/ org.greenstone.gsdl3.util.XSLTUtil 578 public static void main(String args[]) 579 { 580 System.out.println("\n@@@@@\n" + XSLTUtil.getInterfaceStringsAsJavascript("default", "en", "dse", "gs.text") + "@@@@@\n"); 581 } 568 582 }
Note:
See TracChangeset
for help on using the changeset viewer.