Refine search
/** * <p>A factory method made available to Spring to generate a <code>RemoteConfigElement</code> Spring Bean</p> * @return The "remote" element from the "Remote" Config returned by the <code>ConfigService</code> */ public RemoteConfigElement getRemoteConfig() { Config remoteConfig = configService.getConfig("Remote"); RemoteConfigElement remoteConfigElement = (RemoteConfigElement) remoteConfig.getConfigElement("remote"); return remoteConfigElement; }
@Override public Object get(Object identifier) { if (logger.isDebugEnabled()) logger.debug("Getting scoped config for '" + identifier + "'"); Map<String, ConfigElement> map = null; if (configService != null) { Config result = configService.getConfig(identifier); map = result.getConfigElements(); } else { map = Collections.emptyMap(); } if (logger.isDebugEnabled()) logger.debug("Returning config for '" + identifier + "': " + map); return map; } }
Config configStandard = configService.getConfig(USED_STANDARD_CONFIG_CONDITION, clContext); && configStandard.getConfigElement(USED_STANDARD_ELEMENT) != null) standard = configStandard.getConfigElement(USED_STANDARD_ELEMENT).getValue(); Config configConditions = configService.getConfig(CONFIG_CONDITION, clContext); Map<String, ConfigElement> configElements = configConditions.getConfigElements(); logger.warn("Ignoring prefered standard doesn't found, choose : " + configLanguages.getName()); List<ConfigElement> languages = configLanguages.getChildren();
Config securityHeadersConfig = (Config) configService.getConfig("SecurityHeadersPolicy"); if (securityHeadersConfig == null) ConfigElement headersConfig = securityHeadersConfig.getConfigElement("headers"); if (headersConfig == null) List<ConfigElement> headersConfigList = headersConfig.getChildren("header"); if (headersConfigList == null || headersConfigList.size() == 0) String name = headerConfig.getChildValue("name"); Header header; if (allHeaders.containsKey(name)) ConfigElement valueConfig = headerConfig.getChild("value"); if (valueConfig != null)
Config csrfConfig = (Config) configService.getConfig("CSRFPolicy"); if (csrfConfig == null || !enabled) ConfigElement sessionConfig = csrfConfig.getConfigElement("session"); createSession = (sessionConfig != null && "true".equals(sessionConfig.getValue())); if (createSession && logger.isDebugEnabled()) logger.debug("The CSRFFilter will automatically create a user Session on a path match."); ConfigElement propertiesConfig = csrfConfig.getConfigElement("properties"); if (propertiesConfig != null) List<ConfigElement> propertiesConfigList = propertiesConfig.getChildren(); String value; if (propertiesConfigList != null && propertiesConfigList.size() > 0) value = propertyConfig.getValue(); properties.put(propertyConfig.getName(), value != null ? value : ""); ConfigElement filterConfig = csrfConfig.getConfigElement("filter"); if (filterConfig == null)
protected boolean isDebugMode() { if (this.isDebugMode == null) { Boolean debugValue = false; if (configService != null) { Config global = configService.getGlobalConfig(); if (global != null) { ConfigElement flags = global.getConfigElement("flags"); if (flags != null) { ConfigElement clientDebug = flags.getChild("client-debug"); if (clientDebug != null) { debugValue = Boolean.valueOf(clientDebug.getValue()); } } } } this.isDebugMode = debugValue; } return this.isDebugMode; }
ConfigElement globalItem = globalSection.getConfigElement("global-item"); assertEquals("global-item", "The replaced global value", globalItem.getValue()); ConfigElement override = globalSection.getConfigElement("override"); assertNotNull("override should not be null", override); assertEquals("override element", "false", override.getValue()); ConfigElement childrenReplace = globalSection.getConfigElement("children-replace"); assertNotNull("childrenReplace should not be null", childrenReplace); List<ConfigElement> children = childrenReplace.getChildren(); assertEquals("number of children elements", 1, children.size()); Map<String, ConfigElement> elements = replaceTestCfg.getConfigElements(); assertEquals("number of elements", 9, elements.size()); getConfigElement("first-item").getValue()); getConfigElement("second-item").getValue()); getConfigElement("fourth-item").getValue()); ConfigElement childrenElement = replaceTestCfg.getConfigElement("children"); assertEquals("number of children of children", 2, childrenElement.getChildCount());
ConfigElement children = cfg.getConfigElement("children"); assertEquals("There should be four children", 4, children.getChildCount()); ConfigElement childTwo = children.getChild("child-two"); assertNotNull("Child two config element should not be null", childTwo); assertEquals("Child two value should be 'child two value'", "child two value", childTwo.getValue()); assertEquals("The number of attributes should be 0", 0, childTwo.getAttributeCount());
ConfigElement globalItem = globalSection.getConfigElement("global-item"); assertNotNull("globalItem should not be null", globalItem); assertEquals("The global-item value should be 'The global value'", "The global value", globalItem.getValue()); ConfigElement clientElem = globalSection.getConfigElement("client"); assertNotNull(clientElem); ConfigElement fromAddressElem = clientElem.getChild("from-email-address"); assertNotNull(fromAddressElem); String fromAddress = fromAddressElem.getValue(); assertEquals("From address should be 'me@somewhere.net'", "me@somewhere.net", fromAddress);
ConfigElement overrideItem = globalSection.getConfigElement("override"); assertNotNull("overrideItem should not be null", overrideItem); assertEquals("The override item should be true", "true", overrideItem.getValue()); ConfigElement mergeChildren = globalSection.getConfigElement("merge-children"); assertNotNull("mergeChildren should not be null", mergeChildren); List<ConfigElement> kids = mergeChildren.getChildren(); assertEquals("There should be 2 children", 2, kids.size()); ConfigElement first = mergeTest.getConfigElement("first-item"); ConfigElement second = mergeTest.getConfigElement("second-item"); ConfigElement third = mergeTest.getConfigElement("third-item"); ConfigElement fourth = mergeTest.getConfigElement("fourth-item"); assertNotNull("first should not be null", first); assertNotNull("second should not be null", second); String firstValue = first.getValue(); assertEquals("The first value is wrong", "the overridden first value", firstValue); ConfigElement children = mergeTest.getConfigElement("children"); assertNotNull("children should not be null", children); kids = children.getChildren();
ConfigElement globalItem = global.getConfigElement("global-item"); assertNotNull("globalItem should not be null", globalItem); assertEquals("The global-item value should be 'The global value'", "The global value", globalItem.getValue()); ConfigElement globalItemProp = global.getConfigElement("global-item-prop"); assertNotNull("globalItemProp should not be null", globalItemProp); assertEquals("The global-item value should be 'globalValue'", "globalValue", globalItemProp.getValue()); ConfigElement globalItemMissingProp = global.getConfigElement("global-item-missing-prop"); assertNotNull("globalItemMissingProp should not be null", globalItemMissingProp); assertEquals("The global-item value should be '${missingGlobalValue}'", "${missingGlobalValue}", globalItemMissingProp.getValue()); ConfigElement overrideItem = global.getConfigElement("override"); ConfigElement item = unitTest.getConfigElement("item"); ConfigElement itemProp = unitTest.getConfigElement("item-prop"); assertNotNull("item attr should not be null", attrValue); assertEquals("The item attr value should be 'attrValue'", "attrValue", attrValue); ConfigElement itemMissingProp = unitTest.getConfigElement("item-missing-prop"); overrideItem = unitTest.getConfigElement("override"); ConfigElement overrideItemProp = unitTest.getConfigElement("override-prop"); ConfigElement overrideItemMissingProp = unitTest.getConfigElement("override-missing-prop");
String name = newConfigElement.getName(); ConfigElement existingConfigElement = results.getConfigElements().get(name); if (existingConfigElement != null) results.getConfigElements().put(name, newConfigElement); ConfigElement combinedConfigElement = existingConfigElement.combine(newConfigElement); results.getConfigElements().put(name, combinedConfigElement); results.getConfigElements().put(name, newConfigElement);
ConfigElement globalItem = globalSection.getConfigElement("global-item"); assertNotNull("globalItem should not be null", globalItem); assertEquals("The global-item value should be 'The global value'", "The global value", globalItem.getValue()); ConfigElement globalItem2 = globalSection.getConfigElement("another-global-item"); assertNotNull("globalItem2 should not be null", globalItem2); assertEquals("The another-global-item value should be 'Another global value'", "Another global value", globalItem2.getValue()); ConfigElement item = unitTest.getConfigElement("item"); assertNotNull("item should not be null", item); ConfigElement anotherItem = unitTest.getConfigElement("another-item"); assertNotNull("another-item should not be null", anotherItem);
/** * Retrieves the global configuration as a Map. * * @return Map of the global config */ public Map<String, ConfigElement> getGlobal() { if (this.globalConfig == null) { if (this.configService != null) { // get the global config this.globalConfig = this.configService.getGlobalConfig().getConfigElements(); } // if no global config was found create an empty map if (this.globalConfig == null) { this.globalConfig = Collections.emptyMap(); } } return this.globalConfig; }
/** * Make a read-only copy of the given configuration * * @param config the configuration to copy */ public ImmutableConfig(Config config) { if (config.getConfigElements() == null) { this.configElements = Collections.emptyMap(); } else { Map<String, ConfigElement> configElements = new HashMap<String, ConfigElement>(config.getConfigElements()); this.configElements = Collections.unmodifiableMap(configElements); } }
ConfigElement restrictedElement = config.getConfigElement("restricted"); ConfigElement availableElement = config.getConfigElement("available"); assertNull("restrictedElement should be null as a global lookup was performed for a section in an area", restrictedElement); assertNotNull("availableElement should not be null as the element is available in the default area", availableElement); lookupContext.addArea("test-area"); config = svc.getConfig("Area Specific Config", lookupContext); ConfigElement areaTest = config.getConfigElement("parent-item"); assertNotNull("areaTest should not be null as it is defined in test-area", areaTest); ConfigElement unitTest = config.getConfigElement("item"); assertNull("unitTest should be null as it is not defined in test-area", unitTest);
Config configStandard = configService.getConfig(USED_STANDARD_CONFIG_CONDITION, clContext); && configStandard.getConfigElement(USED_STANDARD_ELEMENT) != null) standard = configStandard.getConfigElement(USED_STANDARD_ELEMENT).getValue(); Config configConditions = configService.getConfig(CONFIG_CONDITION, clContext); Map<String, ConfigElement> configElements = configConditions.getConfigElements(); logger.warn("Ignoring prefered standard doesn't found, choose : " + configLanguages.getName()); List<ConfigElement> languages = configLanguages.getChildren();
protected boolean isDebugMode() { if (this.isDebugMode == null) { Boolean debugValue = false; if (configService != null) { Config global = configService.getGlobalConfig(); if (global != null) { ConfigElement flags = global.getConfigElement("flags"); if (flags != null) { ConfigElement clientDebug = flags.getChild("client-debug"); if (clientDebug != null) { debugValue = Boolean.valueOf(clientDebug.getValue()); } } } } this.isDebugMode = debugValue; } return this.isDebugMode; }
/** * Tests loading config from a known JAR file */ public void testJarSource() { String resDir = this.getResourcesDir(); String jarFile = "jar:file:" + resDir + "custom-config.jar!/META-INF/web-client-config-custom.xml"; JarConfigSource source = new JarConfigSource(jarFile); XMLConfigService svc = new XMLConfigService(source); svc.initConfig(); // make sure the global config is present Config config = svc.getGlobalConfig(); assertNotNull(config); // make sure the from address is present and correct ConfigElement clientElem = config.getConfigElement("client"); assertNotNull(clientElem); ConfigElement fromAddressElem = clientElem.getChild("from-email-address"); assertNotNull(fromAddressElem); String fromAddress = fromAddressElem.getValue(); assertEquals("From address should be 'me@somewhere.net'", "me@somewhere.net", fromAddress); }
String name = newConfigElement.getName(); ConfigElement existingConfigElement = results.getConfigElements().get(name); if (existingConfigElement != null) results.getConfigElements().put(name, newConfigElement); ConfigElement combinedConfigElement = existingConfigElement.combine(newConfigElement); results.getConfigElements().put(name, combinedConfigElement); results.getConfigElements().put(name, newConfigElement);