11package org .fugerit .java .core .cfg .xml ;
22
3+ import java .io .File ;
4+ import java .io .FileInputStream ;
35import java .io .IOException ;
6+ import java .io .InputStream ;
47import java .util .Enumeration ;
58import java .util .Map .Entry ;
69import java .util .Properties ;
710import java .util .Set ;
811
9- import org .fugerit .java .core .util .PropsIO ;
12+ import org .fugerit .java .core .lang .helpers .BooleanUtils ;
13+ import org .fugerit .java .core .lang .helpers .ClassHelper ;
1014
1115public class PropertyHolder extends BasicIdConfigType {
1216
@@ -27,6 +31,8 @@ public class PropertyHolder extends BasicIdConfigType {
2731
2832 private String mode ;
2933
34+ private String xml ;
35+
3036 private Properties props ;
3137
3238 public String getDescription () {
@@ -52,19 +58,41 @@ public String getMode() {
5258 public void setMode (String mode ) {
5359 this .mode = mode ;
5460 }
61+
62+ public String getXml () {
63+ return xml ;
64+ }
65+
66+ public void setXml (String xml ) {
67+ this .xml = xml ;
68+ }
69+
70+ private static void loadWorker ( InputStream is , Properties props , boolean xml ) throws IOException {
71+ if ( xml ) {
72+ props .loadFromXML ( is );
73+ } else {
74+ props .load ( is );
75+ }
76+ }
5577
56- public static Properties load ( String mode , String path ) throws IOException {
57- Properties props = null ;
58- if ( MODE_FILE .equalsIgnoreCase ( mode ) ) {
59- props = PropsIO .loadFromFile ( path );
60- } else if ( MODE_CLASS_LOADER .equalsIgnoreCase ( mode ) ) {
61- props = PropsIO .loadFromClassLoader ( path );
78+ public static Properties load ( String mode , String path , String xml ) throws IOException {
79+ Properties props = new Properties ();
80+ if ( MODE_CLASS_LOADER .equalsIgnoreCase ( mode ) ) {
81+ try ( InputStream is = ClassHelper .loadFromDefaultClassLoader ( path ) ) {
82+ loadWorker ( is , props , BooleanUtils .isTrue ( xml ) );
83+ } catch (Exception e ) {
84+ throw new IOException ( e );
85+ }
86+ } else {
87+ try ( InputStream is = new FileInputStream ( new File ( path ) ) ) {
88+ loadWorker ( is , props , BooleanUtils .isTrue ( xml ) );
89+ }
6290 }
6391 return props ;
6492 }
6593
6694 public void init () throws IOException {
67- this .props = load ( this .getMode () , this .getPath () );
95+ this .props = load ( this .getMode () , this .getPath (), this . getXml () );
6896 }
6997
7098 public boolean isEmpty () {
0 commit comments