package be.nikiroo.fanfix.library;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import be.nikiroo.utils.IOUtils;
-import be.nikiroo.utils.StringUtils;
import be.nikiroo.utils.streams.ReplaceInputStream;
public class Template {
valueOne.close();
}
}
+
from[i] = "${" + key + "}";
to[i] = value.toString();
}
InputStream in = IOUtils.openResource(location, name);
-
- //TODO: pending fix in replace stream
- String data = IOUtils.readSmallStream(in);
- in.close();
- for(i = 0 ; i < from.length;i++) {
- data=data.replace(from[i], to[i]);
- }
-
- //in = new ReplaceInputStream(in, from, to);
- in = new ByteArrayInputStream(StringUtils.getBytes(data));
- // END TODO
-
- return in;
+ return new ReplaceInputStream(in, from, to);
}
public synchronized Template set(String key, String value) {
- values.put(key, value);
+ values.put(key, value == null ? "" : value);
valuesTemplate.remove(key);
valuesTemplateList.remove(key);
return this;
}
public synchronized Template set(String key, Template value) {
+ if (value == null) {
+ return set(key, "");
+ }
+
values.remove(key);
valuesTemplate.put(key, value);
valuesTemplateList.remove(key);
+
return this;
}