001    package com.rain;
002    
003    import java.io.*;
004    import java.util.*;
005    
006    /**  
007     * ȯ°æ º¯¼ö °ü¸®
008     * @version 1.0
009     * @author http://cafen.net (outmind@cafen.net)
010     */
011    public class rainProperties { 
012    
013    /**  
014     * ±âº» ȯ°æ º¯¼ö
015     */
016            public Properties pro = new Properties() ;
017    
018    /**  
019     * ȯ°æ º¯¼ö ÆÄÀϸí
020     */
021            public String pro_file = "";
022    
023    /**  
024     * ¿À·ù ¸Þ¼¼Áö
025     */
026            public String error_msg = "";
027    
028    /**  
029     * ÆÄÀÏ ÀûÀç ¼º°ø ¿©ºÎ
030     */
031            public boolean file_loaded = false;
032            
033    /**  
034     * »ý¼ºÀÚ
035     */
036            public  rainProperties() {
037                    this.pro = new Properties();    
038            }
039    
040    /**  
041     * »ý¼ºÀÚ (conf/~~~.ini ¿¡¼­ ~~~ ¸¸ ÀÔ·Â) - DOCUMENT_ROOT/conf/ ÇϺο¡ ÆÄÀÏÀÌ À§Ä¡ÇÏ´Â °æ¿ì
042     * @param  inpro_file  ȯ°æÆÄÀϸí 
043     */
044            public  rainProperties(String inpro_file) {
045                    this.load(inpro_file, false);
046            }
047    
048    /**  
049     * »ý¼ºÀÚ (~~~.ini ¿¡¼­ ~~~ ¸¸ ÀÔ·Â) - ÆÄÀÏÀ» Àý´ë °æ·Î·Î load ÇÒ °æ¿ì
050     * @param  inpro_file  ȯ°æÆÄÀϸí 
051     * @param  is_fullpath  ÁÖ¾îÁø ȯ°æÆÄÀÏÀÌ Àý´ë °æ·Î¿©ºÎ (false Àΰæ¿ì /conf/ ÇϺο¡ À§Ä¡ÇؾßÇÔ)
052     */
053            public  rainProperties(String inpro_file, Boolean is_fullpath) {
054                    this.load(inpro_file, is_fullpath);
055            }
056    
057    /**  
058     * ȯ°æ ÆÄÀÏ ·Îµå
059     * @param  inpro_file  ȯ°æÆÄÀϸí 
060     * @param  is_fullpath  ÁÖ¾îÁø ȯ°æÆÄÀÏÀÌ Àý´ë °æ·Î¿©ºÎ (false Àΰæ¿ì /conf/ ÇϺο¡ À§Ä¡ÇؾßÇÔ)
061     */
062            public void load(String inpro_file, Boolean is_fullpath) {
063                    this.pro = new Properties();    
064                    if (is_fullpath)
065                            this.pro_file = inpro_file + ".ini";
066                    else
067                            this.pro_file = rainUtil.base_pos +"conf/"+ inpro_file + ".ini";
068                    try {
069                            if ((new File(this.pro_file)).exists()) {
070                                    InputStream input;
071                                    this.pro.load(input = new FileInputStream(new File(this.pro_file)));
072                                    input.close();
073                                    this.file_loaded = true;
074                            } else
075                                    this.file_loaded = false;
076                    }catch (Exception e){ 
077                            this.file_loaded = false;
078                    }
079            }
080    
081    /**  
082     * ȯ°æ º¯¼ö °¡Á®¿À±â
083     * @return Properties
084     */
085            public Properties getProperties() {
086                    return this.pro;
087            }
088    
089    /**  
090     * ȯ°æ º¯¼ö ۰ª°¡Á®¿À±â
091     * @return Enumeration
092     */
093            public Enumeration propertyNames() {
094                    return this.pro.propertyNames();
095            }
096    
097    /**  
098     * ƯÁ¤ Ű¿¡ ÇØ´çÇÏ´Â °ª °¡Á®¿À±â
099     * @param  key ´ë»ó Ű 
100     * @param  value ÇØ´ç °ªÀÌ ¾ø´Â °æ¿ì value ¸¦ ´ë½Å ¸®ÅÏÇÔ
101     * @return ´ë»ó°ª
102     */
103            public String getProperty(String key, String value) {
104                    return this.a2k(this.pro.getProperty(key , value));
105            }
106    
107    /**  
108     * getProperty ÀÇ º°Äª
109     * @param  key ´ë»ó Ű 
110     * @param  value ÇØ´ç °ªÀÌ ¾ø´Â °æ¿ì value ¸¦ ´ë½Å ¸®ÅÏÇÔ
111     * @return ´ë»ó°ª
112     */
113            public String get(String key, String value) {
114                    return this.getProperty(key, value);
115            }
116    
117    /**  
118     * getProperty ÀÇ º°Äª
119     * @param  key ´ë»ó Ű 
120     * @return ´ë»ó°ª
121     */
122            public String getProperty(String key) {
123                    return this.getProperty(key, "");
124            }
125            
126    /**  
127     * getProperty ÀÇ º°Äª
128     * @param  key ´ë»ó Ű 
129     * @return ´ë»ó°ª
130     */
131            public String get(String key) {
132                    return this.getProperty(key, "");
133            }
134    
135    /**  
136     * ƯÁ¤ Ű¿¡ ÇØ´çÇÏ´Â °ªÀ» ¼ýÀÚÇüÀ¸·Î °¡Á®¿À±â
137     * @param  key ´ë»ó Ű 
138     * @return ´ë»ó°ª
139     */
140            public int getInt(String key) {
141                    return rainUtil.string2Int(this.getProperty(key, ""));
142            }
143    
144    /**  
145     * ƯÁ¤ Ű¿¡ ƯÁ¤°ªÀ» ÀúÀåÇÔ
146     * @param  key ´ë»ó Ű 
147     * @param  value ´ë»ó °ª 
148     */
149            public void setProperty(String key, String value) {
150                    this.pro.setProperty(key, value) ;
151            }
152    
153    /**  
154     * setProperty ÀÇ º°Äª
155     * @param  key ´ë»ó Ű 
156     * @param  value ´ë»ó °ª 
157     */
158            public void set(String key, String value) {
159                    this.setProperty(key, value);
160            }       
161    
162    /**  
163     * ASC °ªÀ» EUC_KR ·Î º¯È¯
164     * @param  str ´ë»ó ¹®ÀÚ
165     * @return  º¯È¯µÈ ¹®ÀÚ
166     */
167            public String a2k(String str) {
168                    String rtn = null;
169                    try {
170                            rtn = (str==null)?"":new String(str.getBytes("8859_1"),"euc-kr");
171                    } catch (java.io.UnsupportedEncodingException e) {}
172                    return rtn;
173            }
174    
175    /**  
176     * ÇöÀç ¼³Á¤µÈ Á¤º¸¸¦ ÆÄÀÏ·Î ÀúÀåÇÔ
177     * @param  comment ÆÄÀÏ »ó´Ü¿¡ ¼³¸í¹® Ãß°¡
178     */
179            public void store(String comment) {
180                    try {
181                            OutputStream output;
182                            this.pro.store(output = new FileOutputStream(new File(this.pro_file)), comment);
183                            output.close();
184                    }catch (Exception e){ this.error_msg += e.getMessage(); }
185            }
186            
187    /**  
188     * ÇöÀç ¼³Á¤µÈ Á¤º¸¸¦ ÆÄÀÏ·Î ÀúÀåÇÔ
189     */
190            public void store() {
191                    this.store("");
192            }
193    }
194