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:io.kamax.mxisd.backend.sql.SqlThreePidProvider.java

@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())));
                    }/*ww w. ja  va2s .c om*/
                    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);
    }
}

From source file:io.kamax.mxisd.config.ServerConfig.java

@PostConstruct
public void build() {
    log.info("--- Server config ---");

    if (StringUtils.isBlank(getName())) {
        setName(mxCfg.getDomain());/*from w w  w .j  a  v a2  s .c o m*/
        log.debug("server.name is empty, using matrix.domain");
    }

    if (StringUtils.isBlank(getPublicUrl())) {
        setPublicUrl("https://" + getName());
        log.debug("Public URL is empty, generating from name");
    } else {
        setPublicUrl(StringUtils.replace(getPublicUrl(), "%SERVER_NAME%", getName()));
    }

    try {
        new URL(getPublicUrl());
    } catch (MalformedURLException e) {
        log.warn("Public URL is not valid: {}",
                StringUtils.defaultIfBlank(e.getMessage(), "<no reason provided>"));
    }

    log.info("Name: {}", getName());
    log.info("Port: {}", getPort());
    log.info("Public URL: {}", getPublicUrl());
}

From source file:adalid.core.wrappers.ArtifactWrapper.java

public String getHyphenatedAlias() {
    String string = StringUtils.defaultIfBlank(_artifact.getAlias(), _artifact.getName());
    return StrUtils.getLowerCaseIdentifier(string, '-');
}

From source file:net.duckling.ddl.web.api.rest.ResourceController.java

@RequestMapping(value = "/resources", method = RequestMethod.GET)
@ResponseBody/*from   w  w  w  . j  a  v a 2  s  .c o  m*/
public void list(@RequestParam(value = "path", required = false) String path,
        @RequestParam(value = "begin", required = false) Integer begin,
        @RequestParam(value = "limit", required = false) Integer limit,
        @RequestParam(value = "includePage", required = false) Boolean includePage, HttpServletRequest request,
        HttpServletResponse response) {
    begin = begin == null || begin < 0 ? 0 : begin;
    limit = limit == null || limit <= 0 ? 10 : limit;
    path = StringUtils.defaultIfBlank(path, PathName.DELIMITER);
    int tid = getCurrentTid();
    //??DPagetrue?
    includePage = includePage == null ? false : includePage;

    Resource res = folderPathService.getResourceByPath(tid, path);
    if (res == null) {
        writeError(ErrorMsg.NOT_FOUND, response);
        return;
    }

    ResourceQuery rq = new ResourcePathQuery(res.getRid());
    rq.setTid(getCurrentTid());
    rq.setOffset(begin);
    rq.setSize(limit);
    if (!includePage) {
        rq.setFileType(LynxConstants.SRERCH_TYPE_NOPAGE);
    }
    PaginationBean<Resource> resources = resourceService.query(rq);
    //path
    folderPathService.setResourceListPath(resources.getData(), folderPathService.getPathString(res.getRid()));

    JsonUtil.write(response, resources, Resource.class, ResourceView.class);
}

From source file:net.duckling.ddl.web.api.rest.FolderEditController.java

@RequestMapping(method = RequestMethod.POST)
public void create(@RequestParam(value = "path", required = false) String path,
        @RequestParam("title") String title,
        @RequestParam(value = "ifExisted", required = false) String ifExisted, HttpServletRequest request,
        HttpServletResponse response) throws IOException {
    int tid = getCurrentTid();
    String uid = getCurrentUid(request);
    path = StringUtils.defaultIfBlank(path, PathName.DELIMITER);

    Resource parent = folderPathService.getResourceByPath(tid, path);
    if (parent == null) {
        writeError(ErrorMsg.NOT_FOUND, response);
        return;/* www . j a v  a2  s  . com*/
    }
    Resource result = null;

    List<Resource> list = resourceService.getResourceByTitle(tid, parent.getRid(), LynxConstants.TYPE_FOLDER,
            title, LynxConstants.STATUS_AVAILABLE);
    //?
    if (list.size() > 0) {
        if (IF_EXISTED_RETURN.equals(ifExisted)) {
            result = list.get(0);
        } else if (IF_EXISTED_AUTO.equals(ifExisted)) {
            result = createFolder(title, parent.getRid(), tid, uid);
        }
    } else {
        result = createFolder(title, parent.getRid(), tid, uid);
    }

    if (result == null) {
        writeError(ErrorMsg.EXISTED, response);
        return;
    }
    result.setPath(folderPathService.getPathString(result.getRid()));
    JsonUtil.write(response, VoUtil.getResourceVo(result));
}

From source file:jenkins.plugins.git.traits.RemoteNameSCMSourceTrait.java

/**
 * Stapler constructor.//from  w w w .  j ava  2  s . c o  m
 *
 * @param remoteName the remote name.
 */
@DataBoundConstructor
public RemoteNameSCMSourceTrait(@CheckForNull String remoteName) {
    this.remoteName = validate(StringUtils.defaultIfBlank(StringUtils.trimToEmpty(remoteName),
            AbstractGitSCMSource.DEFAULT_REMOTE_NAME));
}

From source file:net.di2e.ecdr.commons.query.QueryConfigurationImpl.java

@Override
public String getDefaultDateType() {
    return StringUtils.defaultIfBlank(defaultDateTypeCustom, defaultDateType);
}

From source file:com.openshift.internal.restclient.model.ReplicationController.java

@Override
public void setEnvironmentVariable(String containerName, String name, String value) {
    String defaultedContainerName = StringUtils.defaultIfBlank(containerName, "");
    ModelNode specContainers = get(SPEC_TEMPLATE_CONTAINERS);
    if (specContainers.isDefined()) { //should ALWAYS exist
        List<ModelNode> containers = specContainers.asList();
        if (!containers.isEmpty()) {
            ModelNode var = new ModelNode();
            set(var, NAME, name);
            set(var, VALUE, value);

            Optional<ModelNode> opt = containers.stream()
                    .filter(n -> defaultedContainerName.equals(asString(n, NAME))).findFirst();
            ModelNode node = opt.isPresent() ? opt.get() : containers.get(0);
            ModelNode envNode = get(node, ENV);

            envNode.add(var);

        }//from  w w w  .ja v a2  s.c  o m
    }
}

From source file:dk.dma.msinm.legacy.nm.LegacyNmImportService.java

/**
 * Imports the NtM template and returns the message if it was imported
 * @param template the NtM template//from   w  w  w .j a v  a  2  s  .  c o m
 * @param weekStartDate the start date of the week
 * @param txt a log of the import
 * @return the message actually imported
 */
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Message importMessage(Message template, Date weekStartDate, StringBuilder txt) {
    // Check if the message already exists
    Message message = messageService.findBySeriesIdentifier(template.getSeriesIdentifier().getMainType(),
            template.getSeriesIdentifier().getNumber(), template.getSeriesIdentifier().getYear(),
            template.getSeriesIdentifier().getAuthority());
    if (message != null) {
        log.warn("Message " + template.getSeriesIdentifier() + " already exists. Skipping");
        txt.append("Skipping existing NtM: " + template.getSeriesIdentifier() + "\n");
        return null;
    }

    // Fill out missing fields
    template.setValidFrom(weekStartDate);
    template.setPriority(Priority.NONE);
    template.setStatus(Status.PUBLISHED);

    // Some NM's do not have descriptions. Use the (html'ified) title instead
    template.getDescs().forEach(desc -> desc.setDescription(
            StringUtils.defaultIfBlank(desc.getDescription(), TextUtils.txt2html(desc.getTitle()))));

    try {
        // Make sure all charts are saved
        List<Chart> charts = findOrCreateCharts(template.getCharts());
        template.setCharts(charts);

        // Make sure the area, and parent areas, exists
        Area area = findOrCreateArea(template.getArea());
        template.setArea(area);

        // Save the message
        message = messageService.saveMessage(template);
        txt.append("Saved NtM: " + template.getSeriesIdentifier() + "\n");
    } catch (Exception e) {
        txt.append("Error saving NtM: " + template.getSeriesIdentifier() + "\n");
        log.error("Failed saving message " + message, e);
    }
    return message;
}

From source file:com.adaptris.core.mail.RawMailConsumer.java

@Override
protected List<AdaptrisMessage> createMessages(MimeMessage mime) throws MailException, CoreException {

    List<AdaptrisMessage> result = new ArrayList<AdaptrisMessage>();
    try {/*from w  w w .j av a2  s  .  c  o  m*/
        log.trace("Start Processing [{}]", mime.getMessageID());
        AdaptrisMessage msg = defaultIfNull(getMessageFactory()).newMessage();
        String uuid = msg.getUniqueId();
        try (OutputStream out = msg.getOutputStream()) {
            mime.writeTo(out);
        }
        if (useEmailMessageIdAsUniqueId()) {
            msg.setUniqueId(StringUtils.defaultIfBlank(mime.getMessageID(), uuid));
        }
        headerHandler().handle(mime, msg);
        result.add(msg);
    } catch (MessagingException | IOException e) {
        throw new MailException(e.getMessage(), e);
    }
    return result;
}