Skip to content
Permalink
4c92353f95
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 27 lines (25 sloc) 1.09 KB
(ns de.mpg.shh.util-properties.properties
(:require [clojure.java.io :as io]
[clojure.string :as str]))
(defn properties->map
"Convert the properties list to a map, transforming the value
whenever a transformer is defined for that key."
([properties]
(properties->map properties {}))
([properties transformer-for]
(letfn [(keyfor [s] (mapv keyword (str/split (key s) #"\.")))]
(reduce (fn [accum entry]
(let [k (keyfor entry)]
(if-let [f (transformer-for k)]
(assoc-in accum k (f (val entry)))
(assoc-in accum k (val entry)))))
{} properties))))
(defn load-properties
"Load named properties file from the classpath, return a map with
values optionally transformed by `transform-map`."
([resource-name]
(load-properties resource-name {}))
([resource-name transform-map]
(when-let [resource (io/resource resource-name)]
(let [properties (doto (java.util.Properties.) (.load (io/input-stream resource)))]
(properties->map properties transform-map)))))