| 8 | import java.util.Set; |
| 9 | |
| 10 | public class MethodCall { |
| 11 | public static void main(String[] args) throws Exception{ |
| 12 | HashMap map = new HashMap(); |
| 13 | System.out.println("before:"+map); |
| 14 | |
| 15 | ModelController mc = new ModelController(); |
| 16 | String viewName = mc.main(map); |
| 17 | |
| 18 | System.out.println("after :"+map); |
| 19 | |
| 20 | render(map, viewName); |
| 21 | } |
| 22 | |
| 23 | static void render(HashMap map, String viewName) throws IOException { |
| 24 | String result = ""; |
| 25 | |
| 26 | // 1. 뷰의 내용을 한줄씩 읽어서 하나의 문자열로 만든다. |
| 27 | Scanner sc = new Scanner(new File(viewName+".txt")); |
| 28 | |
| 29 | while(sc.hasNextLine()) |
| 30 | result += sc.nextLine()+ System.lineSeparator(); |
| 31 | |
| 32 | // 2. map에 담긴 key를 하나씩 읽어서 template의 ${key}를 value바꾼다. |
| 33 | Iterator it = map.keySet().iterator(); |
| 34 | |
| 35 | while(it.hasNext()) { |
| 36 | String key = (String)it.next(); |
| 37 | |
| 38 | // 3. replace()로 key를 value 치환한다. |
| 39 | result = result.replace("${"+key+"}", (String)map.get(key)); |
| 40 | } |
| 41 | |
| 42 | // 4.렌더링 결과를 출력한다. |
| 43 | System.out.println(result); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | class ModelController { |
| 48 | public String main(HashMap map) { |
nothing calls this directly
no outgoing calls
no test coverage detected