use of org.apache.commons.configuration2.HierarchicalConfiguration in project engine by craftercms.
the class ConfigAwareAccessTokenIdResolver method getAccessTokenId.
@Override
public String getAccessTokenId() {
String accessTokenId = null;
HierarchicalConfiguration config = ConfigUtils.getCurrentConfig();
if (config != null) {
accessTokenId = config.getString(ACCESS_TOKEN_ID_KEY);
}
if (StringUtils.isNotEmpty(accessTokenId)) {
return accessTokenId;
} else {
throw new ConfigurationException("Current config for site '" + SiteContext.getCurrent().getSiteName() + "' doesn't contain required property " + ACCESS_TOKEN_ID_KEY);
}
}
use of org.apache.commons.configuration2.HierarchicalConfiguration in project engine by craftercms.
the class SiteContextFactory method getConfig.
protected HierarchicalConfiguration getConfig(SiteContext siteContext, String[] configPaths, ResourceLoader resourceLoader) {
String siteName = siteContext.getSiteName();
try {
logger.info("--------------------------------------------------");
logger.info("<Loading configuration for site: " + siteName + ">");
logger.info("--------------------------------------------------");
ConfigurationBuilder<HierarchicalConfiguration> builder;
if (textEncryptor instanceof NoOpTextEncryptor) {
builder = new MultiResourceConfigurationBuilder(configPaths, resourceLoader);
} else {
builder = new MultiResourceConfigurationBuilder(configPaths, resourceLoader, textEncryptor);
}
HierarchicalConfiguration config = builder.getConfiguration();
logger.info("--------------------------------------------------");
logger.info("</Loading configuration for site: " + siteName + ">");
logger.info("--------------------------------------------------");
return config;
} catch (ConfigurationException e) {
throw new SiteContextCreationException("Unable to load configuration for site '" + siteContext.getSiteName() + "'", e);
}
}
use of org.apache.commons.configuration2.HierarchicalConfiguration in project engine by craftercms.
the class ConfigAwareConnectionFactoryLocator method getCurrentConnectionFactoryLocator.
protected ConnectionFactoryLocator getCurrentConnectionFactoryLocator() {
Callback<ConnectionFactoryLocator> callback = new Callback<ConnectionFactoryLocator>() {
@Override
public ConnectionFactoryLocator execute() {
HierarchicalConfiguration config = ConfigUtils.getCurrentConfig();
ConnectionFactoryRegistry registry = null;
if (config != null) {
try {
HierarchicalConfiguration socialConnectionsConfig = config.configurationAt(SOCIAL_CONNECTIONS_KEY);
for (ConfigurationParser<?> parser : configParsers) {
ConnectionFactory<?> factory = (ConnectionFactory<?>) parser.parse(socialConnectionsConfig);
if (factory != null) {
if (registry == null) {
registry = new ConnectionFactoryRegistry();
}
registry.addConnectionFactory(factory);
}
}
} catch (IllegalArgumentException e) {
// Ignore if != 1
}
}
if (registry != null) {
return registry;
} else {
return defaultLocator;
}
}
};
SiteContext siteContext = SiteContext.getCurrent();
if (siteContext != null) {
return cacheTemplate.getObject(siteContext.getContext(), callback, CONNECTION_FACTORY_LOCATOR_CACHE_KEY);
} else {
return defaultLocator;
}
}
use of org.apache.commons.configuration2.HierarchicalConfiguration in project engine by craftercms.
the class CandidateTargetedUrlsResolverImplTest method setUpCurrentSiteContext.
private void setUpCurrentSiteContext() {
HierarchicalConfiguration config = mock(HierarchicalConfiguration.class);
when(config.getStringArray(ROOT_FOLDERS_CONFIG_KEY)).thenReturn(ROOT_FOLDERS);
SiteContext context = new SiteContext();
context.setSiteName(SITE_NAME);
context.setConfig(config);
SiteContext.setCurrent(context);
}
use of org.apache.commons.configuration2.HierarchicalConfiguration in project engine by craftercms.
the class TargetedContentDescriptorMergeStrategyTest method setUpCurrentSiteContext.
private void setUpCurrentSiteContext() {
HierarchicalConfiguration config = mock(HierarchicalConfiguration.class);
when(config.getStringArray(ROOT_FOLDERS_CONFIG_KEY)).thenReturn(ROOT_FOLDERS);
when(config.getStringArray(AVAILABLE_TARGET_IDS_CONFIG_KEY)).thenReturn(AVAILABLE_TARGET_IDS);
when(config.getString(FALLBACK_ID_CONFIG_KEY)).thenReturn(FALLBACK_TARGET_ID);
SiteContext siteContext = new SiteContext();
siteContext.setSiteName(SITE_NAME);
siteContext.setConfig(config);
SiteContext.setCurrent(siteContext);
}
Aggregations