Java Code Examples for org.apache.commons.lang3.StringUtils#truncate()

The following examples show how to use org.apache.commons.lang3.StringUtils#truncate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InternalDatabaseMessageTransporter.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IStatus send(TransientMessage message) {

	IMessage idbMessage = CoreModelServiceHolder.get().create(IMessage.class);
	String sender = StringUtils.truncate(message.getSender(), 25);
	idbMessage.setSender(sender);
	idbMessage.setMessageText(message.getMessageText());
	idbMessage.setMessageCodes(message.getMessageCodes());
	idbMessage.setMessagePriority(message.getMessagePriority());
	idbMessage.setCreateDateTime(message.getCreateDateTime());
	idbMessage.setSenderAcceptsAnswer(message.isSenderAcceptsAnswer());

	boolean save = CoreModelServiceHolder.get().save(idbMessage);
	if (save) {
		return ObjectStatus.OK_STATUS(idbMessage.getId(), null);
	}

	return ObjectStatus.ERROR_STATUS("Could not save message", null);
}
 
Example 2
Source File: Post.java    From scoold with Apache License 2.0 5 votes vote down vote up
public static String getTagString(String tag) {
	if (StringUtils.isBlank(tag)) {
		return "";
	}
	String s = tag.replaceAll("[\\p{S}\\p{P}\\p{C}&&[^+\\.]]", " ").replaceAll("\\p{Z}+", " ").trim();
	return StringUtils.truncate(Utils.noSpaces(s, "-"), 35);
}
 
Example 3
Source File: StorePlayerStringResultTransaction.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
public StorePlayerStringResultTransaction(DataProvider<String> provider, Parameters parameters, String value) {
    this.pluginName = provider.getProviderInformation().getPluginName();
    this.providerName = provider.getProviderInformation().getName();
    this.serverUUID = parameters.getServerUUID();
    this.playerUUID = parameters.getPlayerUUID();
    this.value = StringUtils.truncate(value, 50);
}
 
Example 4
Source File: StorePlayerGroupsResultTransaction.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void performOperations() {
    execute(deleteOldValues());
    for (String group : value) {
        String groupName = StringUtils.truncate(group, 50);
        execute(insertGroup(groupName));
    }
}
 
Example 5
Source File: AlertMessage.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public byte[] getAlertMessage(String msg, final AlertMessage.AlertCategory category, final AlertMessage.CustomIcon icon, final String title) {
    byte[] messageBytes = new byte[1];
    byte[] titleBytes = new byte[1];
    if (msg.isEmpty())
        msg = title;
    String message = "\0" + StringUtils.truncate(msg, 128) + "\0";
    String titleString = StringUtils.truncate(title, 18) + "\0";
    try {
        messageBytes = message.getBytes("UTF-8");
        titleBytes = titleString.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        //
    }
    int len = 0;
    if (msg.length() > 0)
        len += messageBytes.length;
    if (title.length() > 0)
        len += titleBytes.length;

    if (category == AlertMessage.AlertCategory.CustomHuami) {
        init(3 + len);
    } else {
        init(2 + len);
    }
    putData(category.getValue()); //alertCategory
    putData((byte) 0x01); //number of alerts
    if (category == AlertMessage.AlertCategory.CustomHuami) {
        putData(fromUint8(icon.getValue()));
    }
    if (msg.length() > 0)
        putData(messageBytes);

    if (title.length() > 0)
        putData(titleBytes);
    return getBytes();
}
 
Example 6
Source File: AlertMessage.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public byte[] getAlertMessage(String msg, final AlertMessage.AlertCategory category, final AlertMessage.CustomIcon icon, final String title) {
    byte[] messageBytes = new byte[1];
    byte[] titleBytes = new byte[1];
    if (msg.isEmpty())
        msg = title;
    String message = "\0" + StringUtils.truncate(msg, 128) + "\0";
    String titleString = StringUtils.truncate(title, 18) + "\0";
    try {
        messageBytes = message.getBytes("UTF-8");
        titleBytes = titleString.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        //
    }
    int len = 0;
    if (msg.length() > 0)
        len += messageBytes.length;
    if (title.length() > 0)
        len += titleBytes.length;

    if (category == AlertMessage.AlertCategory.CustomHuami) {
        init(3 + len);
    } else {
        init(2 + len);
    }
    putData(category.getValue()); //alertCategory
    putData((byte) 0x01); //number of alerts
    if (category == AlertMessage.AlertCategory.CustomHuami) {
        putData(fromUint8(icon.getValue()));
    }
    if (msg.length() > 0)
        putData(messageBytes);

    if (title.length() > 0)
        putData(titleBytes);
    return getBytes();
}
 
Example 7
Source File: ArticleService.java    From jakduk-api with MIT License 5 votes vote down vote up
/**
    * 자유게시판 글쓰기
 *
    * @param subject 글 제목
    * @param content 글 내용
    * @param categoryCode 글 말머리 Code
    * @param linkedGallery 사진 연동 여부
    */
public Article insertArticle(CommonWriter writer, Constants.BOARD_TYPE board, String subject, String content, String categoryCode,
							 Boolean linkedGallery) {

	if (BoardCategoryGenerator.notExistCategory(board, categoryCode))
		throw new ServiceException(ServiceError.NOT_FOUND_CATEGORY);

	// shortContent 만듦
	String stripHtmlContent = StringUtils.defaultIfBlank(JakdukUtils.stripHtmlTag(content), StringUtils.EMPTY);
	String shortContent = StringUtils.truncate(stripHtmlContent, Constants.ARTICLE_SHORT_CONTENT_LENGTH);

	ObjectId objectId = new ObjectId();

	Article article = new Article();
	article.setWriter(writer);
	article.setBoard(board.name());
	article.setCategory(Constants.BOARD_TYPE.FREE.equals(board) ? null : categoryCode);
	article.setSubject(subject);
	article.setContent(content);
	article.setShortContent(shortContent);
	article.setViews(0);
	article.setSeq(commonService.getNextSequence(Constants.SEQ_BOARD));
	article.setLogs(this.initBoardLogs(objectId, Constants.ARTICLE_LOG_TYPE.CREATE.name(), writer));
	article.setLastUpdated(LocalDateTime.ofInstant(objectId.getDate().toInstant(), ZoneId.systemDefault()));
	article.setLinkedGallery(linkedGallery);

	articleRepository.save(article);

	log.info("new post created. post seq={}, subject={}", article.getSeq(), article.getSubject());

	return article;
}
 
Example 8
Source File: Table.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
private Factory column(int indx, String columnName, Icon icon) {
    building.columns[indx] = StringUtils.truncate(columnName, 50);
    building.icons[indx] = icon != null ? Icon.called(icon.getName()).of(icon.getFamily()).build() : Icon.called("question").build();
    return this;
}
 
Example 9
Source File: ProviderInformation.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
public String getPluginName() {
    return StringUtils.truncate(pluginName, 50);
}
 
Example 10
Source File: ProviderInformation.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
private String getTruncatedConditionName() {
    return StringUtils.truncate(condition.value(), 50);
}
 
Example 11
Source File: TabInformation.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
public String getTabName() {
    return StringUtils.truncate(tabName, 50);
}
 
Example 12
Source File: StoreServerStringResultTransaction.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
public StoreServerStringResultTransaction(DataProvider<String> provider, Parameters parameters, String value) {
    this.pluginName = provider.getProviderInformation().getPluginName();
    this.providerName = provider.getProviderInformation().getName();
    this.serverUUID = parameters.getServerUUID();
    this.value = StringUtils.truncate(value, 50);
}
 
Example 13
Source File: ExtensionDescriptive.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
public String getName() {
    return StringUtils.truncate(name, 50);
}
 
Example 14
Source File: ExtensionDescriptive.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
public String getText() {
    return StringUtils.truncate(text, 50);
}
 
Example 15
Source File: ArticleService.java    From jakduk-api with MIT License 4 votes vote down vote up
/**
 * 자유게시판 글 고치기
 *
 * @param board 게시판
 * @param seq 글 seq
 * @param subject 글 제목
 * @param content 글 내용
 * @param categoryCode 글 말머리 Code
 * @param linkedGallery 사진 연동 여부
 */
public Article updateArticle(CommonWriter writer, Constants.BOARD_TYPE board, Integer seq, String subject, String content, String categoryCode,
							 Boolean linkedGallery) {

	Article article = articleRepository.findOneByBoardAndSeq(board.name(), seq)
			.orElseThrow(() -> new ServiceException(ServiceError.NOT_FOUND_ARTICLE));

	if (! article.getWriter().getUserId().equals(writer.getUserId()))
		throw new ServiceException(ServiceError.FORBIDDEN);

	if (BoardCategoryGenerator.notExistCategory(board, categoryCode))
		throw new ServiceException(ServiceError.NOT_FOUND_CATEGORY);

	// shortContent 만듦
	String stripHtmlContent = StringUtils.defaultIfBlank(JakdukUtils.stripHtmlTag(content), StringUtils.EMPTY);
	String shortContent = StringUtils.truncate(stripHtmlContent, Constants.ARTICLE_SHORT_CONTENT_LENGTH);

	article.setSubject(subject);
	article.setContent(content);
	article.setCategory(Constants.BOARD_TYPE.FREE.equals(board) ? null : categoryCode);
	article.setShortContent(shortContent);
	article.setLinkedGallery(linkedGallery);

	// boardHistory
	List<BoardLog> logs = article.getLogs();

	if (CollectionUtils.isEmpty(logs))
		logs = new ArrayList<>();

	ObjectId logId = new ObjectId();
	logs.add(new BoardLog(logId.toString(), Constants.ARTICLE_LOG_TYPE.EDIT.name(), new SimpleWriter(writer.getUserId(), writer.getUsername())));
	article.setLogs(logs);

	// lastUpdated
	article.setLastUpdated(LocalDateTime.ofInstant(logId.getDate().toInstant(), ZoneId.systemDefault()));

	articleRepository.save(article);

	log.info("post was edited. post seq={}, subject={}", article.getSeq(), article.getSubject());

	return article;
}