List of usage examples for org.apache.commons.lang StringUtils defaultIfBlank
public static String defaultIfBlank(String str, String defaultStr)
Returns either the passed in String, or if the String is whitespace, empty ("") or null
, the value of defaultStr
.
From source file:net.di2e.ecdr.commons.endpoint.rest.AbstractRestSearchEndpoint.java
protected String getGeoRSSFormat(MultivaluedMap<String, String> queryParameters) { return StringUtils.defaultIfBlank(queryParameters.getFirst(SearchConstants.GEORSS_RESULT_FORMAT_PARAMETER), null);//w w w. java 2 s.co m }
From source file:net.di2e.ecdr.commons.endpoint.rest.AbstractRestSearchEndpoint.java
public Map<String, Serializable> getQueryProperties(MultivaluedMap<String, String> queryParameters, String sourceId) {//from ww w . j a va 2 s .co m Map<String, Serializable> queryProperties = new HashMap<String, Serializable>(); queryProperties.put(SearchConstants.FORMAT_PARAMETER, StringUtils.defaultIfBlank(queryParameters.getFirst(SearchConstants.FORMAT_PARAMETER), queryConfiguration.getDefaultResponseFormat())); queryProperties.put(SearchConstants.STATUS_PARAMETER, SearchUtils.getBoolean(queryParameters.getFirst(SearchConstants.STATUS_PARAMETER), true)); queryProperties.put(SearchConstants.DEDUP_PARAMETER, SearchUtils.getBoolean(queryParameters.getFirst(SearchConstants.DEDUP_PARAMETER), queryConfiguration.isDefaultDeduplication())); for (String key : queryParameters.keySet()) { String value = queryParameters.getFirst(key); if (StringUtils.isNotBlank(value) && (queryConfiguration.getParameterPropertyList().contains(key) || queryConfiguration.getHeaderPropertyList().contains(key))) { LOGGER.trace( "Adding key/value pair [{}]=[{}] to queryProperties that get sent in with query request", key, value); queryProperties.put(key, value); } } LOGGER.trace("Setting the query properties to {} based on values in query parameters {}", queryProperties, queryParameters); return queryProperties; }
From source file:hudson.security.SecurityRealm.java
/** * Perform a calculation where we should go back after successful login * * @return Encoded URI where we should go back after successful login * or "/" if no way back or an issue occurred * * @since 2.4/*from w w w.j a v a 2 s .c om*/ */ @Restricted(DoNotUse.class) public static String getFrom() { String from = null, returnValue = null; final StaplerRequest request = Stapler.getCurrentRequest(); // Try to obtain a return point either from the Session // or from the QueryParameter in this order if (request != null && request.getSession(false) != null) { from = (String) request.getSession().getAttribute("from"); } else if (request != null) { from = request.getParameter("from"); } // If entry point was not found, try to deduce it from the request URI // except pages related to login process if (from == null && request != null && request.getRequestURI() != null && !request.getRequestURI().equals("/loginError") && !request.getRequestURI().equals("/login")) { from = request.getRequestURI(); } // If deduced entry point isn't deduced yet or the content is a blank value // use the root web point "/" as a fallback from = StringUtils.defaultIfBlank(from, "/").trim(); // Encode the return value try { returnValue = java.net.URLEncoder.encode(from, "UTF-8"); } catch (UnsupportedEncodingException e) { } // Return encoded value or at least "/" in the case exception occurred during encode() // or if the encoded content is blank value return StringUtils.isBlank(returnValue) ? "/" : returnValue; }
From source file:com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMNavigator.java
@NonNull @Override/* w w w . j a va 2s. c o m*/ public List<Action> retrieveActions(@NonNull SCMNavigatorOwner owner, @CheckForNull SCMNavigatorEvent event, @NonNull TaskListener listener) throws IOException, InterruptedException { // TODO when we have support for trusted events, use the details from event if event was from trusted source listener.getLogger().printf("Looking up team details of %s...%n", getRepoOwner()); List<Action> result = new ArrayList<>(); StandardCredentials credentials = BitbucketCredentials.lookupCredentials(serverUrl, owner, credentialsId, StandardCredentials.class); if (credentials == null) { listener.getLogger().format("Connecting to %s with no credentials, anonymous access%n", serverUrl); } else { listener.getLogger().format("Connecting to %s using %s%n", serverUrl, CredentialsNameProvider.name(credentials)); } BitbucketAuthenticator authenticator = AuthenticationTokens .convert(BitbucketAuthenticator.authenticationContext(serverUrl), credentials); BitbucketApi bitbucket = BitbucketApiFactory.newInstance(serverUrl, authenticator, repoOwner, null); BitbucketTeam team = bitbucket.getTeam(); if (team != null) { String defaultTeamUrl; if (team instanceof BitbucketServerProject) { defaultTeamUrl = serverUrl + "/projects/" + team.getName(); } else { defaultTeamUrl = serverUrl + "/" + team.getName(); } String teamUrl = StringUtils.defaultIfBlank(getLink(team.getLinks(), "html"), defaultTeamUrl); String teamDisplayName = StringUtils.defaultIfBlank(team.getDisplayName(), team.getName()); result.add(new ObjectMetadataAction(teamDisplayName, null, teamUrl)); String avatarUrl; if (team instanceof BitbucketServerProject) { avatarUrl = UriTemplate.fromTemplate(serverUrl + "/rest/api/1.0/projects/{repo}/avatar.png") .set("repo", repoOwner).expand(); } else { avatarUrl = getLink(team.getLinks(), "avatar"); } result.add(new BitbucketTeamMetadataAction(avatarUrl)); result.add(new BitbucketLink("icon-bitbucket-logo", teamUrl)); listener.getLogger().printf("Team: %s%n", HyperlinkNote.encodeTo(teamUrl, teamDisplayName)); } else { String teamUrl = serverUrl + "/" + repoOwner; result.add(new ObjectMetadataAction(repoOwner, null, teamUrl)); result.add(new BitbucketTeamMetadataAction(null)); result.add(new BitbucketLink("icon-bitbucket-logo", teamUrl)); listener.getLogger().println("Could not resolve team details"); } return result; }
From source file:meta.proyecto.base.ProyectoJava.java
/** * @return the base folder name */ public String getBaseFolderName() { return StringUtils.defaultIfBlank(_baseFolderName, getDefaultBaseFolderName()); }
From source file:meta.proyecto.base.ProyectoJava.java
/** * @return the database name */ public String getDatabaseName() { return StringUtils.defaultIfBlank(_databaseName, getDefaultDatabaseName()); }
From source file:meta.proyecto.base.ProyectoJava.java
/** * @return the root folder name */ public String getRootFolderName() { return StringUtils.defaultIfBlank(_rootFolderName, getDefaultRootFolderName()); }
From source file:meta.proyecto.base.ProyectoJava.java
/** * @return the root package name */ public String getRootPackageName() { return StringUtils.defaultIfBlank(_rootPackageName, getDefaultRootPackageName()); }
From source file:eu.europeana.portal2.web.presentation.model.FullDocPage.java
public String getObjectDcIdentifier() { return StringUtils.defaultIfBlank(getShortcutFirstValue("DcIdentifier"), ""); }
From source file:com.iyonger.apm.web.service.PerfTestService.java
/** * Create {@link GrinderProperties} based on the passed {@link PerfTest}. * * @param perfTest base data/*from w ww.ja v a2s . co m*/ * @param scriptHandler scriptHandler * @return created {@link GrinderProperties} instance */ public GrinderProperties getGrinderProperties(PerfTest perfTest, ScriptHandler scriptHandler) { try { // Use default properties first GrinderProperties grinderProperties = new GrinderProperties( config.getHome().getDefaultGrinderProperties()); User user = perfTest.getCreatedUser(); // Get all files in the script path String scriptName = perfTest.getScriptName(); FileEntry userDefinedGrinderProperties = fileEntryService.getOne(user, FilenameUtils.concat(FilenameUtils.getPath(scriptName), DEFAULT_GRINDER_PROPERTIES), -1L); if (!config.isSecurityEnabled() && userDefinedGrinderProperties != null) { // Make the property overridden by user property. GrinderProperties userProperties = new GrinderProperties(); userProperties.load(new StringReader(userDefinedGrinderProperties.getContent())); grinderProperties.putAll(userProperties); } grinderProperties.setAssociatedFile(new File(DEFAULT_GRINDER_PROPERTIES)); grinderProperties.setProperty(GRINDER_PROP_SCRIPT, scriptHandler.getScriptExecutePath(scriptName)); grinderProperties.setProperty(GRINDER_PROP_TEST_ID, "test_" + perfTest.getId()); grinderProperties.setInt(GRINDER_PROP_AGENTS, getSafe(perfTest.getAgentCount())); grinderProperties.setInt(GRINDER_PROP_PROCESSES, getSafe(perfTest.getProcesses())); grinderProperties.setInt(GRINDER_PROP_THREAD, getSafe(perfTest.getThreads())); if (perfTest.isThresholdDuration()) { grinderProperties.setLong(GRINDER_PROP_DURATION, getSafe(perfTest.getDuration())); grinderProperties.setInt(GRINDER_PROP_RUNS, 0); } else { grinderProperties.setInt(GRINDER_PROP_RUNS, getSafe(perfTest.getRunCount())); if (grinderProperties.containsKey(GRINDER_PROP_DURATION)) { grinderProperties.remove(GRINDER_PROP_DURATION); } } grinderProperties.setProperty(GRINDER_PROP_ETC_HOSTS, StringUtils.defaultIfBlank(perfTest.getTargetHosts(), "")); grinderProperties.setBoolean(GRINDER_PROP_USE_CONSOLE, true); if (BooleanUtils.isTrue(perfTest.getUseRampUp())) { grinderProperties.setBoolean(GRINDER_PROP_THREAD_RAMPUP, perfTest.getRampUpType() == RampUp.THREAD); grinderProperties.setInt(GRINDER_PROP_PROCESS_INCREMENT, getSafe(perfTest.getRampUpStep())); grinderProperties.setInt(GRINDER_PROP_PROCESS_INCREMENT_INTERVAL, getSafe(perfTest.getRampUpIncrementInterval())); if (perfTest.getRampUpType() == RampUp.PROCESS) { grinderProperties.setInt(GRINDER_PROP_INITIAL_SLEEP_TIME, getSafe(perfTest.getRampUpInitSleepTime())); } else { grinderProperties.setInt(GRINDER_PROP_INITIAL_THREAD_SLEEP_TIME, getSafe(perfTest.getRampUpInitSleepTime())); } grinderProperties.setInt(GRINDER_PROP_INITIAL_PROCESS, getSafe(perfTest.getRampUpInitCount())); } else { grinderProperties.setInt(GRINDER_PROP_PROCESS_INCREMENT, 0); } if (BooleanUtils.isTrue(perfTest.getUseFixedRateRPS())) { grinderProperties.setDouble(GRINDER_PROP_FIXED_RPS_RATE, perfTest.getRps()); } grinderProperties.setInt(GRINDER_PROP_REPORT_TO_CONSOLE, 500); grinderProperties.setProperty(GRINDER_PROP_USER, perfTest.getCreatedUser().getUserId()); grinderProperties.setProperty(GRINDER_PROP_JVM_CLASSPATH, getCustomClassPath(perfTest)); grinderProperties.setInt(GRINDER_PROP_IGNORE_SAMPLE_COUNT, getSafe(perfTest.getIgnoreSampleCount())); grinderProperties.setBoolean(GRINDER_PROP_SECURITY, config.isSecurityEnabled()); // For backward agent compatibility. // If the security is not enabled, pass it as jvm argument. // If enabled, pass it to grinder.param. In this case, I drop the // compatibility. if (StringUtils.isNotBlank(perfTest.getParam())) { String param = perfTest.getParam().replace("'", "\\'").replace(" ", ""); if (config.isSecurityEnabled()) { grinderProperties.setProperty(GRINDER_PROP_PARAM, StringUtils.trimToEmpty(param)); } else { String property = grinderProperties.getProperty(GRINDER_PROP_JVM_ARGUMENTS, ""); property = property + " -Dparam=" + param + " "; grinderProperties.setProperty(GRINDER_PROP_JVM_ARGUMENTS, property); } } LOGGER.info("Grinder Properties : {} ", grinderProperties); return grinderProperties; } catch (Exception e) { throw processException("error while prepare grinder property for " + perfTest.getTestName(), e); } }