/*
 * Copyright 2013-2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.cloud.consul.config;

import static org.springframework.util.Base64Utils.decodeFromString;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.core.env.EnumerablePropertySource;

import com.ecwid.consul.v1.ConsulClient;
import com.ecwid.consul.v1.QueryParams;
import com.ecwid.consul.v1.Response;
import com.ecwid.consul.v1.kv.model.GetValue;
import org.springframework.util.StringUtils;

/**
 * @author Spencer Gibb
 */
public class ConsulPropertySource extends EnumerablePropertySource<ConsulClient> {

	private String context;

	private Map<String, String> properties = new LinkedHashMap<>();

	public ConsulPropertySource(String context, ConsulClient source) {
		super(context, source);
		this.context = context;

		if (!this.context.endsWith("/")) {
			this.context = this.context + "/";
		}
	}

	public void init() {
		Response<List<GetValue>> response = source.getKVValues(context,
				QueryParams.DEFAULT);
		List<GetValue> values = response.getValue();

		if (values != null) {
			for (GetValue getValue : values) {
                String key = getValue.getKey();
                if (!StringUtils.endsWithIgnoreCase(key, "/")) {
	    			key = key.replace(context, "").replace('/', '.');
    				String value = getDecoded(getValue.getValue());
					properties.put(key, value);
				}
			}
		}
	}

	public String getDecoded(String value) {
		if (value == null)
			return null;
		return new String(decodeFromString(value));
	}

	@Override
	public Object getProperty(String name) {
		return properties.get(name);
	}

	@Override
	public String[] getPropertyNames() {
		return properties.keySet().toArray(new String[0]);
	}
}

@@ -817,71 +817,8 @@
 p;%0A%0A
-import org.springframework.core.env.EnumerablePropertySource;%0A%0A
 impo
@@ -977,16 +977,78 @@
 tValue;%0A
+import org.springframework.core.env.EnumerablePropertySource;%0A
 import o
@@ -1721,32 +1721,20 @@
 lues) %7B%0A
-                
+%09%09%09%09
 String k
@@ -1761,24 +1761,12 @@
 ();%0A
-                
+%09%09%09%09
 if (
@@ -1811,23 +1811,20 @@
 /%22)) %7B%0A%09
-    
 %09%09%09
+%09
 key = ke
@@ -1865,20 +1865,17 @@
 , '.');%0A
-    
+%09
 %09%09%09%09Stri

Reformat code