下面列出了org.apache.commons.lang3.StringUtils#abbreviate ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public String getDigest(final ResponseData responseData, final String content, final Map<String, Object> dataMap, final int maxWidth) {
if (content == null) {
return StringUtil.EMPTY; // empty
}
String subContent;
if (content.length() < maxWidth * 2) {
subContent = content;
} else {
subContent = content.substring(0, maxWidth * 2);
}
final int[] spaceChars = getSpaceChars();
try (final Reader reader = new StringReader(subContent)) {
final String originalStr = TextUtil.normalizeText(reader).initialCapacity(content.length()).spaceChars(spaceChars).execute();
return StringUtils.abbreviate(originalStr, maxWidth);
} catch (final IOException e) {
return StringUtil.EMPTY; // empty
}
}
public MissingEndTagException(
String endTag,
String startDefintion,
int lineNumber,
int startPosition
) {
super(
startDefintion,
"Missing end tag: " +
endTag +
" for tag defined as: " +
StringUtils.abbreviate(startDefintion, 255),
lineNumber,
startPosition
);
this.endTag = endTag;
this.startDefinition = startDefintion;
}
private String createTitle(String provider, LinkableItem topic, LinkableItem subTopic, ComponentItem arbitraryItem) {
StringBuilder title = new StringBuilder();
title.append("Alert - Provider: ");
title.append(provider);
title.append(createTitlePartStringPrefixedWithComma(topic));
if (null != subTopic) {
title.append(createTitlePartStringPrefixedWithComma(subTopic));
}
if (null != arbitraryItem) {
title.append(createTitlePartStringPrefixedWithComma(arbitraryItem.getComponent()));
arbitraryItem
.getSubComponent()
.ifPresent(linkableItem -> title.append(createTitlePartStringPrefixedWithComma(linkableItem)));
if (arbitraryItem.collapseOnCategory()) {
title.append(", ");
title.append(arbitraryItem.getCategory());
} else {
title.append(createTitlePartStringPrefixedWithComma(arbitraryItem.getCategoryItem()));
}
}
return StringUtils.abbreviate(title.toString(), TITLE_SIZE_LIMIT);
}
@Override
protected void autoFillNameTextField() {
if (useCustomAccountNameToggleButton != null && !useCustomAccountNameToggleButton.isSelected()) {
TradeCurrency singleTradeCurrency = this.paymentAccount.getSingleTradeCurrency();
String currency = singleTradeCurrency != null ? singleTradeCurrency.getCode() : null;
if (currency != null) {
String iban = ibanInputTextField.getText();
if (iban.length() > 9)
iban = StringUtils.abbreviate(iban, 9);
String method = Res.get(paymentAccount.getPaymentMethod().getId());
CountryBasedPaymentAccount countryBasedPaymentAccount = (CountryBasedPaymentAccount) this.paymentAccount;
String country = countryBasedPaymentAccount.getCountry() != null ?
countryBasedPaymentAccount.getCountry().code : null;
if (country != null)
accountNameTextField.setText(method.concat(" (").concat(currency).concat("/").concat(country)
.concat("): ").concat(iban));
}
}
}
@Override
public void doContentSection() {
String deviceAddress = getArguments().getString(MODEL_ADDR, "");
ModelSource<DeviceModel> m = DeviceModelProvider.instance().getModel(deviceAddress);
m.addModelListener(Listeners.runOnUiThread(new Listener<ModelEvent>() {
public void onEvent(ModelEvent e) {
if (e instanceof ModelAddedEvent) {
// model is loaded
}
}
}));
m.load();
if (m.get() != null) {
deviceModel = m.get();
}
capabilityUtils = new CapabilityUtils(deviceModel);
getZoneNames();
stationPicker = (NumberPicker) contentView.findViewById(R.id.station_picker);
stationPicker.setMinValue(1);
stationPicker.setValue(1);
stationPicker.setMaxValue(zoneNameArr.length);
for(int i = 0; i < zoneNameArr.length; i++){
zoneNameArrTrunk[i]=StringUtils.abbreviate(zoneNameArr[i],20);
}
stationPicker.setDisplayedValues(zoneNameArrTrunk);
updateTimeSelector();
zoneSelection = (Version1TextView) contentView.findViewById(R.id.zone_selected);
durationSelection = (Version1TextView) contentView.findViewById(R.id.duration_selected);
}
@Override
public Object generateCell(com.vaadin.v7.ui.Table source, Object itemId, Object columnId) {
Property property = source.getItem(itemId).getItemProperty(columnId);
Object value = property.getValue();
if (value == null) {
return null;
}
String stringValue = value.toString();
if (columnId instanceof MetaPropertyPath) {
MetaProperty metaProperty = ((MetaPropertyPath) columnId).getMetaProperty();
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
stringValue = dynamicAttributesTools.getDynamicAttributeValueAsString(metaProperty, value);
}
}
String cellValue = stringValue;
boolean isMultiLineCell = StringUtils.contains(stringValue, "\n");
if (isMultiLineCell) {
cellValue = StringUtils.replaceChars(cellValue, '\n', ' ');
}
int maxTextLength = column.getMaxTextLength();
if (stringValue.length() > maxTextLength + MAX_TEXT_LENGTH_GAP || isMultiLineCell) {
return StringUtils.abbreviate(cellValue, maxTextLength);
} else {
return cellValue;
}
}
/**
* If string length is more than 500 characters cut it and add "..." in the end.
*
* @param string recipient type letter
* @return cut string
*/
public static String cutRecipientDescription(String string){
try {
return StringUtils.abbreviate(string, MAX_DESCRIPTION_LENGTH);
} catch (IllegalArgumentException e) {
logger.error("RecipientUtils.cutRecipientDescription: " + e, e);
return string;
}
}
@SuppressWarnings("rawtypes")
public void execute(Environment env, Map params, TemplateModel[] loopVars,
TemplateDirectiveBody body) throws TemplateException, IOException {
DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_28);
// 获取页面的参数
String content = params.get("content").toString();
Integer num = Integer.parseInt(params.get("num").toString());
content = Jsoup.clean(content, Whitelist.none());
content = StringUtils.abbreviate(content, num);
env.setVariable("info_content", builder.build().wrap(content));
body.render(env.getOut());
}
@Override
protected void autoFillNameTextField() {
if (useCustomAccountNameToggleButton != null && !useCustomAccountNameToggleButton.isSelected()) {
String currency = paymentAccount.getSingleTradeCurrency() != null ? paymentAccount.getSingleTradeCurrency().getCode() : "";
if (currency != null) {
String address = addressInputTextField.getText();
address = StringUtils.abbreviate(address, 9);
accountNameTextField.setText(currency.concat(": ").concat(address));
}
}
}
public static String abbreviate(String message) {
final int default_limit = 2048;
return StringUtils.abbreviate(message, default_limit);
}
public String getAbbreviatedSectionTitle() {
return StringUtils.abbreviate(sectionTitle, 15);
}
@Override
public void setExceptionMessage(String exceptionMessage) {
this.exceptionMessage = StringUtils.abbreviate(exceptionMessage, JobInfo.MAX_EXCEPTION_MESSAGE_LENGTH);
}
protected String getAbbreviatedMeetingTitle(){
return StringUtils.abbreviate(meeting.getTitle(), 30);
}
public void setFilename(String filename) {
this.filename = StringUtils.abbreviate(filename, 255);
}
public void setExceptionMessage(String exceptionMessage) {
this.exceptionMessage = StringUtils.abbreviate(exceptionMessage, MAX_EXCEPTION_MESSAGE_LENGTH);
}
public String getShortDescription() {
return StringUtils.abbreviate(getDescription(), 100);
}
protected String getAbbreviatedMeetingTitle(){
return StringUtils.abbreviate(meeting.getTitle(), 30);
}
private ProviderProjectEntity convertToProjectEntity(Long providerConfigId, ProviderProject providerProject) {
String trimmedDescription = StringUtils.abbreviate(providerProject.getDescription(), DefaultProviderDataAccessor.MAX_DESCRIPTION_LENGTH);
return new ProviderProjectEntity(providerProject.getName(), trimmedDescription, providerProject.getHref(), providerProject.getProjectOwnerEmail(), providerConfigId);
}
/**
* Sometimes when logging to the sakai_events table it's possible to be logging
* with a string you don't know the size of. (An exception message is a good
* example)
*
* This method is supplied to keep the lengh of logged messages w/in the limits
* of the sakai_event.ref column size.
*
* The sakai_event.ref column size is currently 256
*
* @param target
* @return
*/
static final public String safeEventLength(final String target)
{
return StringUtils.abbreviate(target, 255);
}
/**
* 提取纯文本
* @param html 代码
* @param length 提取文本长度
* @return string
*/
public static String getText(String html, int length){
String text = getText(html);
text = StringUtils.abbreviate(text, length);
return text;
}