/** * Create a memcached client with pippo settings. * * @param settings pippo settings * @return memcached client */ public static final MemcachedClient create(final PippoSettings settings) { String host = settings.getString(HOST, "localhost:11211"); String prot = settings.getString(PROT, "BINARY"); Protocol protocol = Protocol.valueOf(prot); String user = settings.getString(USER, ""); String pass = settings.getString(PASS, ""); List<String> autM = settings.getStrings(AUTM); String[] mechanisms = autM.toArray(new String[autM.size()]); return create(host, protocol, user, pass, mechanisms); }
/** * Tests for the existence of a setting. * * @param name * @return true if the setting exists */ public boolean hasSetting(String name) { return getString(name, null) != null; }
public Languages(PippoSettings pippoSettings) { this.pippoSettings = pippoSettings; this.applicationCookiePrefix = pippoSettings.getString( PippoConstants.SETTING_APPLICATION_COOKIE_PREFIX, "PIPPO"); // build a lookup of supported languages this.languageLookup = new ConcurrentHashMap<>(); List<String> languages = pippoSettings .getStrings(PippoConstants.SETTING_APPLICATION_LANGUAGES); for (String language : languages) { String lang = language.toLowerCase(); String langComponent = getLanguageComponent(lang); languageLookup.put(lang, language); languageLookup.put(langComponent, language); } this.defaultLanguage = getDefaultLanguage(languages); log.info("Using '{}' as default language.", defaultLanguage); }
public String getDomain() { return pippoSettings.getString(DOMAIN, null); }
public String getPath() { return pippoSettings.getString(PATH, "/"); }
public String getApplicationName() { return pippoSettings.getString(PippoConstants.SETTING_APPLICATION_NAME, ""); }
public String getApplicationVersion() { return pippoSettings.getString(PippoConstants.SETTING_APPLICATION_VERSION, ""); }
public WebServerSettings(PippoSettings pippoSettings) { this.port = pippoSettings.getInteger(PippoConstants.SETTING_SERVER_PORT, DEFAULT_PORT); this.host = pippoSettings.getString(PippoConstants.SETTING_SERVER_HOST, host); this.contextPath = pippoSettings.getString(PippoConstants.SETTING_SERVER_CONTEXT_PATH, contextPath); this.keystoreFile = pippoSettings.getString(PippoConstants.SETTING_SERVER_KEYSTORE_FILE, keystoreFile); this.keystorePassword = pippoSettings.getString(PippoConstants.SETTING_SERVER_KEYSTORE_PASSWORD, keystorePassword); this.truststoreFile = pippoSettings.getString(PippoConstants.SETTING_SERVER_TRUSTSTORE_FILE, truststoreFile); this.truststorePassword = pippoSettings.getString(PippoConstants.SETTING_SERVER_TRUSTSTORE_PASSWORD, truststorePassword); }
public TomcatSettings(PippoSettings pippoSettings) { super(pippoSettings); this.baseFolder = pippoSettings.getString(TomcatSettings.BASE_FOLDER, "tomcat_home"); this.maxConnections = pippoSettings.getInteger(TomcatSettings.MAX_CONNECTIONS, 100); this.keyAlias = pippoSettings.getString(TomcatSettings.KEY_ALIAS, "tomcat"); this.keyType = pippoSettings.getString(TomcatSettings.KEY_TYPE, "JKS"); this.clientAuth = pippoSettings.getBoolean(TomcatSettings.CLIENT_AUTH, false); }
private static Map<String, String> getPac4jSettings(PippoSettings settings, String prefix) { Map<String, String> pac4jSettings = new HashMap<>(); int beginIndex = prefix.length(); List<String> names = settings.getSettingNames(prefix); for (String name : names) { pac4jSettings.put(name.substring(beginIndex), settings.getString(name, "")); } return pac4jSettings; }
/** * Create a MongoDB client with pippo settings. * * @param settings pippo settings * @return MongoDB client */ public static MongoClient create(final PippoSettings settings) { String host = settings.getString(HOST, "mongodb://localhost:27017"); return create(host); }
/** * Returns a string value that has been interpolated from System Properties * and Environment Variables using the ${name} or @{name} syntax. * * @param name * @param defaultValue * @return an interpolated string */ public String getInterpolatedString(String name, String defaultValue) { String value = getString(name, defaultValue); return interpolateString(value); }
/** * Returns the string value for the specified name. If the name does not * exist an exception is thrown. * * @param name * @return name value */ public String getRequiredString(String name) { String value = getString(name, null); if (value != null) { return value.trim(); } throw new PippoRuntimeException("Setting '{}' has not been configured!", name); }
/** * Returns the boolean value for the specified name. If the name does not * exist or the value for the name can not be interpreted as a boolean, the * defaultValue is returned. * * @param name * @param defaultValue * @return name value or defaultValue */ public boolean getBoolean(String name, boolean defaultValue) { String value = getString(name, null); if (!StringUtils.isNullOrEmpty(value)) { return Boolean.parseBoolean(value.trim()); } return defaultValue; }
/** * Returns the char value for the specified name. If the name does not exist * or the value for the name can not be interpreted as a char, the * defaultValue is returned. * * @param name * @param defaultValue * @return name value or defaultValue */ public char getChar(String name, char defaultValue) { String value = getString(name, null); if (!StringUtils.isNullOrEmpty(value)) { return value.trim().charAt(0); } return defaultValue; }
/** * Extracts the TimeUnit from the name. * * @param name * @param defaultValue * @return the extracted TimeUnit */ private TimeUnit extractTimeUnit(String name, String defaultValue) { String value = getString(name, defaultValue); try { final String[] s = value.split(" ", 2); return TimeUnit.valueOf(s[1].trim().toUpperCase()); } catch (Exception e) { throw new PippoRuntimeException("{} must have format '<n> <TimeUnit>' where <TimeUnit> is one of 'MILLISECONDS', 'SECONDS', 'MINUTES', 'HOURS', 'DAYS'", name); } }
/** * Returns the long value for the specified name. If the name does not * exist or the value for the name can not be interpreted as an long, the * defaultValue is returned. * * @param name * @param defaultValue * @return name value or defaultValue */ public long getLong(String name, long defaultValue) { try { String value = getString(name, null); if (!StringUtils.isNullOrEmpty(value)) { return Long.parseLong(value.trim()); } } catch (NumberFormatException e) { log.warn("Failed to parse long for " + name + USING_DEFAULT_OF + defaultValue); } return defaultValue; }
/** * Performs common initialization for template engines. * * Implementations must override this method to do their own template engine specific initialization. * To use the convenience of this class, implementations must invoke this class's implementation before * performing their own initialization. * * @param application reference to the Pippo {@link Application} that can be used to retrieve settings * and other settings for the initialization */ @Override public void init(Application application) { languages = application.getLanguages(); messages = application.getMessages(); router = application.getRouter(); pippoSettings = application.getPippoSettings(); fileExtension = pippoSettings.getString(PippoConstants.SETTING_TEMPLATE_EXTENSION, getDefaultFileExtension()); templatePathPrefix = pippoSettings.getString(PippoConstants.SETTING_TEMPLATE_PATH_PREFIX, TemplateEngine.DEFAULT_PATH_PREFIX); }
/** * Create a Jedis poll with pippo settings. URL format: * 'redis://[:password@]host[:port][/db-number][?option=value]' * * @param settings pippo settings * @return Jedis pool */ public static JedisPool create(final PippoSettings settings) { String host = settings.getString(HOST, Protocol.DEFAULT_HOST).trim(); int minIdle = settings.getInteger(MIN_IDLE, GenericObjectPoolConfig.DEFAULT_MIN_IDLE); int maxIdle = settings.getInteger(MAX_IDLE, GenericObjectPoolConfig.DEFAULT_MAX_IDLE); int maxTotal = settings.getInteger(MAX_TOTAL, GenericObjectPoolConfig.DEFAULT_MAX_TOTAL); JedisPoolConfig config = new JedisPoolConfig(); config.setMinIdle(minIdle); config.setMaxIdle(maxIdle); config.setMaxTotal(maxTotal); try { return new JedisPool(config, new URI(host)); } catch (URISyntaxException e) { throw new PippoRuntimeException("Malformed redis URI", e); } }