public ChildSettings(Settings parentSettings) { super(parentSettings.getDefinitions(), parentSettings.getEncryption()); this.parentSettings = parentSettings; }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("Settings"); PropertyDefinitions definitions = settings.getDefinitions(); TreeMap<String, String> orderedProps = new TreeMap<>(settings.getProperties()); for (Map.Entry<String, String> prop : orderedProps.entrySet()) { String key = prop.getKey(); String value = obfuscateValue(definitions, key, prop.getValue()); setAttribute(protobuf, key, value); } return protobuf.build(); }
@Test public void shouldCreateByIntrospectingComponent() { Settings settings = new MapSettings(); settings.getDefinitions().addComponent(MyComponent.class); // property definition has been loaded, ie for default value assertThat(settings.getDefaultValue("foo")).isEqualTo("bar"); }
public ChildSettings(Settings parentSettings) { super(parentSettings.getDefinitions(), parentSettings.getEncryption()); this.parentSettings = parentSettings; }
public Settings setProperty(String key, @Nullable String[] values) { PropertyDefinition property = getDefinitions().get(key); if ((null == property) || (!property.multiValues())) { throw new IllegalStateException("Fail to set multiple values on a single value property " + key); } String text = null; if (values != null) { List<String> escaped = Lists.newArrayList(); for (String value : values) { if (null != value) { escaped.add(value.replace(",", "%2C")); } else { escaped.add(""); } } String escapedValue = Joiner.on(',').join(escaped); text = StringUtils.trim(escapedValue); } return setProperty(key, text); }
/** * Value is split by comma and trimmed. Never returns null. * <p/> * Examples : * <ul> * <li>"one,two,three " -> ["one", "two", "three"]</li> * <li>" one, two, three " -> ["one", "two", "three"]</li> * <li>"one, , three" -> ["one", "", "three"]</li> * </ul> */ public String[] getStringArray(String key) { PropertyDefinition property = getDefinitions().get(key); if ((null != property) && (property.multiValues())) { String value = getString(key); if (value == null) { return ArrayUtils.EMPTY_STRING_ARRAY; } List<String> values = Lists.newArrayList(); for (String v : Splitter.on(",").trimResults().split(value)) { values.add(v.replace("%2C", ",")); } return values.toArray(new String[values.size()]); } return getStringArrayBySeparator(key, ","); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("Settings"); PropertyDefinitions definitions = settings.getDefinitions(); TreeMap<String, String> orderedProps = new TreeMap<>(settings.getProperties()); for (Map.Entry<String, String> prop : orderedProps.entrySet()) { String key = prop.getKey(); String value = obfuscateValue(definitions, key, prop.getValue()); setAttribute(protobuf, key, value); } return protobuf.build(); }