Example usage for org.apache.commons.lang3 StringUtils isBlank

List of usage examples for org.apache.commons.lang3 StringUtils isBlank

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils isBlank.

Prototype

public static boolean isBlank(final CharSequence cs) 

Source Link

Document

Checks if a CharSequence is whitespace, empty ("") or null.

 StringUtils.isBlank(null)      = true StringUtils.isBlank("")        = true StringUtils.isBlank(" ")       = true StringUtils.isBlank("bob")     = false StringUtils.isBlank("  bob  ") = false 

Usage

From source file:controllers.api.v1.Lineage.java

public static Result getDatasetLineageGraphData(int id) {
    ObjectNode result = Json.newObject();
    String username = session("user");
    if (id < 1) {
        result.put("status", "error");
        result.put("message", "wrong dataset id");
        return ok(result);
    }/* w w w.  j  av a2s . co  m*/

    models.Dataset dataset = DatasetsDAO.getDatasetByID(id, username);
    if (dataset == null || StringUtils.isBlank(dataset.urn)) {
        result.put("status", "error");
        result.put("message", "wrong dataset id");
        return ok(result);
    }

    int upLevel = 1;
    String upLevelStr = request().getQueryString("upLevel");
    if (StringUtils.isBlank(upLevelStr)) {
        upLevel = 1;
    } else {
        try {
            upLevel = Integer.parseInt(upLevelStr);
        } catch (NumberFormatException e) {
            Logger.error(
                    "Lineage Controller getDatasetLineageGraphData wrong upLevel parameter. Error message: "
                            + e.getMessage());
            upLevel = 1;
        }
    }
    if (upLevel < 1)
        upLevel = 1;

    int downLevel = 1;
    String downLevelStr = request().getQueryString("downLevel");
    if (StringUtils.isBlank(downLevelStr)) {
        downLevel = 1;
    } else {
        try {
            downLevel = Integer.parseInt(downLevelStr);
        } catch (NumberFormatException e) {
            Logger.error(
                    "Lineage Controller getDatasetLineageGraphData wrong downLevel parameter. Error message: "
                            + e.getMessage());
            downLevel = 1;
        }
    }
    if (downLevel < 1)
        downLevel = 1;

    int lookBackTimeDefault = Integer
            .valueOf(Play.application().configuration().getString(LINEAGE_LOOK_BACK_TIME_KEY, "30"));
    int lookBackTime = lookBackTimeDefault;
    String lookBackTimeStr = request().getQueryString("period");
    if (!StringUtils.isBlank(lookBackTimeStr)) {
        try {
            lookBackTime = Integer.parseInt(lookBackTimeStr);
        } catch (NumberFormatException e) {
            Logger.error("Lineage Controller getDatasetLineageGraphData wrong period parameter. Error message: "
                    + e.getMessage());
            lookBackTime = lookBackTimeDefault;
        }
    }

    result.put("status", "ok");
    result.set("data",
            Json.toJson(LineageDAO.getObjectAdjacnet(dataset.urn, upLevel, downLevel, lookBackTime)));
    System.out
            .println(Json.toJson(LineageDAO.getObjectAdjacnet(dataset.urn, upLevel, downLevel, lookBackTime)));
    System.out.println(ok(result));
    return ok(result);
}

From source file:com.thoughtworks.go.domain.materials.svn.SvnExternalParser.java

private static String combine(String root, String externalDir) {
    return StringUtils.isBlank(root) ? externalDir : root + "/" + externalDir;
}

From source file:cn.imethan.common.mongodb.SearchFilter.java

/**
 * ??/* w ww  . j  a  v  a2 s. com*/
 * searchParamskey?OPERATOR_FIELDNAME
 * 
 * @param searchParams
 * @return
 *
 * @author Ethan Wong
 * @datetime 2015101?1:24:57
 */
public static Map<String, SearchFilter> parse(Map<String, Object> searchParams) {
    Map<String, SearchFilter> filters = Maps.newHashMap();

    for (Entry<String, Object> entry : searchParams.entrySet()) {
        // 
        String key = entry.getKey();
        Object value = entry.getValue();
        if (StringUtils.isBlank((String) value)) {
            continue;
        }

        // operatorfiledAttribute
        String[] names = StringUtils.split(key, "_");
        if (names.length != 2) {
            throw new IllegalArgumentException(key + " is not a valid search filter name");
        }
        String filedName = names[1];
        Operator operator = Operator.valueOf(names[0]);

        // searchFilter
        SearchFilter filter = new SearchFilter(filedName, operator, value);
        filters.put(key, filter);
    }
    return filters;
}

From source file:learningresourcefinder.web.Slugify.java

private static String normalize(String input) {
    String ret = StringUtils.trim(input);
    if (StringUtils.isBlank(ret)) {
        return "";
    }// w ww .j av  a 2s  .co  m
    ret = ret.replace("", "ss");
    ret = Normalizer.normalize(ret, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "")
            .replaceAll("[^a-zA-Z0-9 ]", "");
    return ret;
}

From source file:com.eryansky.modules.sys.utils.DictionaryUtils.java

/**
 *
 * @param dictionaryCode ?//from   w w  w  .  j  a  v  a2s  .  c  o  m
 * @param value 
 * @param defaultValue ?
 * @return
 */
public static String getDictionaryNameByDV(String dictionaryCode, String value, String defaultValue) {
    if (StringUtils.isBlank(value)) {
        return defaultValue;
    }
    DictionaryItem dictionaryItem = dictionaryItemService.getDictionaryItemByDV(dictionaryCode, value);
    if (dictionaryItem != null) {
        defaultValue = dictionaryItem.getName();
    }
    return defaultValue;
}

From source file:de.micromata.genome.gwiki.plugin.rogmp3_1_0.Mp3Stats.java

public static void genStatistics(Mp3Db db, XmlElement node) {
    DecimalFormat df = new DecimalFormat("#,###");
    node.add(Html.p(code("Komponisten: " + df.format(db.composers.table.size()))));
    List<Media> ml = db.getMedia();
    int cdc = 0;/*from w w w .  j ava2  s.  com*/
    for (Media m : ml) {
        String mc = m.get(Media.MEDIACOUNT);
        if (StringUtils.isBlank(mc) == true) {
            ++cdc;
            continue;
        }
        try {
            cdc += NumberUtils.createInteger(mc);
        } catch (NumberFormatException ex) {
            ++cdc;
        }
    }
    int tcest = 36000;
    node.add(Html.p(code("Medien: " + df.format(ml.size()) + ", single: " + df.format(cdc))));
    node.add(Html.p(code("Titel: " + df.format(db.title.table.size()))));
    node.add(Html.p(code("<i>Only Parts with trackinfo</i>:")));
    double factor = (double) tcest / (double) db.tracks.table.size();

    node.add(Html.p(code("Tracks: " + df.format(db.tracks.table.size()))));
    long timesec = 0;
    long sizebytes = 0;
    for (String[] td : db.tracks.table) {
        Track track = new Track(db, td);
        timesec += track.getTime();
        sizebytes += track.getSize();
    }
    long esttimesec = (long) (factor * timesec);
    SimpleDateFormat sd = new SimpleDateFormat("MM-dd HH:mm:ss");
    String dur = sd.format(new Date(timesec * 1000));
    String esdur = sd.format(new Date(esttimesec * 1000));
    String size = df.format(sizebytes);

    node.add(Html.p(code("Total time: " + dur + ", " + df.format((int) (timesec / 3600)) + " hours")));
    node.add(Html.p(code("Total size: " + size + " (Parts)")));

    node.add(Html.p(code("Orchester: " + df.format(db.orchesters.table.size()))));
    node.add(Html.p(code("Intepreten: " + df.format(db.interprets.table.size()))));
}

From source file:ch.aonyx.broker.ib.api.data.historical.BarSizeUnit.java

public static final BarSizeUnit fromAbbreviation(final String abbreviation) {
    if (StringUtils.isBlank(abbreviation)) {
        return EMPTY;
    }//from  w ww .  j a v a  2  s  .co  m
    final String abbreviationUpperCase = abbreviation.toUpperCase();
    if (MAP.containsKey(abbreviationUpperCase)) {
        return MAP.get(abbreviationUpperCase);
    }
    return UNKNOWN;
}

From source file:ch.aonyx.broker.ib.api.order.TimeInForce.java

public static final TimeInForce fromAbbreviation(final String abbreviation) {
    if (StringUtils.isBlank(abbreviation)) {
        return EMPTY;
    }// www  . j  a  v  a2s . c o  m
    final String abbreviationUpperCase = abbreviation.toUpperCase();
    if (MAP.containsKey(abbreviationUpperCase)) {
        return MAP.get(abbreviationUpperCase);
    }
    return UNKNOWN;
}

From source file:me.ineson.demo.app.rest.RestConfig.java

/**
 * @param mediaTypes/*  w ww  .  java 2s.  c  o  m*/
 * @return
 */
public static boolean supportedMediaType(String mediaTypes) {
    if (StringUtils.isBlank(mediaTypes)) {
        return false;
    }

    return (mediaTypes.contains(MediaType.APPLICATION_JSON) || mediaTypes.contains(MediaType.APPLICATION_XML)
            || mediaTypes.contains(MediaType.TEXT_XML));
}

From source file:controllers.services.ServicesApp.java

/**
 * ?//w ww. j a  v  a  2  s.  c o  m
 */
@Transactional(readOnly = true)
public static Result index() {
    DynamicForm requestData = Form.form().bindFromRequest();
    ListOrderedMap cts = SkillTag.getCacheCategory();
    Integer page = StringUtils.isBlank(requestData.get("page")) ? 1 : new Integer(requestData.get("page"));
    Integer pageSize = StringUtils.isBlank(requestData.get("pageSize")) ? 10
            : new Integer(requestData.get("pageSize"));
    Long categoryId = StringUtils.isBlank(requestData.get("categoryId")) ? (Long) cts.asList().get(0)
            : new Long(requestData.get("categoryId"));
    String type = requestData.get("type") == null ? "html" : requestData.get("type");
    Page<ServiceListVO> returnPage = Service.queryServiceByPage(page, pageSize, categoryId);
    if (!type.equals("json")) {
        return ok(views.html.services.index.render(returnPage, cts, categoryId));
    }
    return ok(play.libs.Json.toJson(returnPage));
}