/** * Registers a new variable. * * @param scope The scope to register the variable at * @param name The name of the variable, complete with folders if desired. The folders must have * been previously registered. * @param description The description of the variable * @param type The type of the variable * @param defaultValue The default value. This is ignored for folders. */ public static void register( String scope, String name, String description, VarType type, String defaultValue) { scope = normalizeScope(scope); ConfigStorage storage = getConfigStorage(scope, true); if (type == VarType.folder) { registerFolder(scope, name, description); return; } ConfigVariable valueObject = storage.getVariable(name); String value; if (valueObject == null) value = null; else value = valueObject.getValue(); Variable var = new Variable(extractName(name), description, type, defaultValue, value); getScopeFolder(scope).getParent(name).add(var); }
public static void setText(String scope, String name, String text) { scope = normalizeScope(scope); Variable var = getScopeFolder(scope).getCheckedVariable(name); if (var.type == VarType.bool) { if (text.equals("true")) text = "1"; else if (text.equals("false")) text = "0"; } var.validateConformantValue(text); if (!var.fireFilters(scope, name, text)) return; if (var.type == VarType.guard) { /* * We need to iterate over all the secret variables in the same folder and * unset them. */ for (Setting setting : var.folder.getSettings()) { if ((setting instanceof Variable) && ((Variable) setting).type == VarType.secret) { Variable secretVar = (Variable) setting; String secretName; if (name.contains("/")) secretName = name.substring(0, name.lastIndexOf("/")) + "/" + secretVar.name; else secretName = secretVar.name; setText(scope, secretName, null); } } } ConfigStorage storage = getConfigStorage(scope, true); ConfigVariable storedVar = storage.getVariable(name); if (storedVar == null) { storedVar = storage.createVariable(); storedVar.setName(name); storage.getVariables().add(storedVar); } storedVar.setValue(text); var.value = text; var.fireListeners(scope, name); }