/** * Gets a particular ConfigEntry's value by its type * * @param type of the ConfigEntry * @return the requested value, the default (if there is no entry) or null (if there is no * default) */ public Object getValue(ConfigEntryType type) { ConfigEntry ce = table.get(type); if (ce != null) { return ce.getValue(); } return type.getDefault(); }
private void loadContents(BufferedReader in) throws IOException { StringBuilder buf = new StringBuilder(); while (true) { // Empty out the buffer buf.setLength(0); String line = advance(in); if (line == null) { break; } // skip blank lines if (line.length() == 0) { continue; } Matcher matcher = KEY_VALUE_PATTERN.matcher(line); if (!matcher.matches()) { log.warn("Expected to see '=' in " + internal + ": " + line); continue; } String key = matcher.group(1).trim(); String value = matcher.group(2).trim(); // Only CIPHER_KEYS that are empty are not ignored if (value.length() == 0 && !ConfigEntryType.CIPHER_KEY.getName().equals(key)) { log.warn("Ignoring empty entry in " + internal + ": " + line); continue; } // Create a configEntry so that the name is normalized. ConfigEntry configEntry = new ConfigEntry(internal, key); ConfigEntryType type = configEntry.getType(); ConfigEntry e = table.get(type); if (e == null) { if (type == null) { log.warn("Extra entry in " + internal + " of " + configEntry.getName()); extra.put(key, configEntry); } else if (type.isSynthetic()) { log.warn("Ignoring unexpected entry in " + internal + " of " + configEntry.getName()); } else { table.put(type, configEntry); } } else { configEntry = e; } buf.append(value); getContinuation(configEntry, in, buf); // History is a special case it is of the form History_x.x // The config entry is History without the x.x. // We want to put x.x at the beginning of the string value = buf.toString(); if (ConfigEntryType.HISTORY.equals(type)) { int pos = key.indexOf('_'); value = key.substring(pos + 1) + ' ' + value; } configEntry.addValue(value); } }