1 package org.kuali.common.util.properties;
2
3 import java.util.Properties;
4
5 import org.kuali.common.util.Assert;
6 import org.kuali.common.util.LocationUtils;
7 import org.kuali.common.util.ModeUtils;
8 import org.kuali.common.util.PropertyUtils;
9
10 public final class LocationLoader implements PropertiesLoader {
11
12 private final String value;
13 private final Location location;
14
15 public LocationLoader(Location location) {
16 this(location, location.getValue());
17 }
18
19 public LocationLoader(Location location, String value) {
20 Assert.noNulls(location);
21 Assert.noBlanks(value);
22 this.value = value;
23 this.location = location;
24 }
25
26 @Override
27 public Properties load() {
28 if (!LocationUtils.exists(value)) {
29
30 ModeUtils.validate(location.getMissingMode(), "Non-existent location [" + value + "]");
31 return PropertyUtils.EMPTY;
32 } else {
33 return PropertyUtils.load(value, location.getEncoding(), location.getFormat());
34 }
35 }
36
37 public String getValue() {
38 return value;
39 }
40
41 public Location getLocation() {
42 return location;
43 }
44
45 }