Load a named resource as a Properties object

@param name    String resource name
@return Properties populated from the resource
@throws Throwable
182398
public static Properties getPropertiesFromResource(final String name) throws Throwable {
    Properties pr = new Properties();
    InputStream is = null;

    try {
      try {
        // The jboss?? way - should work for others as well.
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        is = cl.getResourceAsStream(name);
      } catch (Throwable clt) {}

      if (is == null) {
        // Try another way
        is = Util.class.getResourceAsStream(name);
      }

      if (is == null) {
        throw new Exception("Unable to load properties file" + name);
      }

      pr.load(is);

      //if (debug) {
      //  pr.list(System.out);
      //  Logger.getLogger(Util.class).debug(
      //      "file.encoding=" + System.getProperty("file.encoding"));
      //}
      return pr;
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (Throwable t1) {}
      }
    }
  }
1331507
protected ResourceHandle getClassHandle(final String name)
    {
        String path = name.replace('.', '/').concat(".class");
        return getResourceHandle(path);
    }
1100461
public static String getProperty(String name) {
        if (propertyProvider == null) {
            initPropertyProvider();
        }
        
        return propertyProvider.getProperty(name);
    }
146386
public static Properties loadFromResource(ServletContext servletContext, String resource) throws IOException {
		Properties props = new Properties();
		InputStream in = servletContext.getResourceAsStream(resource);
		if(in==null) throw new LocalizedIOException(accessor, "PropertiesUtils.readProperties.resourceNotFound", resource);
		try {
			props.load(in);
		} finally {
			in.close();
		}
		return props;
	}
309072
private static Properties load() {
		Properties properties = new Properties();

		String file = System.getProperty(CONFIGURATION_PROPERTY);
		try {
			if (file != null) {
				InputStream stream;
				if (URL_DETECTION_PATTERN.matcher(file).matches()) {
					stream = new URL(file).openStream();
				} else {
					stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
					if (stream == null) {
						stream = new FileInputStream(file);
					}
				}
				load(properties, stream);
			} else {
				InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(DEFAULT_CONFIGURATION_FILE);
				if (stream != null) {
					load(properties, stream);
				}
			}
		} catch (IOException ex) {
			InternalLogger.log(Level.ERROR, "Failed loading configuration from '" + file + "'");
		}

		for (Object key : new ArrayList<Object>(System.getProperties().keySet())) {
			String name = (String) key;
			if (name.startsWith(PROPERTIES_PREFIX)) {
				properties.put(name.substring(PROPERTIES_PREFIX.length()), System.getProperty(name));
			}
		}

		for (Entry<Object, Object> entry : properties.entrySet()) {
			String value = (String) entry.getValue();
			if (value.indexOf('{') != -1) {
				value = resolve(value, EnvironmentVariableResolver.INSTANCE);
				value = resolve(value, SystemPropertyResolver.INSTANCE);
				properties.put(entry.getKey(), value);
			}
		}

		return properties;
	}
1193172
public String getValue(String name) {
	    	Properties properties = loadProperties();
	    	return (String) properties.getProperty(name);
    }
729989
private T loadResourceValue(final URL resource)
	{
		try (final InputStream is = resource.openStream())
		{
			cached = null; // Prevent the old value from being used

			return setCached(clazz.cast(factory.getInstance(clazz).deserialise(is)));
		}
		catch (IOException e)
		{
			throw new RuntimeException("Error loading JAXB resource " + name + " " + clazz + " from " + resource, e);
		}
	}
1338696
@Override
    public String getProperty(String name) {
        try {
            if (name.startsWith(PREFIX) && initPropertyService()) {
                return propertyService.getValue(name.substring(PREFIX_LEN), null);
            }
        } catch (Exception e) {
            log.error("Exception getting property.", e);
        }
        
        return null;
    }
592459
protected Property getProperty(String name) {
    if (!properties.containsKey(name)) {
      properties.put(name, new Property(name));
    }
    return properties.get(name);
  }
320085
public PropertiesLoaderBuilder loadProperty(String name) {
        if (env.containsProperty(name)) {
            props.put(name, env.getProperty(name));
        }
        return this;
    }
511812
@Override
    protected Enumeration<URL> findResources(String name) {
        URL url = findResource(name);
        Vector<URL> urls = new Vector<>();
        if (url != null) {
            urls.add(url);
        }
        return urls.elements();
    }
1373988
@Override
    public void loadProperties(String restClientName){
        enableDynamicProperties = true;
        setClientName(restClientName);
        loadDefaultValues();
        Configuration props = ConfigurationManager.getConfigInstance().subset(restClientName);
        for (Iterator<String> keys = props.getKeys(); keys.hasNext(); ){
            String key = keys.next();
            String prop = key;
            try {
                if (prop.startsWith(getNameSpace())){
                    prop = prop.substring(getNameSpace().length() + 1);
                }
                setPropertyInternal(prop, getStringValue(props, key));
            } catch (Exception ex) {
                throw new RuntimeException(String.format("Property %s is invalid", prop));
            }
        }
    }
807137
public static String getProperty(String name) {
        return System.getProperty(name, System.getenv(name));
    }
55005
private static Properties loadProperties(String defaultsName, String propertiesName) throws IOException {
        Properties bundle = new Properties();
        ClassLoader loader = SecurityActions.getContextClassLoader();
        URL defaultUrl = null;
        URL url = null;
        // First check for local visibility via a URLClassLoader.findResource
        if (loader instanceof URLClassLoader) {
            URLClassLoader ucl = (URLClassLoader) loader;
            defaultUrl = SecurityActions.findResource(ucl, defaultsName);
            url = SecurityActions.findResource(ucl, propertiesName);
            PicketBoxLogger.LOGGER.traceAttemptToLoadResource(propertiesName);
        }
        // Do a general resource search
        if (defaultUrl == null) {
            defaultUrl = loader.getResource(defaultsName);
            if (defaultUrl == null) {
                try {
                    defaultUrl = new URL(defaultsName);
                } catch (MalformedURLException mue) {
                    PicketBoxLogger.LOGGER.debugFailureToOpenPropertiesFromURL(mue);
                    File tmp = new File(defaultsName);
                    if (tmp.exists()) {
                        defaultUrl = tmp.toURI().toURL();
                    }
                }
            }
        }
        if (url == null) {
            url = loader.getResource(propertiesName);
            if (url == null) {
                try {
                    url = new URL(propertiesName);
                } catch (MalformedURLException mue) {
                    PicketBoxLogger.LOGGER.debugFailureToOpenPropertiesFromURL(mue);
                    File tmp = new File(propertiesName);
                    if (tmp.exists()) {
                        url = tmp.toURI().toURL();
                    }
                }
            }
        }
        if (url == null && defaultUrl == null) {

            String propertiesFiles = propertiesName + "/" + defaultsName;
            throw PicketBoxMessages.MESSAGES.unableToFindPropertiesFile(propertiesFiles);
        }

        if (url != null) {
            InputStream is = null;
            try {
                is = SecurityActions.openStream(url);
            } catch (PrivilegedActionException e) {
                throw new IOException(e.getLocalizedMessage());
            }
            if (is != null) {
                try {
                    bundle.load(is);
                } finally {
                    safeClose(is);
                }
            } else {
                throw PicketBoxMessages.MESSAGES.unableToLoadPropertiesFile(propertiesName);
            }
            PicketBoxLogger.LOGGER.tracePropertiesFileLoaded(propertiesName, bundle.keySet());
        } else {
            InputStream is = null;
            try {
                is = defaultUrl.openStream();
                bundle.load(is);
                PicketBoxLogger.LOGGER.tracePropertiesFileLoaded(defaultsName, bundle.keySet());
            } catch (Throwable e) {
                PicketBoxLogger.LOGGER.debugFailureToLoadPropertiesFile(defaultsName, e);
            } finally {
                safeClose(is);
            }
        }
        return bundle;
    }
1144331
public static InputStream getResourceAsStream(UimaContext context, String name)
      throws ResourceInitializationException {

    InputStream inResource = getOptionalResourceAsStream(context, name);

    if (inResource == null) {
      throw new ResourceInitializationException(
          ExceptionMessages.MESSAGE_CATALOG,
          ExceptionMessages.IO_ERROR_MODEL_READING, new Object[] { name
              + " could not be found!" });
    }

    return inResource;
  }
1212026
public Object getProperty(String name) throws IllegalArgumentException {
		if (name == null) {
			throw new IllegalArgumentException("property name can not be null");
		}
		if (PROPERTY_SERIALIZER_INDENTATION.equals(name)) {
			return indentationString;
		} else if (PROPERTY_SERIALIZER_LINE_SEPARATOR.equals(name)) {
			return lineSeparator;
		} else if (PROPERTY_LOCATION.equals(name)) {
			return location;
		} else {
			return null;
		}
	}
732933
public static Properties loadProperties(Class<?> clazz, String fileName) throws IOException {
        Properties properties = new Properties();
        try (InputStream is = clazz.getClassLoader().getResourceAsStream(fileName)) {
            properties.load(is);
        }
        return properties;
    }