Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / utils / PropertyManager.java @ 40559

History | View | Annotate | Download (3.41 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.remoteclient.utils;
25

    
26
import java.io.IOException;
27
import java.io.InputStream;
28
import java.util.Hashtable;
29
import java.util.Properties;
30

    
31
/**
32
 * Description: Loads the configuration files
33
 *
34
 * @author  Laura Diaz
35
 * @version 1.0 
36
 */
37
public class PropertyManager
38
{
39
 public final static String LOGGER_PROPERTIES = "org/gvsig/remoteClient/conf/logger.properties";
40
 
41
 //The property file names to load
42
 private final static String[] s_propertyFileNames = new String[]{LOGGER_PROPERTIES};
43
                                                                                                                                         
44

    
45
 //Hashtable containing all properties objects that are loaded
46
 private static Hashtable s_propertyFiles = null;
47

    
48
 /**
49
 * Gets a properties object
50
 * If the the property files are not yet loaded, then loads them first
51
 *
52
 * @param propertyFileName, String
53
 * @return Properties
54
 * @throws java.io.IOException
55
 */
56
 public static Properties getProperties(String propertyFileName) throws IOException
57
 {
58
   if (s_propertyFiles == null)
59
   {
60
     loadProperties();
61
   }
62

    
63
   return (Properties)s_propertyFiles.get(propertyFileName);
64
 }
65

    
66
 //Loads the property files
67
 private static synchronized void loadProperties() throws IOException
68
 {
69
   s_propertyFiles = new Hashtable(s_propertyFileNames.length);
70
   ClassLoader loader = PropertyManager.class.getClassLoader();
71

    
72
   for (int i = 0; i < s_propertyFileNames.length; i++)
73
   {
74
     try
75
     {
76
       InputStream input = loader.getResourceAsStream(s_propertyFileNames[i]);
77
       Properties props = new Properties();
78
       props.load(input);
79
       s_propertyFiles.put(s_propertyFileNames[i], props);
80
     }
81
     catch(Exception e)
82
     {
83
             System.err.println("\n[PropertyManager] ERROR - Failed to read properties file \""
84
                          + s_propertyFileNames[i] + "\": "
85
                          + e.getMessage());       
86
     }
87
   }
88
 }
89
 
90
 //Loads the property files
91
 /*
92
 public static synchronized void saveProperties(String propsName) throws IOException
93
 {  
94
     try
95
     {         
96
          //ClassLoader loader = PropertyManager.class.getClassLoader();              
97
          //InputStream input = loader.getResourceAsStream(propsName);                          
98
           FileOutputStream output = new FileOutputStream(propsName);
99
           Properties props = new Properties();
100
           props.store(output, propsName);
101
           output.close();            
102
     }
103
     catch(Exception e)
104
     {
105
             System.err.println("\n[PropertyManager] ERROR - Failed to save properties file \""
106
                          + propsName + "\": "
107
                          + e.getMessage());       
108
     }
109
 }
110
*/
111
 
112
 
113
}