4 import java.io.FileInputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.io.UnsupportedEncodingException;
9 import java.net.URLDecoder;
10 import java.nio.charset.Charset;
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.Comparator;
14 import java.util.Iterator;
16 import java.util.Properties;
18 import java.util.SortedMap;
19 import java.util.TreeMap;
21 import java.util.regex.Pattern;
22 import okw.exceptions.OKWFileDoesNotExistsException;
23 import okw.log.Logger_Sngltn;
24 import okw.parser.Parser;
26 import org.apache.commons.lang3.StringUtils;
27 import org.stringtemplate.v4.ST;
51 String PropPathWin =
"";
99 private static final long serialVersionUID = -6936118958227023483L;
120 if ( Instance ==
null )
125 if ( Instance ==
null )
159 this.CoreProperties.clear();
160 this.ResoursesProperties.clear();
161 this.FileProperties.clear();
183 String Sep = System.getProperty(
"file.separator" );
199 String PropPattern =
".*okw.default.properties.*\\.properties";
200 String PropPath =
"okw" + Sep +
"default" + Sep +
"properties" + Sep;
201 String PropPathWin =
"okw/default/properties/";
203 ArrayList<String> someProperties =
getPropertyFiles( PropPattern, PropPath, PropPathWin);
204 this.CoreProperties.addAll( someProperties );
214 PropPattern =
".*okw.properties.*\\.properties";
215 PropPath =
"okw" + Sep +
"properties" + Sep;
216 PropPathWin =
"okw/properties/";
218 ArrayList<String> some3Properties =
getPropertyFiles( PropPattern, PropPath, PropPathWin);
219 this.ResoursesProperties.addAll( some3Properties );
244 protected ArrayList<String>
getPropertyFiles( String Patternstring, String PropPath, String PropPathWin )
246 String loadResoure =
"";
247 ArrayList<String> myReturn =
new ArrayList<String>();
249 Pattern pattern = Pattern.compile( Patternstring );
253 for ( String element : myList)
257 if ( StringUtils.startsWith( element, PropPath) )
259 loadResoure = element;
261 else if ( StringUtils.startsWith( element, PropPathWin) )
263 loadResoure = element;
267 loadResoure = PropPath + StringUtils.splitByWholeSeparator( element, PropPath )[1];
271 myReturn.add( loadResoure );
300 Collections.sort( this.CoreProperties,
new Comparator<String>() {
302 public int compare(String s1, String s2) {
303 return s1.compareToIgnoreCase(s2);
306 for( String s : this.CoreProperties )
316 Collections.sort( this.ResoursesProperties,
new Comparator<String>() {
318 public int compare(String s1, String s2) {
319 return s1.compareToIgnoreCase(s2);
322 for( String s : this.ResoursesProperties )
330 for( String s : this.FileProperties )
341 loadSystemEnviromentVars();
345 loadSystemProperties();
372 Boolean lvbReturn =
true;
374 lvbReturn = this.ResoursesProperties.add(fpsResourceName);
401 this.FileProperties.add(fpsFileName);
428 ArrayList<String> Return =
new ArrayList<String>();
430 ClassLoader loader = Thread.currentThread().getContextClassLoader();
431 URL url = loader.getResource(folder);
435 path = URLDecoder.decode(url.getPath(), Charset.defaultCharset().name() );
437 String urlResourceFolder = path.replaceAll(folder,
"");
439 File[] FoldersAndFiles =
new File(path).listFiles();
441 for (File FolderOrFile : FoldersAndFiles) {
443 if (FolderOrFile.isDirectory())
446 String Folder = FolderOrFile.getPath().replaceAll(urlResourceFolder,
"");
449 else if (FolderOrFile.isFile())
452 if (FolderOrFile.getName().endsWith((
".properties")))
456 Log.
LogPrint( folder +
"/" + FolderOrFile.getName().replaceAll(urlResourceFolder,
"") );
457 Return.add( folder +
"/" + FolderOrFile.getName().replaceAll(urlResourceFolder,
""));
463 catch (UnsupportedEncodingException e)
497 InputStream overwrites = Thread.currentThread().getContextClassLoader().getResourceAsStream( fpsResource );
499 Boolean lvbReturn =
false;
501 String myLogPrint =
"Load Resource: " + fpsResource;
505 if (overwrites !=
null)
507 this.load(overwrites);
510 myLogPrint = myLogPrint +
" - OK";
514 myLogPrint = myLogPrint +
" - not found!";
517 catch (IOException e)
520 myLogPrint = myLogPrint +
" - failed!";
545 FileInputStream propFile;
546 Boolean lvbReturn =
false;
550 File myFile =
new File(fpsPropertiesFile);
552 if ( myFile.exists() )
554 propFile =
new FileInputStream(
new File(fpsPropertiesFile) );
577 private void loadSystemEnviromentVars()
579 Map<String, String> env = System.getenv();
583 for (String key : env.keySet())
585 String value = env.get(key);
586 if (this.containsKey(key))
588 Log.
LogPrint(
"Override: " + key +
": '" + this.
get(key) +
"'");
589 Log.
LogPrint(
" with: " + key +
": '" + value +
"'");
593 Log.
LogPrint(
" Write: " + key +
": '" + value +
"'");
595 this.setProperty(key, value);
603 private void loadSystemProperties()
605 Properties mySystemProperties = System.getProperties();
607 Set<String> keys = mySystemProperties.stringPropertyNames();
611 for ( String key : keys )
613 String value = (String) mySystemProperties.get(key);
615 if ( this.containsKey( key ) )
617 Log.
LogPrint(
"Override: " + key +
": '" + this.
get(key) +
"'" );
618 Log.
LogPrint(
" with: " + key +
": '" + value +
"'" );
622 Log.
LogPrint(
" Write: " + key +
": '" + value +
"'" );
625 this.setProperty(key, value);
632 public void PrintProperties()
637 SortedMap<Object, Object> sortedSystemProperties =
new TreeMap<Object, Object>(
this);
638 Set<Object> keySet = sortedSystemProperties.keySet();
639 Iterator<Object> iterator = keySet.iterator();
641 while (iterator.hasNext()) {
642 String propertyName = (String) iterator.next();
643 String propertyValue = this.
getProperty(propertyName);
644 Log.
LogPrint( propertyName +
": " + propertyValue );
665 Iterator<String> iterator =
null;
674 while ( iterator.hasNext())
676 String mySource = iterator.next();
689 while ( iterator.hasNext())
691 String mySource = iterator.next();
703 while ( iterator.hasNext())
705 String mySource = iterator.next();
735 ArrayList<String> Return =
new ArrayList<String>();
737 Set<String> keys = this.stringPropertyNames();
739 for ( String key : keys )
741 if ( key.startsWith( Startwitth ) )
772 ArrayList<String> Return =
new ArrayList<String>();
774 Set<String> keys = this.stringPropertyNames();
776 for ( String key : keys )
778 if ( key.startsWith( Startwith ) )
806 String lvsReturn =
"";
811 lvsReturn = super.getProperty( lvsKey );
812 if ( lvsReturn ==
null )
813 okw.log.Logger_Sngltn.getInstance().LogWarning(
"Propertykey (parsed) not found: '" + lvsKey +
"'" );
844 public String
getProperty( String fpsKey, String fpsDefault, Object... Parameters )
846 String lvsReturn =
"";
847 String lvsTemplate =
"";
849 if (fpsDefault ==
null)
855 lvsTemplate = this.
getProperty( fpsKey, fpsDefault );
858 if ( lvsTemplate ==
null )
859 okw.log.Logger_Sngltn.getInstance().LogWarning(
"Propertykey not found: '" + fpsKey +
"'" );
863 ST st =
new ST( lvsTemplate,
'%',
'%' );
865 for ( Integer i=0; i<Parameters.length; i++ )
868 String PName =
"P" + J.toString();
869 Object Value = Parameters[i];
870 st.add( PName, Value );
873 lvsReturn = st.render();
942 Boolean lvbReturn =
false;
943 String lvsReturn =
"";
945 lvsReturn = this.
getProperty( fpsKey, fpsDefault );
946 lvbReturn = Boolean.parseBoolean( lvsReturn );