Commit a5f5092f authored by Jason Song's avatar Jason Song Committed by GitHub

add txt file format

parent dd0a5678
package com.ctrip.framework.apollo.internals;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
public class TxtConfigFile extends PlainTextConfigFile {
public TxtConfigFile(String namespace, ConfigRepository configRepository) {
super(namespace, configRepository);
}
@Override
public ConfigFileFormat getConfigFileFormat() {
return ConfigFileFormat.TXT;
}
}
......@@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.spi;
import com.ctrip.framework.apollo.ConfigService;
import com.ctrip.framework.apollo.PropertiesCompatibleConfigFile;
import com.ctrip.framework.apollo.internals.PropertiesCompatibleFileConfigRepository;
import com.ctrip.framework.apollo.internals.TxtConfigFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -55,6 +56,8 @@ public class DefaultConfigFactory implements ConfigFactory {
return new YamlConfigFile(namespace, configRepository);
case YML:
return new YmlConfigFile(namespace, configRepository);
case TXT:
return new TxtConfigFile(namespace, configRepository);
}
return null;
......
package com.ctrip.framework.apollo.internals;
import static org.junit.Assert.*;
import static org.mockito.Mockito.when;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class TxtConfigFileTest {
private String someNamespace;
@Mock
private ConfigRepository configRepository;
@Before
public void setUp() throws Exception {
someNamespace = "someName";
}
@Test
public void testWhenHasContent() throws Exception {
Properties someProperties = new Properties();
String key = ConfigConsts.CONFIG_FILE_CONTENT_KEY;
String someValue = "someValue";
someProperties.setProperty(key, someValue);
when(configRepository.getConfig()).thenReturn(someProperties);
TxtConfigFile configFile = new TxtConfigFile(someNamespace, configRepository);
assertEquals(ConfigFileFormat.TXT, configFile.getConfigFileFormat());
assertEquals(someNamespace, configFile.getNamespace());
assertTrue(configFile.hasContent());
assertEquals(someValue, configFile.getContent());
}
}
......@@ -6,7 +6,7 @@ import com.ctrip.framework.apollo.core.utils.StringUtils;
* @author Jason Song(song_s@ctrip.com)
*/
public enum ConfigFileFormat {
Properties("properties"), XML("xml"), JSON("json"), YML("yml"), YAML("yaml");
Properties("properties"), XML("xml"), JSON("json"), YML("yml"), YAML("yaml"), TXT("txt");
private String value;
......@@ -22,7 +22,7 @@ public enum ConfigFileFormat {
if (StringUtils.isEmpty(value)) {
throw new IllegalArgumentException("value can not be empty");
}
switch (value) {
switch (value.toLowerCase()) {
case "properties":
return Properties;
case "xml":
......@@ -33,6 +33,8 @@ public enum ConfigFileFormat {
return YML;
case "yaml":
return YAML;
case "txt":
return TXT;
}
throw new IllegalArgumentException(value + " can not map enum");
}
......
......@@ -57,7 +57,7 @@
<li>
通过创建一个私有的Namespace可以实现分组管理配置
</li>
<li>私有Namespace的格式可以是xml、yml、yaml、json. 您可以通过apollo-client中ConfigFile接口来获取非properties格式Namespace的内容</li>
<li>私有Namespace的格式可以是xml、yml、yaml、json、txt. 您可以通过apollo-client中ConfigFile接口来获取非properties格式Namespace的内容</li>
<li>1.3.0及以上版本的apollo-client针对yaml/yml提供了更好的支持,可以通过ConfigService.getConfig("someNamespace.yml")直接获取Config对象,也可以通过@EnableApolloConfig("someNamespace.yml")或apollo.bootstrap.namespaces=someNamespace.yml注入yml配置到Spring/Spring Boot中去</li>
</ul>
</div>
......@@ -113,6 +113,7 @@
<option value="json">json</option>
<option value="yml">yml</option>
<option value="yaml">yaml</option>
<option value="txt">txt</option>
</select>
</div>
......
......@@ -92,7 +92,7 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
//namespace view name hide suffix
namespace.viewName = namespace.baseInfo.namespaceName.replace(".xml", "").replace(
".properties", "").replace(".json", "").replace(".yml", "")
.replace(".yaml", "");
.replace(".yaml", "").replace(".txt", "");
}
function init() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment