Project

General

Profile

« Previous | Next » 

Revision 2665

Added by sgarg over 18 years ago

Commited the wrong MetaCatUtil.java file last time. Making the changes again.

1. Replacing MetaCatUtil.debugMessage or MetaCatUtil.logMetacat call with logMetacat (private Logger object) call
2. Commented out debugMessage()
3. Removed getLog() and earlier old log4j code
4. Removed formattedDebugMessage

View differences:

src/edu/ucsb/nceas/metacat/MetaCatUtil.java
36 36
import java.util.regex.PatternSyntaxException;
37 37

  
38 38
import org.apache.log4j.Logger;
39
import org.apache.log4j.PropertyConfigurator;
40
import org.apache.log4j.BasicConfigurator;
41 39

  
42 40
import edu.ucsb.nceas.dbadapter.AbstractDatabase;
43 41
import edu.ucsb.nceas.utilities.Options;
......
63 61
    private static String[] allowedSubmitters;
64 62

  
65 63
    private static String[] deniedSubmitters;
64
    
65
    private static Logger logMetacat = Logger.getLogger(MetaCatUtil.class);
66 66

  
67
    public static Logger logMetacat = null;
68

  
69
    private static Logger logInfoMetacat = null;
70
    
71 67
    static {
72

  
73
        MetaCatUtil.logMetacat = Logger.getLogger("Metacat");
74
        PropertyConfigurator.configure(MetaCatServlet.LOG_CONFIG_NAME);
75
    	
76
        MetaCatUtil.logInfoMetacat = Logger.getLogger("Metacat");
77
        //BasicConfigurator.configure();
78

  
79 68
    	// Determine our db adapter class and create an instance of that class
80 69
        try {
81 70
            dbAdapter = (AbstractDatabase) createObject(getOption("dbAdapter"));
......
87 76
        // read administrator and moderator lists from metacat.properties
88 77
        getUserAccessControlLists();
89 78
    }
90

  
79
    
91 80
    /**
92 81
     * Instantiate a class using the name of the class at runtime
93 82
     *
......
125 114
        return value;
126 115
    }
127 116
    
128
    
129
    public static Logger getLog() {
130
    	  return logMetacat;
131
    }
132
    
133 117
    /**
134 118
     * Utility method to set an option value from the properties file
135 119
     *
......
242 226
     * @param msg, the content of the message
243 227
     * @param debugLevel, an integer indicating the message debug leve
244 228
     */
245
    public static void debugMessage(String msg, int debugLevel)
246
    {
247
        if (debug) {
248
            int limit = 1;
249
            try {
250
                limit = Integer.parseInt(getOption("debuglevel"));
229
    /** 
230
     * Commenting out the function for now...
231
     * public static void debugMessage(String msg, int debugLevel)
232
     * {
233
     *   if (debug) {
234
     *       int limit = 1;
235
     *       try {
236
     *           limit = Integer.parseInt(getOption("debuglevel"));
237
     *
238
     *       } catch (Exception e) {
239
     *           System.out.println(e.getMessage());
240
     *       }
241
     *       //don't allow the user set debugLevel less than or equals 0
242
     *       if (debugLevel <= 0) {
243
     *           debugLevel = 1;
244
     *       }
245
     *
246
     *       if (debugLevel < limit) {
247
     *           System.err.println("@debugprefix@ " + msg);
248
     *       }
249
     *   }
250
     *}
251
     */
251 252

  
252
            } catch (Exception e) {
253
                System.out.println(e.getMessage());
254
            }
255
            //don't allow the user set debugLevel less than or equals 0
256
            if (debugLevel <= 0) {
257
                debugLevel = 1;
258
            }
259 253

  
260
            if (debugLevel < limit) {
261
                System.err.println("@debugprefix@ " + msg);
262
            }
263
        }
264
    }
265

  
266

  
267 254
    /**
268 255
     * Utility method to print debugging messages. User can set debug level for
269
     * this message. The number is fewer, the message is more important. Can be
270
     * used to control if the carriage return and debugPrefix are printed
256
     * this message. The number is fewer, the message is more important
271 257
     *
272 258
     * @param msg, the content of the message
273
     * @param debugLevel, an integer indicating the message debug level
274
     * @param debugPrefix, a boolean indicating whether debugprefix
275
     *                    should be printed or not
259
     * @param debugLevel, an integer indicating the message debug leve
276 260
     */
277
    public static void formattedDebugMessage(String msg, int debugLevel,
278
                                      boolean carriageReturn,
279
                                      boolean debugPrefix)
261
    public static void printMessage(String msg)
280 262
    {
281
        if (debug) {
282
            int limit = 1;
283
            try {
284
                limit = Integer.parseInt(getOption("debuglevel"));
285

  
286
            } catch (Exception e) {
287
                System.out.println(e.getMessage());
288
            }
289
            //don't allow the user set debugLevel less than or equals 0
290
            if (debugLevel <= 0) {
291
                debugLevel = 1;
292
            }
293

  
294
            if (debugLevel < limit) {
295
                if(debugPrefix) {
296
                    if(carriageReturn)
297
                        System.err.println("@debugprefix@ " + msg);
298
                    else
299
                        System.err.print("@debugprefix@ " + msg);
300
                } else {
301
                    if(carriageReturn)
302
                        System.err.println(msg);
303
                    else
304
                        System.err.print(msg);
305
                }
306
            }
307
        }
263
    	System.err.println("@debugprefix@ " + msg);
308 264
    }
309

  
310

  
265
    
266
  
311 267
    public static Vector getOptionList(String optiontext)
312 268
    {
313 269
        Vector optionsVector = new Vector();
......
414 370
        int count = 0; //keep track how many & was found
415 371
        Vector list = new Vector();// keep index number for &
416 372
        if (url == null) {
417
            MetaCatUtil.debugMessage("url is null and null will be returned",
418
                    30);
373
            logMetacat.info("url is null and null will be returned");
419 374
            return docid;
420 375
        }
421 376
        // the first element in list is 0
......
428 383
                // get substring beween two &
429 384
                String str = url.substring(
430 385
                        ((Integer) list.elementAt(count - 1)).intValue(), i);
431
                MetaCatUtil.debugMessage("substring between two & is: " + str,
432
                        30);
386
                logMetacat.info("substring between two & is: " + str);
433 387
                //if the subString contains docid, we got it
434 388
                if (str.indexOf(DOCID) != -1) {
435 389
                    //get index of '="
......
444 398
        // and
445 399
        // the end of string
446 400
        if (!find) {
447
            MetaCatUtil.debugMessage("Checking the last substring", 35);
401
            logMetacat.info("Checking the last substring");
448 402
            String str = url.substring(((Integer) list.elementAt(count))
449 403
                    .intValue() + 1, url.length());
450
            MetaCatUtil.debugMessage("Last substring is: " + str, 30);
404
            logMetacat.info("Last substring is: " + str);
451 405
            if (str.indexOf(DOCID) != -1) {
452 406
                //get index of '="
453 407
                int start = getIndexForGivenChar(str, '=') + 1;
......
456 410
                find = true;
457 411
            }//if
458 412
        }//if
459
        MetaCatUtil.debugMessage("The docid from online url is:" + docid, 30);
413
        logMetacat.info("The docid from online url is:" + docid);
460 414
        return docid.trim();
461 415
    }
462 416

  
......
479 433
        int end   = identifier.length();
480 434
        accessionNumber = identifier.substring(start, end);
481 435
      }
482
      MetaCatUtil.debugMessage("The accession number from url is " +
483
                                 accessionNumber, 10);
436
      logMetacat.warn("The accession number from url is " +
437
                                 accessionNumber);
484 438
      return accessionNumber;
485 439
    }
486 440

  
......
489 443
        int index = -1;
490 444
        // make sure str is not null
491 445
        if (str == null) {
492
            MetaCatUtil.debugMessage(
493
                    "The given str is null and -1 will be returned", 30);
446
            logMetacat.info(
447
                    "The given str is null and -1 will be returned");
494 448
            return index;
495 449
        }
496 450
        // got though the string
......
501 455
                break;
502 456
            }//if
503 457
        }//for
504
        MetaCatUtil.debugMessage("the index for char " + character + " is: "
505
                + index, 30);
458
        logMetacat.info("the index for char " + character + " is: "
459
                + index);
506 460
        return index;
507 461
    }
508 462

  
......
518 472
    {
519 473
        String docId = null;
520 474
        if (str == null) {
521
            MetaCatUtil.debugMessage(
475
            logMetacat.info(
522 476
                    "The given str is null and null will be returned"
523
                            + " in getDocIdfromString", 30);
477
                            + " in getDocIdfromString");
524 478
            return docId;
525 479
        } //make sure docid is not null
526 480
        int dotNumber = 0;//count how many dots in given string
......
649 603
        String seperator = getOption("accNumSeparator");
650 604
        int indexOfLastSeperator = accessionNumber.lastIndexOf(seperator);
651 605
        docid = accessionNumber.substring(0, indexOfLastSeperator);
652
        MetaCatUtil.debugMessage("after parsing accessionnumber, docid is "
653
                + docid, 30);
606
        logMetacat.info("after parsing accessionnumber, docid is "
607
                + docid);
654 608
        return docid;
655 609
    }
656 610

  
......
669 623
        accessionNumber = accessionNumber.substring(0, indexOfLastSeperator);
670 624
        indexOfLastSeperator = accessionNumber.lastIndexOf(seperator);
671 625
        docid = accessionNumber.substring(0, indexOfLastSeperator) + version;
672
        MetaCatUtil.debugMessage("after parsing accessionnumber, docid is "
673
                                 + docid, 30);
626
        logMetacat.info("after parsing accessionnumber, docid is "
627
                                 + docid);
674 628

  
675 629
        return docid;
676 630
    }
......
694 648
        if (docid == null) {
695 649
            docid = getDocIdFromAccessionNumber(str);
696 650
        }
697
        MetaCatUtil.debugMessage("The docid get from smart docid getor is "
698
                + docid, 30);
651
        logMetacat.info("The docid get from smart docid getor is "
652
                + docid);
699 653
        return docid;
700 654
    }
701 655

  
......
715 669
        rev = accessionNumber.substring(indexOfLastSeperator + 1,
716 670
                accessionNumber.length());
717 671
        revNumber = Integer.parseInt(rev);
718
        MetaCatUtil.debugMessage("after parsing accessionnumber, rev is "
719
                + revNumber, 30);
672
        logMetacat.info("after parsing accessionnumber, rev is "
673
                + revNumber);
720 674
        return revNumber;
721 675
    }
722 676

  
......
759 713
            }
760 714
        }
761 715

  
762
        MetaCatUtil.debugMessage("Docid without rev from inlinedata id: "
763
                + docidWithoutRev, 35);
716
        logMetacat.info("Docid without rev from inlinedata id: "
717
                + docidWithoutRev);
764 718
        return docidWithoutRev;
765 719

  
766 720
    }
......
801 755
            }
802 756

  
803 757
        }//for
804
        MetaCatUtil.debugMessage("The new string without space is:"
805
                + newUrl.toString(), 35);
758
        logMetacat.info("The new string without space is:"
759
                + newUrl.toString());
806 760
        return newUrl.toString();
807 761

  
808 762
    }// replaceWhiteSpaceForUR
......
834 788
            
835 789
        } catch (PatternSyntaxException pse) {
836 790
        	list = null;
837
            MetaCatUtil.debugMessage("Error in MetacatServlet.init: "
838
                + pse.getMessage(), 20);
791
            logMetacat.error("Error in MetacatServlet.init: "
792
                + pse.getMessage());
839 793
        }
840 794
        return list;
841 795
    }

Also available in: Unified diff