Project

General

Profile

« Previous | Next » 

Revision 1538

Added by berkley over 21 years ago

added a prefix to the debug statements. the default is the build name property. The prefix can be set in the build.xml file. the property name is 'debugprefix'

View differences:

src/edu/ucsb/nceas/metacat/MetaCatUtil.java
5 5
 *             National Center for Ecological Analysis and Synthesis
6 6
 *    Authors: Matt Jones, Jivka Bojilova
7 7
 *    Release: @release@
8
 * 
8
 *
9 9
 *   '$Author$'
10 10
 *     '$Date$'
11 11
 * '$Revision$'
......
52 52

  
53 53
  //private Hashtable connectionPool = new Hashtable();
54 54

  
55
  /** 
55
  /**
56 56
   * Determine our db adapter class and create an instance of that class
57 57
   */
58 58
  static {
......
71 71
   * @param className the fully qualified name of the class to instantiate
72 72
   */
73 73
  public static Object createObject(String className) throws Exception {
74
 
74

  
75 75
    Object object = null;
76 76
    try {
77 77
      Class classDefinition = Class.forName(className);
......
86 86
    return object;
87 87
  }
88 88

  
89
  /** 
89
  /**
90 90
   * Utility method to get an option value from the properties file
91 91
   *
92 92
   * @param optionName the name of the option requested
......
101 101
      return value;
102 102
  }
103 103

  
104
  /** 
104
  /**
105 105
   * Utility method to get an option value from a properties file
106 106
   *
107 107
   * @param optionName the name of the option requested
......
115 115
    return value;
116 116
  }
117 117

  
118
 
119
  
120
  
118

  
119

  
120

  
121 121
  /** Utility method to convert a file handle into a URL */
122 122
  public static URL fileToURL(File file)
123 123
  {
......
137 137
     }
138 138
  }
139 139

  
140
  /** 
140
  /**
141 141
   * Utility method to parse the query part of a URL into parameters. This
142
   * method assumes the format of the query par tof the url is an 
142
   * method assumes the format of the query par tof the url is an
143 143
   * ampersand separated list of name/value pairs, with equal signs separating
144 144
   * the name from the value (e.g., name=tom&zip=99801 ). Returns a
145 145
   * has of the name value pairs, hashed on name.
......
155 155
    int arrcount = 0;
156 156

  
157 157
    if ( query != null ) {
158
      for (int i=0; i < query.length(); i++) { 
158
      for (int i=0; i < query.length(); i++) {
159 159

  
160 160
        // go throught the remainder of the query one character at a time.
161
        if (query.charAt(i) == '=') { 
161
        if (query.charAt(i) == '=') {
162 162
          // if the current char is a # then the preceding should be a name
163 163
          if (!poundflag && ampflag) {
164 164
            params[arrcount][0] = temp.trim();
165 165
            temp = "";
166
          } else { 
166
          } else {
167 167
            //if there are two #s or &s in a row throw an exception.
168 168
            throw new MalformedURLException("metacatURL: Two parameter names "+
169 169
                                            "not allowed in sequence");
170 170
          }
171 171
          poundflag = true;
172 172
          ampflag = false;
173
        } else if (query.charAt(i) == '&' || i == query.length()-1) { 
173
        } else if (query.charAt(i) == '&' || i == query.length()-1) {
174 174
          //the text preceding the & should be the param value.
175
          if (i == query.length() - 1) { 
175
          if (i == query.length() - 1) {
176 176
            //if at the end of the string grab the last value and append it.
177
            if (query.charAt(i) != '=') { 
177
            if (query.charAt(i) != '=') {
178 178
            //ignore an extra & on the end of the string
179 179
              temp += query.charAt(i);
180 180
            }
181 181
          }
182
  
182

  
183 183
          if (!ampflag && poundflag) {
184 184
            params[arrcount][1] = temp.trim();
185 185
            parameters.put(params[arrcount][0], params[arrcount][1]);
186 186
            temp = "";
187 187
            arrcount++; //increment the array to the next row.
188
          } else { 
188
          } else {
189 189
            //if there are two =s or &s in a row through an exception
190 190
            throw new MalformedURLException("metacatURL: Two parameter values "+
191 191
                                            "not allowed in sequence");
192 192
          }
193 193
          poundflag = false;
194 194
          ampflag = true;
195
        } else { 
195
        } else {
196 196
          //get the next character in the string
197 197
          temp += query.charAt(i);
198 198
        }
......
201 201
    return parameters;
202 202
  }
203 203

  
204
   /** 
204
   /**
205 205
   * Utility method to print debugging messages. User can set debug level
206 206
   * for this message. The number is fewer, the message is more important
207 207
   * @param msg, the content of the message
208 208
   * @param debugLevel, an integer indicating the message debug leve
209 209
   */
210
  public static void debugMessage(String msg, int debugLevel) 
210
  public static void debugMessage(String msg, int debugLevel)
211 211
  {
212 212
    if (debug)
213 213
    {
214 214
      int limit = 1;
215
      try 
215
      try
216 216
      {
217 217
        limit=Integer.parseInt(getOption("debuglevel"));
218
     
218

  
219 219
      }
220 220
      catch (Exception e)
221 221
      {
......
226 226
      {
227 227
        debugLevel=1;
228 228
      }
229
    
230
      if (debugLevel < limit) 
229

  
230
      if (debugLevel < limit)
231 231
      {
232
        System.err.println(msg);
232
        System.err.println("@debugprefix@ " +msg);
233 233
      }
234 234
    }
235 235
  }
236
  
237
  
236

  
237

  
238 238
  public static Vector getOptionList(String optiontext)
239 239
  {
240 240
    Vector options = new Vector();
......
243 243
      options.addElement(optiontext);
244 244
      return options;
245 245
    }
246
    
246

  
247 247
    while(optiontext.indexOf(",") != -1)
248 248
    {
249 249
      String s = optiontext.substring(0, optiontext.indexOf(","));
250 250
      options.addElement(s.trim());
251
      optiontext = optiontext.substring(optiontext.indexOf(",") + 1, 
251
      optiontext = optiontext.substring(optiontext.indexOf(",") + 1,
252 252
                                        optiontext.length());
253 253
      if(optiontext.indexOf(",") == -1)
254 254
      { //catch the last list entry
......
257 257
    }
258 258
    return options;
259 259
  }
260
  
260

  
261 261
  /** Normalizes the given string. Taken from configXML.java*/
262 262
  public static String normalize(String s)
263 263
  {
......
301 301
      }
302 302
    }
303 303
    return (str.toString());
304
  } 
305
  
306
  /** 
304
  }
305

  
306
  /**
307 307
   * Utility method to get docid from a given string
308 308
   * @param string, the given string should be these two format:
309 309
   *              1) str1.str2  in this case docid= str1.str2
......
315 315
    String docId = null;
316 316
    int dotNumber = 0;//count how many dots in given string
317 317
    int indexOfLastDot = 0;
318
    
318

  
319 319
    //assume that seperator is one charactor string
320 320
    char seperator=getOption("accNumSeparator").charAt(0);
321
     
321

  
322 322
    for (int i=0; i<str.length(); i++)
323 323
    {
324 324
      if ( str.charAt(i)==seperator)
......
327 327
        indexOfLastDot=i;//keep the last dot postion
328 328
      }
329 329
    }//for
330
    
330

  
331 331
    //The string formatt is wrong, because it has more than two or less than
332 332
    //one seperator
333 333
    if ( dotNumber>2 || dotNumber < 1)
......
342 342
    {
343 343
      docId=str;
344 344
    }
345
    
346
    return docId;  
345

  
346
    return docId;
347 347
  }//getDocIdFromString
348 348

  
349
  /** 
349
  /**
350 350
   * Utility method to get version number from a given string
351 351
   * @param string, the given string should be these two format:
352 352
   *              1) str1.str2(no version)  version =-1;
......
360 360
    String versionString=null;
361 361
    int dotNumber = 0;//count how many dots in given string
362 362
    int indexOfLastDot = 0;
363
    
363

  
364 364
    //assume that seperator is one charactor string
365 365
    char seperator=getOption("accNumSeparator").charAt(0);
366
    
366

  
367 367
    for (int i=0; i<str.length(); i++)
368 368
    {
369 369
      if ( str.charAt(i)==seperator)
......
372 372
        indexOfLastDot=i;//keep the last dot postion
373 373
      }
374 374
    }//for
375
    
375

  
376 376
    //The string formatt is wrong, because it has more than two or less than
377 377
    //one seperator
378 378
    if ( dotNumber>2 || dotNumber < 1)
379 379
    {
380 380
      version=-2;
381 381
    }
382
    else if (dotNumber == 2 && (indexOfLastDot != (str.length() -1))) 
382
    else if (dotNumber == 2 && (indexOfLastDot != (str.length() -1)))
383 383
     //the case for str1.str2.str3
384 384
    {
385 385
       versionString=str.substring((indexOfLastDot+1), str.length());
......
389 389
    {
390 390
      version=-1;
391 391
    }
392
    
393
    return version;  
392

  
393
    return version;
394 394
  }//getVersionFromString
395
  
396
  
397
  /** 
395

  
396

  
397
  /**
398 398
   * Utility method to get version string from a given string
399 399
   * @param string, the given string should be these two format:
400 400
   *              1) str1.str2(no version)  version=null;
......
408 408
    String versionString=null;
409 409
    int dotNumber = 0;//count how many dots in given string
410 410
    int indexOfLastDot = 0;
411
    
411

  
412 412
    //assume that seperator is one charactor string
413 413
    char seperator=getOption("accNumSeparator").charAt(0);
414
    
414

  
415 415
    for (int i=0; i<str.length(); i++)
416 416
    {
417 417
      if ( str.charAt(i)==seperator)
......
420 420
        indexOfLastDot=i;//keep the last dot postion
421 421
      }
422 422
    }//for
423
    
423

  
424 424
    //The string formatt is wrong, because it has more than two or less than
425 425
    //one seperator
426 426
    if ( dotNumber>2 || dotNumber < 1)
427 427
    {
428 428
      versionString = null;
429 429
    }
430
    else if (dotNumber == 2 && (indexOfLastDot != (str.length() -1))) 
430
    else if (dotNumber == 2 && (indexOfLastDot != (str.length() -1)))
431 431
    {
432 432
      //the case for str1.str2.str3
433 433
      // indexOfLastDot != (str.length() -1) means get rid of str1.str2.
......
437 437
    {
438 438
      versionString=null;
439 439
    }
440
    
441
    return versionString;  
440

  
441
    return versionString;
442 442
  }//getVersionFromString
443
   
443

  
444 444
  /**
445 445
   * Method to get the name of local replication server
446 446
   */
......
452 452
     // append "context/servelet/replication" to the host name
453 453
     replicationServerName=serverHost+getOption("replicationpath");
454 454
     return replicationServerName;
455
       
455

  
456 456
   }
457
   
457

  
458 458
   /**
459 459
    * Method to get docidwithrev from eml2 inline data id
460 460
    * The eml inline data id would look like eml.200.2.3
......
485 485
         break;
486 486
       }
487 487
     }
488
      
489
     MetaCatUtil.debugMessage("Docid without rev from inlinedata id: " + 
488

  
489
     MetaCatUtil.debugMessage("Docid without rev from inlinedata id: " +
490 490
                               docidWithoutRev, 35);
491 491
     return docidWithoutRev;
492
     
492

  
493 493
   }
494
  
494

  
495 495
}
build.xml
44 44
   <target name="postgresql">
45 45
     <!-- Customize these properties if you are using postgres -->
46 46
     <property name="jdbc-connect"
47
               value="jdbc:postgresql://localhost/exp"/>
47
               value="jdbc:postgresql://localhost/metacat"/>
48 48
     <property name="dbDriver" value="org.postgresql.Driver"/>
49 49
     <property name="dbAdapter"
50 50
               value="edu.ucsb.nceas.dbadapter.PostgresqlAdapter"/>
......
57 57

  
58 58
      <!-- Customize these properties for your system -->
59 59
      <property name="tomcat" value="/usr/local/devtools/jakarta-tomcat" />
60
      <property name="webapps" value="/usr/local/devtools/jakarta-tomcat/webapps" />
61
      <property name="context" value="tao" />
62
      <property name="user" value="tao"/>
63
      <property name="password" value="tdataint"/>
64
      <property name="server" value="pine.nceas.ucsb.edu:8443"/>
65
      <property name="systemidserver" value="http://pine.nceas.ucsb.edu:8080" />
66
      <property name="datafilepath" value="/usr/local/devtools/jakarta-tomcat/data/tao/data" />
67
      <property name="inlinedatafilepath" value="/usr/local/devtools/jakarta-tomcat/data/tao/inlinedata" />
60
      <property name="webapps" value="/opt/tomcat/webapps" />
61
      <property name="context" value="metacat" />
62
      <property name="user" value="berkley"/>
63
      <property name="password" value=""/>
64
      <property name="server" value="trestles.nceas.ucsb.edu:8080"/>
65
      <property name="systemidserver" value="http://trestles.nceas.ucsb.edu:8080" />
66
      <property name="datafilepath" value="/opt/tomcat/data/metacat/data" />
67
      <property name="inlinedatafilepath" value="/opt/tomcat/data/metacat/inlinedata" />
68 68
      <property name="debuglevel" value="45" />
69 69
      <property name="forcereplicationwaitingtime" value="30000"/>
70 70
      <property name="cvsroot"
71
                value=":ext:tao@cvs.ecoinformatics.org:/cvs" />
71
                value=":ext:berkley@cvs.ecoinformatics.org:/cvs" />
72 72
      <property name="web-base-url"
73 73
                value="http://knb.ecoinformatics.org"/>
74 74
      <property name="default-style" value="knb" />
......
110 110
      <property name="installdir" value="${webapps}/${context}" />
111 111
      <property name="name" value="metacat"/>
112 112
      <property name="Name" value="MetaCat"/>
113
      <property name="debugprefix" value="${Name}:"/>
113 114
      <property name="release" value="1.2.1"/>
114 115
      <property name="replication-path"
115 116
                value="/${context}/servlet/replication"/>
......
153 154
      <filter token="datafilepath" value="${datafilepath}" />
154 155
      <filter token="inlinedatafilepath" value="${inlinedatafilepath}" />
155 156
      <filter token="defaultcontenttype" value="${defaultcontenttype}" />
157
      <filter token="debugprefix" value="${debugprefix}"/>
156 158

  
157 159
      <property name="srcdir" value="./src" />
158 160
      <property name="junittestsdir" value="./test/edu/ucsb/nceas/metacattest" />

Also available in: Unified diff