List of usage examples for org.apache.commons.configuration Configuration getInt
int getInt(String key, int defaultValue);
From source file:openlr.properties.OpenLRPropertyAccess.java
/** * Gets the integer property value.//from w ww .j a v a 2 s .c om * * @param properties * the properties * @param property * the property * @return the integer property int value * @throws OpenLRPropertyException * the open lr property exception */ public static int getIntegerPropertyValue(final Configuration properties, final OpenLRProperty property) throws OpenLRPropertyException { if (property.getPropertyType() != PropertyType.INTEGER) { String error = property.getKey() + " is not an integer"; LOG.error(error); throw new OpenLRPropertyException(PropertyError.INVALID_PROPERTY_TYPE, error); } if (properties == null) { return (Integer) property.getDefault(); } return properties.getInt(property.getKey(), (Integer) property.getDefault()); }
From source file:openlr.properties.OpenLRPropertyAccess.java
/** * Gets the integer property value.// w w w . ja v a 2s. c o m * * @param properties * the properties * @param property * the property * @param id * the id * @return the boolean property value * @throws OpenLRProcessingException * the open lr processing exception */ public static int getIntegerPropertyValueById(final Configuration properties, final OpenLRProperty property, final String id) throws OpenLRProcessingException { if (property.getPropertyType() != PropertyType.INTEGER_BY_ID) { String error = property.getKey() + " is not an integer by id"; LOG.error(error); throw new OpenLRPropertyException(PropertyError.INVALID_PROPERTY_TYPE, error); } if (properties == null) { return (Integer) property.getDefault(); } return properties.getInt(property.getKey() + "." + id, (Integer) property.getDefault()); }
From source file:openlr.properties.OpenLRPropertyAccess.java
/** * Gets the integer property value.//from ww w. j a va 2 s . c o m * * @param properties * the properties * @param property * the property * @param id * the id * @return the boolean property value * @throws OpenLRProcessingException * the open lr processing exception */ @SuppressWarnings("unchecked") public static int getIntegerPropertyValueFromMap(final Configuration properties, final OpenLRProperty property, final String id) throws OpenLRProcessingException { if (property.getPropertyType() != PropertyType.INTEGER_BY_MAP) { String error = property.getKey() + " is not an integer from map"; LOG.error(error); throw new OpenLRPropertyException(PropertyError.INVALID_PROPERTY_TYPE, error); } Map<String, Integer> data = (Map<String, Integer>) property.getDefault(); Integer defaultValue = data.get(id); if (properties == null) { if (defaultValue == null) { String error = property.getKey() + "[" + id + "] has no default value"; LOG.error(error); throw new OpenLRPropertyException(PropertyError.INVALID_PROPERTY_TYPE, error); } return data.get(id); } if (!properties.containsKey(property.getKey() + "." + id) && defaultValue == null) { String error = property.getKey() + "[" + id + "] has no value"; LOG.error(error); throw new OpenLRPropertyException(PropertyError.INVALID_PROPERTY_TYPE, error); } return properties.getInt(property.getKey() + "." + id, defaultValue); }
From source file:org.acmsl.queryj.ConfigurationQueryJCommandImpl.java
/** * Retrieves the setting for given key./*from ww w. j av a 2 s .c om*/ * @param key the key. * @param defaultValue the default value. * @param settings the settings. * @return the value for such key. */ protected int getIntSetting(@NotNull final String key, final int defaultValue, @NotNull final Configuration settings) { return settings.getInt(key, defaultValue); }
From source file:org.ambraproject.article.service.BrowseServiceImpl.java
/** * Set the configuration class/*from w w w .j ava 2 s . c o m*/ * * @param config the configuration class to use * @throws ApplicationException if required configuration settings are missing */ @Required public void setConfiguration(Configuration config) throws ApplicationException { if (config.containsKey("ambra.services.browse.sortOptions.option")) { validSorts = new HashMap(); displaySorts = new ArrayList(); HierarchicalConfiguration hc = (HierarchicalConfiguration) config; List<HierarchicalConfiguration> sorts = hc.configurationsAt("ambra.services.browse.sortOptions.option"); for (HierarchicalConfiguration s : sorts) { String key = s.getString("[@displayName]"); String value = s.getString(""); validSorts.put(key, value); displaySorts.add(key); } ((HierarchicalConfiguration) config).setExpressionEngine(null); } else { throw new ApplicationException( "ambra.services.browse.sortOptions.option not defined " + "in configuration."); } this.cacheTimeToLive = config.getInt("ambra.services.browse.time", 15) * 60; this.useCache = config.getBoolean("ambra.services.browse.cache", true); }
From source file:org.ambraproject.freemarker.AmbraFreemarkerConfig.java
/** * Constructor that loads the list of css and javascript files and page titles for pages which follow the standard * templates. Creates its own composite configuration by iterating over each of the configs in the config to assemble * a union of pages defined./*w ww. j a v a 2 s . c o m*/ * * @param configuration Ambra configuration * @throws Exception Exception */ public AmbraFreemarkerConfig(Configuration configuration) throws Exception { if (log.isDebugEnabled()) { log.debug("Creating FreeMarker configuration"); } debug = configuration.getBoolean("struts.devMode"); dirPrefix = configuration.getString("ambra.platform.appContext"); subdirPrefix = configuration.getString("ambra.platform.resourceSubDir"); host = configuration.getString("ambra.platform.host"); casLoginURL = configuration.getString("ambra.services.cas.url.login"); casLogoutURL = configuration.getString("ambra.services.cas.url.logout"); registrationURL = configuration.getString("ambra.services.registration.url.registration"); changePasswordURL = configuration.getString("ambra.services.registration.url.change-password"); changeEmailURL = configuration.getString("ambra.services.registration.url.change-email"); doiResolverURL = configuration.getString("ambra.services.crossref.plos.doiurl"); defaultJournalName = configuration.getString(DEFAULT_JOURNAL_NAME_CONFIG_KEY); journals = new HashMap<String, JournalConfig>(); journalsByIssn = new HashMap<String, JournalConfig>(); orgName = configuration.getString("ambra.platform.name"); feedbackEmail = configuration.getString("ambra.platform.email.feedback"); cache_storage_strong = configuration.getInt("ambra.platform.template_cache.strong", DEFAULT_TEMPLATE_CACHE_STRONG); cache_storage_soft = configuration.getInt("ambra.platform.template_cache.soft", DEFAULT_TEMPLATE_CACHE_SOFT); templateUpdateDelay = configuration.getInt("ambra.platform.template_cache.update_delay", DEFAULT_TEMPLATE_UPDATE_DELAY); String date = configuration.getString("ambra.platform.cisStartDate"); freemarkerProperties = configuration.subset("ambra.platform.freemarker"); nedProfileURL = configuration.getString("ned.profile"); nedRegistrationURL = configuration.getString("ned.registration"); if (date == null) { throw new Exception("Could not find the cisStartDate node in the " + "ambra platform configuration. Make sure the " + "ambra/platform/cisStartDate node exists."); } try { cisStartDate = DateFormat.getDateInstance(DateFormat.SHORT).parse(date); } catch (ParseException ex) { throw new Exception("Could not parse the cisStartDate value of \"" + date + "\" in the ambra platform configuration. Make sure the cisStartDate is in the " + "following format: dd/mm/yyyy", ex); } loadConfig(configuration); processVirtualJournalConfig(configuration); // Now that the "journals" Map exists, index that map by Eissn to populate "journalsByEissn". if (journals.entrySet() != null && journals.entrySet().size() > 0) { for (Entry<String, JournalConfig> e : journals.entrySet()) { JournalConfig j = e.getValue(); journalsByIssn.put(j.getIssn(), j); } } journalUrls = buildUrlMap(journals); journalsUrlsByIssn = buildUrlMap(journalsByIssn); if (log.isTraceEnabled()) { for (Entry<String, JournalConfig> e : journals.entrySet()) { JournalConfig j = e.getValue(); log.trace("Journal: " + e.getKey()); log.trace("Journal url: " + j.getUrl()); log.trace("Default Title: " + j.getDefaultTitle()); log.trace("Default CSS: " + printArray(j.getDefaultCss())); log.trace("Default JavaScript: " + printArray(j.getDefaultCss())); Map<String, String[]> map = j.getCssFiles(); for (Entry<String, String[]> entry : map.entrySet()) { log.trace("PageName: " + entry.getKey()); log.trace("CSS FILES: " + printArray(entry.getValue())); } map = j.getJavaScriptFiles(); for (Entry<String, String[]> entry : map.entrySet()) { log.trace("PageName: " + entry.getKey()); log.trace("JS FILES: " + printArray(entry.getValue())); } for (Entry<String, String> entry : j.getTitles().entrySet()) { log.trace("PageName: " + entry.getKey()); log.trace("Title: " + entry.getValue()); } } log.trace("Dir Prefix: " + dirPrefix); log.trace("SubDir Prefix: " + subdirPrefix); log.trace("Host: " + host); log.trace("Cas url login: " + casLoginURL); log.trace("Case url logout: " + casLogoutURL); log.trace("Registration URL: " + registrationURL); log.trace("Registration Change Pass URL: " + changePasswordURL); log.trace("Registration Change EMail URL: " + changeEmailURL); log.trace("DOI Resolver URL: " + doiResolverURL); log.trace("Default Journal Name: " + defaultJournalName); log.trace("NED Profile URL: " + nedProfileURL); log.trace("NED Registration URL: " + nedRegistrationURL); } if (log.isDebugEnabled()) { log.debug("End FreeMarker Configuration Reading"); } }
From source file:org.ambraproject.search.service.IndexingServiceImpl.java
@Required public void setAmbraConfiguration(Configuration ambraConfiguration) { indexingQueue = ambraConfiguration.getString("ambra.services.search.articleIndexingQueue", null); if (indexingQueue != null && indexingQueue.trim().length() == 0) { indexingQueue = null;//w w w . ja v a 2 s.co m } log.info("Article indexing queue set to " + indexingQueue); deleteQueue = ambraConfiguration.getString("ambra.services.search.articleDeleteQueue", null); if (deleteQueue != null && deleteQueue.trim().length() == 0) { deleteQueue = null; } log.info("Article delete queue set to " + deleteQueue); incrementLimitSize = ambraConfiguration.getInt("ambra.services.search.incrementLimitSize", DEFAULT_INCREMENT_LIMIT_SIZE); }
From source file:org.ambraproject.search.service.SolrSearchService.java
public void setConfiguration(Configuration config) throws ApplicationException { StringBuilder hightlightFieldBuilder = new StringBuilder(); queryTimeout = config.getInt("ambra.services.search.timeout", 60000); // default to 1 min List sizes = config.getList("ambra.services.search.pageSizes.size"); if (sizes == null) { throw new ApplicationException("ambra.services.search.pageSizes not defined " + "in configuration."); }//w ww . ja v a2s . c o m pageSizes = sizes; if (config.containsKey("ambra.services.search.sortOptions.option")) { validSorts = new HashMap(); displaySorts = new ArrayList(); HierarchicalConfiguration hc = (HierarchicalConfiguration) config; List<HierarchicalConfiguration> sorts = hc.configurationsAt("ambra.services.search.sortOptions.option"); for (HierarchicalConfiguration s : sorts) { String key = s.getString("[@displayName]"); String value = s.getString(""); validSorts.put(key, value); displaySorts.add(key); } ((HierarchicalConfiguration) config).setExpressionEngine(null); } else { throw new ApplicationException( "ambra.services.search.sortOptions.option not defined " + "in configuration."); } List hFields = config.getList("ambra.services.search.highlightFields.field"); if (hFields == null) { throw new ApplicationException( "ambra.services.search.highlightFields.field not defined " + "in configuration."); } for (Object field : hFields) { if (hightlightFieldBuilder.length() > 0) { hightlightFieldBuilder.append(","); } hightlightFieldBuilder.append(field.toString()); } if (config.containsKey("ambra.services.search.keywordFields.field")) { validKeywords = new HashMap(); HierarchicalConfiguration hc = (HierarchicalConfiguration) config; List<HierarchicalConfiguration> sorts = hc .configurationsAt("ambra.services.search.keywordFields.field"); for (HierarchicalConfiguration s : sorts) { String key = s.getString("[@displayName]"); String value = s.getString(""); validKeywords.put(key, value); //These fields can be highlighted too! if (hightlightFieldBuilder.length() > 0) { hightlightFieldBuilder.append(","); } hightlightFieldBuilder.append(value); } } else { throw new ApplicationException( "ambra.services.search.keywordFields.field not defined " + "in configuration."); } this.highlightFields = hightlightFieldBuilder.toString(); }
From source file:org.ambraproject.service.article.BrowseServiceImpl.java
/** * Set the configuration class/* ww w . j a v a 2 s . co m*/ * * @param config the configuration class to use * @throws ApplicationException if required configuration settings are missing */ @Required public void setConfiguration(Configuration config) throws ApplicationException { this.cacheTimeToLive = config.getInt("ambra.services.browse.time", 15) * 60; this.useCache = config.getBoolean("ambra.services.browse.cache", true); }
From source file:org.ambraproject.service.feed.FeedServiceImpl.java
@Required public void setConfiguration(Configuration configuration) throws ApplicationException { this.configuration = configuration; StringBuilder hightlightFieldBuilder = new StringBuilder(); queryTimeout = configuration.getInt("ambra.services.search.timeout", 60000); // default to 1 min if (configuration.containsKey("ambra.services.search.sortOptions.option")) { validSorts = new HashMap(); displaySorts = new ArrayList(); HierarchicalConfiguration hc = (HierarchicalConfiguration) configuration; List<HierarchicalConfiguration> sorts = hc.configurationsAt("ambra.services.search.sortOptions.option"); for (HierarchicalConfiguration s : sorts) { String key = s.getString("[@displayName]"); String value = s.getString(""); validSorts.put(key, value);//from w ww.j a va 2s. c o m displaySorts.add(key); } ((HierarchicalConfiguration) configuration).setExpressionEngine(null); } else { throw new ApplicationException( "ambra.services.search.sortOptions.option not defined " + "in configuration."); } if (configuration.containsKey("ambra.services.search.keywordFields.field")) { validKeywords = new HashMap(); HierarchicalConfiguration hc = (HierarchicalConfiguration) configuration; List<HierarchicalConfiguration> sorts = hc .configurationsAt("ambra.services.search.keywordFields.field"); for (HierarchicalConfiguration s : sorts) { String key = s.getString("[@displayName]"); String value = s.getString(""); validKeywords.put(key, value); //These fields can be highlighted too! if (hightlightFieldBuilder.length() > 0) { hightlightFieldBuilder.append(","); } hightlightFieldBuilder.append(value); } } else { throw new ApplicationException( "ambra.services.search.keywordFields.field not defined " + "in configuration."); } }