[FELIX-4433] Provide more control over the substitution
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1570599 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java b/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java
index b3a07fb..833f92a 100644
--- a/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java
+++ b/utils/src/main/java/org/apache/felix/utils/properties/InterpolationHelper.java
@@ -267,11 +267,11 @@
return val;
}
- private static class BundleContextSubstitutionCallback implements SubstitutionCallback
+ static class BundleContextSubstitutionCallback implements SubstitutionCallback
{
private final BundleContext context;
- private BundleContextSubstitutionCallback(BundleContext context)
+ public BundleContextSubstitutionCallback(BundleContext context)
{
this.context = context;
}
diff --git a/utils/src/main/java/org/apache/felix/utils/properties/Properties.java b/utils/src/main/java/org/apache/felix/utils/properties/Properties.java
index bb15907..81817aa 100644
--- a/utils/src/main/java/org/apache/felix/utils/properties/Properties.java
+++ b/utils/src/main/java/org/apache/felix/utils/properties/Properties.java
@@ -86,22 +86,36 @@
private List<String> header;
private List<String> footer;
private File location;
- private BundleContext context;
+ private InterpolationHelper.SubstitutionCallback callback;
+ private boolean substitute = true;
public Properties() {
}
public Properties(File location) throws IOException {
- this(location, null);
+ this(location, (InterpolationHelper.SubstitutionCallback) null);
}
public Properties(File location, BundleContext context) throws IOException {
+ this(location, new InterpolationHelper.BundleContextSubstitutionCallback(context));
+ }
+
+ public Properties(File location, InterpolationHelper.SubstitutionCallback callback) throws IOException {
this.location = location;
- this.context = context;
+ this.callback = callback;
if(location.exists())
load(location);
}
+ public Properties(boolean substitute) throws IOException {
+ this.substitute = substitute;
+ }
+
+ public Properties(File location, boolean substitute) throws IOException {
+ this.location = location;
+ this.substitute = substitute;
+ }
+
public void load(File location) throws IOException {
InputStream is = new FileInputStream(location);
try {
@@ -347,13 +361,27 @@
new ArrayList<String>(reader.getValueLines())));
}
footer = new ArrayList<String>(reader.getCommentLines());
- if(context != null)
+ if (substitute)
{
- InterpolationHelper.performSubstitution(storage, context);
+ substitute();
+ }
+ }
+
+ public void substitute()
+ {
+ substitute(callback);
+ }
+
+ public void substitute(InterpolationHelper.SubstitutionCallback callback)
+ {
+ if(callback != null)
+ {
+ InterpolationHelper.performSubstitution(storage, callback);
}
else {
InterpolationHelper.performSubstitution(storage);
}
+
}
/**