Example usage for org.apache.commons.lang StringUtils defaultIfBlank

List of usage examples for org.apache.commons.lang StringUtils defaultIfBlank

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultIfBlank.

Prototype

public static String defaultIfBlank(String str, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is whitespace, empty ("") or null, the value of defaultStr.

Usage

From source file:net.ymate.framework.core.taglib.bootstrap.PanelTag.java

@Override
protected StringBuilder __doTagStart() {
    StringBuilder _classSB = new StringBuilder(StringUtils.trimToEmpty(this.get_class()));
    if (tabs) {/*from   w  w  w.  j  a v  a  2s  . c  om*/
        _classSB.append(" tab-pane");
        //
        if (fade) {
            _classSB.append(" fade");
        }
        if (active) {
            if (fade) {
                _classSB.append(" in");
            }
            _classSB.append(" active");
        }
    } else {
        _classSB.append(" panel panel-").append(StringUtils.defaultIfBlank(style, "default"));
    }
    //
    this.set_class(_classSB.toString());
    //
    return super.__doTagStart();
}

From source file:net.ymate.framework.core.taglib.bootstrap.TextTag.java

@Override
protected void __doSetTagName() {
    this.set_tag(StringUtils.defaultIfBlank(this.get_tag(), "p"));
}

From source file:net.ymate.framework.core.taglib.ElementsTag.java

protected void __doSetTagName() {
    _tag = StringUtils.defaultIfBlank(_tag, "div");
}

From source file:net.ymate.framework.core.taglib.I18nTag.java

@Override
protected Object doProcessTagData() throws JspException {
    String _defaultResourceName = StringUtils
            .defaultIfBlank(YMP.get().getConfig().getParam(Optional.I18N_RESOURCE_NAME), "messages");
    return I18N.formatMessage(StringUtils.defaultIfBlank(getResourceName(), _defaultResourceName), getKey(),
            getDefaultValue());/*  ww  w .  j a  va 2 s  .  c  o  m*/
}

From source file:net.ymate.framework.core.taglib.TokenTag.java

@Override
public int doStartTag() throws JspException {
    StringBuilder _contentSB = new StringBuilder();
    HttpSession session = pageContext.getSession();
    if (session != null) {
        String _tokenKey = TokenProcessHelper.TRANSACTION_TOKEN_KEY;
        String _token = null;// www  .  ja  v  a2 s. c om
        if (create) {
            if (StringUtils.trimToNull(name) != null) {
                _token = TokenProcessHelper.getInstance()
                        .saveToken((HttpServletRequest) pageContext.getRequest(), name);
                _tokenKey += "|" + name;
            } else {
                _token = TokenProcessHelper.getInstance()
                        .saveToken((HttpServletRequest) pageContext.getRequest());
            }
        } else {
            if (StringUtils.trimToNull(name) != null) {
                _tokenKey += "|" + name;
            }
            _token = (String) session.getAttribute(_tokenKey);
        }
        //
        if (_token != null) {
            _contentSB.append("<input type=\"hidden\" name=\"")
                    .append(StringUtils.defaultIfBlank(name, TokenProcessHelper.TOKEN_KEY))
                    .append("\" value=\"").append(_token).append("\">");
        }
    }
    try {
        pageContext.getOut().println(_contentSB.toString());
    } catch (IOException e) {
        throw new JspException(e.getMessage(), RuntimeUtils.unwrapThrow(e));
    }
    return SKIP_BODY;
}

From source file:net.ymate.framework.core.taglib.ui.ScriptTag.java

@Override
public int doEndTag() throws JspException {
    StringBuilder _scriptTmpl = new StringBuilder("<script");
    if (StringUtils.isNotBlank(this.getId())) {
        _scriptTmpl.append(" id=\"").append(this.getId()).append("\"");
    }/*w ww. j  av  a  2 s  .c o  m*/
    boolean _isEmpty = true;
    if (StringUtils.isNotBlank(this.getSrc())) {
        _scriptTmpl.append(" src=\"").append(this.getSrc()).append("\"");
        _isEmpty = false;
    }
    _scriptTmpl.append(" type=\"").append(StringUtils.defaultIfBlank(this.getType(), "text/javascript"))
            .append("\">");
    if (_isEmpty && StringUtils.isNotEmpty(this.getValue())) {
        String _wrapper = StringUtils.defaultIfBlank(this.getWrapper(), "script");
        String _content = StringUtils.substringBetween(this.getValue(), "<" + _wrapper + ">",
                "</" + _wrapper + ">");
        if (StringUtils.isNotBlank(_content)) {
            this.setValue(_content);
        }
        _scriptTmpl.append(this.getValue()).append("\n");
        _isEmpty = false;
    }
    _scriptTmpl.append("</script>\n");
    if (!_isEmpty) {
        __ui.writerToScriptPart(_scriptTmpl.toString());
    }
    //
    this.__ui = null;
    this.src = null;
    this.value = null;
    this.id = null;
    this.type = null;
    this.wrapper = null;
    return super.doEndTag();
}

From source file:net.ymate.framework.core.util.WebUtils.java

private static String __doGetSafeServerName(HttpServletRequest request) {
    String _serverName = YMP.get().getConfig().getParam(Optional.SERVER_NAME);
    return StringUtils.defaultIfBlank(_serverName, request.getServerName());
}

From source file:net.ymate.framework.core.util.WebUtils.java

public static String getResourceName(YMP owner) {
    if (__resourceName == null) {
        synchronized (WebUtils.class) {
            if (__resourceName == null) {
                __resourceName = StringUtils
                        .defaultIfBlank(owner.getConfig().getParam(Optional.I18N_RESOURCE_NAME), "messages");
            }/*from   ww w . ja  v  a  2  s .com*/
        }
    }
    return __resourceName;
}

From source file:net.ymate.framework.core.util.WebUtils.java

public static String buildRedirectURL(InterceptContext context, String redirectUrl, boolean needPrefix) {
    String _redirectUrl = StringUtils.trimToNull(redirectUrl);
    if (_redirectUrl == null) {
        _redirectUrl = StringUtils.defaultIfBlank(WebContext.getRequest().getParameter(Optional.REDIRECT_URL),
                context != null ? context.getContextParams().get(Optional.REDIRECT_URL) : "");
        if (StringUtils.isBlank(_redirectUrl)) {
            _redirectUrl = WebContext.getContext().getOwner().getOwner().getConfig()
                    .getParam(Optional.REDIRECT_HOME_URL);
            if (StringUtils.isBlank(_redirectUrl)) {
                _redirectUrl = StringUtils.defaultIfBlank(_redirectUrl,
                        WebUtils.baseURL(WebContext.getRequest()));
            }/*from w w w . ja  v a 2 s  .  c o m*/
        }
    }
    if (needPrefix && !StringUtils.startsWithIgnoreCase(_redirectUrl, "http://")
            && !StringUtils.startsWithIgnoreCase(_redirectUrl, "https://")) {
        _redirectUrl = WebUtils.buildURL(WebContext.getRequest(), _redirectUrl, true);
    }
    return _redirectUrl;
}

From source file:net.ymate.framework.core.util.WebUtils.java

public static String buildRedirectCustomURL(InterceptContext context, String defaultValue) {
    String _returnValue = null;//ww  w  .  ja v a  2 s  . com
    if (context.getContextParams().containsKey(Optional.CUSTOM_REDIRECT)) {
        String _value = context.getContextParams().get(Optional.CUSTOM_REDIRECT);
        if (StringUtils.equalsIgnoreCase(_value, Optional.CUSTOM_REDIRECT)) {
            _value = Optional.REDIRECT_CUSTOM_URL;
        } else if (StringUtils.startsWithIgnoreCase(_value, "http://")
                || StringUtils.startsWithIgnoreCase(_value, "https://")) {
            return _value;
        }
        if (StringUtils.isNotBlank(_value)) {
            _returnValue = context.getOwner().getConfig().getParam(_value);
        }
    }
    return StringUtils.trimToEmpty(StringUtils.defaultIfBlank(_returnValue, defaultValue));
}