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

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

Introduction

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

Prototype

public static String defaultString(final String str) 

Source Link

Document

Returns either the passed in String, or if the String is null , an empty String ("").

 StringUtils.defaultString(null)  = "" StringUtils.defaultString("")    = "" StringUtils.defaultString("bat") = "bat" 

Usage

From source file:name.martingeisse.admin.navigation.component.NavigationMenuPanel.java

@Override
protected void onBeforeRender() {
    currentPagePath = StringUtils.defaultString(NavigationUtil.getNavigationPathForPage(getPage()));
    super.onBeforeRender();
}

From source file:com.navercorp.pinpoint.collector.dao.hbase.HbaseMapStatisticsCallerDao.java

@Override
public void update(String callerApplicationName, ServiceType callerServiceType, String callerAgentid,
        String calleeApplicationName, ServiceType calleeServiceType, String calleeHost, int elapsed,
        boolean isError) {
    if (callerApplicationName == null) {
        throw new NullPointerException("callerApplicationName must not be null");
    }/*from   ww w . j  a v  a 2s .  co  m*/
    if (calleeApplicationName == null) {
        throw new NullPointerException("calleeApplicationName must not be null");
    }

    if (logger.isDebugEnabled()) {
        logger.debug("[Caller] {} ({}) {} -> {} ({})[{}]", callerApplicationName, callerServiceType,
                callerAgentid, calleeApplicationName, calleeServiceType, calleeHost);
    }

    // there may be no endpoint in case of httpclient
    calleeHost = StringUtils.defaultString(calleeHost);

    // make row key. rowkey is me
    final long acceptedTime = acceptedTimeService.getAcceptedTime();
    final long rowTimeSlot = timeSlot.getTimeSlot(acceptedTime);
    final RowKey callerRowKey = new CallRowKey(callerApplicationName, callerServiceType.getCode(), rowTimeSlot);

    final short calleeSlotNumber = ApplicationMapStatisticsUtils.getSlotNumber(calleeServiceType, elapsed,
            isError);
    final ColumnName calleeColumnName = new CalleeColumnName(callerAgentid, calleeServiceType.getCode(),
            calleeApplicationName, calleeHost, calleeSlotNumber);
    if (useBulk) {
        TableName mapStatisticsCalleeTableName = getTableName();
        bulkIncrementer.increment(mapStatisticsCalleeTableName, callerRowKey, calleeColumnName);
    } else {
        final byte[] rowKey = getDistributedKey(callerRowKey.getRowKey());
        // column name is the name of caller app.
        byte[] columnName = calleeColumnName.getColumnName();
        increment(rowKey, columnName, 1L);
    }
}

From source file:com.sonicle.webtop.core.app.util.EmailNotification.java

public String write() throws IOException, TemplateException {
    HashMap<String, Object> data = new HashMap<>();
    data.put("notification", buildTplStrings());

    if (builder instanceof BecauseBuilder) {
        data.put("recipientEmail", StringUtils.defaultString(((BecauseBuilder) builder).recipientEmail));
    }/*from w w  w .  j a  v a2s. c  o  m*/

    return WT.buildTemplate("tpl/email/notification.html", data);
}

From source file:baggage.hypertoolkit.request.RequestParser.java

protected String optionalString(String key, Bag<String, String> bag, String defaultValue) {
    if (bag.containsKey(StringUtils.defaultString(key))) {
        return bag.get(key);
    } else {/*w  ww . j a  v  a2 s.c  om*/
        return defaultValue;
    }
}

From source file:io.wcm.handler.url.impl.Externalizer.java

/**
 * Externalizes an URL without applying Sling Mapping. Instead the servlet context path is added and sling namespace
 * mangling is applied manually.//w w w  . j ava  2 s . c  o m
 * Hostname and scheme are not added because they are added by the link handler depending on site URL configuration
 * and secure/non-secure mode. URLs that are already externalized remain untouched.
 * @param url Unexternalized URL (without scheme or hostname)
 * @param request Request
 * @return Exernalized URL without scheme or hostname, the path is URL-encoded if it contains special chars.
 */
public static String externalizeUrlWithoutMapping(String url, SlingHttpServletRequest request) {

    // apply externalization only path part
    String path = url;

    // split off query string or fragment that may be appended to the URL
    String urlRemainder = null;
    int urlRemainderPos = StringUtils.indexOfAny(path, '?', '#');
    if (urlRemainderPos >= 0) {
        urlRemainder = path.substring(urlRemainderPos);
        path = path.substring(0, urlRemainderPos);
    }

    // apply namespace mangling (e.g. replace jcr: with _jcr_)
    path = mangleNamespaces(path);

    // add webapp context path
    if (request != null) {
        path = StringUtils.defaultString(request.getContextPath()) + path; //NOPMD
    }

    // url-encode path
    path = Escape.urlEncode(path);
    path = StringUtils.replace(path, "+", "%20");
    // replace %2F back to / for better readability
    path = StringUtils.replace(path, "%2F", "/");

    // build full URL again
    return path + (urlRemainder != null ? urlRemainder : "");
}

From source file:dtu.ds.warnme.app.model.impl.User.java

@Override
public void merge(User user) {
    setUsername(StringUtils.defaultString(user.getUsername()));
    setPassword(StringUtils.defaultString(user.getPassword()));
    setEmail(StringUtils.defaultString(user.getEmail()));
    setRole(user.getRole());/*www  .  j a v  a2 s  . c  om*/
    setComment(StringUtils.defaultIfBlank(user.getComment(), null));
    setLocked(user.isLocked());
    setDeleted(user.isDeleted());
}

From source file:com.creditcloud.interestbearing.model.CreditCloudTAConfig.java

public Pair<String, String> firstFund() {
    if (registeredProducts == null || registeredProducts.isEmpty()) {
        return null;
    }/*  ww w  .  j ava2  s. c  om*/
    ProductFundMetadata p = registeredProducts.get(0).getProduct();
    if (p == null) {
        return null;
    }

    String broker = StringUtils.defaultString(p.getBroker());
    String fundId = StringUtils.defaultString(p.getFund_id());

    return ImmutablePair.of(broker, fundId);
}

From source file:com.funtl.framework.smoke.core.modules.act.service.ActModelService.java

/**
 * /*from w  w w .  j  a  va2s .  co m*/
 *
 * @throws UnsupportedEncodingException
 */
@Transactional(readOnly = false)
public Model create(String name, String key, String description, String category)
        throws UnsupportedEncodingException {

    ObjectNode editorNode = objectMapper.createObjectNode();
    editorNode.put("id", "canvas");
    editorNode.put("resourceId", "canvas");
    ObjectNode properties = objectMapper.createObjectNode();
    properties.put("process_author", "lusifer");
    editorNode.set("properties", properties);
    //      editorNode.put("properties", properties); //  - 2016-09-03 by Lusifer
    ObjectNode stencilset = objectMapper.createObjectNode();
    stencilset.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
    editorNode.set("stencilset", stencilset);
    //      editorNode.put("stencilset", stencilset); //  - 2016-09-03 by Lusifer

    Model modelData = repositoryService.newModel();
    description = StringUtils.defaultString(description);
    modelData.setKey(StringUtils.defaultString(key));
    modelData.setName(name);
    modelData.setCategory(category);
    modelData.setVersion(Integer.parseInt(
            String.valueOf(repositoryService.createModelQuery().modelKey(modelData.getKey()).count() + 1)));

    ObjectNode modelObjectNode = objectMapper.createObjectNode();
    modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, name);
    modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, modelData.getVersion());
    modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);
    modelData.setMetaInfo(modelObjectNode.toString());

    repositoryService.saveModel(modelData);
    repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));

    return modelData;
}

From source file:gr.forth.ics.isl.x3mlEditor.upload.MultipartUploadParser.java

private void parseFormFields(List<FileItem> items) {
    for (FileItem item : items) {
        if (item.isFormField()) {
            String key = item.getFieldName();
            String value = item.getString();
            if (StringUtils.isNotBlank(key)) {
                params.put(key.toLowerCase(), StringUtils.defaultString(value));
            }//from  w ww  .  j a  va  2 s . co m
        } else {
            files.add(item);
        }
    }
}

From source file:io.mapzone.controller.vm.http.ServiceAuthProvision.java

/**
 *
 *//*ww  w.  j a  va  2s.  co m*/
protected boolean checkAuthToken() {
    ProjectInstanceIdentifier pid = new ProjectInstanceIdentifier(request.get());

    // check param token; ignore parameter char case
    Optional<String> requestToken = requestParameter(REQUEST_PARAM_TOKEN);
    if (requestToken.isPresent()) {
        if (!isValidToken(requestToken.get(), pid)) {
            throw new HttpProvisionRuntimeException(401, "Given auth token is not valid for this project.");
        }
        return true;
    }

    // check path parts
    String path = StringUtils.defaultString(request.get().getPathInfo());
    for (String part : StringUtils.split(path, '/')) {
        if (isValidToken(part, pid)) {
            return true;
        }
    }
    return false;
}