KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > core > ConfigurationManager


1 /*
2  * ConfigurationManager.java
3  *
4  * Version: $Revision: 1.27 $
5  *
6  * Date: $Date: 2006/11/24 04:56:53 $
7  *
8  * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
9  * Institute of Technology. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *
15  * - Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * - Neither the name of the Hewlett-Packard Company nor the name of the
23  * Massachusetts Institute of Technology nor the names of their
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38  * DAMAGE.
39  */

40 package org.dspace.core;
41
42 import java.io.BufferedReader JavaDoc;
43 import java.io.File JavaDoc;
44 import java.io.FileInputStream JavaDoc;
45 import java.io.FileOutputStream JavaDoc;
46 import java.io.FileReader JavaDoc;
47 import java.io.FileWriter JavaDoc;
48 import java.io.IOException JavaDoc;
49 import java.io.InputStream JavaDoc;
50 import java.io.InputStreamReader JavaDoc;
51 import java.io.OutputStreamWriter JavaDoc;
52 import java.io.PrintWriter JavaDoc;
53 import java.net.MalformedURLException JavaDoc;
54 import java.util.Enumeration JavaDoc;
55 import java.util.Properties JavaDoc;
56
57 import org.apache.log4j.Logger;
58 import org.apache.log4j.PropertyConfigurator;
59 import org.apache.log4j.xml.DOMConfigurator;
60
61 /**
62  * Class for reading the DSpace system configuration. The main configuration is
63  * read in as properties from a standard properties file. Email templates and
64  * configuration files for other tools are also be accessed via this class.
65  * <P>
66  * The main configuration is by default read from the <em>resource</em>
67  * <code>/dspace.cfg</code>.
68  * To specify a different configuration, the system property
69  * <code>dspace.configuration</code> should be set to the <em>filename</em>
70  * of the configuration file.
71  * <P>
72  * Other configuration files are read from the <code>config</code> directory
73  * of the DSpace installation directory (specified as the property
74  * <code>dspace.dir</code> in the main configuration file.)
75  * <P>
76  * Configuration files for other tools are kept in <code>config/templates</code>
77  * and can contain placeholders for configuration values from
78  * <code>dspace.cfg</code>. See <code>installConfigurations</code> for
79  * details.
80  *
81  * @author Robert Tansley
82  * @author Larry Stone - Interpolated values.
83  * @version $Revision: 1.27 $
84  */

85 public class ConfigurationManager
86 {
87     /** log4j category */
88     private static Logger log = null;
89
90     /** The configuration properties */
91     private static Properties JavaDoc properties = null;
92
93     /** The default license */
94     private static String JavaDoc license;
95
96     // limit of recursive depth of property variable interpolation in
97
// configuration; anything greater than this is very likely to be a loop.
98
private final static int RECURSION_LIMIT = 9;
99
100     /**
101      * Get a configuration property
102      *
103      * @param property
104      * the name of the property
105      *
106      * @return the value of the property, or <code>null</code> if the property
107      * does not exist.
108      */

109     public static String JavaDoc getProperty(String JavaDoc property)
110     {
111         if (properties == null)
112         {
113             loadConfig(null);
114         }
115
116         return properties.getProperty(property);
117     }
118
119     /**
120      * Get a configuration property as an integer
121      *
122      * @param property
123      * the name of the property
124      *
125      * @return the value of the property. <code>0</code> is returned if the
126      * property does not exist. To differentiate between this case and
127      * when the property actually is zero, use <code>getProperty</code>.
128      */

129     public static int getIntProperty(String JavaDoc property)
130     {
131         if (properties == null)
132         {
133             loadConfig(null);
134         }
135
136         String JavaDoc stringValue = properties.getProperty(property);
137         int intValue = 0;
138
139         if (stringValue != null)
140         {
141             try
142             {
143                 intValue = Integer.parseInt(stringValue.trim());
144             }
145             catch (NumberFormatException JavaDoc e)
146             {
147                 warn("Warning: Number format error in property: " + property);
148             }
149         }
150
151         return intValue;
152     }
153
154     /**
155      * Get a configuration property as a boolean. True is indicated if the value
156      * of the property is <code>TRUE</code> or <code>YES</code> (case
157      * insensitive.)
158      *
159      * @param property
160      * the name of the property
161      *
162      * @return the value of the property. <code>false</code> is returned if
163      * the property does not exist. To differentiate between this case
164      * and when the property actually is false, use
165      * <code>getProperty</code>.
166      */

167     public static boolean getBooleanProperty(String JavaDoc property)
168     {
169         return getBooleanProperty(property, false);
170     }
171
172     /**
173      * Get a configuration property as a boolean, with default.
174      * True is indicated if the value
175      * of the property is <code>TRUE</code> or <code>YES</code> (case
176      * insensitive.)
177      *
178      * @param property
179      * the name of the property
180      *
181      * @param defaultValue
182      * value to return if property is not found.
183      *
184      * @return the value of the property. <code>default</code> is returned if
185      * the property does not exist. To differentiate between this case
186      * and when the property actually is false, use
187      * <code>getProperty</code>.
188      */

189     public static boolean getBooleanProperty(String JavaDoc property, boolean defaultValue)
190     {
191         if (properties == null)
192         {
193             loadConfig(null);
194         }
195
196         String JavaDoc stringValue = properties.getProperty(property);
197
198         if (stringValue != null)
199         {
200             stringValue = stringValue.trim();
201             return stringValue.equalsIgnoreCase("true") ||
202                     stringValue.equalsIgnoreCase("yes");
203         }
204         else
205         {
206             return defaultValue;
207         }
208     }
209
210     /**
211      * Returns an enumeration of all the keys in the DSpace configuration
212      *
213      * @return an enumeration of all the keys in the DSpace configuration
214      */

215     public static Enumeration JavaDoc propertyNames()
216     {
217         if (properties == null)
218             loadConfig(null);
219
220         return properties.propertyNames();
221     }
222
223     /**
224      * Get the template for an email message. The message is suitable for
225      * inserting values using <code>java.text.MessageFormat</code>.
226      *
227      * @param template
228      * name for the email template, for example "register".
229      *
230      * @return the email object, with the content and subject filled out from
231      * the template
232      *
233      * @throws IOException
234      * if the template couldn't be found, or there was some other
235      * error reading the template
236      */

237     public static Email getEmail(String JavaDoc template) throws IOException JavaDoc
238     {
239         String JavaDoc subject = "";
240         StringBuffer JavaDoc contentBuffer = new StringBuffer JavaDoc();
241
242         // Read in template
243
BufferedReader JavaDoc reader = null;
244         try
245         {
246             reader = new BufferedReader JavaDoc(new FileReader JavaDoc(
247                     getProperty("dspace.dir") +
248
249                     File.separator + "config" + File.separator + "emails"
250                             + File.separator + template));
251
252             boolean more = true;
253
254             while (more)
255             {
256                 String JavaDoc line = reader.readLine();
257
258                 if (line == null)
259                 {
260                     more = false;
261                 }
262                 else if (line.toLowerCase().startsWith("subject:"))
263                 {
264                     // Extract the first subject line - everything to the right
265
// of the colon, trimmed of whitespace
266
subject = line.substring(8).trim();
267                 }
268                 else if (!line.startsWith("#"))
269                 {
270                     // Add non-comment lines to the content
271
contentBuffer.append(line);
272                     contentBuffer.append("\n");
273                 }
274             }
275         }
276         finally
277         {
278             if (reader != null)
279             {
280                 reader.close();
281             }
282         }
283         // Create an email
284
Email email = new Email();
285         email.setSubject(subject);
286         email.setContent(contentBuffer.toString());
287
288         return email;
289     }
290
291     /**
292      * Get the site-wide default license that submitters need to grant
293      *
294      * @return the default license
295      */

296     public static String JavaDoc getDefaultSubmissionLicense()
297     {
298         if (properties == null)
299         {
300             loadConfig(null);
301         }
302
303         return license;
304     }
305
306     /**
307      * Get the path for the news files.
308      *
309      */

310     public static String JavaDoc getNewsFilePath()
311     {
312         String JavaDoc filePath = ConfigurationManager.getProperty("dspace.dir")
313                 + File.separator + "config" + File.separator;
314
315         return filePath;
316     }
317
318     /**
319      * Reads news from a text file.
320      *
321      * @param position
322      * a constant indicating which file (top or side) should be read
323      * in.
324      */

325     public static String JavaDoc readNewsFile(int position)
326     {
327         String JavaDoc fileName = getNewsFilePath();
328
329         if (position == Constants.NEWS_TOP)
330         {
331             fileName += "news-top.html";
332         }
333         else
334         {
335             fileName += "news-side.html";
336         }
337
338         String JavaDoc text = "";
339
340         try
341         {
342             // retrieve existing news from file
343
FileInputStream JavaDoc fir = new FileInputStream JavaDoc(fileName);
344             InputStreamReader JavaDoc ir = new InputStreamReader JavaDoc(fir, "UTF-8");
345             BufferedReader JavaDoc br = new BufferedReader JavaDoc(ir);
346
347             String JavaDoc lineIn;
348
349             while ((lineIn = br.readLine()) != null)
350             {
351                 text += lineIn;
352             }
353
354             br.close();
355         }
356         catch (IOException JavaDoc e)
357         {
358             warn("news_read: " + e.getLocalizedMessage());
359         }
360
361         return text;
362     }
363
364     /**
365      * Writes news to a text file.
366      *
367      * @param position
368      * a constant indicating which file (top or side) should be
369      * written to.
370      *
371      * @param news
372      * the text to be written to the file.
373      */

374     public static String JavaDoc writeNewsFile(int position, String JavaDoc news)
375     {
376         String JavaDoc fileName = getNewsFilePath();
377
378         if (position == Constants.NEWS_TOP)
379         {
380             fileName += "news-top.html";
381         }
382         else
383         {
384             fileName += "news-side.html";
385         }
386
387         try
388         {
389             // write the news out to the appropriate file
390
FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(fileName);
391             OutputStreamWriter JavaDoc osr = new OutputStreamWriter JavaDoc(fos, "UTF-8");
392             PrintWriter JavaDoc out = new PrintWriter JavaDoc(osr);
393             out.print(news);
394             out.close();
395         }
396         catch (IOException JavaDoc e)
397         {
398             warn("news_write: " + e.getLocalizedMessage());
399         }
400
401         return news;
402     }
403
404     /**
405      * Writes license to a text file.
406      *
407      * @param news
408      * the text to be written to the file.
409      */

410     public static void writeLicenseFile(String JavaDoc newLicense)
411     {
412         String JavaDoc licenseFile = getProperty("dspace.dir") + File.separator
413                              + "config" + File.separator + "default.license";
414
415         try
416         {
417             // write the news out to the appropriate file
418
FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(licenseFile);
419             OutputStreamWriter JavaDoc osr = new OutputStreamWriter JavaDoc(fos, "UTF-8");
420             PrintWriter JavaDoc out = new PrintWriter JavaDoc(osr);
421             out.print(newLicense);
422             out.close();
423         }
424         catch (IOException JavaDoc e)
425         {
426             warn("license_write: " + e.getLocalizedMessage());
427         }
428
429         license = newLicense;
430      }
431
432     private static File JavaDoc loadedFile = null;
433
434     /**
435      * Return the file that configuration was actually loaded from. Only returns
436      * a valid File after configuration has been loaded.
437      *
438      * @return File naming configuration data file, or null if not loaded yet.
439      */

440     public static File JavaDoc getConfigurationFile()
441     {
442         // in case it hasn't been done yet.
443
loadConfig(null);
444
445         return loadedFile;
446     }
447
448     /**
449      * Load the DSpace configuration properties. Only does anything if
450      * properties are not already loaded. Properties are loaded in from the
451      * specified file, or default locations.
452      *
453      * @param configFile
454      * The <code>dspace.cfg</code> configuration file to use, or
455      * <code>null</code> to try default locations
456      */

457     public static void loadConfig(String JavaDoc configFile)
458     {
459         InputStream JavaDoc is;
460
461         if (properties != null)
462         {
463             return;
464         }
465
466         String JavaDoc configProperty = System.getProperty("dspace.configuration");
467
468         try
469         {
470             if (configFile != null)
471             {
472                 is = new FileInputStream JavaDoc(configFile);
473                 loadedFile = new File JavaDoc(configFile);
474             }
475             // Has the default configuration location been overridden?
476
else if (configProperty != null)
477             {
478                 // Load the overriding configuration
479
is = new FileInputStream JavaDoc(configProperty);
480                 loadedFile = new File JavaDoc(configProperty);
481             }
482             else
483             {
484                 // Load configuration from default location
485
is = ConfigurationManager.class
486                         .getResourceAsStream("/dspace.cfg");
487                 loadedFile = new File JavaDoc(ConfigurationManager.class.getResource(
488                         "/dspace.cfg").getPath());
489             }
490
491             if (is == null)
492             {
493                 fatal("Cannot find dspace.cfg");
494                 throw new RuntimeException JavaDoc("Cannot find dspace.cfg");
495             }
496             else
497             {
498                 properties = new Properties JavaDoc();
499                 properties.load(is);
500
501                 // walk values, interpolating any embedded references.
502
for (Enumeration JavaDoc pe = properties.propertyNames(); pe.hasMoreElements(); )
503                 {
504                     String JavaDoc key = (String JavaDoc)pe.nextElement();
505                     String JavaDoc value = interpolate(key, 1);
506                     if (value != null)
507                         properties.setProperty(key, value);
508                 }
509             }
510
511             // Load in default license
512
String JavaDoc licenseFile = getProperty("dspace.dir") + File.separator
513                     + "config" + File.separator + "default.license";
514             
515             FileInputStream JavaDoc fir = new FileInputStream JavaDoc(licenseFile);
516             InputStreamReader JavaDoc ir = new InputStreamReader JavaDoc(fir, "UTF-8");
517             BufferedReader JavaDoc br = new BufferedReader JavaDoc(ir);
518             String JavaDoc lineIn;
519             license = "";
520
521             while ((lineIn = br.readLine()) != null)
522             {
523                 license = license + lineIn + '\n';
524             }
525
526             is.close();
527
528             // Load in log4j config
529
// Load the log4j config, if a log4j.xml version exists use that
530
// configuration format over the log4j.properties version
531
String JavaDoc log4jConfProp = ConfigurationManager
532                     .getProperty("dspace.dir")
533                     + File.separator
534                     + "config"
535                     + File.separator
536                     + "log4j.properties";
537             String JavaDoc log4jConfXml = ConfigurationManager
538                     .getProperty("dspace.dir")
539                     + File.separator + "config" + File.separator + "log4j.xml";
540
541             File JavaDoc xmlFile = new File JavaDoc(log4jConfXml);
542             if (xmlFile.exists())
543             {
544                 try
545                 {
546                     DOMConfigurator.configure(xmlFile.toURL());
547                     initLog();
548                     info("DSpace logging installed using log4j.xml");
549                 }
550                 catch (MalformedURLException JavaDoc e)
551                 {
552                     PropertyConfigurator.configure(log4jConfProp);
553                     initLog();
554                     error("Logger failed to load log4j.xml, defaulted to "
555                             + "log4j.properties: " + e);
556                 }
557             }
558             else
559             {
560                 PropertyConfigurator.configure(log4jConfProp);
561                 initLog();
562                 info("DSpace logging installed using log4j.properties");
563             }
564         }
565         catch (IOException JavaDoc e)
566         {
567             fatal("Can't load configuration", e);
568
569             // FIXME: Maybe something more graceful here, but with the
570
// configuration we can't do anything
571
throw new RuntimeException JavaDoc("Cannot find dspace.cfg",e);
572         }
573     }
574
575     /**
576      * Recursively interpolate variable references in value of
577      * property named "key".
578      * @return new value if it contains interpolations, or null
579      * if it had no variable references.
580      */

581     private static String JavaDoc interpolate(String JavaDoc key, int level)
582     {
583         if (level > RECURSION_LIMIT)
584             throw new IllegalArgumentException JavaDoc("ConfigurationManager: Too many levels of recursion in configuration property variable interpolation, property="+key);
585         String JavaDoc value = (String JavaDoc)properties.get(key);
586         int from = 0;
587         StringBuffer JavaDoc result = null;
588         while (from < value.length())
589         {
590             int start = value.indexOf("${", from);
591             if (start >= 0)
592             {
593                 int end = value.indexOf("}", start);
594                 if (end < 0)
595                     break;
596                 String JavaDoc var = value.substring(start+2, end);
597                 if (result == null)
598                     result = new StringBuffer JavaDoc(value.substring(from, start));
599                 else
600                     result.append(value.substring(from, start));
601                 if (properties.containsKey(var))
602                 {
603                     String JavaDoc ivalue = interpolate(var, level+1);
604                     if (ivalue != null)
605                     {
606                         result.append(ivalue);
607                         properties.setProperty(var, ivalue);
608                     }
609                     else
610                         result.append((String JavaDoc)properties.getProperty(var));
611                 }
612                 else
613                 {
614                     log.warn("Interpolation failed in value of property \""+key+
615                              "\", there is no property named \""+var+"\"");
616                 }
617                 from = end+1;
618             }
619             else
620                 break;
621         }
622         if (result != null && from < value.length())
623             result.append(value.substring(from));
624         return (result == null) ? null : result.toString();
625     }
626
627     /**
628      * Fill out of the configuration file templates in
629      * <code>dspace.dir/config/templates</code> with appropriate values from
630      * <code>dspace.cfg</code>, and copy to their appropriate destination.
631      * The destinations are defined as properties in <code>dspace.cfg</code>
632      * called <code>config.template.XXX</code> where <code>XXX</code> is the
633      * filename of the template. If this property doesn't exist, the
634      * configuration file template is skipped.
635      *
636      * @throws IOException
637      * if there was some problem reading the templates or writing
638      * the filled-out configuration files
639      */

640     public static void installConfigurations() throws IOException JavaDoc
641     {
642         // Get the templates
643
File JavaDoc templateDir = new File JavaDoc(getProperty("dspace.dir") + File.separator
644                 + "config" + File.separator + "templates");
645
646         File JavaDoc[] templateFiles = templateDir.listFiles();
647
648         for (int i = 0; i < templateFiles.length; i++)
649         {
650             installConfigurationFile(templateFiles[i].getName());
651         }
652     }
653
654     /**
655      * Install the given configuration file template in its required location.
656      * Configuration values in the template, specified as
657      * <code>@@property.name@@</code> are filled out with appropriate properties from
658      * the configuration. The filled-out configuration file is
659      * written to the file named by the property
660      * <code>config.template.XXX</code> where
661      * <code>XXX</code> is the name of the template as
662      * passed in to this method.
663      *
664      * @param template
665      * the name of the configuration template. This must correspond
666      * to the filename in <code>dspace.dir/config/templates</code>
667      * and the property starting with <code>config.template.</code>.
668      *
669      * @throws IOException
670      * if there was some problem reading the template or writing the
671      * filled-out configuration file
672      */

673     private static void installConfigurationFile(String JavaDoc template)
674             throws IOException JavaDoc
675     {
676         // Get the destination: specified in property config.template.XXX
677
String JavaDoc destination = getProperty("config.template." + template);
678
679         if (destination == null)
680         {
681             // If no destination is specified
682
info("Not processing config file template " + template
683                     + " because no destination specified (no property "
684                     + "config.template." + template + ")");
685
686             return;
687         }
688
689         info("Installing configuration file template " + template + " to "
690                 + destination);
691
692         // Open the template
693
BufferedReader JavaDoc in = new BufferedReader JavaDoc(new FileReader JavaDoc(
694                 getProperty("dspace.dir") + File.separator + "config"
695                         + File.separator + "templates" + File.separator
696                         + template));
697
698         // Open the destination for writing
699
PrintWriter JavaDoc out = new PrintWriter JavaDoc(new FileWriter JavaDoc(destination));
700
701         // We'll keep track of line numbers for error messages etc.
702
int lineNumber = 0;
703         String JavaDoc line;
704
705         // Copy the template, filling out config values
706
while ((line = in.readLine()) != null)
707         {
708             lineNumber++;
709
710             // Find configuration values
711
boolean moreValues = true;
712
713             while (moreValues)
714             {
715                 // Look for "@@"
716
int first = line.indexOf("@@");
717
718                 if (first > -1)
719                 {
720                     // Look for the "@@" on the other side
721
int second = line.indexOf("@@", first + 2);
722
723                     if (second > -1)
724                     {
725                         // We have a property
726
String JavaDoc propName = line.substring(first + 2, second);
727
728                         String JavaDoc propValue = getProperty(propName);
729
730                         if (propValue == null)
731                         {
732                             warn(template + " line " + lineNumber
733                                     + ": Property " + propName
734                                     + " not defined in DSpace configuration - "
735                                     + "using empty string");
736
737                             propValue = "";
738                         }
739
740                         // Fill in the value
741
line = line.substring(0, first) + propValue
742                                 + line.substring(second + 2);
743                     }
744                     else
745                     {
746                         // There's a "@@" with no second one... just leave as-is
747
warn(template + " line " + lineNumber
748                                 + ": Single @@ - leaving as-is");
749                         moreValues = false;
750                     }
751                 }
752                 else
753                 {
754                     // No more @@'s
755
moreValues = false;
756                 }
757             }
758
759             // Write the line
760
out.println(line);
761         }
762
763         in.close();
764         out.close();
765     }
766
767     /**
768      * Command-line interface for running configuration tasks. Possible
769      * arguments:
770      * <ul>
771      * <li><code>-installTemplates</code> processes and installs the
772      * configuration file templates for other tools</li>
773      * <li><code>-property name</code> prints the value of the property
774      * <code>name</code> from <code>dspace.cfg</code> to the standard
775      * output. If the property does not exist, nothing is written.</li>
776      * </ul>
777      *
778      * @param argv
779      * command-line arguments
780      */

781     public static void main(String JavaDoc[] argv)
782     {
783         if ((argv.length == 1) && argv[0].equals("-installTemplates"))
784         {
785             try
786             {
787                 info("Installing configuration files for other tools");
788                 installConfigurations();
789                 System.exit(0);
790             }
791             catch (IOException JavaDoc ie)
792             {
793                 warn("Error installing configuration files", ie);
794             }
795         }
796         else if ((argv.length == 2) && argv[0].equals("-property"))
797         {
798             String JavaDoc val = getProperty(argv[1]);
799
800             if (val != null)
801             {
802                 System.out.println(val);
803             }
804             else
805             {
806                 System.out.println("");
807             }
808
809             System.exit(0);
810         }
811         else
812         {
813             System.err
814                     .println("Usage: ConfigurationManager OPTION\n -installTemplates install config files for external tools\n -property prop.name get value of prop.name from dspace.cfg");
815         }
816
817         System.exit(1);
818     }
819
820     private static void info(String JavaDoc string)
821     {
822         if (log == null)
823         {
824             System.out.println("INFO: " + string);
825         }
826         else
827         {
828             log.info(string);
829         }
830     }
831
832     private static void warn(String JavaDoc string, Exception JavaDoc e)
833     {
834         if (log == null)
835         {
836             System.out.println("WARN: " + string);
837             e.printStackTrace();
838         }
839         else
840         {
841             log.warn(string, e);
842         }
843     }
844
845     private static void warn(String JavaDoc string)
846     {
847         if (log == null)
848         {
849             System.out.println("WARN: " + string);
850         }
851         else
852         {
853             log.warn(string);
854         }
855     }
856
857     private static void error(String JavaDoc string)
858     {
859         if (log == null)
860         {
861             System.err.println("ERROR: " + string);
862         }
863         else
864         {
865             log.error(string);
866         }
867     }
868
869     private static void fatal(String JavaDoc string, Exception JavaDoc e)
870     {
871         if (log == null)
872         {
873             System.out.println("FATAL: " + string);
874             e.printStackTrace();
875         }
876         else
877         {
878             log.fatal(string, e);
879         }
880     }
881
882     private static void fatal(String JavaDoc string)
883     {
884         if (log == null)
885         {
886             System.out.println("FATAL: " + string);
887         }
888         else
889         {
890             log.fatal(string);
891         }
892     }
893
894     private static void initLog()
895     {
896         log = Logger.getLogger(ConfigurationManager.class);
897     }
898
899 }
900
Popular Tags