Java ClassLoader loadCorrectedConfiguration(String configurationFilename)

Here you can find the source of loadCorrectedConfiguration(String configurationFilename)

Description

load Corrected Configuration

License

Open Source License

Declaration

public static Properties loadCorrectedConfiguration(String configurationFilename) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileInputStream;

import java.net.URL;
import java.net.URLDecoder;
import java.util.Properties;

public class Main {
    public static Properties loadCorrectedConfiguration(String configurationFilename) {
        try {//w w  w .java2 s .co  m
            // Use -Drepox.data.dir= in the VM parameters in order to pass an already existing configuration.properties and gui.properties
            String configsDataDir = System.getProperty("repox.data.dir");
            String configurationFile;
            if (configDataDirAlreadyExists(configsDataDir, configurationFilename))
                configurationFile = URLDecoder.decode(configsDataDir + File.separator + configurationFilename,
                        "ISO-8859-1");
            else {
                URL configurationURL = Thread.currentThread().getContextClassLoader()
                        .getResource(configurationFilename);
                configurationFile = URLDecoder.decode(configurationURL.getFile(), "ISO-8859-1");
            }

            Properties properties = new Properties();
            properties.load(new FileInputStream(configurationFile));

            return properties;
        } catch (Exception e) {
            throw new IllegalArgumentException("could not load [" + configurationFilename + "]");
        }
    }

    public static boolean configDataDirAlreadyExists(String configsDataDir, String configurationFilename) {
        if (configsDataDir == null || configsDataDir.isEmpty())
            return false;

        File configFile = new File(configsDataDir + File.separator + configurationFilename);
        if (!configFile.exists()) {
            System.out.println("Load Config files from Java Variables -- " + configurationFilename
                    + " file doesn't exist on the specified directory");
            return false;
        }

        return true;
    }
}

Related

  1. load(File propsFile)
  2. load(final String filename)
  3. load(String propertiesName)
  4. load(String propsName)
  5. loadAttachApi()
  6. loadFile(String file)
  7. loadGuiConfiguration(String configurationFilename)
  8. loadProperties(File inFile)
  9. loadProperties(final String configFile, final String chainProperty)