/** * Convenience method used to load properties from the given file. * * @param props the properties object to be loaded into * @param propertyFile the properties file to read */ public static void loadProperties(Properties props, File propertyFile) { try { loadProperties(props, new FileInputStream(propertyFile)); } catch (FileNotFoundException fnfe) { log.error("Unable to find properties file" + fnfe); } }
/** * Convenience method to scan the available properties files, looking for the one that has a * definition for the given code. * * @param code * @return the file which defines the code, or null if not found */ private Resource findPropertiesFileFor(String code) { Properties props = new Properties(); Resource foundFile = null; for (Resource propertiesFile : findPropertiesFiles()) { props.clear(); try { OpenmrsUtil.loadProperties(props, propertiesFile.getInputStream()); } catch (Exception e) { log.error("Error generated", e); } if (props.containsKey(code)) { foundFile = propertiesFile; break; } } return foundFile; }
URL url = getClass().getResource("/hibernate.default.properties"); File file = new File(url.getPath()); OpenmrsUtil.loadProperties(props, file);
OpenmrsUtil.loadProperties(props, propertyStream);
private DefaultMessageSourceServiceImpl() { InputStream stream = OpenmrsClassLoader.getInstance().getResourceAsStream("messages.properties"); if (stream != null) { OpenmrsUtil.loadProperties(props, stream); } }
/** * Returns all available messages. * * @see org.openmrs.messagesource.MessageSourceService#getPresentations() */ @Override public Collection<PresentationMessage> getPresentations() { Collection<PresentationMessage> presentations = new ArrayList<>(); for (Resource propertiesFile : findPropertiesFiles()) { Locale currentLocale = parseLocaleFrom(propertiesFile.getFilename()); Properties props = new Properties(); try { OpenmrsUtil.loadProperties(props, propertiesFile.getInputStream()); for (Map.Entry<Object, Object> property : props.entrySet()) { presentations.add(new PresentationMessage(property.getKey().toString(), currentLocale, property .getValue().toString(), "")); } } catch (Exception e) { // skip over errors in loading a single file log.error("Unable to load properties from file: " + propertiesFile.getFilename(), e); } } return presentations; }
OpenmrsUtil.loadProperties(props, propertyStream); propertyStream.close(); log.info("Using runtime properties file: " + pathName);
/** * @see org.openmrs.messagesource.MutableMessageSource#removePresentation(org.openmrs.messagesource.PresentationMessage) */ @Override public void removePresentation(PresentationMessage message) { Resource propertyFile = findPropertiesFileFor(message.getCode()); if (propertyFile != null) { Properties props = new Properties(); try { OpenmrsUtil.loadProperties(props, propertyFile.getInputStream()); props.remove(message.getCode()); //TODO properties files are now in api jar files which cannot be modified. TRUNK-4097 //We should therefore remove this method implementation or stop claiming that we are a mutable resource //OpenmrsUtil.storeProperties(props, propertyFile, PROPERTIES_FILE_COMMENT); } catch (Exception e) { log.error("Error generated", e); } } }
/** * @see org.openmrs.messagesource.MutableMessageSource#addPresentation(org.openmrs.messagesource.PresentationMessage) */ @Override public void addPresentation(PresentationMessage message) { Resource propertyFile = findPropertiesFileFor(message.getCode()); if (propertyFile != null) { Properties props = new Properties(); try { OpenmrsUtil.loadProperties(props, propertyFile.getInputStream()); props.setProperty(message.getCode(), message.getMessage()); //TODO properties files are now in api jar files which cannot be modified. TRUNK-4097 //We should therefore remove this method implementation or stop claiming that we are a mutable resource //OpenmrsUtil.storeProperties(props, propertyFile.getInputStream(), "OpenMRS Application Messages"); } catch (Exception e) { log.error("Error generated", e); } } }
OpenmrsUtil.loadProperties(props, propertiesFile.getInputStream()); fileToPropertiesMap.put(propertiesFile, props);
Properties props = new Properties(); OpenmrsUtil.loadProperties(props, propertyStream); propertyStream.close();
OpenmrsUtil.loadProperties(props, propertyStream); propertyStream.close();
/** * Determines the name of the proper test dataset based on what version of OpenMRS we are testing against */ public String getTestDatasetFilename(String testDatasetName) throws Exception { InputStream propertiesFileStream = null; // try to load the file if its a straight up path to the file or // if its a classpath path to the file if (new File(TEST_DATASETS_PROPERTIES_FILE).exists()) { propertiesFileStream = new FileInputStream(TEST_DATASETS_PROPERTIES_FILE); } else { propertiesFileStream = getClass().getClassLoader().getResourceAsStream(TEST_DATASETS_PROPERTIES_FILE); if (propertiesFileStream == null) throw new FileNotFoundException("Unable to find '" + TEST_DATASETS_PROPERTIES_FILE + "' in the classpath"); } Properties props = new Properties(); OpenmrsUtil.loadProperties(props, propertiesFileStream); if (props.getProperty(testDatasetName) == null) { throw new Exception ("Test dataset named " + testDatasetName + " not found in properties file"); } return props.getProperty(testDatasetName); }