From 494314f93acb15cc503e70b013d9901e4f305056 Mon Sep 17 00:00:00 2001 From: KNKIM Date: Fri, 16 Jul 2021 14:56:00 +0900 Subject: [PATCH] =?UTF-8?q?NLIB=20=ED=94=84=EB=A1=9C=ED=8F=AC=ED=8B=B0=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/nlib/cmm/service/NlibProperty.java | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/main/java/nlib/cmm/service/NlibProperty.java diff --git a/src/main/java/nlib/cmm/service/NlibProperty.java b/src/main/java/nlib/cmm/service/NlibProperty.java new file mode 100644 index 00000000..0d73e205 --- /dev/null +++ b/src/main/java/nlib/cmm/service/NlibProperty.java @@ -0,0 +1,112 @@ +package nlib.cmm.service; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.Properties; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +/** + *
+ * @Class Name : NlibProperty.java
+ * 
+ * @Description : NLIB용 프로퍼티 파일을 읽어서 메모리에 로딩하고 관리하는 클래스 
+ * 
+ * 
+ * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
+ *
+ * 
+ * + * @ ------------ -------- --------------------------- + * @ 수정일 수정자 수정내용 + * @ ------------ -------- --------------------------- + * @ 2021. 7. 16. KNKIM 최초 생성 + * + * + * @author 이씨플라자 * DIGITALSHIP KNKIM + * @since 2021. 7. 16. + * @version 1.0 + * + */ +@Service("nlibProperty") +public class NlibProperty { + + private static final Logger log = LoggerFactory.getLogger(NlibProperty.class); + + /** + * 메모리에 로딩될 프로퍼티 객체 선언 + */ + public static Properties properties = null; + + /** + * nlib.properties 파일로 부터 속성을 읽어 들인다. + * + * @return 정상적으로 로딩한 건수를 리턴한다. 오류 발생 시, 음수값이 리턴된다. + */ + public static int loadProperties() { + + String nlibPropPath = null; + int propCount = -1; + + try { + + if(properties == null) properties = new Properties(); + else properties.clear(); + + nlibPropPath = NlibProperty.class.getResource("").getPath(); + nlibPropPath = nlibPropPath.substring(0, nlibPropPath.lastIndexOf("/nlib/") + 6) + "nlib.properties"; + + log.debug("NLIB Properties File Path : " + nlibPropPath); + + try (InputStream input = new FileInputStream(nlibPropPath)) { + + properties.load(input); + + Enumeration propEnum = (Enumeration)properties.propertyNames(); + + String propName = null; + while(propEnum.hasMoreElements()) { + propName = propEnum.nextElement(); + log.debug("Loading NLIB Properties : " + propName + " = " + properties.getProperty(propName)); + } + + log.debug("Loading is Done!"); + + propCount = properties.size(); + + } catch (IOException ex) { + if(properties != null) properties.clear(); + log.error("Error in Loading NLIB Properties : " + nlibPropPath); + ex.printStackTrace(); + return -2; + } + + } catch(Exception e) { + if(properties != null) properties.clear(); + log.error("Error in Solving NLIB Properties Path : " + nlibPropPath); + e.printStackTrace(); + return -3; + } + + return propCount; + } + + /** + * name 값을 키로하는 속성값을 리턴한다. + * + * @param name + * @return + */ + public String getProperty(String name) { + + if(properties == null || properties.size() < 1) { + if(loadProperties() < 0) return null; + } + + return properties.getProperty(name); + } +}