Changeset 8230


Ignore:
Timestamp:
2004-10-07T16:17:08+13:00 (20 years ago)
Author:
mdewsnip
Message:

Made this class static. Accesses to the configuration via Gatherer.config should now go directly through Configuration.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/Configuration.java

    r8015 r8230  
    9595    static final private String TOKENIZER_PATTERN3 = ",\n\t";
    9696
    97     public File exec_file;
     97    static public Configuration self = null;
     98
     99    static public File exec_file;
    98100    /** 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;
    100102    /** The path to the Greenstone Suite installation directory. */
    101     public String gsdl_path = "";
     103    static public String gsdl_path = "";
    102104    /** If we are using GLI in Greenstone 3, the path to gsdl3 directory */
    103     public String gsdl3_path = "";
     105    static public String gsdl3_path = "";
    104106    /** The path to the PERL executable, up to and including Perl.exe. */
    105     public String perl_path = "";
     107    static public String perl_path = "";
    106108    /** The password for the proxy server indicated above. */
    107     public String proxy_pass = null;
     109    static public String proxy_pass = null;
    108110    /** The username for the proxy server indicated above. */
    109     public String proxy_user = null;
     111    static public String proxy_user = null;
    110112    /** 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();
    112114    /** The site name if we are using GS3 */
    113     public String site_name = "";
     115    static public String site_name = "";
    114116    /** The servlet path if we are using GS3 */
    115     private String servlet_path = "";
     117    static private String servlet_path = "";
    116118    /** 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;
    118120    /** Collection level configuration (which in some cases overrides general configuration. */
    119     private Document collection_config;
     121    static private Document collection_config;
    120122    /** The general configuration settings. */
    121     private Document general_config;
     123    static private Document general_config;
    122124   
    123125    /** 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;
    131133
    132134    public URL exec_address = null;
     
    141143    public Configuration(String gsdl_path, String gsdl3_path, String exec_path, String perl_path, boolean mirroring_enabled, String site_name) {
    142144    super();
     145    self = this;
     146
    143147    this.gsdl_path = gsdl_path;
    144148    this.gsdl3_path = gsdl3_path;
     
    293297
    294298    /** Add a special directory mapping. */
    295     public boolean addDirectoryMapping(String name, File file) {
     299    static public boolean addDirectoryMapping(String name, File file) {
    296300    boolean result = false;
    297301    try {
     
    324328
    325329    /** 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) {
    327331    if(general && mirroring_enabled && property.equals(StaticStrings.WORKFLOW_MIRROR)) {
    328332        return mirroring_enabled;
     
    333337
    334338    /** 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) {
    336340    HashMap properties = new HashMap();
    337341    try {
     
    353357            String result = XMLTools.getValue(argument_element);
    354358            // 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));
    356360            // Add mapping to the properties we're going to return
    357361            properties.put(argument_element.getAttribute(ARGUMENT_NAME), result);
     
    366370
    367371    /** 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) {
    369373    Element argument_element = null;
    370374    try {
     
    396400    /** Gets the language for the other arguments subtree
    397401     @return empty string if no language specified */
    398     public String getArgumentsLanguage() {
     402    static public String getArgumentsLanguage() {
    399403    Element document_element = general_config.getDocumentElement();
    400404    Element other_element = (Element) XMLTools.getNodeFromNamed(document_element, OTHER);
     
    407411
    408412    /** 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) {
    410414    Rectangle result = null;
    411415    try {
     
    426430
    427431    /** 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) {
    429433    Color result = Color.white; // Default
    430434    try {
     
    438442    }
    439443    catch(Exception error) {
    440         Gatherer.printStackTrace(error);
     444        error.printStackTrace();
    441445    }
    442446    return result;
    443447    }
    444448
    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); // Default
    448     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     } */
    461449
    462450    /** Retrieve the special directory mappings associated with this collection.
    463451     * @return A <strong>HashMap</strong> containing mappings from names to directories.
    464452     */
    465     public HashMap getDirectoryMappings() {
     453    static public HashMap getDirectoryMappings() {
    466454    HashMap special_directories = new HashMap();
    467455    try {
     
    489477     * @return the email address, if it is set, as a String
    490478     */
    491     public String getEmail() {
     479    static public String getEmail() {
    492480    String email = getString(GENERAL_EMAIL_SETTING, true);
    493481    return (email.length() > 0 ? email : null);
    494482    }
    495483
    496     public Element getFileAssociations() {
     484    static public Element getFileAssociations() {
    497485    NodeList file_association_elements = general_config.getDocumentElement().getElementsByTagName(StaticStrings.ASSOCIATIONS_ELEMENT);
    498486    return (Element) file_association_elements.item(0);
     
    500488
    501489    /** 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) {
    503491    FontUIResource result = new FontUIResource("Times New Roman", Font.PLAIN, 10);
    504492    try {
     
    528516
    529517    /** 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) {
    531519    int result = 0;
    532520    try {
     
    541529
    542530    /** Retrieves the current interface language two letter code. */
    543     public String getLanguage() {
     531    static public String getLanguage() {
    544532    Locale locale = getLocale("general.locale", GENERAL_SETTING);
    545533    String code = "en"; // Default
     
    551539
    552540    /** 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) {
    554542    Locale result = Locale.getDefault();
    555543    try {
     
    575563     * @return an int representing the mode
    576564     */
    577     public int getMode() {
     565    static public int getMode() {
    578566    return getInt("general.mode", GENERAL_SETTING);
    579567    }
     
    582570     * @return the mode as a String
    583571     */
    584     public String getModeAsString() {
     572    static public String getModeAsString() {
    585573    String result;
    586574    switch(getInt("general.mode", GENERAL_SETTING)) {
     
    600588    }
    601589
    602     public String getPreviewCommand() {
     590    static public String getPreviewCommand() {
    603591    return getString("general.preview_program", GENERAL_SETTING);
    604592    }
    605593
    606     public String getServletPath() {
     594    static public String getServletPath() {
    607595    if (servlet_path == null) {
    608596        servlet_path = Gatherer.servlet_config.getServletPath(site_name);
     
    611599    }
    612600    /** 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) {
    614602    // Its up to this method to find the appropriate node and retrieve the data itself.
    615603    String result = "";
    616604    try {
    617605        // 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);
    619607        if(reference != null) {
    620608        Element argument_element = (Element) reference.get();
     
    644632                result = XMLTools.getValue(argument_element);
    645633                // 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));
    647635            }
    648636            }
     
    651639    }
    652640    catch (Exception error) {
    653         Gatherer.printStackTrace(error);
     641        error.printStackTrace();
    654642    }
    655643    // If we still have no result, and the search was made in the collection configuration, retrieve the general one instead.
     
    663651     * @return A <strong>String</strong> containing the path.
    664652     */
    665     public String getScriptPath() {
     653    static public String getScriptPath() {
    666654    return gsdl_path + "bin" + File.separator + "script" + File.separator;
    667655    }
    668656
    669     public String getGS3ScriptPath() {
     657    static public String getGS3ScriptPath() {
    670658    return gsdl3_path + "bin" + File.separator + "script" + File.separator;
    671659    }
    672660
    673661
    674     public String getWGetPath() {
     662    static public String getWGetPath() {
    675663    return (wget_path != null ? wget_path : "");
    676664    }
    677665
    678     public String getWGetVersion() {
     666    static public String getWGetVersion() {
    679667    return (wget_version_str != null ? wget_version_str : StaticStrings.NO_WGET_STR);
    680668    }
     
    684672     * @return The <strong>File</strong> of the mapping removed.
    685673     */
    686     public File removeDirectoryMapping(String name) {
     674    static public File removeDirectoryMapping(String name) {
    687675    File file = null;
    688676    try {
     
    708696
    709697    /** Export the general configuration to file. */
    710     public void save() {
     698    static public void save() {
    711699    ///ystem.err.println("Hits " + cache_hit + " vs Misses " + cache_miss);
    712700    // We first try exporting to a user specific place
     
    734722
    735723    /** 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) {
    737725    if(property.startsWith("workflow")) {
    738726        Gatherer.println("Set property: " + property + ", general=" + general + ", value=" + value);
     
    742730
    743731    /** 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) {
    745733    try {
    746734        Element document_element = general_config.getDocumentElement();
     
    774762
    775763    /** Sets the language for the other arguments subtree */
    776     public void setArgumentsLanguage(String lang) {
     764    static public void setArgumentsLanguage(String lang) {
    777765    Element document_element = general_config.getDocumentElement();
    778766    Element other_element = (Element) XMLTools.getNodeFromNamed(document_element, OTHER);
     
    782770   
    783771    /** Set the collection configuration. */
    784     public void setCollectionConfiguration(Document collection_config) {
     772    static public void setCollectionConfiguration(Document collection_config) {
    785773    // clear the cached values
    786     clear();
    787     this.collection_config = collection_config;
     774    self.clear();
     775    collection_config = collection_config;
    788776    updateUI();
    789777    ///atherer.println("Collection configuration set.");
     
    791779
    792780    /** 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) {
    794782    StringBuffer text = new StringBuffer("");
    795783    text.append(value.x);
     
    804792
    805793    /** 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) {
    807795    StringBuffer text = new StringBuffer("");
    808796    text.append(value.getRed());
     
    814802    }
    815803
    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 
    825804    /** Establish the current users email.
    826805     * @param email the email as a String
    827806     */
    828     public void setEmail(String email) {
     807    static public void setEmail(String email) {
    829808    setString(GENERAL_EMAIL_SETTING, true, email);
    830809    }
    831810
    832811    /** 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) {
    834813    StringBuffer text = new StringBuffer("");
    835814    text.append(value.getName());
     
    851830
    852831    /** 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) {
    854833        setString(property, general, String.valueOf(value));
    855834    }
    856835
    857836    /** 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) {
    859838    StringBuffer text = new StringBuffer("");
    860839    text.append(value.getLanguage());
     
    871850     * @param value the new value for mode
    872851     */
    873     public void setMode(int value) {
     852    static public void setMode(int value) {
    874853    setInt("general.mode", GENERAL_SETTING, value);
    875854    }
    876855
    877     public void setPreviewCommand(String value) {
     856    static public void setPreviewCommand(String value) {
    878857    setString("general.preview_program", GENERAL_SETTING, value);
    879858    }
    880859
    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;
    884863    setString("general.site_name", GENERAL_SETTING, site);
    885864    setString("general.servlet_path", GENERAL_SETTING, servlet);
     
    887866    }
    888867    /** 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) {
    890869    Gatherer.println("Set configuration property: " + property + " = " + value + (general ? "" : " [Collection]"));
    891870    try {
     
    897876        Element argument_element = null;
    898877        // Try to retrieve from cache
    899         SoftReference reference = (SoftReference) get(property + general);
     878        SoftReference reference = (SoftReference) self.get(property + general);
    900879        if(reference != null) {
    901880            argument_element = (Element) reference.get();
     
    919898            }
    920899            // Update cache
    921             put(property + general, new SoftReference(argument_element));
     900            self.put(property + general, new SoftReference(argument_element));
    922901
    923902        }
     
    938917    }
    939918
    940     public void setWGetPath(String path) {
     919    static public void setWGetPath(String path) {
    941920    wget_path  = path;
    942921    }
    943922
    944     public void setWGetVersion(String version) {
     923    static public void setWGetVersion(String version) {
    945924    wget_version_str = version;
    946925    }
    947926
    948     private void updateUI() {
     927    static private void updateUI() {
    949928    // Buttons
    950929    UIManager.put("Button.select", new ColorUIResource(getColor("coloring.button_selected_background", false)));
Note: See TracChangeset for help on using the changeset viewer.