Java Code Examples for org.apache.commons.lang.StringUtils.isBlank()

The following are Jave code examples for showing how to use isBlank() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: osc-core   File: VirtualizationConnectorDtoValidator.java   View Source Code Vote up 8 votes
public static void checkFieldFormat(VirtualizationConnectorDto dto) throws VmidcBrokerInvalidEntryException {
    ValidateUtil.checkForValidIpAddressFormat(dto.getProviderIP());

    if (dto.getType().isOpenstack() && dto.getProviderAttributes() != null) {
        String rabbitMqPort = dto.getProviderAttributes().get(ATTRIBUTE_KEY_RABBITMQ_PORT);
        if (!StringUtils.isNumeric(rabbitMqPort)) {
            throw new VmidcBrokerInvalidEntryException(
                    ATTRIBUTE_KEY_RABBITMQ_PORT + " expected to be an Integer. Value is: " + rabbitMqPort);
        }

        String rabbitMQIP = dto.getProviderAttributes().get(ATTRIBUTE_KEY_RABBITMQ_IP);
        if (!StringUtils.isBlank(rabbitMQIP)) {
            ValidateUtil.checkForValidIpAddressFormat(rabbitMQIP);
        }
    }
}
 
Example 2
Project: monarch   File: GemFireCacheImpl.java   View Source Code Vote up 6 votes
public static boolean isMisConfigured(Properties clusterProps, Properties serverProps,
    String key) {
  String clusterPropValue = clusterProps.getProperty(key);
  String serverPropValue = serverProps.getProperty(key);

  // if this server prop is not specified, this is always OK.
  if (StringUtils.isBlank(serverPropValue))
    return false;

  // server props is not blank, but cluster props is blank, NOT OK.
  if (StringUtils.isBlank(clusterPropValue))
    return true;

  // at this point check for eqality
  return !clusterPropValue.equals(serverPropValue);
}
 
Example 3
Project: Hydrograph   File: MouseHoverOnSchemaGridListener.java   View Source Code Vote up 6 votes
private String setToolTipForMixedSchemeGridRow(MixedSchemeGridRow mixedSchemeGridRow, String componentType){
	
	if(StringUtils.isBlank(mixedSchemeGridRow.getDelimiter())
			&& StringUtils.isBlank(mixedSchemeGridRow.getLength())){
		return Messages.LENGTH_OR_DELIMITER_MUST_NOT_BE_BLANK;
	}else if(StringUtils.isNotBlank(mixedSchemeGridRow.getLength()) && !(mixedSchemeGridRow.getLength().matches(REGULAR_EXPRESSION_FOR_NUMBER))){
		return Messages.LENGTH_MUST_BE_AN_INTEGER_VALUE;
	}else if(StringUtils.isNotBlank(mixedSchemeGridRow.getDelimiter()) 
			&& StringUtils.isNotBlank(mixedSchemeGridRow.getLength())){
		return Messages.ONLY_SPECIFY_LENGTH_OR_DELIMITER;
	}
	else if(StringUtils.isNotBlank(mixedSchemeGridRow.getLength()) && Integer.parseInt(mixedSchemeGridRow.getLength())==0){
		return Messages.LENGTH_SHOULD_NOT_BE_ZERO;
	}
	
	if(StringUtils.equalsIgnoreCase(mixedSchemeGridRow.getDataTypeValue(), JAVA_UTIL_DATE) 
			&& StringUtils.isBlank(mixedSchemeGridRow.getDateFormat())){
		return setToolTipForDateFormatIfBlank(mixedSchemeGridRow);
	}else if((StringUtils.equalsIgnoreCase(mixedSchemeGridRow.getDataTypeValue(), JAVA_MATH_BIG_DECIMAL))){
		return setToolTipForBigDecimal(mixedSchemeGridRow, componentType);			
	}
	
	return "";
}
 
Example 4
Project: datax   File: JarLoader.java   View Source Code Vote up 6 votes
private static void collectDirs(String path, List<String> collector) {
    if (null == path || StringUtils.isBlank(path)) {
        return;
    }

    File current = new File(path);
    if (!current.exists() || !current.isDirectory()) {
        return;
    }

    for (File child : current.listFiles()) {
        if (!child.isDirectory()) {
            continue;
        }

        collector.add(child.getAbsolutePath());
        collectDirs(child.getAbsolutePath(), collector);
    }
}
 
Example 5
Project: bloomfilter-center   File: FileUtil.java   View Source Code Vote up 6 votes
/**
 * getSimilarFile
 *
 * @param directory
 * @param prefix
 * @param asc
 * @return
 */
public static List<File> getSimilarFile(String directory, String prefix, final boolean asc) {
    if (StringUtils.isBlank(directory)) {
        return Lists.newArrayList();
    }
    File dir = new File(directory);
    if (!dir.exists() || !dir.isDirectory()) {
        return Lists.newArrayList();
    }
    boolean isFilter = StringUtils.isNotBlank(prefix);
    File[] files = dir.listFiles((d, name) -> {
        return isFilter ? name.startsWith(prefix) : true;
    });
    List<File> filelist = Arrays.asList(files);
    Collections.sort(filelist, (file1, file2) -> {
        long fm1 = ((file1 == null) ? 0 : file1.lastModified());
        long fm2 = ((file2 == null) ? 0 : file2.lastModified());
        if (fm1 == fm2) {
            return 0;
        }
        return asc ? ((fm1 > fm2) ? 1 : -1) : ((fm1 > fm2) ? -1 : 1);
    });
    return filelist;
}
 
Example 6
Project: rure   File: StringUtil.java   View Source Code Vote up 5 votes
/**
 * 首字母转大写
 * @param s
 * @return
 */
public static String toUpperCaseFirstOne(String s) {
    if (StringUtils.isBlank(s)) {
        return s;
    }
    if (Character.isUpperCase(s.charAt(0))) {
        return s;
    } else {
        return (new StringBuffer()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString();
    }
}
 
Example 7
Project: Spring-Boot-Server   File: AppUserFriendRestful.java   View Source Code Vote up 5 votes
/**
 * 获取新的好友列表
 * @return
 */
@RequestMapping(value = "/getNewFriendList")
@ResponseBody
public PageData getNewFriendList(@RequestBody PageData pd) throws Exception {
	if (StringUtils.isBlank(pd.getString("UI_ID"))) {
		return WebResult.requestFailed(10001, "参数缺失!", null);
	}
	else {
		List<PageData> res = appUserFriendMapper.getNewFriendList(pd);
		return WebResult.requestSuccess(res);
	}
}
 
Example 8
Project: Dragonfly   File: PieceSucServlet.java   View Source Code Vote up 5 votes
@Override
protected void doPost(HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException {
    try {
        Map<String, String> params = getSingleParameter(request);
        String taskId = params.get("taskId");
        String cid = params.get("cid");
        String dstCid = params.get("dstCid");
        String range = params.get("pieceRange");

        if (StringUtils.isBlank(taskId) || StringUtils.isBlank(cid)
            || StringUtils.isBlank(range)) {
            result(response, new ResultInfo(ResultCode.PARAM_ERROR,
                "some param is empty", null));
            return;
        }
        int pieceNum = RangeParseUtil.calculatePieceNum(range);
        ResultInfo resultInfo = null;
        if (pieceNum >= 0) {
            resultInfo = progressService.updateProgress(taskId, cid,
                dstCid, pieceNum, PeerPieceStatus.SUCCESS);
        } else {
            logger.error("do piece suc fail for cid:{} pieceNum:{}", cid,
                pieceNum);
        }
        if (resultInfo == null) {
            resultInfo = new ResultInfo(ResultCode.SYSTEM_ERROR);
        }
        result(response, resultInfo);
    } catch (Exception e) {
        result(response,
            new ResultInfo(ResultCode.SYSTEM_ERROR, e.getMessage(),
                null));
    }
}
 
Example 9
Project: Spring-Boot-Server   File: AppUserScanRestful.java   View Source Code Vote up 5 votes
/**
 * 用户浏览列表(专家)
 * @return
 */
@RequestMapping(value = "/getScanList")
@ResponseBody
public PageData getScanList(@RequestBody PageData pd) throws Exception {
	if (StringUtils.isBlank(pd.getString("UI_ID"))) {
		return WebResult.requestFailed(10001, "参数缺失!", null);
	}
	else {
		List<PageData> list = appUserScanMapper.getScanList(pd);
		return WebResult.requestSuccess(list);
	}
}
 
Example 10
Project: airsonic   File: PlayerService.java   View Source Code Vote up 5 votes
/**
 * Returns the player with the given ID.
 *
 * @param id The unique player ID.
 * @return The player with the given ID, or <code>null</code> if no such player exists.
 */
public Player getPlayerById(String id) {
    if (StringUtils.isBlank(id)) {
        return null;
    } else {
        return playerDao.getPlayerById(id);
    }
}
 
Example 11
Project: urule   File: NullAssertor.java   View Source Code Vote up 5 votes
public boolean eval(Object left, Object right,Datatype datatype) {
	if(left==null){
		return true;
	}else{
		return StringUtils.isBlank(left.toString());
	}
}
 
Example 12
Project: ymate-payment-v2   File: TradeCloseData.java   View Source Code Vote up 5 votes
public TradeCloseData(String outTradeNo, String tradeNo) {
    if (StringUtils.isBlank(outTradeNo) && StringUtils.isBlank(tradeNo)) {
        throw new NullArgumentException("outTradeNo or tradeNo");
    }
    this.outTradeNo = outTradeNo;
    this.tradeNo = tradeNo;
}
 
Example 13
Project: Spring-Boot-Server   File: AppUserSportRestful.java   View Source Code Vote up 5 votes
/**
 * 用户运动排行榜个人信息
 * @return
 */
@RequestMapping(value = "/step/ranking/self")
@ResponseBody
public PageData getUserSportStepRankingBySelf(@RequestBody PageData pd) throws Exception {
	if(StringUtils.isBlank(pd.getString("UI_ID"))){
		return WebResult.requestFailed(10001, "参数缺失!", null);
	}else{
		PageData accInfo = appUserSportMapper.getUserSportStepRankingBySelf(pd);
		return WebResult.requestSuccess(accInfo);
	}
}
 
Example 14
Project: lams   File: ForumUserDao.java   View Source Code Vote up 5 votes
private void buildNameSearch(StringBuilder queryText, String searchString) {
if (!StringUtils.isBlank(searchString)) {
    String[] tokens = searchString.trim().split("\\s+");
    for (String token : tokens) {
	String escToken = StringEscapeUtils.escapeSql(token);
	queryText.append(" AND (user.first_name LIKE '%").append(escToken)
		.append("%' OR user.last_name LIKE '%").append(escToken).append("%' OR user.login_name LIKE '%")
		.append(escToken).append("%')");
    }
}
   }
 
Example 15
Project: gitea-plugin   File: GiteaServer.java   View Source Code Vote up 5 votes
/**
 * @param displayName   Optional name to use to describe the end-point.
 * @param serverUrl     The URL of this Bitbucket Server
 * @param manageHooks   {@code true} if and only if Jenkins is supposed to auto-manage hooks for this end-point.
 * @param credentialsId The {@link StandardUsernamePasswordCredentials#getId()} of the credentials to use for
 *                      auto-management of hooks.
 */
@DataBoundConstructor
public GiteaServer(@CheckForNull String displayName, @NonNull String serverUrl, boolean manageHooks,
                   @CheckForNull String credentialsId) {
    this.manageHooks = manageHooks && StringUtils.isNotBlank(credentialsId);
    this.credentialsId = manageHooks ? credentialsId : null;
    this.serverUrl = GiteaServers.normalizeServerUrl(serverUrl);
    this.displayName = StringUtils.isBlank(displayName)
            ? SCMName.fromUrl(this.serverUrl, COMMON_PREFIX_HOSTNAMES)
            : displayName;
}
 
Example 16
Project: lambo   File: UpmsUserController.java   View Source Code Vote up 5 votes
@ApiOperation(value = "用户列表")
@RequiresPermissions("upms:user:read")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public Object list(
        @RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
        @RequestParam(required = false, defaultValue = "10", value = "limit") int limit,
        @RequestParam(required = false, defaultValue = "", value = "search") String search,
        @RequestParam(required = false, value = "sort") String sort,
        @RequestParam(required = false, value = "order") String order) {
    UpmsUserExample upmsUserExample = new UpmsUserExample();
    if (!StringUtils.isBlank(sort) && !StringUtils.isBlank(order)) {
        upmsUserExample.setOrderByClause(sort + " " + order);
    }
    if (StringUtils.isNotBlank(search)) {
        upmsUserExample.or()
                .andRealnameLike("%" + search + "%");
        upmsUserExample.or()
                .andUsernameLike("%" + search + "%");
    }
    List<UpmsUser> rows = upmsUserService.selectByExampleForOffsetPage(upmsUserExample, offset, limit);
    long total = upmsUserService.countByExample(upmsUserExample);
    Map<String, Object> result = new HashMap<>();
    result.put("rows", rows);
    result.put("total", total);
    return result;
}
 
Example 17
Project: -Spring-SpringMVC-Mybatis-   File: QaController.java   View Source Code Vote up 4 votes
/**
 * 首页
 * @param page
 * @param sort
 * @param order
 * @param request
 * @param model
 * @return
 */
@RequestMapping(value = "", method = RequestMethod.GET)
public String index(@RequestParam(required = false, defaultValue = "1", value = "page") int page,
                    @RequestParam(required = false, defaultValue = "orders", value = "sort") String sort,
                    @RequestParam(required = false, defaultValue = "desc", value = "order") String order,
                    HttpServletRequest request,
                    Model model) {
    // 系统id
    CmsSystemExample cmsSystemExample = new CmsSystemExample();
    cmsSystemExample.createCriteria()
            .andCodeEqualTo(CODE);
    CmsSystem system = cmsSystemService.selectFirstByExample(cmsSystemExample);
    model.addAttribute("system", system);
    // 该系统类目
    CmsCategoryExample cmsCategoryExample = new CmsCategoryExample();
    cmsCategoryExample.createCriteria()
            .andSystemIdEqualTo(system.getSystemId());
    cmsCategoryExample.setOrderByClause("orders asc");
    List<CmsCategory> categories = cmsCategoryService.selectByExample(cmsCategoryExample);
    model.addAttribute("categories", categories);
    // 该系统标签
    CmsTagExample cmsTagExample = new CmsTagExample();
    cmsTagExample.createCriteria()
            .andSystemIdEqualTo(system.getSystemId());
    cmsTagExample.setOrderByClause("orders asc");
    List<CmsTag> tags = cmsTagService.selectByExample(cmsTagExample);
    model.addAttribute("tags", tags);
    // 该系统文章列表
    int rows = 10;
    CmsArticleExample cmsArticleExample = new CmsArticleExample();
    cmsArticleExample.createCriteria()
            .andStatusEqualTo((byte) 1)
            .andSystemIdEqualTo(system.getSystemId());
    if (!StringUtils.isBlank(sort) && !StringUtils.isBlank(order)) {
        cmsArticleExample.setOrderByClause(sort + " " + order);
    }
    List<CmsArticle> articles = cmsArticleService.selectByExampleForOffsetPage(cmsArticleExample, (page - 1) * rows, rows);
    model.addAttribute("articles", articles);
    // 文章总数
    long total = cmsArticleService.countByExample(cmsArticleExample);
    // 分页
    Paginator paginator = new Paginator(total, page, rows, request);
    model.addAttribute("paginator", paginator);
    return thymeleaf("/qa/index");
}
 
Example 18
Project: pds   File: SysMenuController.java   View Source Code Vote up 4 votes
/**
 * 验证参数是否正确
 */
private void verifyForm(SysMenuEntity menu) {
    if (StringUtils.isBlank(menu.getName())) {
        throw new RRException("菜单名称不能为空");
    }

    if (menu.getParentId() == null) {
        throw new RRException("上级菜单不能为空");
    }

    //菜单
    if (menu.getType() == Constant.MenuType.MENU.getValue()) {
        if (StringUtils.isBlank(menu.getUrl())) {
            throw new RRException("菜单URL不能为空");
        }
    }

    //上级菜单类型
    int parentType = Constant.MenuType.CATALOG.getValue();
    if (menu.getParentId() != 0) {
        SysMenuEntity parentMenu = sysMenuService.queryObject(menu.getParentId());
        parentType = parentMenu.getType();
    }

    //目录、菜单
    if (menu.getType() == Constant.MenuType.CATALOG.getValue() ||
            menu.getType() == Constant.MenuType.MENU.getValue()) {
        if (parentType != Constant.MenuType.CATALOG.getValue()) {
            throw new RRException("上级菜单只能为目录类型");
        }
        return;
    }

    //按钮
    if (menu.getType() == Constant.MenuType.BUTTON.getValue()) {
        if (parentType != Constant.MenuType.MENU.getValue()) {
            throw new RRException("上级菜单只能为菜单类型");
        }
        return;
    }
}
 
Example 19
Project: kaltura-ce-sakai-extension   File: MediaService.java   View Source Code Vote up 4 votes
/**
 * Adds an item to a collection (and also to the site library if not already part of it)
 * 
 * @param collectionId the collection id (should be playlist id)
 * @param locationId the location (i.e. the site library id - e.g. /site/3674fc9f-8d5c-4ede-86f0-2f7432edb0db)
 * @param kalturaId the id for the kaltura item (not the media id) (e.g. 0_5soq7x2r)
 * @param position the position to add the item,
 * <= 0 indicates to put the item at the end,
 * any other number will place the item at that location in the collection
 * @return the newly added item
 * @throws SecurityException if the user is not allowed to add to this collection
 * @throws IllegalArgumentException if the params are blank or invalid and do not exist
 * @throws IllegalStateException if the item is already in the collection
 */
public MediaItem addKalturaItemToCollection(String collectionId, String locationId, String kalturaId, int position) {
    if (StringUtils.isBlank(kalturaId)) {
        throw new IllegalArgumentException("kalturaId must be set");
    }
    if (StringUtils.isBlank(collectionId) ) {
        throw new IllegalArgumentException("collectionId must be set");
    }
    if (log.isDebugEnabled()) log.debug("addKalturaItemToCollection(collectionId="+collectionId+", locationId="+locationId+", kalturaId="+kalturaId+", position="+position+")");
    MediaCollection mc = getCollection(collectionId, 0, -1); // include all items
    if (mc == null) {
        throw new IllegalArgumentException("MediaCollection (id="+collectionId+") could not be found");
    }
    locationId = mc.getLocationId();
    if (StringUtils.isBlank(locationId)) {
        throw new IllegalArgumentException("locationId is not set while trying to add kaltura item ("+kalturaId+") to collection ("+collectionId+")");
    }
    // Try to add this to the library (won't do anything if it already exists in the library)
    String mediaId;
    try {
        mediaId = addKalturaItemToLibrary(locationId, kalturaId);
    } catch (Exception e) {
        // The user might not have permission to add the item to the site library
        log.warn("Kaltura user ("+external.getCurrentUserName()+") cannot add item ("+kalturaId+") to library ("+locationId+") while adding it to the collection ("+collectionId+")");
        mediaId = kalturaId;
    }

    // add the item to the collection - handles security checks

    // do perm checks and get the collection
    if (! mc.isAddItems()) { // check the add items flag
        // also, admin can always add items, otherwise fail
        checkPermsOrException(
                new String[] {ExternalLogic.PERM_ADMIN, ExternalLogic.PERM_MANAGER}, 
                mc.getLocationId());
    }
    MediaItem item = mc.getItemById(mediaId); // exists already if not null
    if (item != null) {
        // TODO do we really want to throw exception if this is already in the collection
        throw new IllegalStateException("item ("+mediaId+") already exists in the collection");
    } else {
        KalturaMediaEntry entry = kalturaAPIService.getKalturaItem(mediaId);
        item = new MediaItem(mc, entry, null);
        // force the creator of the new item to the current user id (maintain the owner id)
        item.setCreatorId(entry.creatorId);
        String currentUsername = external.getCurrentUserName();
        if (currentUsername != null) {
            item.setOwnerId(currentUsername);
        } else {
            item.setOwnerId(item.getCreatorId());
        }
        // update the entry's metadata, if necessary
        updateEntryMetadataIfNeeded(item, KalturaAPIService.METADATA_PERMISSIONS_CONTAINER_TYPE_PLAYLIST, collectionId, locationId, null, kalturaAPIService, external);
        // assume the mediaId is the kaltura entry id and the collectionId is the playlist id
        KalturaPlaylist playlist = kalturaAPIService.updatePlaylistEntryOrdering(mc.getId(), mediaId, position);
        int playlistLength = StringUtils.split(playlist.playlistContent, ',').length;
        if (position <= 0 || position > playlistLength) {
            position = playlistLength - 1;
        }
        item.setPosition(position);
        log.info("User ("+external.getCurrentUserId()+") added media item ("+mediaId+") to collection: " + mc + " at position: " + position);
    }
    if (log.isDebugEnabled()) log.debug("addKalturaItemToCollection : COMPLETED");
    return item;
}
 
Example 20
Project: va-vedem-api   File: EmailService.java   View Source Code Vote up 4 votes
public void send(EmailModel model) throws VaVedemEmailException {
    Email from = new Email(model.getFrom());
    String subject = model.getSubject();
    Email to = new Email(model.getTo());
    Content content = new Content("text/plain", model.getContent());
    Mail mail = new Mail(from, subject, to, content);

    Map<String, String> fileNames = listFormulare(formulareDir);
    final String formular = model.getFormular();
    final String fileName = fileNames.get(formular);

    if (StringUtils.isBlank(fileName) && StringUtils.isNotBlank(formular)) {
        logger.error("[VaVedem] :  formularul : " + formular + " nu a fost gasit pe disk. ");
        throw new VaVedemEmailException("Eroare la trimiterea emailului.");
    }

    String base64 = null;
    try {
        base64 = DatatypeConverter.printBase64Binary(Files.readAllBytes(
                Paths.get(fileName)));
    } catch (IOException e) {
        logger.error("[VaVedem] Eroare la conversia in base64 a fisierului: " + fileName);
        throw new VaVedemEmailException("Eroare la trimiterea emailului.");
    }

    Attachments ats = new Attachments();
    ats.setContent(base64);
    ats.setFilename(formular);

    mail.addAttachments(ats);

    SendGrid sg = new SendGrid(sendGridApiKey);
    System.out.println("LOG [VaVedem] :  send grid api-key: " + sendGridApiKey);
    Request request = new Request();
    try {
        request.setMethod(Method.POST);
        request.setEndpoint("mail/send");
        request.setBody(mail.build());
        Response response = sg.api(request);
    } catch (IOException ex) {
        ex.printStackTrace();
        throw new VaVedemEmailException("Eroare la trimiterea emailului.");
    }
}