public List<String> getPropertiesPrefixes() { return getPropertiesPrefixes(getClass()); }
public void initProperties() { initProperties(getPropertiesReader().orElse(null)); }
@Override public void init() { if(initialized) return; initialized = true; initProperties(); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public AbstractTextTerminal() { this.properties = new TerminalProperties(this); addDefaultProperty(PropertiesConstants.PROP_USER_INTERRUPT_KEY, DEFAULT_USER_INTERRUPT_KEY); }
public void initProperties(Reader propsReader) { Properties rawProps = new Properties(); if(propsReader != null) { try { rawProps.load(propsReader); } catch (IOException e) { logger.warn("Failed to read terminal properties.", e); } } initProperties(rawProps); }
private List<String> getPropertiesPrefixes(Class<?> cls) { if((cls == null) || !(TextTerminal.class.isAssignableFrom(cls))) return Collections.emptyList(); List<String> superPrefixes = getPropertiesPrefixes(cls.getSuperclass()); PropertiesPrefixes annotation = cls.getAnnotation(PropertiesPrefixes.class); if(annotation == null) return superPrefixes; List<String> prefixes = Arrays.asList(annotation.value()); if(superPrefixes.isEmpty()) return prefixes; List<String> allPrefixes = new ArrayList<>(superPrefixes); allPrefixes.addAll(prefixes); return allPrefixes; }
public void initProperties(Properties rawProps) { Map<String,String> props = new HashMap<>(defaultProperties); for(String pp : getPropertiesPrefixes()) { String prefix = pp + "."; int prefixLen = prefix.length(); for(String key : rawProps.stringPropertyNames()) { key = key.trim(); if(key.startsWith(prefix)) { String value = rawProps.getProperty(key); if(value != null) { value = value.trim(); } props.put(key.substring(prefixLen), value); } } } properties.putAll(props); } }