Assign image keyname and pubkey at vnf level
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / apps / devicemanager / impl / src / main / java / org / opendaylight / mwtn / base / internalTypes / TemplateFile.java
1 package org.opendaylight.mwtn.base.internalTypes;
2
3 import java.io.BufferedReader;
4 import java.io.File;
5 import java.io.FileReader;
6 import java.io.IOException;
7 import java.util.HashMap;
8 import java.util.Map;
9
10 public class TemplateFile {
11
12         protected final HashMap<String, Object> mKeyValuePairs;
13         private final String mContent;
14
15         public TemplateFile(String content)
16         {
17                 this.mKeyValuePairs = new HashMap<>();
18                 this.mContent=content;
19
20         }
21         public TemplateFile(File f) throws IOException {
22                 this.mKeyValuePairs = new HashMap<>();
23                 BufferedReader br = new BufferedReader(new FileReader(f));
24                 StringBuilder sb = new StringBuilder();
25                 String line = br.readLine();
26
27                 while (line != null) {
28                         sb.append(line);
29                         line = br.readLine();
30                 }
31                 this.mContent = sb.toString();
32                 br.close();
33         }
34
35         public void addValue(String key, Object value) {
36                 this.mKeyValuePairs.put(key, value);
37         }
38
39         public void removeValue(String key) {
40                 this.mKeyValuePairs.remove(key);
41         }
42
43         private String replace() {
44                 String s=this.mContent;
45                 String key;
46                 Object value;
47                 for (Map.Entry<String, Object> entry : this.mKeyValuePairs.entrySet()) {
48                     key = entry.getKey();
49                     value = entry.getValue();
50                     if(value!=null)
51                         s=s.replace(key, value.toString());
52                 }
53                 return s;
54         }
55
56         @Override
57         public String toString() {
58                 return this.replace();
59         }
60
61 }