/* 
 * The MIT License
 *
 * Copyright 2014 exsio.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package pl.exsio.jin.file.loader;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import org.yaml.snakeyaml.Yaml;
import pl.exsio.jin.file.locator.TranslationFileLocator;

public class YamlTranslationFileLoaderImpl implements TranslationFileLoader {

    protected TranslationFileLocator locator;

    @Override
    public Map<String, String> loadFile(String filePath) throws IOException {
        InputStream input = this.locator.locateFile(filePath);
        Map<String, Object> loadedMap = (Map<String, Object>) new Yaml().load(input);
        return this.parseMap(loadedMap, null);
    }

    protected Map<String, String> parseMap(Map<String, Object> map, String parentKey) {
        Map<String, String> parsedMap = new HashMap<>();
        for (String key : map.keySet()) {
            String mapKey = parentKey != null ? parentKey + "." + key : key;
            Object value = map.get(key);
            if (value instanceof String) {
                parsedMap.put(mapKey, (String) value);
            } else if (value instanceof Map) {
                parsedMap.putAll(this.parseMap((Map<String, Object>) value, mapKey));
            }
        }

        return parsedMap;
    }

    @Override
    public void setLocator(TranslationFileLocator locator) {
        this.locator = locator;
    }

}

@@ -1641,30 +1641,30 @@
         Map%3C
-String
+Object
 , Object%3E lo
@@ -1674,30 +1674,30 @@
 dMap = (Map%3C
-String
+Object
 , Object%3E) n
@@ -1816,30 +1816,30 @@
 arseMap(Map%3C
-String
+Object
 , Object%3E ma
@@ -1931,22 +1931,22 @@
    for (
-String
+Object
  key : m
@@ -1956,24 +1956,69 @@
 keySet()) %7B%0A
+            if (key instanceof String) %7B%0A    
             
@@ -2078,16 +2078,42 @@
  key
- : key;%0A
+.toString() : key.toString();%0A    
     
@@ -2157,24 +2157,28 @@
             
+    
 if (value in
@@ -2204,32 +2204,36 @@
                 
+  
+  
 parsedMap.put(ma
@@ -2267,16 +2267,20 @@
         
+    
 %7D else i
@@ -2302,24 +2302,28 @@
 ceof Map) %7B%0A
+    
             
@@ -2362,22 +2362,22 @@
 ap((Map%3C
-String
+Object
 , Object
@@ -2396,16 +2396,34 @@
 pKey));%0A
+                %7D%0A
         

secure YamlTranslationFileLoder from reading a key as non-String