Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/xpn/xwiki/XWikiConfig.java


1   /**
2    * ===================================================================
3    *
4    * Copyright (c) 2003-2005 Ludovic Dubost, All rights reserved.
5    *
6    * This program is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU General Public License
8    * as published by the Free Software Foundation; either version 2
9    * of the License, or (at your option) any later version.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details, published at
15   * http://www.gnu.org/copyleft/gpl.html or in gpl.txt in the
16   * root folder of this distribution.
17   */
18  package com.xpn.xwiki;
19  
20  import java.io.FileInputStream;
21  import java.io.FileNotFoundException;
22  import java.io.IOException;
23  import java.io.InputStream;
24  import java.util.Properties;
25  
26  public class XWikiConfig extends Properties {
27  
28      public XWikiConfig() {
29          // Default constructor so that properties can be added after constructing the instance 
30          // by using XWikiConfig.put().
31      }
32      
33      public XWikiConfig(String path) throws XWikiException {
34         try {
35             FileInputStream fis = new FileInputStream(path);
36             loadConfig(fis, path);
37         }
38         catch (FileNotFoundException e) {
39             Object[] args = { path };
40             throw new XWikiException(XWikiException.MODULE_XWIKI_CONFIG,
41                 XWikiException.ERROR_XWIKI_CONFIG_FILENOTFOUND,
42                 <font color=red>"Configuration file {0} not found"font>, e, args);
43             }
44      }
45  
46      public XWikiConfig(InputStream is) throws XWikiException {
47         loadConfig(is, "");
48      }
49  
50      public void loadConfig(InputStream is, String path) throws XWikiException {
51          try {
52              load(is);
53          }
54          catch (IOException e) {
55              Object[] args = { path };
56              throw new XWikiException(XWikiException.MODULE_XWIKI_CONFIG,
57                  XWikiException.ERROR_XWIKI_CONFIG_FORMATERROR,
58                  <font color=red>"Error reading configuration file"font>, e, args);
59          }
60      }
61  }