/*
 * Copyright (c) 2016-2017 by OpenText Corporation. All Rights Reserved.
 */
package com.opentext.ia.sdk.configurer;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

import org.yaml.snakeyaml.Yaml;


public class YamlConfiguration {

  private final Map<String, String> map = new HashMap<>();

  public YamlConfiguration(File yaml) throws IOException {
    try (InputStream input = new FileInputStream(yaml)) {
      expand(input);
    }
  }

  public YamlConfiguration(InputStream yaml) throws IOException {
    expand(yaml);
  }

  public YamlConfiguration(String yaml) throws IOException {
    try (InputStream input = new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8))) {
      expand(input);
    }
  }

  @SuppressWarnings("unchecked")
  private void expand(InputStream input) {
    expand((Map<String, Object>)new Yaml().load(input));
  }

  @SuppressWarnings("PMD.UnusedFormalParameter")
  private void expand(Map<String, Object> source) {
    // TODO: Expand the YAML in [source] into [map]
  }

  public Map<String, String> toMap() {
    return map;
  }

}

@@ -862,16 +862,8 @@
     
-expand((
 Map%3C
@@ -877,17 +877,66 @@
  Object%3E
-)
+ source = new HashMap%3C%3E();%0A    for (Object data : 
 new Yaml
@@ -946,16 +946,19 @@
 load
+All
 (input))
 ;%0A  
@@ -953,16 +953,91 @@
 (input))
+ %7B%0A      source.putAll((Map%3CString, Object%3E)data);%0A    %7D%0A    expand(source)
 ;%0A  %7D%0A%0A 

Support multiple documents in single YAML file