Changeset 8230
- Timestamp:
- 2004-10-07T16:17:08+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/Configuration.java
r8015 r8230 95 95 static final private String TOKENIZER_PATTERN3 = ",\n\t"; 96 96 97 public File exec_file; 97 static public Configuration self = null; 98 99 static public File exec_file; 98 100 /** The path (or url) to the webserver which is serving the Greenstone collection. */ 99 public String exec_path = null;101 static public String exec_path = null; 100 102 /** The path to the Greenstone Suite installation directory. */ 101 public String gsdl_path = "";103 static public String gsdl_path = ""; 102 104 /** If we are using GLI in Greenstone 3, the path to gsdl3 directory */ 103 public String gsdl3_path = "";105 static public String gsdl3_path = ""; 104 106 /** The path to the PERL executable, up to and including Perl.exe. */ 105 public String perl_path = "";107 static public String perl_path = ""; 106 108 /** The password for the proxy server indicated above. */ 107 public String proxy_pass = null;109 static public String proxy_pass = null; 108 110 /** The username for the proxy server indicated above. */ 109 public String proxy_user = null;111 static public String proxy_user = null; 110 112 /** The screen size of the desktop the Gatherer will be displayed on. */ 111 public Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();113 static public Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize(); 112 114 /** The site name if we are using GS3 */ 113 public String site_name = "";115 static public String site_name = ""; 114 116 /** The servlet path if we are using GS3 */ 115 private String servlet_path = "";117 static private String servlet_path = ""; 116 118 /** If true, overrides the mirroring enabled setting in the config.xml file. */ 117 private boolean mirroring_enabled = false;119 static private boolean mirroring_enabled = false; 118 120 /** Collection level configuration (which in some cases overrides general configuration. */ 119 private Document collection_config;121 static private Document collection_config; 120 122 /** The general configuration settings. */ 121 private Document general_config;123 static private Document general_config; 122 124 123 125 /** The element, from glis config file, that contains the various directory mappings. */ 124 private Element directory_mappings_element;125 126 private int cache_hit = 0;127 private int cache_miss = 0;128 129 private String wget_path = null;130 private String wget_version_str = StaticStrings.NO_WGET_STR;126 static private Element directory_mappings_element; 127 128 static private int cache_hit = 0; 129 static private int cache_miss = 0; 130 131 static private String wget_path = null; 132 static private String wget_version_str = StaticStrings.NO_WGET_STR; 131 133 132 134 public URL exec_address = null; … … 141 143 public Configuration(String gsdl_path, String gsdl3_path, String exec_path, String perl_path, boolean mirroring_enabled, String site_name) { 142 144 super(); 145 self = this; 146 143 147 this.gsdl_path = gsdl_path; 144 148 this.gsdl3_path = gsdl3_path; … … 293 297 294 298 /** Add a special directory mapping. */ 295 public boolean addDirectoryMapping(String name, File file) {299 static public boolean addDirectoryMapping(String name, File file) { 296 300 boolean result = false; 297 301 try { … … 324 328 325 329 /** The default get action retrieves the named property from the desired configuration, and returns a true or false. */ 326 public boolean get(String property, boolean general) {330 static public boolean get(String property, boolean general) { 327 331 if(general && mirroring_enabled && property.equals(StaticStrings.WORKFLOW_MIRROR)) { 328 332 return mirroring_enabled; … … 333 337 334 338 /** Retrieve all of the configuration preferences which match a certain string. They are returned as a hash map of property names to String objects. */ 335 public HashMap getAll(String property_pattern, boolean general) {339 static public HashMap getAll(String property_pattern, boolean general) { 336 340 HashMap properties = new HashMap(); 337 341 try { … … 353 357 String result = XMLTools.getValue(argument_element); 354 358 // Store a mapping in the cache. Sometimes we will overwrite an existing value (say for collection and general level workflow options) but the processing overhead of detecting these clashes far exceeds any savings. 355 put(argument_element.getAttribute(ARGUMENT_NAME) + general, new SoftReference(argument_element));359 self.put(argument_element.getAttribute(ARGUMENT_NAME) + general, new SoftReference(argument_element)); 356 360 // Add mapping to the properties we're going to return 357 361 properties.put(argument_element.getAttribute(ARGUMENT_NAME), result); … … 366 370 367 371 /** Retrieve the information subtree containing the arguments for the desired external program. If the program has marked superclasses append their arguments as well. */ 368 public Element getArguments(String filename) {372 static public Element getArguments(String filename) { 369 373 Element argument_element = null; 370 374 try { … … 396 400 /** Gets the language for the other arguments subtree 397 401 @return empty string if no language specified */ 398 public String getArgumentsLanguage() {402 static public String getArgumentsLanguage() { 399 403 Element document_element = general_config.getDocumentElement(); 400 404 Element other_element = (Element) XMLTools.getNodeFromNamed(document_element, OTHER); … … 407 411 408 412 /** Retrieve the value of the named property as a Rectangle. */ 409 public Rectangle getBounds(String property, boolean general) {413 static public Rectangle getBounds(String property, boolean general) { 410 414 Rectangle result = null; 411 415 try { … … 426 430 427 431 /** Retrieve the value of the named property as a Color. */ 428 public Color getColor(String property, boolean general) {432 static public Color getColor(String property, boolean general) { 429 433 Color result = Color.white; // Default 430 434 try { … … 438 442 } 439 443 catch(Exception error) { 440 Gatherer.printStackTrace(error);444 error.printStackTrace(); 441 445 } 442 446 return result; 443 447 } 444 448 445 /** Retrieve the value of the named property as a Dimension. */446 /* private Dimension getDimension(String property, boolean general) {447 Dimension result = new Dimension(100, 100); // Default448 try {449 String raw = getString(property, general);450 // Dimension is a width by height pair, comma separated (also remove whitespace)451 StringTokenizer tokenizer = new StringTokenizer(raw, TOKENIZER_PATTERN1);452 int width = Integer.parseInt(tokenizer.nextToken());453 int height = Integer.parseInt(tokenizer.nextToken());454 result = new Dimension(width, height);455 }456 catch(Exception error) {457 Gatherer.printStackTrace(error);458 }459 return result;460 } */461 449 462 450 /** Retrieve the special directory mappings associated with this collection. 463 451 * @return A <strong>HashMap</strong> containing mappings from names to directories. 464 452 */ 465 public HashMap getDirectoryMappings() {453 static public HashMap getDirectoryMappings() { 466 454 HashMap special_directories = new HashMap(); 467 455 try { … … 489 477 * @return the email address, if it is set, as a String 490 478 */ 491 public String getEmail() {479 static public String getEmail() { 492 480 String email = getString(GENERAL_EMAIL_SETTING, true); 493 481 return (email.length() > 0 ? email : null); 494 482 } 495 483 496 public Element getFileAssociations() {484 static public Element getFileAssociations() { 497 485 NodeList file_association_elements = general_config.getDocumentElement().getElementsByTagName(StaticStrings.ASSOCIATIONS_ELEMENT); 498 486 return (Element) file_association_elements.item(0); … … 500 488 501 489 /** Retrieve the value of the named property as a FontUIResource. */ 502 public FontUIResource getFont(String property, boolean general) {490 static public FontUIResource getFont(String property, boolean general) { 503 491 FontUIResource result = new FontUIResource("Times New Roman", Font.PLAIN, 10); 504 492 try { … … 528 516 529 517 /** Retrieve the value of the named property as an integer. */ 530 public int getInt(String property, boolean general) {518 static public int getInt(String property, boolean general) { 531 519 int result = 0; 532 520 try { … … 541 529 542 530 /** Retrieves the current interface language two letter code. */ 543 public String getLanguage() {531 static public String getLanguage() { 544 532 Locale locale = getLocale("general.locale", GENERAL_SETTING); 545 533 String code = "en"; // Default … … 551 539 552 540 /** Retrieve the value of the named property as a Locale. */ 553 public Locale getLocale(String property, boolean general) {541 static public Locale getLocale(String property, boolean general) { 554 542 Locale result = Locale.getDefault(); 555 543 try { … … 575 563 * @return an int representing the mode 576 564 */ 577 public int getMode() {565 static public int getMode() { 578 566 return getInt("general.mode", GENERAL_SETTING); 579 567 } … … 582 570 * @return the mode as a String 583 571 */ 584 public String getModeAsString() {572 static public String getModeAsString() { 585 573 String result; 586 574 switch(getInt("general.mode", GENERAL_SETTING)) { … … 600 588 } 601 589 602 public String getPreviewCommand() {590 static public String getPreviewCommand() { 603 591 return getString("general.preview_program", GENERAL_SETTING); 604 592 } 605 593 606 public String getServletPath() {594 static public String getServletPath() { 607 595 if (servlet_path == null) { 608 596 servlet_path = Gatherer.servlet_config.getServletPath(site_name); … … 611 599 } 612 600 /** Retrieve the value of the named property, and noting whether we consult the general or collection specific configuration. */ 613 public String getString(String property, boolean general) {601 static public String getString(String property, boolean general) { 614 602 // Its up to this method to find the appropriate node and retrieve the data itself. 615 603 String result = ""; 616 604 try { 617 605 // First of all we look in the cache to see if we have a match. 618 SoftReference reference = (SoftReference) get(property + general);606 SoftReference reference = (SoftReference) self.get(property + general); 619 607 if(reference != null) { 620 608 Element argument_element = (Element) reference.get(); … … 644 632 result = XMLTools.getValue(argument_element); 645 633 // Store a mapping in the cache. Sometimes we will overwrite an existing value (say for collection and general level workflow options) but the processing overhead of detecting these clashes far exceeds any savings. 646 put(property + general, new SoftReference(argument_element));634 self.put(property + general, new SoftReference(argument_element)); 647 635 } 648 636 } … … 651 639 } 652 640 catch (Exception error) { 653 Gatherer.printStackTrace(error);641 error.printStackTrace(); 654 642 } 655 643 // If we still have no result, and the search was made in the collection configuration, retrieve the general one instead. … … 663 651 * @return A <strong>String</strong> containing the path. 664 652 */ 665 public String getScriptPath() {653 static public String getScriptPath() { 666 654 return gsdl_path + "bin" + File.separator + "script" + File.separator; 667 655 } 668 656 669 public String getGS3ScriptPath() {657 static public String getGS3ScriptPath() { 670 658 return gsdl3_path + "bin" + File.separator + "script" + File.separator; 671 659 } 672 660 673 661 674 public String getWGetPath() {662 static public String getWGetPath() { 675 663 return (wget_path != null ? wget_path : ""); 676 664 } 677 665 678 public String getWGetVersion() {666 static public String getWGetVersion() { 679 667 return (wget_version_str != null ? wget_version_str : StaticStrings.NO_WGET_STR); 680 668 } … … 684 672 * @return The <strong>File</strong> of the mapping removed. 685 673 */ 686 public File removeDirectoryMapping(String name) {674 static public File removeDirectoryMapping(String name) { 687 675 File file = null; 688 676 try { … … 708 696 709 697 /** Export the general configuration to file. */ 710 public void save() {698 static public void save() { 711 699 ///ystem.err.println("Hits " + cache_hit + " vs Misses " + cache_miss); 712 700 // We first try exporting to a user specific place … … 734 722 735 723 /** Set the named property, from the specified configuration, using the given boolean value. */ 736 public void set(String property, boolean general, boolean value) {724 static public void set(String property, boolean general, boolean value) { 737 725 if(property.startsWith("workflow")) { 738 726 Gatherer.println("Set property: " + property + ", general=" + general + ", value=" + value); … … 742 730 743 731 /** Add a subtree of argument information to the other arguments part of the general configuration. This overwrites any such existing subtree. */ 744 public void setArguments(Element arguments_element) {732 static public void setArguments(Element arguments_element) { 745 733 try { 746 734 Element document_element = general_config.getDocumentElement(); … … 774 762 775 763 /** Sets the language for the other arguments subtree */ 776 public void setArgumentsLanguage(String lang) {764 static public void setArgumentsLanguage(String lang) { 777 765 Element document_element = general_config.getDocumentElement(); 778 766 Element other_element = (Element) XMLTools.getNodeFromNamed(document_element, OTHER); … … 782 770 783 771 /** Set the collection configuration. */ 784 public void setCollectionConfiguration(Document collection_config) {772 static public void setCollectionConfiguration(Document collection_config) { 785 773 // clear the cached values 786 clear();787 this.collection_config = collection_config;774 self.clear(); 775 collection_config = collection_config; 788 776 updateUI(); 789 777 ///atherer.println("Collection configuration set."); … … 791 779 792 780 /** Set the named property, from the specified configuration, using the given Rectangle value. */ 793 public void setBounds(String property, boolean general, Rectangle value) {781 static public void setBounds(String property, boolean general, Rectangle value) { 794 782 StringBuffer text = new StringBuffer(""); 795 783 text.append(value.x); … … 804 792 805 793 /** Set the named property, from the specified configuration, using the given Color value. */ 806 public void setColor(String property, boolean general, Color value) {794 static public void setColor(String property, boolean general, Color value) { 807 795 StringBuffer text = new StringBuffer(""); 808 796 text.append(value.getRed()); … … 814 802 } 815 803 816 /** Set the named property, from the specified configuration, using the given Dimension value. */817 /* private void setDimension(String property, boolean general, Dimension value) {818 StringBuffer text = new StringBuffer("");819 text.append(value.width);820 text.append(", ");821 text.append(value.height);822 setString(property, general, text.toString());823 } */824 825 804 /** Establish the current users email. 826 805 * @param email the email as a String 827 806 */ 828 public void setEmail(String email) {807 static public void setEmail(String email) { 829 808 setString(GENERAL_EMAIL_SETTING, true, email); 830 809 } 831 810 832 811 /** Set the named property, from the specified configuration, using the given Font value. */ 833 public void setFont(String property, boolean general, Font value) {812 static public void setFont(String property, boolean general, Font value) { 834 813 StringBuffer text = new StringBuffer(""); 835 814 text.append(value.getName()); … … 851 830 852 831 /** Set the named property, from the specified configuration, using the given integer value. */ 853 public void setInt(String property, boolean general, int value) {832 static public void setInt(String property, boolean general, int value) { 854 833 setString(property, general, String.valueOf(value)); 855 834 } 856 835 857 836 /** Set the named property, from the specified configuration, using the given Locale value. */ 858 public void setLocale(String property, boolean general, Locale value) {837 static public void setLocale(String property, boolean general, Locale value) { 859 838 StringBuffer text = new StringBuffer(""); 860 839 text.append(value.getLanguage()); … … 871 850 * @param value the new value for mode 872 851 */ 873 public void setMode(int value) {852 static public void setMode(int value) { 874 853 setInt("general.mode", GENERAL_SETTING, value); 875 854 } 876 855 877 public void setPreviewCommand(String value) {856 static public void setPreviewCommand(String value) { 878 857 setString("general.preview_program", GENERAL_SETTING, value); 879 858 } 880 859 881 public void setSiteAndServlet(String site, String servlet) {882 this.site_name = site;883 this.servlet_path = servlet;860 static public void setSiteAndServlet(String site, String servlet) { 861 site_name = site; 862 servlet_path = servlet; 884 863 setString("general.site_name", GENERAL_SETTING, site); 885 864 setString("general.servlet_path", GENERAL_SETTING, servlet); … … 887 866 } 888 867 /** Sets the value of the named property argument using the given string. */ 889 public void setString(String property, boolean general, String value) {868 static public void setString(String property, boolean general, String value) { 890 869 Gatherer.println("Set configuration property: " + property + " = " + value + (general ? "" : " [Collection]")); 891 870 try { … … 897 876 Element argument_element = null; 898 877 // Try to retrieve from cache 899 SoftReference reference = (SoftReference) get(property + general);878 SoftReference reference = (SoftReference) self.get(property + general); 900 879 if(reference != null) { 901 880 argument_element = (Element) reference.get(); … … 919 898 } 920 899 // Update cache 921 put(property + general, new SoftReference(argument_element));900 self.put(property + general, new SoftReference(argument_element)); 922 901 923 902 } … … 938 917 } 939 918 940 public void setWGetPath(String path) {919 static public void setWGetPath(String path) { 941 920 wget_path = path; 942 921 } 943 922 944 public void setWGetVersion(String version) {923 static public void setWGetVersion(String version) { 945 924 wget_version_str = version; 946 925 } 947 926 948 private void updateUI() {927 static private void updateUI() { 949 928 // Buttons 950 929 UIManager.put("Button.select", new ColorUIResource(getColor("coloring.button_selected_background", false)));
Note:
See TracChangeset
for help on using the changeset viewer.