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:com.adaptris.core.services.exception.SimpleExceptionReport.java

String elementName() {
    return StringUtils.defaultIfBlank(getElementName(), "Exception");
}

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

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

    Resource parent = folderPathService.getResourceByPath(tid, path);
    if (parent == null) {
        writeError(ErrorMsg.NOT_FOUND, response);
        return;/*  ww w  .j a v a  2  s. co  m*/
    }

    List<Resource> list = resourceService.getResourceByTitle(tid, parent.getRid(), LynxConstants.TYPE_FILE,
            file.getOriginalFilename());
    if (list.size() > 0 && !IF_EXISTED_UPDATE.equals(ifExisted)) {
        writeError(ErrorMsg.EXISTED, response);
        return;
    }

    FileVersion fv = null;
    try {
        fv = resourceOperateService.upload(uid, super.getCurrentTid(), parent.getRid(),
                file.getOriginalFilename(), file.getSize(), file.getInputStream());
    } catch (NoEnoughSpaceException e) {
        writeError(ErrorMsg.NO_ENOUGH_SPACE, response);
        return;
    }

    Resource resource = resourceService.getResource(fv.getRid());
    resource.setPath(folderPathService.getPathString(resource.getRid()));
    JsonUtil.write(response, VoUtil.getResourceVo(resource));
}

From source file:ch.ralscha.extdirectspring.bean.ExtDirectFormPostResult.java

private void addErrors(Locale locale, MessageSource messageSource, BindingResult bindingResult) {
    if (bindingResult != null && bindingResult.hasFieldErrors()) {
        Map<String, String> errorMap = new HashMap<String, String>();
        for (ObjectError objectError : bindingResult.getAllErrors()) {
            FieldError fieldError = (FieldError) objectError;
            String message = null;
            for (String code : fieldError.getCodes()) {
                message = MessageUtil.getMessage(code, null, locale); // , new Object[] {(fieldError.getObjectName() +"." + fieldError.getField()), fieldError.getRejectedValue()}
                if (StringUtils.isNotBlank(message)) {
                    break;
                }//from w w w.  ja  v  a2 s  .c om
            }
            errorMap.put(fieldError.getField(),
                    StringUtils.defaultIfBlank(message, fieldError.getDefaultMessage()));
        }
        if (errorMap.isEmpty()) {
            addResultProperty("success", true);
        } else {
            addResultProperty("errors", errorMap);
            addResultProperty("success", false);
        }
    } else {
        setSuccess(true);
    }

    //        if (bindingResult != null && bindingResult.hasFieldErrors()) {
    //            Map<String, List<String>> errorMap = new HashMap<String, List<String>>();
    //            for (FieldError fieldError : bindingResult.getFieldErrors()) {
    //                String message = fieldError.getDefaultMessage();
    //                if (messageSource != null) {
    //                    Locale loc = (locale != null ? locale : Locale.getDefault());
    //                    message = messageSource.getMessage(fieldError.getCode(), fieldError.getArguments(), loc);
    //                }
    //                List<String> fieldErrors = errorMap.get(fieldError.getField());
    //
    //                if (fieldErrors == null) {
    //                    fieldErrors = new ArrayList<String>();
    //                    errorMap.put(fieldError.getField(), fieldErrors);
    //                }
    //
    //                fieldErrors.add(message);
    //            }
    //            if (errorMap.isEmpty()) {
    //                addResultProperty("success", true);
    //            } else {
    //                addResultProperty("errors", errorMap);
    //                addResultProperty("success", false);
    //            }
    //        } else {
    //            setSuccess(true);
    //        }
}

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

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

From source file:io.fabric8.elasticsearch.RequestRunner.java

public Response run(final String query, Headers headers) throws Exception {
    switch (StringUtils.defaultIfBlank(method, "get").toLowerCase()) {
    case "head":
        return executeHeadRequest(query, headers);
    case "put":
        return executePutRequest(query, body, headers);
    case "delete":
        return executeDeleteRequest(query, headers);
    case "post":
        return executePostRequest(query, body, headers);
    default:/*from   w w  w  .  j  a va2 s .  com*/
        return executeGetRequest(query, headers);
    }
}

From source file:elaborate.editor.solr.ElaborateSolrIndexer.java

public static SolrInputDocument getSolrInputDocument(ProjectEntry projectEntry, boolean forPublication,
        Collection<String> facetsToSplit) {
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField(ID, projectEntry.getId());
    doc.addField(NAME, projectEntry.getName());
    Project project = projectEntry.getProject();
    for (String field : project.getProjectEntryMetadataFieldnames()) {
        String facetName = SolrUtils.facetName(field);
        String value = projectEntry.getMetadataValue(field);
        doc.addField(facetName,//from w w  w .j av a  2  s  . c  o m
                StringUtils.defaultIfBlank(value, EMPTYVALUE_SYMBOL).replaceAll("\\r?\\n|\\r", "/"), 1.0f);
        if (forPublication) {
            // TODO: This is CNW/BoschDoc specific, refactoring needed
            handleCNWFacets(facetName, value, doc);
            if (facetsToSplit.contains(facetName)) {
                handleMultiValuedFields(facetName, value, doc);
            }
        }
    }
    Set<String> textLayersProcessed = Sets.newHashSet();
    for (Transcription transcription : projectEntry.getTranscriptions()) {
        String tBody = convert(transcription.getBody());
        String textLayer = SolrUtils.normalize(transcription.getTextLayer());
        if (textLayersProcessed.contains(textLayer)) {
            Log.error("duplicate textlayer {} for entry {}", textLayer, projectEntry.getId());
        } else {
            doc.addField(TEXTLAYER_PREFIX + textLayer, tBody);
            doc.addField(TEXTLAYERCS_PREFIX + textLayer, tBody);
            for (Annotation annotation : transcription.getAnnotations()) {
                String body = annotation.getBody();
                if (body != null) {
                    String aBody = convert(body);
                    doc.addField(ANNOTATION_PREFIX + textLayer, aBody);
                    doc.addField(ANNOTATIONCS_PREFIX + textLayer, aBody);
                }
            }
            textLayersProcessed.add(textLayer);
        }
    }
    if (!forPublication) {
        doc.addField(PUBLISHABLE, projectEntry.isPublishable(), 1.0f);
        doc.addField(PROJECT_ID, projectEntry.getProject().getId());
    }
    Log.info("doc={}", doc);
    return doc;
}

From source file:com.cloudbees.jenkins.plugins.awscredentials.AmazonWebServicesCredentialsBinding.java

/**
 *
 * @param accessKeyVariable if {@code null}, {@value DEFAULT_ACCESS_KEY_ID_VARIABLE_NAME} will be used.
 * @param secretKeyVariable if {@code null}, {@value DEFAULT_SECRET_ACCESS_KEY_VARIABLE_NAME} will be used.
 * @param credentialsId/*from   w ww  . ja v  a  2  s .c o  m*/
 */
@DataBoundConstructor
public AmazonWebServicesCredentialsBinding(@Nullable String accessKeyVariable,
        @Nullable String secretKeyVariable, String credentialsId) {
    super(credentialsId);
    this.accessKeyVariable = StringUtils.defaultIfBlank(accessKeyVariable, DEFAULT_ACCESS_KEY_ID_VARIABLE_NAME);
    this.secretKeyVariable = StringUtils.defaultIfBlank(secretKeyVariable,
            DEFAULT_SECRET_ACCESS_KEY_VARIABLE_NAME);
}

From source file:net.duckling.ddl.web.agent.csp.CspSharingController.java

@RequestMapping(method = RequestMethod.GET)
public void sharing(@RequestParam("path") String path, HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    String teamCode = request.getParameter("teamCode");
    String auth = request.getParameter("auth");

    String uid = AuthUtil.getAuthEmail(auth);
    if (StringUtils.isEmpty(uid)) {
        LOG.error("need permission. {uid:" + uid + ",path:" + path + "\"teamCode\":" + teamCode + "}");
        writeError(ErrorMsg.NEED_PERMISSION, request, response);
        return;//from w w  w  .j  a va 2 s  .  co m
    }
    Team team = getUserTeam(uid, teamCode);
    if (team == null) {
        LOG.error("need permission. {uid:" + uid + "path:" + path + "\"teamCode\":" + teamCode + "}");
        writeError(ErrorMsg.NEED_PERMISSION, request, response);
        return;
    }

    path = StringUtils.defaultIfBlank(path, PathName.DELIMITER);
    path = UrlCoder.decode(path);
    Resource r = folderPathService.getResourceByPath(team.getId(), path);
    if (r == null || r.getRid() == 0) {
        LOG.error("file not found. {path:" + path + ",\"teamCode\":" + teamCode + "}");
        writeError(ErrorMsg.NOT_FOUND, request, response);
        return;
    }

    ShareResource sr = shareResourceService.get(r.getRid());
    if (sr == null) {
        sr = createShareResource(r.getRid(), uid);
    } else {
        //         sr.setLastEditor(uid);
        //         sr.setLastEditTime(new Date());
        //         shareResourceService.update(sr);
    }
    sr.setTitle(r.getTitle());
    sr.setShareUrl(sr.generateShareUrl(urlGenerator));

    LOG.info("file shared successfully. {teamCode:" + teamCode + ",path:" + path + ",title:" + r.getTitle()
            + "}");
    JsonUtil.writeJSONP(request, response, VoUtil.getShareResourceVo(sr), null);
}

From source file:jenkins.branch.BranchEventCause.java

/**
 * {@inheritDoc}
 */
@Override
public String getShortDescription() {
    return StringUtils.defaultIfBlank(description, "Branch event");
}

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

@RequestMapping(method = RequestMethod.POST)
public void create(@RequestParam("teamCode") String teamCode, @RequestParam("displayName") String displayName,
        @RequestParam("description") String description,
        @RequestParam(value = "accessType", required = false) String accessType,
        @RequestParam(value = "autoTeamCode", required = false) Boolean autoTeamCode,
        @RequestParam(value = "type", required = false) String type, HttpServletRequest request,
        HttpServletResponse response) {/*from  w  w  w  . j  a  v a  2  s.  c o m*/
    String uid = getCurrentUid(request);
    accessType = StringUtils.defaultIfBlank(accessType, Team.ACCESS_PRIVATE);
    autoTeamCode = autoTeamCode == null ? false : autoTeamCode;
    teamCode = StringUtils.defaultString(teamCode).trim();

    LOG.info("create team start... {uid:" + uid + ",teamCode:" + teamCode + ",displayName:" + displayName
            + ",accessType:" + accessType + ",autoTeamCode:" + autoTeamCode + ",type:" + type + "}");

    //??
    if (!ClientValidator.validate(request)) {
        LOG.warn("client is not allowed. {teamCode:" + teamCode + ",type:" + type + ",host:"
                + ClientValidator.getRealIp(request) + ",pattern:" + ClientValidator.getClientIpPattern(request)
                + "}");

        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        JsonUtil.write(response, ErrorMsg.NEED_PERMISSION);
        return;
    }

    if (Team.CONFERENCE_TEAM.equals(type)) {
        //nothing
    } else {
        //
        type = Team.COMMON_TEAM;
    }

    if (autoTeamCode) {
        teamCode = tidyTeamCode(teamCode);
        if ("".equals(teamCode)) {
            teamCode = getRandomString(5);
        }
        teamCode = teamCodeIncrement(teamCode, 0);
    }
    if (!checkParams(teamCode, displayName, description, accessType, response)) {
        return;
    }

    Map<String, String> params = getParamsForCreate(uid, teamCode, displayName, description, accessType, type);
    int teamId = teamService.createAndStartTeam(uid, params);
    teamService.addTeamMembers(teamId, new String[] { uid }, new String[] { super.getCurrentUsername(request) },
            Team.AUTH_ADMIN);
    LOG.info("create team success. {uid:" + uid + ", tid:" + teamId + ", parmas:" + params + "}");

    response.setStatus(HttpServletResponse.SC_CREATED);
    JsonUtil.write(response, VoUtil.getTeamVo(teamService.getTeamByID(teamId)));
}