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:com.adaptris.core.management.BootstrapProperties.java
private static Properties createProperties(final String resourceName) throws Exception { String propertiesFile = StringUtils.defaultIfBlank(resourceName, DEFAULT_PROPS_RESOURCE); log.trace("Properties resource is [{}]", propertiesFile); Properties config = PropertyHelper.loadQuietly(() -> { return openResource(propertiesFile); });//www . j a va 2 s. com return config; }
From source file:com.adaptris.mail.MatchProxyFactory.java
static MatchProxy create(String regularExpressionType, String expression) throws Exception { String type = StringUtils.defaultIfBlank(regularExpressionType, DEFAULT_REGEXP_STYLE); if (expression == null) { return null; }//from w w w . j ava 2s . c o m for (ProxyBuilder c : ProxyBuilder.values()) { if (c.matches(type)) { return c.build(expression); } } throw new IllegalArgumentException(regularExpressionType + " not supported"); }
From source file:ips1ap101.lib.base.util.TimeUtils.java
public static String getTimeFormat() { String string = BundleWebui.getTrimmedToNullString("DateTimeConverter.time.pattern"); String format = StringUtils.defaultIfBlank(string, DEFAULT_TIME_FORMAT); return format; }
From source file:com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications.java
private static void createStatus(@NonNull Run<?, ?> build, @NonNull TaskListener listener, @NonNull BitbucketApi bitbucket, @NonNull String hash) throws IOException, InterruptedException { String url;//from w ww .j a va2 s . c om try { url = getRootURL(build); } catch (IllegalStateException e) { listener.getLogger() .println("Can not determine Jenkins root URL " + "or Jenkins URL is not a valid URL regarding Bitbucket API. " + "Commit status notifications are disabled until a root URL is " + "configured in Jenkins global configuration."); return; } String key = build.getParent().getFullName(); // use the job full name as the key for the status String name = build.getFullDisplayName(); // use the build number as the display name of the status BitbucketBuildStatus status; Result result = build.getResult(); String buildDescription = build.getDescription(); String statusDescription; String state; if (Result.SUCCESS.equals(result)) { statusDescription = StringUtils.defaultIfBlank(buildDescription, "This commit looks good."); state = "SUCCESSFUL"; } else if (Result.UNSTABLE.equals(result)) { statusDescription = StringUtils.defaultIfBlank(buildDescription, "This commit has test failures."); state = "FAILED"; } else if (Result.FAILURE.equals(result)) { statusDescription = StringUtils.defaultIfBlank(buildDescription, "There was a failure building this commit."); state = "FAILED"; } else if (Result.NOT_BUILT.equals(result)) { // Bitbucket Cloud and Server support different build states. state = (bitbucket instanceof BitbucketCloudApiClient) ? "STOPPED" : "SUCCESSFUL"; statusDescription = StringUtils.defaultIfBlank(buildDescription, "This commit was not built (probably the build was skipped)"); } else if (result != null) { // ABORTED etc. statusDescription = StringUtils.defaultIfBlank(buildDescription, "Something is wrong with the build of this commit."); state = "FAILED"; } else { statusDescription = StringUtils.defaultIfBlank(buildDescription, "The build is in progress..."); state = "INPROGRESS"; } status = new BitbucketBuildStatus(hash, statusDescription, state, url, key, name); new BitbucketChangesetCommentNotifier(bitbucket).buildStatus(status); if (result != null) { listener.getLogger().println("[Bitbucket] Build result notified"); } }
From source file:com.kibana.multitenancy.plugin.KibanaUserReindexFilter.java
private String getUser(RestRequest request) { //Sushant:Getting user in case of Basic Authentication String username = ""; //Sushant:Scenario when user Authenticated at Proxy level itself String proxyAuthUser = StringUtils.defaultIfBlank(request.header(proxyUserHeader), ""); //Sushant: Scenario when user Authenticated at Proxy level itself String basicAuthorizationHeader = StringUtils.defaultIfBlank(request.header("Authorization"), ""); if (StringUtils.isNotEmpty(basicAuthorizationHeader)) { String decodedBasicHeader = new String( DatatypeConverter.parseBase64Binary(basicAuthorizationHeader.split(" ")[1]), StandardCharsets.US_ASCII); final String[] decodedBasicHeaderParts = decodedBasicHeader.split(":"); username = decodedBasicHeaderParts[0]; decodedBasicHeader = null;// w ww.j ava 2s . c o m basicAuthorizationHeader = null; logger.debug("User '{}' is authenticated", username); } return username; }
From source file:eu.europeana.portal2.web.presentation.model.FullDocPage.java
/** * Returns the url for the image that links to the source image * /*from www. j a va 2 s.co m*/ * @return image reference */ public String getImageRef() { return StringUtils.defaultIfBlank(getShortcutFirstValue("EdmIsShownBy"), getShortcutFirstValue("EdmIsShownAt")); }
From source file:ips1ap101.lib.base.util.TimeUtils.java
public static String getTimestampFormat() { String string = BundleWebui.getTrimmedToNullString("DateTimeConverter.both.pattern"); String format = StringUtils.defaultIfBlank(string, DEFAULT_TIMESTAMP_FORMAT); return format; }
From source file:net.duckling.ddl.web.api.rest.FileEditController.java
@RequestMapping(value = "/fileShared", method = RequestMethod.POST) public void fileShared(@RequestParam(value = "path", required = false) String path, @RequestParam("file") MultipartFile file, @RequestParam(value = "ifExisted", required = false) String ifExisted, HttpServletRequest request, HttpServletResponse response) throws IOException { String uid = getCurrentUid(request); int tid = getCurrentTid(); path = StringUtils.defaultIfBlank(path, PathName.DELIMITER); LOG.info("file shared start... {uid:" + uid + ",tid:" + tid + ",path:" + path + ",fileName:" + file.getOriginalFilename() + ",ifExisted:" + ifExisted + "}"); Resource parent = folderPathService.getResourceByPath(tid, path); if (parent == null) { LOG.error("path not found. {tid:" + tid + ", path:" + path + "}"); writeError(ErrorMsg.NOT_FOUND, response); return;// w w w. j ava 2 s . c o m } List<Resource> list = resourceService.getResourceByTitle(tid, parent.getRid(), LynxConstants.TYPE_FILE, file.getOriginalFilename()); if (list.size() > 0 && !IF_EXISTED_UPDATE.equals(ifExisted)) { LOG.error("file existed. {ifExisted:" + ifExisted + ",fileName:" + file.getOriginalFilename() + "}"); writeError(ErrorMsg.EXISTED, response); return; } FileVersion fv = null; try { fv = resourceOperateService.upload(uid, getCurrentTid(), parent.getRid(), file.getOriginalFilename(), file.getSize(), file.getInputStream()); } catch (NoEnoughSpaceException e) { LOG.error("no enough space. {tid:" + tid + ",size:" + file.getSize() + ",fileName:" + file.getOriginalFilename() + "}"); writeError(ErrorMsg.NO_ENOUGH_SPACE, response); return; } ShareResource sr = shareResourceService.get(fv.getRid()); if (sr == null) { sr = createShareResource(fv.getRid(), uid); } else { sr.setLastEditor(uid); sr.setLastEditTime(new Date()); shareResourceService.update(sr); } sr.setTitle(fv.getTitle()); sr.setShareUrl(sr.generateShareUrl(urlGenerator)); LOG.info("file uploaded and shared successfully. {tid:" + tid + ",path:" + path + ",title:" + fv.getTitle() + "}"); JsonUtil.write(response, VoUtil.getShareResourceVo(sr)); }
From source file:com.adaptris.core.services.exception.ExceptionHandlingServiceWrapper.java
/** @see com.adaptris.core.Service#doService(com.adaptris.core.AdaptrisMessage) */ public void doService(AdaptrisMessage msg) throws ServiceException { try {//from w w w . ja v a 2 s. co m service.doService(msg); } catch (ServiceException e) { log.warn("exception has occurred, applying exceptionService"); log.trace("exception details", e); msg.getObjectHeaders().put(CoreConstants.OBJ_METADATA_EXCEPTION, e); msg.addMetadata(getExceptionMessageMetadataKey(), StringUtils.defaultIfBlank(e.getMessage(), "")); exceptionHandlingService.doService(msg); } }
From source file:com.sonicle.webtop.core.app.LogManager.java
public boolean write(UserProfileId profileId, String serviceId, String action, String softwareName, String remoteIp, String userAgent, String sessionId, String data) { Connection con = null;/*from w ww . jav a 2 s. co m*/ if (!initialized) return false; if (!isEnabled(profileId.getDomain(), serviceId)) return false; try { con = WT.getCoreConnection(); SysLogDAO dao = SysLogDAO.getInstance(); OSysLog item = new OSysLog(); item.setSyslogId(dao.getSequence(con)); item.setTimestamp(DateTime.now(DateTimeZone.UTC)); item.setDomainId(profileId.getDomain()); item.setUserId(profileId.getUserId()); item.setServiceId(serviceId); item.setAction(action); item.setSwName(StringUtils.defaultIfBlank(softwareName, wta.getPlatformName())); item.setIpAddress(remoteIp); item.setUserAgent(userAgent); item.setSessionId(sessionId); item.setData(data); dao.insert(con, item); return true; } catch (SQLException ex) { logger.error("DB error", ex); return false; } finally { DbUtils.closeQuietly(con); } }