Java tutorial
/* * Copyright 2010 MOPAS(Ministry of Public Administration and Security). * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package egovframework.oe1.cms.com.service; import java.io.File; import java.io.FileInputStream; import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * properties? ? ? Globals?? ? ? ? * ? ?? . * * @author ?1 ? * @since 2010.07.20 * @version 1.0 * @see * * <pre> * << ?(Modification Information) >> * * ? ? * ------- -------- --------------------------- * 2010.07.20 ? ? * * Copyright (C) 2009 by MOPAS All right reserved. * </pre> */ public class EgovOe1Properties { /** LOG */ static protected Log log = LogFactory.getLog(EgovOe1Properties.class); // ? ?? ? ?? /** ERR_CODE */ public static String errCode = " EXCEPTION OCCURRED"; /** ERR_CODE_FNFE */ public static String errCodeFnfe = " EXCEPTION(FNFE) OCCURRED"; /** ERR_CODE_IOE */ public static String errCodeIoe = " EXCEPTION(IOE) OCCURRED"; // ?? /** FILE_SEPARATOR */ static final char FILE_SEPARATOR = File.separatorChar; // ? ?? ? /** GLOBALS_PROPERTIES_FILE */ public static String globalsPropertiesFile // = // "D:/project/egov/workspace/egovcmm/target/classes/egovframework/cmm/utl/globals.properties"; = System.getProperty("user.home") + System.getProperty("file.separator") + "egovProps" + System.getProperty("file.separator") + "globals.properties"; /** * ?? ?? Key ? ? (Globals.java ) * * @param ??? * ? ? Key * @return ?? ?? Key ? */ public static String getProperty(String keyName) { // System.out.println("====="+globalsPropertiesFile); String value = errCode; value = "99"; debug(globalsPropertiesFile + " : " + keyName); FileInputStream fis = null; java.io.BufferedInputStream bis = null; try { Properties props = new Properties(); String file1 = globalsPropertiesFile.replace('\\', FILE_SEPARATOR).replace('/', FILE_SEPARATOR); fis = new FileInputStream(file1); bis = new java.io.BufferedInputStream(fis); props.load(bis); value = props.getProperty(keyName).trim(); props.clear(); } catch (java.io.FileNotFoundException fne) { debug(fne); } catch (java.io.IOException ioe) { debug(ioe); } catch (java.lang.Exception e) { debug(e); } finally { if (fis != null) try { fis.close(); } catch (Exception e) { debug(e); } if (bis != null) try { bis.close(); } catch (Exception e) { debug(e); } } return value; } /** * ?? ?? ?? Key ? ? * * @param ?? * @param ??? * ? ? Key * @return ?? ?? Key ? */ public static String getProperty(String fileName, String key) { FileInputStream fis = null; java.io.BufferedInputStream bis = null; try { java.util.Properties props = new java.util.Properties(); String file1 = fileName.replace('\\', FILE_SEPARATOR).replace('/', FILE_SEPARATOR); fis = new FileInputStream(file1); bis = new java.io.BufferedInputStream(fis); props.load(bis); String value = props.getProperty(key); return value; } catch (java.io.FileNotFoundException fne) { return errCodeFnfe; } catch (java.io.IOException ioe) { return errCodeIoe; } finally { if (fis != null) try { fis.close(); } catch (Exception e) { debug(e); } if (bis != null) try { bis.close(); } catch (Exception e) { debug(e); } } } /** * . * * @param Object * obj ? * @return void */ private static void debug(Object obj) { if (obj instanceof java.lang.Exception) { ((Exception) obj).getMessage(); } } }