Load aliases from a property file.

@param applicationContext The application context.
@param propertyFile A property file.
483872
private void loadAliases(ApplicationContext applicationContext, String propertyFile) {
        if (propertyFile.isEmpty()) {
            return;
        }

        Resource[] resources;

        try {
            resources = applicationContext.getResources(propertyFile);
        } catch (IOException e) {
            log.error("Failed to locate alias property file: " + propertyFile, e);
            return;
        }

        for (Resource resource : resources) {
            if (!resource.exists()) {
                log.info("Did not find alias property file: " + resource.getFilename());
                continue;
            }

            try (InputStream is = resource.getInputStream();) {

                Properties props = new Properties();
                props.load(is);

                for (Entry<Object, Object> entry : props.entrySet()) {
                    try {
                        register((String) entry.getKey(), (String) entry.getValue());
                        entryCount++;
                    } catch (Exception e) {
                        log.error("Error registering alias for '" + entry.getKey() + "'.", e);
                    }
                }

                fileCount++;
            } catch (IOException e) {
                log.error("Failed to load alias property file: " + resource.getFilename(), e);
            }
        }
    }
41805
public void loadFromPropertyFile() throws IOException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "loadFromPropertyFile()");

        String key        = null;
        Properties config = new Properties();
        InputStream is    = this.getClass().getResourceAsStream(PROPERTY_FILE);

        if (is == null) {
            throw new IOException("Resource " + PROPERTY_FILE + " not found in current classloader");
        }

        config.load(is);

        Enumeration vEnum = config.propertyNames();

        while (vEnum.hasMoreElements())
        {
            key = (String) vEnum.nextElement();

            if (key.equals("datasourceClassname"))
                datasourceClassname = config.getProperty(key);
            else if (key.equals("username"))
                datasourceUsername  = config.getProperty(key);
            else if (key.equals("password"))
                datasourcePassword  = config.getProperty(key);
            else if (key.equals("schemaname"))
                schemaName = config.getProperty(key);
            else if (key.equals("poolSize"))
                numberOfPooledConnections = Integer.parseInt(config.getProperty(key));
            else if (key.equals("verbose"))
                verbose = Boolean.valueOf(config.getProperty(key)).booleanValue();
            else
                datasourceProperties.setProperty(key, config.getProperty(key));
        }

        if (datasourceClassname == null)
            throw new IllegalStateException("The properties file must specify datasourceClassname");

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "loadFromPropertyFile()");
    }
641328
private void buildupPropertiesBundles(final File file) throws IOException {
		File[] files = file.listFiles();

		for (File f : files) {
			if (f.getName().endsWith("properties")) {
				String bundleName = f.getName().substring(0,
						f.getName().indexOf("properties") - 1);

				LOG.info("Loading: " + bundleName);
				ResourceBundle bundle = new PropertyResourceBundle(
						new FileInputStream(f));
				bundles.put(bundleName, bundle);
			}
		}
	}
686708
Properties loadCostProperties(Path cachePath, String machineType) {
    Properties prop = new Properties();
    InputStream inp = null;
    try {
      inp = new FileInputStream(cachePath.toString());
      prop.load(inp);
      return prop;
    } catch (FileNotFoundException fnf) {
      LOG.error("cost properties does not exist, using default values");
      return null;
    } catch (IOException e) {
      LOG.error("error loading properties, using default values");
      return null;
    } finally {
      if (inp != null) {
        try {
          inp.close();
        } catch (IOException ignore) {
          // do nothing
        }
      }
    }
  }
409351
protected void loadQueryProperties(String propertyFilename) throws IOException {

        Properties properties = new Properties();
        properties.load(getClass().getClassLoader().getResourceAsStream(propertyFilename));
        @SuppressWarnings("unchecked")
        Enumeration<String> propertyNames = (Enumeration<String>)properties.propertyNames();
        while (propertyNames.hasMoreElements()) {
            String propertyName = propertyNames.nextElement();
            m_queries.put(propertyName, properties.getProperty(propertyName));
        }
    }
518238
private Map<String, String> getOptionsFromPropertiesFile(String newPropertiesFile) throws MojoExecutionException {

        this.getLog().debug("Using search path at: " + this.basedir.getAbsolutePath());
        this.resourceManager.addSearchPath(FileResourceLoader.ID, this.basedir.getAbsolutePath());

        Properties properties = new Properties();
        try {
            properties.load(this.resourceManager.getResourceAsInputStream(newPropertiesFile));
        } catch (ResourceNotFoundException e) {
            getLog().debug("Property file [" + newPropertiesFile + "] cannot be found", e);
            return new HashMap<>();
        } catch (IOException e) {
            throw new MojoExecutionException("Cannot read config file [" + newPropertiesFile + "]", e);
        }

        final Map<String, String> map = new HashMap<>();
        for (final String name : properties.stringPropertyNames()) {
            map.put(name, properties.getProperty(name));
        }
        return map;
    }
964386
public static Properties loadProperties(final URL fileURL) {
        checkNotNull("fileURL", fileURL);
        final Properties props = new Properties();
        try (final InputStream inStream = fileURL.openStream()) {
            props.load(inStream);
        } catch (final IOException ex) {
            throw new RuntimeException(ex);
        }
        return props;
    }
440764
private static void loadProperties(Properties properties,InputStream inputStream,boolean internal)
    {
        try
        {
            properties.load(inputStream);
            LibraryConfigurationLoader.closeResource(inputStream);
        }
        catch(Exception exception)
        {
            LibraryConfigurationLoader.closeResource(inputStream);
            String prefix="External";
            if(internal)
            {
                prefix="Internal";
            }
            throw new FaxException(prefix+" "+LibraryConfigurationLoader.CONFIGURATION_FILE_NAME+" not found.",exception);
        }
    }
597875
public void loadPropertiesAsVariables() {
        BufferedReader reader = null;

        try {
            if (propertyFilesSet()) {
                for (String propertyFilePath : propertyFiles) {
                    Resource propertyFile = new PathMatchingResourcePatternResolver().getResource(propertyFilePath.trim());

                    log.debug("Reading property file " + propertyFile.getFilename());

                    // Use input stream as this also allows to read from resources in a JAR file
                    reader = new BufferedReader(new InputStreamReader(propertyFile.getInputStream()));

                    // local context instance handling variable replacement in property values
                    TestContext context = new TestContext();

                    // Careful!! The function registry *must* be set before setting the global variables.
                    // Variables can contain functions which are resolved when context.setGlobalVariables is invoked.
                    context.setFunctionRegistry(functionRegistry);
                    context.setGlobalVariables(globalVariables);

                    String propertyExpression;
                    while ((propertyExpression = reader.readLine()) != null) {

                        log.debug("Property line [ {} ]", propertyExpression);

                        propertyExpression = propertyExpression.trim();
                        if (!isPropertyLine(propertyExpression)) {
                            continue;
                        }

                        String key = propertyExpression.substring(0, propertyExpression.indexOf('=')).trim();
                        String value = propertyExpression.substring(propertyExpression.indexOf('=') + 1).trim();

                        log.debug("Property value replace dynamic content [ {} ]", value);
                        value = context.replaceDynamicContentInString(value);

                        if (log.isDebugEnabled()) {
                            log.debug("Loading property: " + key + "=" + value + " into default variables");
                        }

                        if (log.isDebugEnabled() && globalVariables.getVariables().containsKey(key)) {
                            log.debug("Overwriting property " + key + " old value:" + globalVariables.getVariables().get(key)
                                    + " new value:" + value);
                        }

                        globalVariables.getVariables().put(key, value);
                        // we need to keep local context up to date in case of recursive variable usage
                        context.setVariable(key, globalVariables.getVariables().get(key));
                    }

                    log.info("Loaded property file " + propertyFile.getFilename());
                }
            }
        } catch (IOException e) {
            throw new CitrusRuntimeException("Error while loading property file", e);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    log.warn("Unable to close property file reader", e);
                }
            }
        }
    }
1024842
public static void loadPropertiesFile(final String filenameOrUrl)
    {
        final Properties properties = new Properties(System.getProperties());
        System.getProperties().forEach(properties::put);

        final URL resource = ClassLoader.getSystemClassLoader().getResource(filenameOrUrl);
        if (null != resource)
        {
            try (InputStream in = resource.openStream())
            {
                properties.load(in);
            }
            catch (final Exception ignore)
            {
            }
        }

        final File file = new File(filenameOrUrl);
        if (file.exists())
        {
            try (FileInputStream in = new FileInputStream(file))
            {
                properties.load(in);
            }
            catch (final Exception ignore)
            {
            }
        }

        try (InputStream in = new URL(filenameOrUrl).openStream())
        {
            properties.load(in);
        }
        catch (final Exception ignore)
        {
        }

        System.setProperties(properties);
    }
1347911
public static ApplicationTemplateDescriptor load( File f ) throws IOException {

		// Read the file's content
		String fileContent = Utils.readFileContent( f );
		Logger logger = Logger.getLogger( ApplicationTemplateDescriptor.class.getName());
		Properties properties = Utils.readPropertiesQuietly( fileContent, logger );
		if( properties.get( "fail.read" ) != null )
			throw new IOException( "This is for test purpose..." );

		ApplicationTemplateDescriptor result = load( properties );

		// Resolve line numbers then
		int lineNumber = 1;
		for( String line : fileContent.split( "\n" )) {

			for( String property : ALL_PROPERTIES ) {
				if( line.trim().matches( "(" + LEGACY_PREFIX + ")?" + property + "\\s*[:=].*" )) {
					result.propertyToLine.put( property, lineNumber );
					break;
				}
			}

			lineNumber ++;
		}

		return result;
	}
980194
public void setProjectProperties(final Properties properties) {
        generateProjectPropertiesFile(getName(), propertyFile, true, properties, false, null, false);
        loadProperties();
    }
220196
public void loadPropertyFile(String file, Properties target)
  {
    try
    {
      // Use SecuritySupport class to provide priveleged access to property file
      SecuritySupport ss = SecuritySupport.getInstance();

      InputStream is = ss.getResourceAsStream(ObjectFactory.findClassLoader(),
                                              file);

      // get a buffered version
      BufferedInputStream bis = new BufferedInputStream(is);

      target.load(bis);  // and load up the property bag from this
      bis.close();  // close out after reading
    }
    catch (Exception ex)
    {
      // ex.printStackTrace();
      throw new org.apache.xml.utils.WrappedRuntimeException(ex);
    }
  }
1104125
private void loadBuildPropertyFile(Project project, TestContext context) {
        if (StringUtils.hasText(propertyFilePath)) {
            String propertyFileResource = context.replaceDynamicContentInString(propertyFilePath);
            log.info("Reading build property file: " + propertyFileResource);
            Properties fileProperties;
            try {
                fileProperties = PropertiesLoaderUtils.loadProperties(new PathMatchingResourcePatternResolver().getResource(propertyFileResource));
                
                for (Entry<Object, Object> entry : fileProperties.entrySet()) {
                    String propertyValue = entry.getValue() != null ? context.replaceDynamicContentInString(entry.getValue().toString()) : "";

                    if (log.isDebugEnabled()) {
                        log.debug("Set build property from file resource: " + entry.getKey() + "=" + propertyValue);
                    }
                    project.setProperty(entry.getKey().toString(), propertyValue);
                }
            } catch (IOException e) {
                throw new CitrusRuntimeException("Failed to read build property file", e);
            }
        }
    }
1284787
private Properties loadConfigurationProperties() {
        String configurationFileName = getConfigurationFileName();
        if (Strings.isNullOrEmpty(configurationFileName)) {
            log.info("JSLint property file not specified. Using default configuration.");
            return null;
        }
        return loadProperties(configurationFileName);
    }
1115497
@InitParam(name = "accept-mappings-file")
    public void setAcceptMappingsFile(String pPropertiesFile) throws ServletConfigException {
        // NOTE: Format is:
        // <agent-name>=<reg-exp>
        // <agent-name>.accept=<http-accept-header>

        Properties mappings = new Properties();

        try {
            log("Reading Accept-mappings properties file: " + pPropertiesFile);
            mappings.load(getServletContext().getResourceAsStream(pPropertiesFile));

            //System.out.println("--> Loaded file: " + pPropertiesFile);
        }
        catch (IOException e) {
            throw new ServletConfigException("Could not read Accept-mappings properties file: " + pPropertiesFile, e);
        }

        parseMappings(mappings);
    }
1235061
private void loadAndCheckPropertyFile() {
        final String methodName = "loadAndCheckPropertyFile()";
        final File f = new File(htodPropertyFileName);
        final File swapDirPathFile = new File(swapDirPath);
        final CacheOnDisk cod = this;
        traceDebug(methodName, "cacheName=" + this.cacheName);
        AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                cod.propertyFileStatus = PROPERTY_FILE_OK;
                String[] files = swapDirPathFile.list();
                if (files != null && files.length > 0) {
                    for (int i = 0; i < files.length; i++) {
                        if (files[i].startsWith(HTOD_PREF + HTODDynacache.object_suffix)) {
                            cod.dataFiles++;
                        } else if (files[i].startsWith(HTOD_PREF + HTODDynacache.dependency_suffix)) {
                            cod.dependencyIdFiles++;
                        } else if (files[i].startsWith(HTOD_PREF + HTODDynacache.template_suffix)) {
                            cod.templateFiles++;
                        }
                    }
                } else {
                    traceDebug(methodName, "cacheName=" + cod.cacheName + " no disk cache files exist");
                    cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_NO_FILES);
                    return null;
                }
                if (f.exists()) {
                    FileInputStream fis = null;
                    try {
                        fis = new FileInputStream(f);
                        Properties htodProp = new Properties();
                        htodProp.load(fis);

                        String sTemp = (String) htodProp.get(DISABLE_DEPENDENCY_ID);
                        if (sTemp != null) {
                            cod.disableDependencyIdFromPropertyFile = (Boolean.valueOf(sTemp)).booleanValue();
                        } else {
                            cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_DISABLE_DEPID);
                        }
                        sTemp = (String) htodProp.get(DISABLE_TEMPLATE_SUPPORT);
                        if (sTemp != null) {
                            cod.disableTemplatesSupprotFromPropertyFile = (Boolean.valueOf(sTemp)).booleanValue();
                        } else {
                            cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_DISABLE_TEMPLATE);
                        }
                        sTemp = (String) htodProp.get(CACHE_SIZE_IN_BYTES);
                        long currentCacheSizeInBytes = 0;
                        if (sTemp != null) {
                            currentCacheSizeInBytes = Long.parseLong(sTemp);
                        } else {
                            cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_CACHE_SIZE);
                            return null;
                        }
                        byte[] b = sTemp.getBytes("UTF-8");
                        int fieldCheck = 0;
                        for (int i = 0; i < b.length; i++) {
                            fieldCheck += (int) b[i];
                        }
                        fieldCheck = fieldCheck * 3;
                        sTemp = (String) htodProp.get(FIELD_CHECK);
                        if (sTemp != null) {
                            int expFieldCheck = Integer.parseInt(sTemp);
                            if (fieldCheck != expFieldCheck) {
                                cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_FIELD_CHECK);
                                return null;
                            }
                        } else {
                            cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_FIELD_CHECK);
                            return null;
                        }

                        sTemp = (String) htodProp.get(DATA_GB);
                        int dataGB = 0;
                        if (sTemp != null) {
                            dataGB = Integer.parseInt(sTemp);
                        } else {
                            cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_GB);
                            return null;
                        }
                        sTemp = (String) htodProp.get(DEPID_GB);
                        int dependencyIdGB = 0;
                        if (sTemp != null) {
                            dependencyIdGB = Integer.parseInt(sTemp);
                        } else {
                            cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_GB);
                            return null;
                        }
                        sTemp = (String) htodProp.get(TEMPLATE_GB);
                        int templateGB = 0;
                        if (sTemp != null) {
                            templateGB = Integer.parseInt(sTemp);
                        } else {
                            cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_GB);
                            return null;
                        }
                        cod.currentCacheSizeInBytes = currentCacheSizeInBytes;
                        cod.dataGB = dataGB;
                        cod.dependencyIdGB = dependencyIdGB;
                        cod.templateGB = templateGB;

                        traceDebug(methodName, "cacheName=" + cod.cacheName + " htod.properties exist with status=" + cod.propertyFileStatus
                                               + " disableDependencyIdFromProperty=" + cod.disableDependencyIdFromPropertyFile
                                               + " disableTemplatesSupportFromProperty=" + cod.disableTemplatesSupprotFromPropertyFile + " cacheSizeInBytes="
                                               + cod.currentCacheSizeInBytes + " dataGB=" + cod.dataGB + " dependencyIdGB=" + cod.dependencyIdGB + " templateGB="
                                               + cod.templateGB);
                    } catch (Throwable t) {
                        com.ibm.ws.ffdc.FFDCFilter.processException(t, "com.ibm.ws.cache.CacheOnDisk.loadAndCheckPropertyFile", "782", cod);
                        traceDebug(methodName, "cacheName=" + cod.cacheName + "\nException: " + ExceptionUtility.getStackTrace(t));
                        cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_FILE_CORRUPT);
                    } finally {
                        try {
                            if (fis != null) {
                                fis.close();
                            }
                        } catch (Throwable t) {
                            com.ibm.ws.ffdc.FFDCFilter.processException(t, "com.ibm.ws.cache.CacheOnDisk.loadAndCheckPropertyFile", "791", cod);
                            traceDebug(methodName, "cacheName=" + cod.cacheName + "\nException: " + ExceptionUtility.getStackTrace(t));
                        }
                    }

                } else {
                    cod.propertyFileStatus = (byte) (cod.propertyFileStatus | PROPERTY_ERROR_FILE_NOT_EXIST);
                    traceDebug(methodName, "cacheName=" + cod.cacheName + " htod.properties not exist" + " dependencyIdFiles="
                                           + cod.dependencyIdFiles + " templateFiles=" + cod.templateFiles);
                }
                return null;
            }
        });
    }