org.apache.commons.configuration2.tree.ImmutableNode Java Examples
The following examples show how to use
org.apache.commons.configuration2.tree.ImmutableNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StudioAuthenticationTokenProcessingFilter.java From studio with GNU General Public License v3.0 | 6 votes |
public void init() { List<HierarchicalConfiguration<ImmutableNode>> chainConfig = studioConfiguration.getSubConfigs(CONFIGURATION_AUTHENTICATION_CHAIN_CONFIG); if (chainConfig != null) { authenticationHeadersEnabled = chainConfig.stream().anyMatch(providerConfig -> providerConfig.getString(AUTHENTICATION_CHAIN_PROVIDER_TYPE).toUpperCase() .equals(AUTHENTICATION_CHAIN_PROVIDER_TYPE_HEADERS) && providerConfig.getBoolean(AUTHENTICATION_CHAIN_PROVIDER_ENABLED)); usernameHeaders = chainConfig.stream().filter(providerConfig -> providerConfig.getString(AUTHENTICATION_CHAIN_PROVIDER_TYPE).toUpperCase() .equals(AUTHENTICATION_CHAIN_PROVIDER_TYPE_HEADERS) && providerConfig.getBoolean(AUTHENTICATION_CHAIN_PROVIDER_ENABLED)) .map(providerConfig -> { return providerConfig.getString(AUTHENTICATION_CHAIN_PROVIDER_USERNAME_HEADER); }).collect(Collectors.toList()); } }
Example #2
Source File: TestConfigurationNodePointerFactory.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Tests using indices to specify elements. */ @Test public void testIndices() { assertEquals("Incorrect value", "1.2.3", context.getValue("/" + CHILD_NAME2 + "[1]/" + CHILD_NAME1 + "[1]/" + CHILD_NAME2 + "[2]")); assertEquals("Incorrect value of last node", String .valueOf(CHILD_COUNT), context.getValue(CHILD_NAME2 + "[last()]")); final List<?> nodes = context.selectNodes("/" + CHILD_NAME1 + "[1]/*"); assertEquals("Wrong number of children", CHILD_COUNT, nodes.size()); int index = 1; for (final Iterator<?> it = nodes.iterator(); it.hasNext(); index++) { final ImmutableNode node = (ImmutableNode) it.next(); assertEquals("Wrong node value for child " + index, "2." + index, node.getValue()); } }
Example #3
Source File: TestINIConfiguration.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Tests whether the node handler of a global section correctly returns a * child by index. */ @Test public void testGlobalSectionNodeHandlerGetChildByIndex() throws ConfigurationException { final INIConfiguration config = setUpConfig(INI_DATA_GLOBAL); final SubnodeConfiguration sub = config.getSection(null); final NodeHandler<ImmutableNode> handler = sub.getModel().getNodeHandler(); final ImmutableNode child = handler.getChild(handler.getRootNode(), 0); assertEquals("Wrong child", "globalVar", child.getNodeName()); try { handler.getChild(handler.getRootNode(), 1); fail("Could obtain child with invalid index!"); } catch (final IndexOutOfBoundsException iex) { // ok } }
Example #4
Source File: LMTPServer.java From james-project with Apache License 2.0 | 6 votes |
@Override public void doConfigure(HierarchicalConfiguration<ImmutableNode> configuration) throws ConfigurationException { super.doConfigure(configuration); if (isEnabled()) { // get the message size limit from the conf file and multiply // by 1024, to put it in bytes maxMessageSize = configuration.getLong("maxmessagesize", maxMessageSize) * 1024; if (maxMessageSize > 0) { LOGGER.info("The maximum allowed message size is {} bytes.", maxMessageSize); } else { LOGGER.info("No maximum message size is enforced for this server."); } // get the lmtpGreeting lmtpGreeting = configuration.getString("lmtpGreeting", null); } }
Example #5
Source File: CombinedConfiguration.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Handles a single component of the at path. A corresponding node is * created and added to the hierarchical path to the original root node * of the configuration. * * @param builder the current node builder object * @param currentComponent the name of the current path component * @param components an iterator with all components of the at path * @param orgRoot the original root node of the wrapped configuration */ private void prependAtPathComponent(final ImmutableNode.Builder builder, final String currentComponent, final Iterator<String> components, final ImmutableNode orgRoot) { builder.name(currentComponent); if (components.hasNext()) { final ImmutableNode.Builder childBuilder = new ImmutableNode.Builder(); prependAtPathComponent(childBuilder, components.next(), components, orgRoot); builder.addChild(childBuilder.create()); } else { builder.addChildren(orgRoot.getChildren()); builder.addAttributes(orgRoot.getAttributes()); builder.value(orgRoot.getValue()); } }
Example #6
Source File: TestConfigurationNodeIteratorChildren.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Tests defining a start node for a reverse iteration. */ @Test public void testIterateStartsWithReverse() { final ConfigurationNodePointer<ImmutableNode> childPointer = new ConfigurationNodePointer<>(rootPointer, root .getChildren().get(3), handler); final ConfigurationNodeIteratorChildren<ImmutableNode> it = new ConfigurationNodeIteratorChildren<>( rootPointer, null, true, childPointer); int value = 3; for (int index = 1; it.setPosition(index); index++, value--) { final ImmutableNode node = (ImmutableNode) it.getNodePointer().getNode(); assertEquals("Incorrect value at index " + index, String.valueOf(value), node.getValue()); } assertEquals("Iteration ended not at end node", 0, value); }
Example #7
Source File: QuotaBeanFactoryPostProcessor.java From james-project with Apache License 2.0 | 6 votes |
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { ConfigurationProvider confProvider = beanFactory.getBean(ConfigurationProvider.class); try { HierarchicalConfiguration<ImmutableNode> config = confProvider.getConfiguration("quota"); String quotaRootResolver = config.configurationAt(QUOTA_ROOT_RESOLVER_BEAN).getString(PROVIDER, DEFAULT_IMPLEMENTATION); String currentQuotaManager = config.configurationAt(CURRENT_QUOTA_MANAGER_BEAN).getString(PROVIDER, "none"); String maxQuotaManager = config.configurationAt(MAX_QUOTA_MANAGER).getString(PROVIDER, FAKE_IMPLEMENTATION); String quotaManager = config.configurationAt(QUOTA_MANAGER_BEAN).getString(PROVIDER, FAKE_IMPLEMENTATION); String quotaUpdater = config.configurationAt(UPDATES_BEAN).getString(PROVIDER, FAKE_IMPLEMENTATION); BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; registerAliasForQuotaRootResolver(quotaRootResolver, registry); registerAliasForCurrentQuotaManager(currentQuotaManager, registry); registerAliasForMaxQuotaManager(maxQuotaManager, registry); registerAliasForQuotaManager(quotaManager, registry); registerAliasForQuotaUpdater(quotaUpdater, registry); } catch (ConfigurationException e) { throw new FatalBeanException("Unable to configure Quota system", e); } }
Example #8
Source File: XMLConfiguration.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Helper method for updating the values of all attributes of the * specified node. * * @param node the affected node * @param elem the element that is associated with this node */ private static void updateAttributes(final ImmutableNode node, final Element elem) { if (node != null && elem != null) { clearAttributes(elem); for (final Map.Entry<String, Object> e : node.getAttributes() .entrySet()) { if (e.getValue() != null) { elem.setAttribute(e.getKey(), e.getValue().toString()); } } } }
Example #9
Source File: XMLListReference.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Checks whether the specified configuration node has to be taken into * account for list handling. This is the case if the node's parent has at * least one child node with the same name which has a special list * reference assigned. (Note that the passed in node does not necessarily * have such a reference; if it has been added at a later point in time, it * also has to become an item of the list.) * * @param node the configuration node * @param handler the reference node handler * @return a flag whether this node is relevant for list handling */ public static boolean isListNode(final ImmutableNode node, final ReferenceNodeHandler handler) { if (hasListReference(node, handler)) { return true; } final ImmutableNode parent = handler.getParent(node); if (parent != null) { for (int i = 0; i < handler.getChildrenCount(parent, null); i++) { final ImmutableNode child = handler.getChild(parent, i); if (hasListReference(child, handler) && nameEquals(node, child)) { return true; } } } return false; }
Example #10
Source File: TestConfigurationUtils.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Tests that the structure of the resulting hierarchical configuration * does not depend on the order of properties in the source configuration. * This test is related to CONFIGURATION-604. */ @Test public void testConvertToHierarchicalOrderOfProperties() { final PropertiesConfiguration config = new PropertiesConfiguration(); config.addProperty("x.y.z", true); config.addProperty("x.y", true); @SuppressWarnings("unchecked") final HierarchicalConfiguration<ImmutableNode> hc = (HierarchicalConfiguration<ImmutableNode>) ConfigurationUtils.convertToHierarchical(config); final ImmutableNode rootNode = hc.getNodeModel().getNodeHandler().getRootNode(); final ImmutableNode nodeX = rootNode.getChildren().get(0); assertEquals("Wrong number of children of x", 1, nodeX.getChildren().size()); }
Example #11
Source File: TestHierarchicalConfigurationEvents.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Tests events generated by the clearTree() method. */ @Test public void testClearTreeEvent() { final BaseHierarchicalConfiguration hc = (BaseHierarchicalConfiguration) config; final String key = EXIST_PROPERTY.substring(0, EXIST_PROPERTY.indexOf('.')); final NodeHandler<ImmutableNode> nodeHandler = hc.getNodeModel().getNodeHandler(); final Collection<QueryResult<ImmutableNode>> nodes = hc.getExpressionEngine() .query(nodeHandler.getRootNode(), key, nodeHandler); hc.clearTree(key); listener.checkEvent(ConfigurationEvent.CLEAR_TREE, key, null, true); listener.checkEvent(ConfigurationEvent.CLEAR_TREE, key, nodes, false); listener.done(); }
Example #12
Source File: CamelCompositeProcessorTest.java From james-project with Apache License 2.0 | 6 votes |
@Override protected AbstractStateCompositeProcessor createProcessor(HierarchicalConfiguration<ImmutableNode> config) throws Exception { CamelCompositeProcessor processor = new CamelCompositeProcessor(new RecordingMetricFactory(), FakeMailContext.defaultContext(), new MockMatcherLoader(), new MockMailetLoader()); try { processor.setCamelContext(new DefaultCamelContext()); processor.configure(config); processor.init(); return processor; } catch (Exception e) { processor.dispose(); throw e; } }
Example #13
Source File: TestXMLConfiguration.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Tests whether the addNodes() method triggers an auto save. */ @Test public void testAutoSaveAddNodes() throws ConfigurationException { final FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>( XMLConfiguration.class); builder.configure(new FileBasedBuilderParametersImpl() .setFileName(testProperties)); conf = builder.getConfiguration(); builder.getFileHandler().setFile(testSaveConf); builder.setAutoSave(true); final ImmutableNode node = NodeStructureHelper.createNode( "addNodesTest", Boolean.TRUE); final Collection<ImmutableNode> nodes = new ArrayList<>(1); nodes.add(node); conf.addNodes("test.autosave", nodes); final XMLConfiguration c2 = new XMLConfiguration(); load(c2, testSaveConf.getAbsolutePath()); assertTrue("Added nodes are not saved", c2 .getBoolean("test.autosave.addNodesTest")); }
Example #14
Source File: SearchServiceInternalImpl.java From studio with GNU General Public License v3.0 | 6 votes |
/** * Maps the item type for the given source based on the configuration * @param source the source to map * @return the item type */ protected String getItemType(Map<String, Object> source) { if(MapUtils.isNotEmpty(types)) { for (HierarchicalConfiguration<ImmutableNode> typeConfig : types.values()) { String fieldName = typeConfig.getString(CONFIG_KEY_TYPE_FIELD); if(source.containsKey(fieldName)) { String fieldValue = source.get(fieldName).toString(); if (StringUtils.isNotEmpty(fieldValue) && fieldValue.matches(typeConfig.getString(CONFIG_KEY_TYPE_MATCHES))) { return typeConfig.getString(CONFIG_KEY_TYPE_NAME); } } } } return defaultType; }
Example #15
Source File: TestINIConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Tests whether the node handler of a global section correctly determines * the number of children. */ @Test public void testGlobalSectionNodeHandlerGetChildrenCount() throws ConfigurationException { final INIConfiguration config = setUpConfig(INI_DATA_GLOBAL); final SubnodeConfiguration sub = config.getSection(null); final NodeHandler<ImmutableNode> handler = sub.getModel().getNodeHandler(); assertEquals("Wrong number of children", 1, handler.getChildrenCount(handler.getRootNode(), null)); }
Example #16
Source File: BaseHierarchicalConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
@Override public void visitBeforeChildren(final ImmutableNode node, final NodeHandler<ImmutableNode> handler) { final ReferenceNodeHandler refHandler = (ReferenceNodeHandler) handler; updateNode(node, refHandler); insertNewChildNodes(node, refHandler); }
Example #17
Source File: TestINIConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Tests querying the content of the global section if there is none. */ @Test public void testGetSectionGlobalNonExisting() throws ConfigurationException { final INIConfiguration config = setUpConfig(INI_DATA); final HierarchicalConfiguration<ImmutableNode> section = config.getSection(null); assertTrue("Sub config not empty", section.isEmpty()); }
Example #18
Source File: TestConfigurationNodePointer.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Tests the leaf flag for a real leaf node. */ @Test public void testIsLeafTrue() { final ImmutableNode leafNode = new ImmutableNode.Builder().name("leafNode").create(); pointer = new ConfigurationNodePointer<>(pointer, leafNode, handler); assertTrue("Not a leaf node", pointer.isLeaf()); }
Example #19
Source File: PreDeletionHookConfigurationTest.java From james-project with Apache License 2.0 | 5 votes |
@Test void fromShouldThrowWhenClassNameIsEmpty() { HierarchicalConfiguration<ImmutableNode> configuration = new BaseHierarchicalConfiguration(); configuration.addProperty("class", ""); assertThatThrownBy(() -> PreDeletionHookConfiguration.from(configuration)) .isInstanceOf(ConfigurationException.class); }
Example #20
Source File: TestHierarchicalConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { final ImmutableNode root = new ImmutableNode.Builder(1).addChild( NodeStructureHelper.ROOT_TABLES_TREE).create(); config = new BaseHierarchicalConfiguration(); config.getNodeModel().setRootNode(root); }
Example #21
Source File: LanguageComponentConfigService.java From spoofax with Apache License 2.0 | 5 votes |
@Override protected HierarchicalConfiguration<ImmutableNode> fromConfig(ILanguageComponentConfig config) { if(!(config instanceof IConfig)) { configBuilder.reset(); configBuilder.copyFrom(config); config = configBuilder.build((FileObject) null); } return ((IConfig) config).getConfig(); }
Example #22
Source File: MailRepositoryStoreConfiguration.java From james-project with Apache License 2.0 | 5 votes |
private static Item readItem(HierarchicalConfiguration<ImmutableNode> configuration) { String className = configuration.getString("[@class]"); List<Protocol> protocolStream = Arrays.stream(configuration.getStringArray("protocols.protocol")).map(Protocol::new).collect(Guavate.toImmutableList()); HierarchicalConfiguration<ImmutableNode> extraConfig = extraConfig(configuration); return new Item(protocolStream, className, extraConfig); }
Example #23
Source File: CombinedConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Returns a set with the configuration sources, in which the specified key * is defined. This method determines the configuration nodes that are * identified by the given key. It then determines the configuration sources * to which these nodes belong and adds them to the result set. Note the * following points: * <ul> * <li>If no node object is found for this key, an empty set is returned.</li> * <li>For keys that have been added directly to this combined configuration * and that do not belong to the namespaces defined by existing child * configurations this combined configuration is contained in the result * set.</li> * </ul> * * @param key the key of a configuration property * @return a set with the configuration sources, which contain this property * @since 2.0 */ public Set<Configuration> getSources(final String key) { beginRead(false); try { final List<QueryResult<ImmutableNode>> results = fetchNodeList(key); final Set<Configuration> sources = new HashSet<>(); for (final QueryResult<ImmutableNode> result : results) { final Set<Configuration> resultSources = findSourceConfigurations(result.getNode()); if (resultSources.isEmpty()) { // key must be defined in combined configuration sources.add(this); } else { sources.addAll(resultSources); } } return sources; } finally { endRead(); } }
Example #24
Source File: INIConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Return a set containing the sections in this ini configuration. Note that * changes to this set do not affect the configuration. * * @return a set containing the sections. */ public Set<String> getSections() { final Set<String> sections = new LinkedHashSet<>(); boolean globalSection = false; boolean inSection = false; beginRead(false); try { for (final ImmutableNode node : getModel().getNodeHandler().getRootNode() .getChildren()) { if (isSectionNode(node)) { inSection = true; sections.add(node.getNodeName()); } else { if (!inSection && !globalSection) { globalSection = true; sections.add(null); } } } } finally { endRead(); } return sections; }
Example #25
Source File: MaxQuotaConfigurationReader.java From james-project with Apache License 2.0 | 5 votes |
@Override public void configure(HierarchicalConfiguration<ImmutableNode> config) throws ConfigurationException { Long globalMaxMessage = config.configurationAt("maxQuotaManager").getLong("globalMaxMessage", null); Long globalMaxStorage = config.configurationAt("maxQuotaManager").getLong("globalMaxStorage", null); Map<String, Long> maxMessage = parseMaxMessageConfiguration(config, "maxMessage"); Map<String, Long> maxStorage = parseMaxMessageConfiguration(config, "maxStorage"); try { configureGlobalValues(globalMaxMessage, globalMaxStorage); configureQuotaRootSpecificValues(maxMessage, maxStorage); } catch (MailboxException e) { throw new ConfigurationException("Exception caught while configuring max quota manager", e); } }
Example #26
Source File: LanguageSpecConfigService.java From spoofax with Apache License 2.0 | 5 votes |
@Override protected HierarchicalConfiguration<ImmutableNode> fromConfig(ILanguageSpecConfig config) { if(!(config instanceof IConfig)) { configBuilder.reset(); configBuilder.copyFrom(config); config = configBuilder.build(null); } return ((IConfig) config).getConfig(); }
Example #27
Source File: TestHierarchicalConfigurationEvents.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Tests events generated by addNodes() when the list of nodes is empty. In * this case no events should be generated. */ @Test public void testAddNodesEmptyEvent() { ((BaseHierarchicalConfiguration) config).addNodes(TEST_PROPNAME, new ArrayList<ImmutableNode>()); listener.done(); }
Example #28
Source File: TestXPathExpressionEngine.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Helper method for testing queries with undefined keys. * * @param key the key */ private void checkEmptyKey(final String key) { final XPathContextFactory factory = EasyMock.createMock(XPathContextFactory.class); EasyMock.replay(factory); final XPathExpressionEngine engine = new XPathExpressionEngine(factory); final List<QueryResult<ImmutableNode>> results = engine.query(root, key, handler); assertEquals("Incorrect number of results", 1, results.size()); assertSame("Wrong result node", root, results.get(0).getNode()); }
Example #29
Source File: DbEnvironmentXmlEnricherTest.java From obevo with Apache License 2.0 | 5 votes |
private Object getNodeValue(ImmutableNode node) { if (node.getChildren().isEmpty()) { if (node.getAttributes() != null && !node.getAttributes().isEmpty()) { return constructMap(node); } else { return node.getValue(); } } else { return constructMap(node); } }
Example #30
Source File: MailRepositoryStoreBeanFactory.java From james-project with Apache License 2.0 | 5 votes |
/** * <p> * Registers a new mail repository type in the mail store's registry based * upon a passed in <code>Configuration</code> object. * </p> * <p/> * <p> * This is presumably synchronized to prevent corruption of the internal * registry. * </p> * * @param repConf the Configuration object used to register the repository * @throws ConfigurationException if an error occurs accessing the Configuration object */ public synchronized void registerRepository(HierarchicalConfiguration<ImmutableNode> repConf) throws ConfigurationException { String className = repConf.getString("[@class]"); for (String protocol : repConf.getStringArray("protocols.protocol")) { HierarchicalConfiguration<ImmutableNode> defConf = null; if (repConf.getKeys("config").hasNext()) { // Get the default configuration for these protocol/type // combinations. defConf = repConf.configurationAt("config"); } LOGGER.info("Registering Repository instance of class {} to handle {} protocol requests", className, protocol); if (classes.get(new Protocol(protocol)) != null) { throw new ConfigurationException("The combination of protocol and type comprise a unique key for repositories. This constraint has been violated. Please check your repository configuration."); } classes.put(new Protocol(protocol), className); if (defConf != null) { defaultConfigs.put(new Protocol(protocol), defConf); } } }