List of usage examples for org.apache.commons.configuration2 HierarchicalConfiguration clearTree
void clearTree(String key);
From source file:com.github.technosf.posterer.modules.commons.config.CommonsConfiguratorPropertiesImpl.java
/** * Check for actionability//from w ww .j a v a2 s . c o m * <p> * If not actionable, remove, otherwise re-key as needed. * * @param actionable * the actionable being checked * @param nodeId * the node id of the of actionable representation * @param node * the actionable representation * @param config * the config holding the actionable representation * @return true if rekeys */ private static boolean actionable(Actionable actionable, int nodeId, HierarchicalConfiguration<ImmutableNode> node, HierarchicalConfiguration<ImmutableNode> config) { if (actionable.isActionable()) /* * Property is good. */ { // System.out.printf("%1$S::%2$s", hashCode, pdi.hashCode()); if (nodeId != actionable.hashCode()) /* * The config hash changed and needs reindexing */ { node.setProperty("id", actionable.hashCode()); } return true; } // if (proxy.isActionable()) else /* * Property was ill formed - remove from file */ { String key = node.getString("id"); config.clearTree(key); return false; } }
From source file:com.gs.obevo.api.factory.XmlFileConfigReader.java
/** * Backwards-compatible changes to ensure existing XML consumers are not negatively affected. *///from www.j ava 2s. c om private void postProcess(XMLConfiguration sysCfg) { ImmutableSet<String> ignorableSysAttributes = Sets.immutable.of("cleanBuildAllowed", "name", "defaultUserId", "defaultPassword", "dbHost", "dbPort", "dbServer", "dbSchemaPrefix", "dbSchemaSuffix", "dbDataSourceName", "jdbcUrl", "driverClass", "defaultTablespace", "persistToFile", "disableAuditTracking", "inMemoryDbType", "includeSchemas", "excludeSchemas"); ImmutableSet<String> ignorableSysNodes = Sets.immutable.of("excludeSchemas", "includeSchemas", "schemaOverrides", "tokens"); final ImmutableSet<String> ignorableEnvNodes = Sets.immutable.of("groups", "users"); final ImmutableSet<String> ignorableEnvAttributes = Sets.immutable.of("sourceDirs", "acceptedExtensions", "dataDelimiter", "nullToken"); for (String ignorableAttribute : ignorableSysAttributes) { if (sysCfg.containsKey(ignorableAttribute)) { sysCfg.clearProperty(ignorableAttribute); } } for (String ignorableSysNode : ignorableSysNodes) { if (!sysCfg.configurationsAt(ignorableSysNode).isEmpty()) { sysCfg.clearTree(ignorableSysNode); } } for (String ignorableAttribute : ignorableEnvAttributes) { sysCfg.clearProperty("environments.environment[@" + ignorableAttribute + "]"); sysCfg.clearProperty("environments.dbEnvironment[@" + ignorableAttribute + "]"); } for (String ignorableSysNode : ignorableEnvNodes) { sysCfg.clearTree("environments.environment." + ignorableSysNode); sysCfg.clearTree("environments.dbEnvironment." + ignorableSysNode); } ImmutableList<HierarchicalConfiguration<ImmutableNode>> envConfigs = ListAdapter .adapt(sysCfg.configurationsAt("environments.dbEnvironment")).toImmutable(); if (envConfigs.isEmpty()) { envConfigs = ListAdapter.adapt(sysCfg.configurationsAt("environments.environment")).toImmutable(); } envConfigs.each(new Procedure<HierarchicalConfiguration<ImmutableNode>>() { @Override public void value(HierarchicalConfiguration<ImmutableNode> envCfg) { for (String ignorableAttribute : ignorableEnvAttributes) { if (envCfg.containsKey(ignorableAttribute)) { envCfg.clearProperty(ignorableAttribute); } } for (String ignorableSysNode : ignorableEnvNodes) { if (!envCfg.configurationsAt(ignorableSysNode).isEmpty()) { envCfg.clearTree(ignorableSysNode); } } } }); }