Project

General

Profile

« Previous | Next » 

Revision 1951

Added by Matt Jones over 20 years ago

Moved the metacat.properties file from the jar file to now be located in
the tomcat context directory in WEB-INF. Now the metacat configuration is
editable in place. This change depends on a new Options.java class in the
utilities module, so be sure you do a "clean" build in metacat so that you
pick up this new class. This satisfies needs for bug 1230.

View differences:

lib/metacat.properties
3 3
# Matt Jones, Dan Higgins, Jivka Bojilova
4 4
# '$Id$'
5 5
#
6
configured=false
6 7
user=@user@
7 8
password=@password@
8 9
defaultDB=@jdbc-connect@
src/edu/ucsb/nceas/metacat/MetaCatUtil.java
40 40
import java.util.Vector;
41 41

  
42 42
import edu.ucsb.nceas.dbadapter.AbstractDatabase;
43
import edu.ucsb.nceas.utilities.Options;
43 44

  
44 45
/**
45 46
 * A suite of utility classes for the metadata catalog server
......
47 48
public class MetaCatUtil {
48 49

  
49 50
  public static AbstractDatabase dbAdapter;
50
  private static PropertyResourceBundle options = null;
51
  private static String propertiesFile = "edu.ucsb.nceas.metacat.metacat";
51
  private static Options options = null;
52 52
  private static boolean debug = true;
53 53

  
54 54
  //private Hashtable connectionPool = new Hashtable();
......
91 91
   * Utility method to get an option value from the properties file
92 92
   *
93 93
   * @param optionName the name of the option requested
94
   * @return the String value for the option, or null if not set
94 95
   */
95 96
  public static String getOption(String optionName) {
96
      // Get the configuration file information
97 97
      if (options == null) {
98
        options = (PropertyResourceBundle)
99
          PropertyResourceBundle.getBundle(propertiesFile);
98
        options = Options.getInstance();
100 99
      }
101
      String value = (String)options.handleGetObject(optionName);
100
      String value = options.getOption(optionName);
102 101
      return value;
103 102
  }
104 103

  
105
  /**
106
   * Utility method to get an option value from a properties file
107
   *
108
   * @param optionName the name of the option requested
109
   * @param propFile the name of the file where to get the properties from
110
   */
111
  public String getOption(String optionName, String propFile) {
112
    // Get the configuration file information
113
    PropertyResourceBundle options = (PropertyResourceBundle)
114
                                     PropertyResourceBundle.getBundle(propFile);
115
    String value = (String)options.handleGetObject(optionName);
116
    return value;
117
  }
118

  
119

  
120

  
121

  
122 104
  /** Utility method to convert a file handle into a URL */
123 105
  public static URL fileToURL(File file)
124 106
  {
......
238 220

  
239 221
  public static Vector getOptionList(String optiontext)
240 222
  {
241
    Vector options = new Vector();
223
    Vector optionsVector = new Vector();
242 224
    if(optiontext.indexOf(",") == -1)
243 225
    {
244
      options.addElement(optiontext);
245
      return options;
226
      optionsVector.addElement(optiontext);
227
      return optionsVector;
246 228
    }
247 229

  
248 230
    while(optiontext.indexOf(",") != -1)
249 231
    {
250 232
      String s = optiontext.substring(0, optiontext.indexOf(","));
251
      options.addElement(s.trim());
233
      optionsVector.addElement(s.trim());
252 234
      optiontext = optiontext.substring(optiontext.indexOf(",") + 1,
253 235
                                        optiontext.length());
254 236
      if(optiontext.indexOf(",") == -1)
255 237
      { //catch the last list entry
256
        options.addElement(optiontext.trim());
238
        optionsVector.addElement(optiontext.trim());
257 239
      }
258 240
    }
259
    return options;
241
    return optionsVector;
260 242
  }
261 243

  
262 244
  /** Normalizes the given string. Taken from configXML.java*/
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
66 66
import javax.servlet.ServletOutputStream;
67 67

  
68 68
import org.ecoinformatics.eml.EMLParser;
69
import edu.ucsb.nceas.utilities.Options;
69 70

  
70 71
import org.xml.sax.SAXException;
71 72

  
......
127 128
  public static final String SCHEMALOCATIONKEYWORD = ":schemaLocation";
128 129
  public static final String NONAMESPACELOCATION = ":noNamespaceSchemaLocation";
129 130
  public static final String EML2KEYWORD =":eml";
131
  private static final String CONFIG_DIR  = "WEB-INF";
132
  private static final String CONFIG_NAME = "metacat.properties";
130 133

  
131 134
  /**
132 135
   * Initialize the servlet by creating appropriate database connections
......
138 141
      this.context = config.getServletContext();
139 142
      System.out.println("MetaCatServlet Initialize");
140 143

  
144
      // Initialize the properties file for our options
145
      String dirPath = context.getRealPath(CONFIG_DIR);
146
      File propertyFile = new File(dirPath,CONFIG_NAME);
147
      Options options = null;
148
      try {
149
          options = Options.initialize(propertyFile);
150
          MetaCatUtil.debugMessage("Options configured: " + 
151
            options.getOption("configured"), 20);
152
      } catch (IOException ioe) {
153
        MetaCatUtil.debugMessage("Error in loading options: "
154
           +ioe.getMessage(), 20);
155
      }
156

  
141 157
      util = new MetaCatUtil();
142 158

  
143 159
      //initial DBConnection pool
build.xml
286 286
              classpath="${cpath}"
287 287
              debug="${debug}"
288 288
              excludes="**/*.sql **/stringclient/** **/client/*.java"/>
289
       <copy file="lib/metacat.properties"
290
             tofile="${build.dest}/${package.home}/metacat.properties"
291
             filtering="yes" />
292 289
       <copy file="lib/srbProps.properties"
293 290
             tofile="${build.dest}/${package.home}/srbProps.properties"/>
294 291
   </target>
......
513 510
       <copy file="${jdbc}" tofile="${installdir}/WEB-INF/lib/jdbc.jar" />
514 511
       <copy file="lib/web.xml.${tomcatversion}"
515 512
             tofile="${installdir}/WEB-INF/web.xml" />
513
       <copy file="lib/metacat.properties" todir="${installdir}/WEB-INF"
514
             filtering="yes" />
516 515
       <copy todir="${installdir}" filtering="no">
517 516
         <fileset dir="lib">
518 517
           <include name="**/*.jpg"/>

Also available in: Unified diff