NLIB 프로포티 관리 클래스 추가
This commit is contained in:
parent
98ce35ca8c
commit
494314f93a
112
src/main/java/nlib/cmm/service/NlibProperty.java
Normal file
112
src/main/java/nlib/cmm/service/NlibProperty.java
Normal file
@ -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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* @Class Name : NlibProperty.java
|
||||||
|
*
|
||||||
|
* @Description : NLIB용 프로퍼티 파일을 읽어서 메모리에 로딩하고 관리하는 클래스
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @ ------------ -------- ---------------------------
|
||||||
|
* @ 수정일 수정자 수정내용
|
||||||
|
* @ ------------ -------- ---------------------------
|
||||||
|
* @ 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<String> propEnum = (Enumeration<String>)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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user