Java Code Examples for org.apache.commons.lang.StringUtils.defaultIfBlank()

The following are Jave code examples for showing how to use defaultIfBlank() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: ymate-module-oauth   File: DefaultModuleCfg.java   Source Code and License Vote up 6 votes
public DefaultModuleCfg(YMP owner) {
    Map<String, String> _moduleCfgs = owner.getConfig().getModuleConfigs(IOAuth.MODULE_NAME);
    //
    __accessTokenExpireIn = BlurObject.bind(_moduleCfgs.get("access_token_expire_in")).toIntValue();
    if (__accessTokenExpireIn <= 0) {
        __accessTokenExpireIn = 7200;
    }
    //
    __cacheNamePrefix = StringUtils.trimToEmpty(_moduleCfgs.get("cache_name_prefix"));
    //
    __snsEnabled = BlurObject.bind(_moduleCfgs.get("sns_enabled")).toBooleanValue();
    if (__snsEnabled) {
        __authorizationView = StringUtils.defaultIfBlank(_moduleCfgs.get("authorization_view"), "_views/oauth2/sns-authorization");
        __userInfoAdaptor = ClassUtils.impl(_moduleCfgs.get("userinfo_adapter_class"), IOAuthUserInfoAdapter.class, getClass());
    }
    //
    __tokenGenerator = ClassUtils.impl(_moduleCfgs.get("token_generator_class"), IOAuthTokenGenerator.class, getClass());
    if (__tokenGenerator == null) {
        __tokenGenerator = new DefaultTokenGenerator();
    }
    //
    __storageAdapter = ClassUtils.impl(_moduleCfgs.get("storage_adapter_class"), IOAuthStorageAdapter.class, getClass());
}
 
Example 2
Project: mxisd   File: PlaceholderNotificationGenerator.java   Source Code and License Vote up 6 votes
protected String populateForInvite(IThreePidInviteReply invite, String input) {
    ThreePid tpid = new ThreePid(invite.getInvite().getMedium(), invite.getInvite().getAddress());

    String senderName = invite.getInvite().getProperties().getOrDefault("sender_display_name", "");
    String senderNameOrId = StringUtils.defaultIfBlank(senderName, invite.getInvite().getSender().getId());
    String roomName = invite.getInvite().getProperties().getOrDefault("room_name", "");
    String roomNameOrId = StringUtils.defaultIfBlank(roomName, invite.getInvite().getRoomId());

    return populateForCommon(input, tpid)
            .replace("%SENDER_ID%", invite.getInvite().getSender().getId())
            .replace("%SENDER_NAME%", senderName)
            .replace("%SENDER_NAME_OR_ID%", senderNameOrId)
            .replace("%INVITE_MEDIUM%", tpid.getMedium())
            .replace("%INVITE_ADDRESS%", tpid.getAddress())
            .replace("%ROOM_ID%", invite.getInvite().getRoomId())
            .replace("%ROOM_NAME%", roomName)
            .replace("%ROOM_NAME_OR_ID%", roomNameOrId);
}
 
Example 3
Project: ymate-payment-v2   File: DefaultModuleCfg.java   Source Code and License Vote up 6 votes
public DefaultModuleCfg(YMP owner) {
    Map<String, String> _moduleCfgs = owner.getConfig().getModuleConfigs(IWxPay.MODULE_NAME);
    //
    __accountProvider = ClassUtils.impl(_moduleCfgs.get("account_provider_class"), IWxPayAccountProvider.class, getClass());
    if (__accountProvider == null) {
        __accountProvider = new DefaultWxPayAccountProvider();
        //
        WxPayAccountMeta _meta = new WxPayAccountMeta(_moduleCfgs.get("app_id"),
                _moduleCfgs.get(IWxPay.Const.MCH_ID),
                _moduleCfgs.get(IWxPay.Const.MCH_KEY),
                _moduleCfgs.get("cert_file_path"),
                _moduleCfgs.get(IWxPay.Const.NOTIFY_URL));
        _meta.setSandboxEnabled(BlurObject.bind(_moduleCfgs.get("sandbox_enabled")).toBooleanValue());
        _meta.setSandboxPrefix(StringUtils.defaultIfBlank(_moduleCfgs.get("sandbox_prefix"), "sandboxnew"));
        //
        __defaultAccountId = _meta.getAppId();
        __accountProvider.registerAccount(_meta);
    } else {
        __defaultAccountId = StringUtils.trimToNull(_moduleCfgs.get("default_account_id"));
    }
    //
    __eventHandler = ClassUtils.impl(_moduleCfgs.get("event_handler_class"), IWxPayEventHandler.class, getClass());
    if (__eventHandler == null) {
        throw new NullArgumentException("event_handler_class");
    }
    //
    __jsApiView = StringUtils.defaultIfBlank(_moduleCfgs.get("jsapi_view"), "wxpay_jsapi");
    __nativeView = StringUtils.defaultIfBlank(_moduleCfgs.get("native_view"), "wxpay_native");
    //
    __signCheckDisabled = BlurObject.bind(_moduleCfgs.get("sign_check_disabled")).toBooleanValue();
}
 
Example 4
Project: ymate-payment-v2   File: AliPayBaseRequest.java   Source Code and License Vote up 6 votes
public AliPayBaseRequest(AliPayAccountMeta accountMeta, String method, String version, DATA bizContent, boolean needNotify, boolean needReturn, IAliPayResponseParser<RESPONSE> responseParser) {
    if (accountMeta == null) {
        throw new NullArgumentException("accountMeta");
    }
    if (StringUtils.isBlank(method)) {
        throw new NullArgumentException("method");
    }
    if (bizContent == null) {
        throw new NullArgumentException("bizContent");
    }
    if (responseParser == null) {
        throw new NullArgumentException("responseParser");
    }
    //
    this.accountMeta = accountMeta;
    this.method = method;
    this.version = StringUtils.defaultIfBlank(version, "1.0");
    this.bizContent = bizContent;
    //
    this.needNotify = needNotify;
    this.needReturn = needReturn;
    //
    this.responseParser = responseParser;
}
 
Example 5
Project: ymate-module-sso   File: DefaultSSOToken.java   Source Code and License Vote up 5 votes
public DefaultSSOToken(String uid, String userAgent, String remoteAddr, long createTime) {
    this();
    this.uid = uid;
    this.remoteAddr = StringUtils.defaultIfBlank(remoteAddr, WebUtils.getRemoteAddr(WebContext.getRequest()));
    this.userAgent = StringUtils.defaultIfBlank(userAgent, WebContext.getRequest().getHeader("User-Agent"));
    this.createTime = createTime > 0 ? createTime : System.currentTimeMillis();
}
 
Example 6
Project: ymate-module-sso   File: DefaultModuleCfg.java   Source Code and License Vote up 5 votes
public DefaultModuleCfg(YMP owner) {
    Map<String, String> _moduleCfgs = owner.getConfig().getModuleConfigs(ISSO.MODULE_NAME);
    //
    __tokenCookieName = StringUtils.defaultIfBlank(_moduleCfgs.get("token_cookie_name"), ISSO.MODULE_NAME + "_token");
    //
    __tokenHeaderName = StringUtils.defaultIfBlank(_moduleCfgs.get("token_header_name"), "X-ModuleSSO-Token");
    //
    __tokenParamName = StringUtils.defaultIfBlank(_moduleCfgs.get("token_param_name"), "token");
    //
    __tokenMaxage = BlurObject.bind(_moduleCfgs.get("token_maxage")).toIntValue();
    //
    __tokenValidateTimeInterval = BlurObject.bind(_moduleCfgs.get("token_validate_time_interval")).toIntValue();
    //
    __cacheNamePrefix = StringUtils.trimToEmpty(_moduleCfgs.get("cache_name_prefix"));
    //
    __multiSessionEnabled = BlurObject.bind(_moduleCfgs.get("multi_session_enabled")).toBooleanValue();
    //
    __ipCheckEnabled = BlurObject.bind(_moduleCfgs.get("ip_check_enabled")).toBooleanValue();
    //
    __isClientMode = BlurObject.bind(_moduleCfgs.get("client_mode")).toBooleanValue();
    //
    __serviceAuthKey = StringUtils.trimToEmpty(_moduleCfgs.get("service_auth_key"));
    //
    if (__isClientMode) {
        __serviceBaseUrl = StringUtils.trimToNull(_moduleCfgs.get("service_base_url"));
        if (__serviceBaseUrl != null) {
            if (!StringUtils.startsWithIgnoreCase(__serviceBaseUrl, "http://") &&
                    !StringUtils.startsWithIgnoreCase(__serviceBaseUrl, "https://")) {
                throw new IllegalArgumentException("The parameter service_base_url is invalid");
            } else if (!StringUtils.endsWith(__serviceBaseUrl, "/")) {
                __serviceBaseUrl = __serviceBaseUrl + "/";
            }
        }
    }
    //
    __tokenApater = ClassUtils.impl(_moduleCfgs.get("token_adapter_class"), ISSOTokenAdapter.class, getClass());
    if (__tokenApater == null) {
        __tokenApater = new DefaultSSOTokenAdapter();
    }
    //
    __tokenStorageAdapter = ClassUtils.impl(_moduleCfgs.get("storage_adapter_class"), ISSOTokenStorageAdapter.class, getClass());
    if (!__isClientMode && __tokenStorageAdapter == null) {
        throw new IllegalArgumentException("The parameter storage_adapter_class is invalid");
    }
    //
    if (!__isClientMode) {
        __tokenAttributeAdapter = ClassUtils.impl(_moduleCfgs.get("attribute_adapter_class"), ISSOTokenAttributeAdapter.class, getClass());
    }
}
 
Example 7
Project: mxisd   File: SqlThreePidProvider.java   Source Code and License Vote up 5 votes
@Override
public Optional<SingleLookupReply> find(SingleLookupRequest request) {
    log.info("SQL lookup");
    String stmtSql = StringUtils.defaultIfBlank(cfg.getIdentity().getMedium().get(request.getType()), cfg.getIdentity().getQuery());
    log.info("SQL query: {}", stmtSql);
    try (Connection conn = pool.get()) {
        try (PreparedStatement stmt = conn.prepareStatement(stmtSql)) {
            stmt.setString(1, request.getType().toLowerCase());
            stmt.setString(2, request.getThreePid().toLowerCase());

            try (ResultSet rSet = stmt.executeQuery()) {
                while (rSet.next()) {
                    String uid = rSet.getString("uid");
                    log.info("Found match: {}", uid);
                    if (StringUtils.equals("uid", cfg.getIdentity().getType())) {
                        log.info("Resolving as localpart");
                        return Optional.of(new SingleLookupReply(request, new MatrixID(uid, mxCfg.getDomain())));
                    }
                    if (StringUtils.equals("mxid", cfg.getIdentity().getType())) {
                        log.info("Resolving as MXID");
                        return Optional.of(new SingleLookupReply(request, new MatrixID(uid)));
                    }

                    log.info("Identity type is unknown, skipping");
                }

                log.info("No match found in SQL");
                return Optional.empty();
            }
        }
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
 
Example 8
Project: ymate-payment-v2   File: WxPayAccountMeta.java   Source Code and License Vote up 5 votes
public void setSandboxPrefix(String sandboxPrefix) {
    sandboxPrefix = StringUtils.defaultIfBlank(sandboxPrefix, "sandboxnew");
    if (StringUtils.startsWith(sandboxPrefix, "/")) {
        sandboxPrefix = StringUtils.substringAfter(sandboxPrefix, "/");
    }
    if (!StringUtils.endsWith(this.sandboxPrefix, "/")) {
        sandboxPrefix = sandboxPrefix + "/";
    }
    this.sandboxPrefix = sandboxPrefix;
}
 
Example 9
Project: ymate-payment-v2   File: AliPayBaseRequest.java   Source Code and License Vote up 5 votes
public IAliPayReqeustSender<RESPONSE> build() throws Exception {
    Map<String, String> _params = new HashMap<String, String>();
    //
    String _charset = StringUtils.defaultIfBlank(accountMeta.getCharset(), IAliPay.Const.CHARSET_UTF8);
    //
    _params.put(IAliPay.Const.APP_ID, accountMeta.getAppId());
    _params.put(IAliPay.Const.METHOD, method);
    _params.put(IAliPay.Const.CHARSET, _charset);
    _params.put(IAliPay.Const.FORMAT, accountMeta.getFormat());
    _params.put(IAliPay.Const.SIGN_TYPE, accountMeta.getSignType().name());
    _params.put(IAliPay.Const.TIMESTAMP, DateTimeUtils.formatTime(System.currentTimeMillis(), IAliPay.Const.DATE_TIME_FORMAT));
    _params.put(IAliPay.Const.VERSION, version);
    //
    if (needNotify) {
        if (StringUtils.isNotBlank(accountMeta.getNotifyUrl())) {
            _params.put(IAliPay.Const.NOTIFY_URL, accountMeta.getNotifyUrl());
        }
    }
    if (needReturn) {
        if (StringUtils.isNotBlank(accountMeta.getReturnUrl())) {
            _params.put(IAliPay.Const.RETURN_URL, accountMeta.getReturnUrl());
        }
    }
    //
    String _bizContentStr = JSON.toJSONString(this.bizContent.buildRequestParams(), SerializerFeature.QuoteFieldNames);
    _params.put(IAliPay.Const.BIZ_CONTENT_KEY, _bizContentStr);
    //
    String _signStr = SignatureUtils.sign(_params, accountMeta.getPrivateKey(), _charset, accountMeta.getSignType());
    _params.put(IAliPay.Const.SIGN, _signStr);
    //
    return new DefaultAliPayRequestSender<RESPONSE>(_params, _charset, this.responseParser);
}
 
Example 10
Project: ymate-payment-v2   File: DefaultModuleCfg.java   Source Code and License Vote up 5 votes
public DefaultModuleCfg(YMP owner) {
    Map<String, String> _moduleCfgs = owner.getConfig().getModuleConfigs(IAliPay.MODULE_NAME);
    //
    __gatewayUrl = StringUtils.defaultIfBlank(_moduleCfgs.get("gateway_url"), "https://openapi.alipay.com/gateway.do");
    if (!StringUtils.startsWithIgnoreCase(__gatewayUrl, "https://") && !StringUtils.startsWithIgnoreCase(__gatewayUrl, "http://")) {
        throw new IllegalArgumentException("gateway_url address is invalid");
    }
    //
    __accountProvider = ClassUtils.impl(_moduleCfgs.get("account_provider_class"), IAliPayAccountProvider.class, getClass());
    if (__accountProvider == null) {
        __accountProvider = new DefaultAliPayAccountProvider();
        //
        AliPayAccountMeta _meta = new AliPayAccountMeta(_moduleCfgs.get(IAliPay.Const.APP_ID), _moduleCfgs.get(IAliPay.Const.SIGN_TYPE), _moduleCfgs.get("private_key"), _moduleCfgs.get("public_key"));
        _meta.setCharset(StringUtils.defaultIfBlank(_moduleCfgs.get(IAliPay.Const.CHARSET), IAliPay.Const.CHARSET_UTF8));
        _meta.setFormat(StringUtils.defaultIfBlank(_moduleCfgs.get(IAliPay.Const.FORMAT), IAliPay.Const.FORMAT_JSON));
        _meta.setNotifyUrl(StringUtils.trimToNull(_moduleCfgs.get(IAliPay.Const.NOTIFY_URL)));
        _meta.setReturnUrl(StringUtils.trimToNull(_moduleCfgs.get(IAliPay.Const.RETURN_URL)));
        //
        __defaultAccountId = _meta.getAppId();
        __accountProvider.registerAccount(_meta);
    } else {
        __defaultAccountId = StringUtils.trimToNull(_moduleCfgs.get("default_account_id"));
    }
    //
    __eventHandler = ClassUtils.impl(_moduleCfgs.get("event_handler_class"), IAliPayEventHandler.class, getClass());
    if (__eventHandler == null) {
        throw new NullArgumentException("event_handler_class");
    }
    //
    __signCheckDisabled = BlurObject.bind(_moduleCfgs.get("sign_check_disabled")).toBooleanValue();
}
 
Example 11
Project: ymate-module-oauth-connector   File: OAuthConnectController.java   Source Code and License Vote up 5 votes
/**
 * @param connectName 连接器名称
 * @param state       自定义状态值(用于防CSRF攻击)
 * @return 跳转至获取第三方授权码的URL地址
 * @throws Exception 可能产生的任何异常
 */
@RequestMapping("/{connectName}")
public IView __toConnect(@PathVariable String connectName, @RequestParam String state) throws Exception {
    IOAuthConnectProcessor _processor = OAuthConnector.get().getConnectProcessor(connectName);
    if (_processor != null) {
        state = StringUtils.defaultIfBlank(state, ParamUtils.createNonceStr());
        IView _view = OAuthConnector.get().getModuleCfg().getConnectCallbackHandler().connect(connectName, state);
        //
        if (_view == null) {
            return View.redirectView(_processor.getAuthorizeUrl(state));
        }
        return _view;
    }
    return View.httpStatusView(HttpServletResponse.SC_BAD_REQUEST);
}
 
Example 12
Project: jenkins-aws-bucket-credentials   File: AwsBucketCredentialsBinding.java   Source Code and License Vote up 5 votes
/**
 * For use with {@link DataBoundConstructor}.
 *
 * @param credentialsId
 */
@DataBoundConstructor
public AwsBucketCredentialsBinding(@Nullable String usernameVariable, @Nullable String passwordVariable,
                                   String credentialsId) {
    super(credentialsId);
    this.usernameVariable = StringUtils.defaultIfBlank(usernameVariable, DEFAULT_USERNAME_VARIABLE);
    this.passwordVariable = StringUtils.defaultIfBlank(passwordVariable, DEFAULT_PASSWORD_VARIABLE);
}
 
Example 13
Project: ymate-payment-v2   File: AliPayException.java   Source Code and License Vote up 4 votes
public AliPayException(String errCode) {
    this.errCode = StringUtils.defaultIfBlank(errCode, "UNKNOWN_ERROR");
    this.errMsg = __ERRORS.get(this.errCode);
}
 
Example 14
Project: ymate-module-oauth-connector   File: AbstractOAuthConnectProcessor.java   Source Code and License Vote up 4 votes
public AbstractOAuthConnectProcessor(String clientParamName, String secretParamName, String openIdParamName) {
    __clientParamName = StringUtils.defaultIfBlank(clientParamName, "client_id");
    __secretParamName = StringUtils.defaultIfBlank(secretParamName, "client_secret");
    __openIdParamName = openIdParamName;
}
 
Example 15
Project: ymate-module-oauth-connector   File: AbstractOAuthConnectProcessor.java   Source Code and License Vote up 4 votes
protected void __doSetErrorFlag(String errorFlag) {
    __errorFlag = StringUtils.defaultIfBlank(errorFlag, "error");
}
 
Example 16
Project: matrix-appservice-email   File: BridgeMessageContent.java   Source Code and License Vote up 4 votes
public BridgeMessageContent(String mime, String encoding, byte[] content) {
    this.mime = mime;
    this.encoding = StringUtils.defaultIfBlank(encoding, "");
    this.content = content;
}
 
Example 17
Project: bdf2   File: ExcelReportModelGenerater.java   Source Code and License Vote up 4 votes
@SuppressWarnings("unchecked")
private void createGridColumnHeader(List<Map<String, Object>> columnInfos, List<ReportGridHeader> headerList, ReportGridHeader parent) {
	if (columnInfos == null)
		return;
	for (Map<String, Object> column : columnInfos) {
		String columnName = (String) column.get("columnName");
		int level = (Integer) column.get("level");
		String label = (String) column.get("label");
		int width = (Integer) column.get("width");
		String bgColor = (String) column.get("bgColor");
		String fontColor = (String) column.get("fontColor");
		int fontSize = 10;
		if (column.get("fontSize") != null) {
			fontSize = (Integer) column.get("fontSize");
		}
		int align = 1;
		if (column.get("align") != null) {
			align = (Integer) column.get("align");
		}
		int dataAlign = 1;
		if (column.get("dataAlign") != null) {
			dataAlign = (Integer) column.get("dataAlign");
		}
		String dataTypeName = "String";
		if (column.containsKey("dataType")){
			dataTypeName = StringUtils.defaultIfBlank((String)column.get("dataType"), "String");
		}
		String displayFormat = "";
		if (column.containsKey("displayFormat")){
			displayFormat = StringUtils.defaultIfBlank((String)column.get("displayFormat"), "");
		}
		ReportGridHeader header = new ReportGridHeader();
		header.setLevel(level);
		header.setAlign(align);
		header.setDataAlign(dataAlign);
		if (StringUtils.isNotEmpty(bgColor)) {
			header.setBgColor(this.createRGB(bgColor));
		}
		if (StringUtils.isNotEmpty(fontColor)) {
			header.setFontColor(this.createRGB(fontColor));
		}
		header.setColumnName(columnName);
		header.setLabel(label);
		header.setFontSize(fontSize);
		header.setWidth(width);
		header.setDataTypeName(dataTypeName);
		header.setDisplayFormat(displayFormat);
		if (parent != null) {
			parent.addGridHeader(header);
			header.setParent(parent);
		} else {
			headerList.add(header);
		}
		List<Map<String, Object>> children = (List<Map<String, Object>>) column.get("children");
		if (children != null) {
			this.createGridColumnHeader(children, headerList, header);
		}
	}
}