Loads a configuration from jcors.xml in classpath. If this file is not found, uses a default configuration

@return
331468
public static JCorsConfig load() {

		log.info("Initializing JCors...");
		InputStream fileStream = findFileInClasspath(CONFIG_FILE_NAME);

		JCorsConfig config = new JCorsConfig();

		if (fileStream != null) {
			config = loadFromFileStream(fileStream);
			Constraint.ensureNotNull(config, "It was not possible to get a valid configuration instance");
			log.info(String.format("Configuration loaded from classpath file '%s'", CONFIG_FILE_NAME));
		} else {
			log.info(String.format("No file '%s' found in classpath. Using default configurations.", CONFIG_FILE_NAME));
		}

		log.info(config);
		return config;

	}
742904
protected void loadConfigs() {
        configs = new Properties();
        // If run as a jar, find in file system classpath first, if not found, then get resource in jar.
        if (ClassPathUtil.testRunMainInJar()) {
            String[] classPathsInFileSystem = ClassPathUtil.getAllClassPathNotInJar();
            String workDir = System.getProperty("user.dir");
            String mainJarRelativePath = ClassPathUtil.getClassPathsInSystemProperty()[0];
            File mainJar = new File(workDir, mainJarRelativePath);
            File mainJarDir = mainJar.getParentFile();
            for (String classPath : classPathsInFileSystem) {
                File classPathFile = new File(classPath);
                File configFile;
                if (classPathFile.isAbsolute()) {
                    configFile = new File(classPathFile, propertiesAbsoluteClassPath);
                } else {
                    configFile = new File(new File(mainJarDir, classPath), propertiesAbsoluteClassPath);
                }
                if (configFile.exists() && configFile.isFile()) {
                    InputStream is = null;
                    try {
                        is = new FileInputStream(configFile);
                        loadConfigsFromStream(is);
                    } catch (FileNotFoundException e) {
                        LOGGER.warn("Load config file " + configFile.getPath() + " error!", e);
                    }
                    return;
                }
            }
        }
        if (propertiesFilePath == null) {
            if (propertiesAbsoluteClassPath == null) {
                return;
            }
            InputStream is = OneProperties.class.getResourceAsStream(propertiesAbsoluteClassPath);
            loadConfigsFromStream(is);
        } else {
            configs = PropertiesIO.load(propertiesFilePath);
        }
    }
883036
public static JNRPEConfiguration createConfiguration(final String configurationFilePath) throws ConfigurationException {
        JNRPEConfiguration conf = null;

        if (configurationFilePath.toLowerCase().endsWith(".conf") || configurationFilePath.toLowerCase().endsWith(".ini")) {
            conf = new IniJNRPEConfiguration();
        } else if (configurationFilePath.toLowerCase().endsWith(".xml")) {
            conf = new XmlJNRPEConfiguration();
        }

        if (conf == null) {
            throw new ConfigurationException("Config file name must end with either '.ini' " 
                                + "(ini file) or '.xml' (xml file). Received file name is : " + new File(configurationFilePath).getName());
        }

        conf.load(new File(configurationFilePath));

        return conf;
    }
561897
@Override
    protected synchronized void loadConfiguration() throws IOException {
        final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        final TypeReference<HashMap<String, String>> typeRef = new TypeReference<HashMap<String, String>>() {};
        namespaces = mapper.readValue(new File(configPath), typeRef);
    }
48886
protected void load()
    {
        properties = new Properties();

        String filename = getFilename();
        
        try
        {
            URL url = ClassHelper.getResource(filename);

            if (url == null)
            {
                url = (new File(filename)).toURL();
            }

            logger.info("Loading OJB's properties: " + url);

            URLConnection conn = url.openConnection();
            conn.setUseCaches(false);
            conn.connect();
            InputStream strIn = conn.getInputStream();
            properties.load(strIn);
            strIn.close();
        }
        catch (FileNotFoundException ex)
        {
            // [tomdz] If the filename is explicitly reset (null or empty string) then we'll
            //         output an info message because the user did this on purpose
            //         Otherwise, we'll output a warning
            if ((filename == null) || (filename.length() == 0))
            {
                logger.info("Starting OJB without a properties file. OJB is using default settings instead.");
            }
            else
            {
                logger.warn("Could not load properties file '"+filename+"'. Using default settings!", ex);
            }
            // [tomdz] There seems to be no use of this setting ?
            //properties.put("valid", "false");
        }
        catch (Exception ex)
        {
            throw new MetadataException("An error happend while loading the properties file '"+filename+"'", ex);
        }
    }
781378
public static ApplicationConfiguration load(InputStream input) throws Exception {
		XMLStreamReader xml = XMLInputFactory.newFactory().createXMLStreamReader(input);
		while (xml.hasNext()) {
			xml.next();
			if (xml.getEventType() == XMLStreamConstants.START_ELEMENT) {
				if (!"project".equals(xml.getLocalName()))
					throw new Exception("Root element of an lc-project.xml file must be <project>");
				ApplicationConfiguration cfg = new ApplicationConfiguration();
				boolean found = false;
				while (xml.hasNext()) {
					xml.next();
					if (xml.getEventType() == XMLStreamConstants.START_ELEMENT) {
						if ("application".equals(xml.getLocalName())) {
							found = true;
							cfg.load(xml);
							break;
						}
					}
				}
				if (!found)
					throw new Exception("No application element found in lc-project.xml file");
				return cfg;
			}
		}
		throw new Exception("Nothing found in lc-project.xml file");
	}
415295
public Configuration fromFile(URL path) throws ConfigurationLoadException {
    PropertiesConfiguration configuration = setupConfiguration(new PropertiesConfiguration());
    configuration.setURL(path);
    try {
      configuration.load();
      return configuration;
    } catch (ConfigurationException e) {
      throw new ConfigurationLoadException(
          "Encountered a problem reading the provided configuration file \"" + path + "\"!", e);
    }
  }
136698
private List<StringKeyValueBean> loadConfiguration(){
		List<StringKeyValueBean> result = new LinkedList<StringKeyValueBean>();
		Resource resource = null;
		if (primaryConfigFileLocation == null){
			return result;		// fail silently because we must be in test
		}else{
			resource = new ClassPathResource(primaryConfigFileLocation);
			if (!resource.exists()){
				if (secondaryConfigFileLocation == null){
					return result;		// fail silently because we must be in test
				}
				resource = new ClassPathResource(secondaryConfigFileLocation);
			}
		}

		Properties properties = null;
		try {
			properties = PropertiesLoaderUtils.loadProperties(resource);
			
			// sort them, make the more specific ones at the top, and "*"/".*" at the bottom
			List<StringKeyValueBean> sorted = new ArrayList<StringKeyValueBean>(properties.size());
			for (Entry<Object, Object> entry: properties.entrySet()){
				sorted.add(new StringKeyValueBean(entry.getKey().toString(), entry.getValue().toString()));
			}
			Collections.sort(sorted, new Comparator<StringKeyValueBean>(){
				@Override
				public int compare(StringKeyValueBean b0,	StringKeyValueBean b1) {
					if (b0.getKey().equals(b1.getKey())){
						return 0;
					}
					if ("*".equals(b0.getKey()) || ".*".equals(b0.getKey())){
						return 1;
					}else if ("*".equals(b1.getKey()) || ".*".equals(b1.getKey())){
						return -1;
					}
					return b1.getKey().compareTo(b0.getKey());
				}
			});
			result.addAll(sorted);
		} catch (Exception e) {
			logger.warn("Cannot load environments configuration file from class path: " + 
					(resource == null ? "<null>" : resource.getDescription()), e);
		}
		
		return result;
	}
1206238
public Config load() {

        ConfigResolveOptions resolveOptions = getResolveOptions();
        HashMapBindings bindings = this.bindings;
        Config config = emptyConfig();

        for (int i = 0; i < 2; i++) {

            config = emptyConfig();

            for (ConfigSource source
                    : sources.fromHighestToLowestPrecedence()) {

                config = config.withFallback(source.load(bindings));
            }

            config = config.resolve(resolveOptions);
            bindings = bindings.set(Config.class, config);
        }

        return config;
    }
65184
private static ClusterConfig loadConfig(File config, ClassLoader classLoader) {
    return new ConfigMapper(classLoader).loadResources(ClusterConfig.class, config.getAbsolutePath());
  }
83502
public void loadConfiguration()
	{

		XMLFileChooser fc = new XMLFileChooser();
		if (fc.showOpenDialog(new JPanel()) == XMLFileChooser.APPROVE_OPTION) {
			this.loadConfig(fc.getSelectedFile().getPath());
		}
	}
291251
protected org.apache.commons.configuration.Configuration getConfiguration() {
        try {
            return ApplicationProperties.get();
        } catch (AtlasException e) {
            throw new RuntimeException("Unable to load configuration: " + ApplicationProperties.APPLICATION_PROPERTIES);
        }
    }
104779
public static function loadConfiguration()
    {
        $defaultsFile = __DIR__ . '/../../../../app/config/defaults.yml';
        $draggyFile   = __DIR__ . '/../../../../app/config/draggy.yml';
        $userFile     = __DIR__ . '/../../../../app/config/user.yml';

        $defaultsArray = Yaml::parse($defaultsFile);

        $configurationArray = is_file($userFile)
            ? Yaml::parse($userFile)
            : Yaml::parse($draggyFile);

        $mergedArray = self::mergeConfigurations($defaultsArray, $configurationArray);

        return $mergedArray;
    }
114147
protected String loadOnlyConfig(final Class<T> cl) {
    try {
      /* Load up the config */

      ConfigurationStore cs = getStore();

      List<String> configNames = cs.getConfigs();

      if (configNames.isEmpty()) {
        error("No configuration on path " + cs.getLocation());
        return "No configuration on path " + cs.getLocation();
      }

      if (configNames.size() != 1) {
        error("1 and only 1 configuration allowed");
        return "1 and only 1 configuration allowed";
      }

      String configName = configNames.iterator().next();

      cfg = getConfigInfo(cs, configName, cl);

      if (cfg == null) {
        error("Unable to read configuration");
        return "Unable to read configuration";
      }

      setConfigName(configName);

      return null;
    } catch (Throwable t) {
      error("Failed to load configuration: " + t.getLocalizedMessage());
      error(t);
      return "failed";
    }
  }
1001107
public ShardingConfiguration load() throws IOException {
        Collection<String> schemaNames = new HashSet<>();
        YamlProxyServerConfiguration serverConfig = loadServerConfiguration(new File(ShardingConfigurationLoader.class.getResource(CONFIG_PATH + SERVER_CONFIG_FILE).getFile()));
        File configPath = new File(ShardingConfigurationLoader.class.getResource(CONFIG_PATH).getFile());
        Collection<YamlProxyRuleConfiguration> ruleConfigurations = new LinkedList<>();
        for (File each : findRuleConfigurationFiles(configPath)) {
            Optional<YamlProxyRuleConfiguration> ruleConfig = loadRuleConfiguration(each, serverConfig);
            if (ruleConfig.isPresent()) {
                Preconditions.checkState(schemaNames.add(ruleConfig.get().getSchemaName()), "Schema name `%s` must unique at all rule configurations.", ruleConfig.get().getSchemaName());
                ruleConfigurations.add(ruleConfig.get());
            }
        }
        Preconditions.checkState(!ruleConfigurations.isEmpty() || null != serverConfig.getOrchestration(), "Can not find any sharding rule configuration file in path `%s`.", configPath.getPath());
        Map<String, YamlProxyRuleConfiguration> ruleConfigurationMap = new HashMap<>(ruleConfigurations.size(), 1);
        for (YamlProxyRuleConfiguration each : ruleConfigurations) {
            ruleConfigurationMap.put(each.getSchemaName(), each);
        }
        return new ShardingConfiguration(serverConfig, ruleConfigurationMap);
    }
939405
@Override
  public Class<?> loadClassImpl(String name, boolean resolve)
    throws ClassNotFoundException
  {
    // The JVM has already cached the classes, so we don't need to
    Class<?> cl = findLoadedClass(name);

    if (cl != null) {
      if (resolve) {
        resolveClass(cl);
      }
      
      return cl;
    }

    String className = name;
    
    if (_hasBootClassPath) {
      className = name.replace('.', '/') + ".class";

      if (findPath(className) == null) {
        return null;
      }
    }

    try {
      return super.loadClassImpl(name, resolve);
    } catch (Error e) {
      className = name.replace('.', '/') + ".class";
      
      if (findPath(className) != null) {
        String msg =  (e + "\n  while loading " + name + " in " + this
                       + "\n  which exists in " + findPath(className)
                       + "\n  check for missing dependencies");
        
        log().warning(msg);
      }
      
      throw e;
    } catch (ClassNotFoundException e) {
      className = name.replace('.', '/') + ".class";
      
      if (findPath(className) != null) {
        String msg =  (e + "\n  " + name + " in " + this
            + "\n  exists in " + findPath(className)
            + "\n  check for missing dependencies");
        
        log().fine(msg);
        
        throw new ClassNotFoundException(e.getMessage() + "\n" + msg, e);
      }
      
      throw e;
    }
  }
779266
protected Element getIndexingConfigurationDOM()
   {
      if (indexingConfiguration == null)
      {
         if (indexingConfigPath != null)
         {

            // File config = PrivilegedFileHelper.file(indexingConfigPath);
            SecurityHelper.doPrivilegedAction(new PrivilegedAction<Object>()
            {
               public Object run()
               {
                  InputStream is = SearchIndex.class.getResourceAsStream(indexingConfigPath);
                  if (is == null)
                  {
                     try
                     {
                        is = cfm.getInputStream(indexingConfigPath);
                     }
                     catch (Exception e1)
                     {
                        log.warn("Unable to load configuration " + indexingConfigPath);
                     }
                  }

                  try
                  {
                     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                     DocumentBuilder builder = factory.newDocumentBuilder();
                     builder.setEntityResolver(new IndexingConfigurationEntityResolver());
                     String content = Deserializer.resolveVariables(Utils.readStream(is));
                     InputSource source = new InputSource(new StringReader(content));
                     indexingConfiguration = builder.parse(source).getDocumentElement();
                  }
                  catch (ParserConfigurationException e)
                  {
                     log.warn("Unable to create XML parser", e);
                  }
                  catch (IOException e)
                  {
                     log.warn("Exception parsing " + indexingConfigPath, e);
                  }
                  catch (SAXException e)
                  {
                     log.warn("Exception parsing " + indexingConfigPath, e);
                  }
                  return null;
               }
            });
         }
      }
      return indexingConfiguration;
   }