List of usage examples for org.apache.commons.lang3 StringUtils defaultIfBlank
public static <T extends CharSequence> T defaultIfBlank(final T str, final T defaultStr)
Returns either the passed in CharSequence, or if the CharSequence is whitespace, empty ("") or null , the value of defaultStr .
StringUtils.defaultIfBlank(null, "NULL") = "NULL" StringUtils.defaultIfBlank("", "NULL") = "NULL" StringUtils.defaultIfBlank(" ", "NULL") = "NULL" StringUtils.defaultIfBlank("bat", "NULL") = "bat" StringUtils.defaultIfBlank("", null) = null
From source file:com.ibm.cf.Manifest.java
public Manifest(HttpServletRequest request) { this.appName = request.getParameter("appName"); this.memory = Integer.parseInt(StringUtils.defaultIfBlank(request.getParameter("memory"), "128")); this.instances = Integer.parseInt(StringUtils.defaultIfBlank(request.getParameter("instances"), "1")); this.buildpack = request.getParameter("buildpack"); this.host = request.getParameter("host"); this.domain = request.getParameter("domain"); this.path = request.getParameter("path"); this.timeout = Integer.parseInt(StringUtils.defaultIfBlank(request.getParameter("timeout"), "60")); this.command = request.getParameter("command"); this.noRoute = "on".equalsIgnoreCase(request.getParameter("route")) ? true : false; String servicesStr = request.getParameter("services"); if (servicesStr.length() != 0) { this.services = Arrays.asList(request.getParameter("services").split(",")); }// w w w . j a v a 2 s. c o m ObjectMapper mapper = new ObjectMapper(); try { TypeReference<HashMap<String, String>> typeRef = new TypeReference<HashMap<String, String>>() { }; this.envVars = mapper.readValue(request.getParameter("envVars"), typeRef); } catch (Exception e) { LOG.warn("Error parsing JSON object for environment variables", e); } }
From source file:ch.cyberduck.core.manta.MantaAccountHomeInfo.java
private Path buildNormalizedHomePath(final String rawHomePath) { final String defaultPath = StringUtils.defaultIfBlank(rawHomePath, Path.HOME); final String accountRootRegex = String.format("^/?(%s|~~?)/?", accountRoot.getAbsolute()); final String subdirectoryRawPath = defaultPath.replaceFirst(accountRootRegex, ""); if (StringUtils.isEmpty(subdirectoryRawPath)) { return accountRoot; }/*w w w . j a v a 2s .c o m*/ final String[] subdirectoryPathSegments = StringUtils.split(subdirectoryRawPath, Path.DELIMITER); Path homePath = accountRoot; for (final String pathSegment : subdirectoryPathSegments) { EnumSet<Path.Type> types = EnumSet.of(Path.Type.directory); if (homePath.getParent().equals(accountRoot) && StringUtils.equalsAny(pathSegment, HOME_PATH_PRIVATE, HOME_PATH_PUBLIC)) { types.add(Path.Type.volume); } homePath = new Path(homePath, pathSegment, types); } return homePath; }
From source file:com.sonicle.webtop.core.util.LoggerUtils.java
public synchronized static String getUserVariable() { return StringUtils.defaultIfBlank(MDC.get(VAR_USER), DEFAULT_USER); }
From source file:com.esri.geoportal.harvester.waf.WafFolder.java
/** * Creates instance of the folder.//from w ww . j a v a2 s . com * * @param broker broker * @param folderUrl folder URL * @param creds credentials */ public WafFolder(WafBroker broker, URL folderUrl, String matchPattern, SimpleCredentials creds) { this.broker = broker; this.folderUrl = folderUrl; this.matchPattern = StringUtils.defaultIfBlank(matchPattern, DEFAULT_MATCH_PATTERN); this.creds = creds; }
From source file:com.esri.geoportal.harvester.api.base.BotsBrokerDefinitionAdaptor.java
/** * Gets bots config.//from ww w . java 2 s . c om * * @return bots config */ public BotsConfig getBotsConfig() { return new BotsConfigImpl(StringUtils.defaultIfBlank(get(P_BOTS_AGENT), BotsConfig.DEFAULT.getUserAgent()), BooleanUtils.toBoolean(StringUtils.defaultIfBlank(get(P_BOTS_ENABLED), Boolean.toString(BotsConfig.DEFAULT.isEnabled()))), BooleanUtils.toBoolean(StringUtils.defaultIfBlank(get(P_BOTS_OVERRIDE), Boolean.toString(BotsConfig.DEFAULT.isOverride())))); }
From source file:com.thinkbiganalytics.metadata.sla.SlaEmailService.java
/** * Send an email/*w w w .j av a 2 s. c o m*/ * * @param to the user(s) to send the email to * @param subject the subject of the email * @param body the email body */ public void sendMail(String to, String subject, String body) { try { if (testConnection()) { MimeMessage message = mailSender.createMimeMessage(); String fromAddress = StringUtils.defaultIfBlank(emailConfiguration.getFrom(), emailConfiguration.getUsername()); message.setFrom(new InternetAddress(fromAddress)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); message.setSubject(subject); message.setText(body); mailSender.send(message); log.debug("Email send to {}", to); } } catch (MessagingException ex) { log.error("Exception while sending mail : {}", ex.getMessage()); Throwables.propagate(ex); } }
From source file:com.yqboots.web.thymeleaf.processor.element.ProgressElementProcessor.java
@Override protected List<Node> getMarkupSubstitutes(final Arguments arguments, final Element element) { final List<Node> nodes = new ArrayList<>(); final Configuration configuration = arguments.getConfiguration(); // Obtain the Thymeleaf Standard Expression parser final IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration); String value = element.getAttributeValue(ATTR_VALUE); final IStandardExpression expression = parser.parseExpression(configuration, arguments, value); value = (String) expression.execute(configuration, arguments); nodes.add(build(StringUtils.defaultIfBlank(value, "0"))); return nodes; }
From source file:com.sonicle.webtop.core.util.LoggerUtils.java
public synchronized static String getCustomVariable() { return StringUtils.defaultIfBlank(MDC.get(VAR_CUSTOM), null); }
From source file:com.kumarvv.setl.Setl.java
/** * load definition file/*w ww . j a v a2 s. c o m*/ * @param filePath * @return */ protected Def loadFile(String filePath) { ObjectMapper mapper = new ObjectMapper(); try { Path path = Paths.get(filePath); final Def def = mapper.readValue(path.toFile(), Def.class); def.setFilePath(path); initCsvPaths(def, path); loadDataStores(def); LoggingContext.put("def", StringUtils.defaultIfBlank(def.getName(), "")); if (def.getFromDS() != null) { Logger.info("fromDS = {}@{}", def.getFromDS().getUsername(), def.getFromDS().getUrl()); } if (def.getToDS() != null) { Logger.info("toDS = {}@{}", def.getToDS().getUsername(), def.getToDS().getUrl()); } return def; } catch (Exception e) { Logger.error("Invalid definition file: {}", e.getMessage()); Logger.trace(e); } return null; }
From source file:ca.simplegames.micro.extensions.i18n.I18NExtension.java
public Extension register(String name, SiteContext site, Map<String, Object> locales) throws Exception { Assert.notNull(name, "The name of the extension must not be null!"); this.name = StringUtils.defaultIfBlank(name, "i18N"); if (locales != null) { Map interceptConfig = (Map<String, Object>) locales.get("intercept"); if (interceptConfig != null) { intercept = StringUtils.defaultString((String) interceptConfig.get("parameter_name"), "lang"); scopesSrc = StringUtils.defaultString((String) interceptConfig.get("scope"), "context"); scopes = StringUtils.split(scopesSrc, ","); }/*ww w . jav a 2 s . co m*/ defaultEncoding = StringUtils.defaultString((String) locales.get("default_encoding"), Globals.UTF8); fallbackToSystemLocale = locales.get("fallback_to_system_locale") != null ? (Boolean) locales.get("fallback_to_system_locale") : true; resourceCacheRefreshInterval = Integer .parseInt(StringUtils.defaultString((locales.get("resource_cache")).toString(), "10")); List<String> paths = (List<String>) locales.get("base_names"); if (paths != null && !paths.isEmpty()) { List<String> absPaths = new ArrayList<String>(); for (String path : paths) { File realPath = new File(path); if (!realPath.exists()) { realPath = new File(site.getWebInfPath().getAbsolutePath(), path); } try { absPaths.add(realPath.toURI().toURL().toString()); //absPaths.add(pathConfig.getValue()); } catch (MalformedURLException e) { e.printStackTrace(); } } resourceBasePaths = absPaths.toArray(new String[absPaths.size()]); } else { resourceBasePaths = new String[] { "config/locales/messages" }; } //Configure the i18n messageSource = new ReloadableResourceBundleMessageSource(); messageSource.setDefaultEncoding(defaultEncoding); messageSource.setFallbackToSystemLocale(fallbackToSystemLocale); messageSource.setCacheSeconds(resourceCacheRefreshInterval); messageSource.setBasenames(resourceBasePaths); Filter i18N = new I18NFilter(this); final FilterManager filterManager = site.getFilterManager(); filterManager.addFilter(i18N); // now make sure the i18N filter is always first (if present) Collections.swap(filterManager.getBeforeFilters(), 0, filterManager.getBeforeFilters().size() - 1); infoDetails.add(String.format(" default encoding ........: %s", defaultEncoding)); infoDetails.add(String.format(" fallback to system locale: %s", fallbackToSystemLocale)); infoDetails.add(String.format(" cache refresh ...........: %s", resourceCacheRefreshInterval)); infoDetails.add(String.format(" resource bundle .........: %s", Arrays.toString(resourceBasePaths))); infoDetails.add(String.format(" Listening for ...........: '%s'", intercept)); infoDetails.add(String.format(" in scope(s) ........: %s", scopesSrc)); } return this; }