/** * Returns a substring of the source, which is at most length characters long.<p> * * If a char is cut, <code>" ..."</code> is appended to the result.<p> * * @param input the string to trim * @param length the maximum length of the string to be returned * * @return a substring of the source, which is at most length characters long * * @see CmsStringUtil#trimToSize(String, int, String) */ public static String trimToSize(String input, int length) { return CmsStringUtil.trimToSize(input, length, " ..."); }
/** * Returns a substring of the source, which is at most length characters long.<p> * * This is the same as calling {@link #trimToSize(String, int, String)} with the * parameters <code>(source, length, " ...")</code>.<p> * * @param source the string to trim * @param length the maximum length of the string to be returned * * @return a substring of the source, which is at most length characters long */ public static String trimToSize(String source, int length) { return trimToSize(source, length, length, " ..."); }
/** * Returns a substring of the source, which is at most length characters long.<p> * * This is the same as calling {@link #trimToSize(String, int, String)} with the * parameters <code>(source, length, " ...")</code>.<p> * * @param source the string to trim * @param length the maximum length of the string to be returned * * @return a substring of the source, which is at most length characters long */ public static String trimToSize(String source, int length) { return trimToSize(source, length, length, " ..."); }
/** * Returns a substring of the source, which is at most length characters long.<p> * * If a char is cut, <code>" ..."</code> is appended to the result.<p> * * @param input the string to trim * @param length the maximum length of the string to be returned * * @return a substring of the source, which is at most length characters long * * @see CmsStringUtil#trimToSize(String, int, String) */ public static String trimToSize(String input, int length) { return CmsStringUtil.trimToSize(input, length, " ..."); }
/** * Returns a substring of the source, which is at most length characters long.<p> * * If a char is cut, the given <code>suffix</code> is appended to the result.<p> * * This is almost the same as calling {@link #trimToSize(String, int, int, String)} with the * parameters <code>(source, length, length*, suffix)</code>. If <code>length</code> * if larger then 100, then <code>length* = length / 2</code>, * otherwise <code>length* = length</code>.<p> * * @param source the string to trim * @param length the maximum length of the string to be returned * @param suffix the suffix to append in case the String was trimmed * * @return a substring of the source, which is at most length characters long */ public static String trimToSize(String source, int length, String suffix) { int area = (length > 100) ? length / 2 : length; return trimToSize(source, length, area, suffix); }
/** * Returns a substring of the source, which is at most length characters long.<p> * * If a char is cut, the given <code>suffix</code> is appended to the result.<p> * * This is almost the same as calling {@link #trimToSize(String, int, int, String)} with the * parameters <code>(source, length, length*, suffix)</code>. If <code>length</code> * if larger then 100, then <code>length* = length / 2</code>, * otherwise <code>length* = length</code>.<p> * * @param source the string to trim * @param length the maximum length of the string to be returned * @param suffix the suffix to append in case the String was trimmed * * @return a substring of the source, which is at most length characters long */ public static String trimToSize(String source, int length, String suffix) { int area = (length > 100) ? length / 2 : length; return trimToSize(source, length, area, suffix); }
/** * Applies the max length limitation of the current field to the given value.<p> * * @param cms the current users OpenCms context * @param xmlContentValue the XML content value * @param value the String value generated form the XML content value * @param maxLength the max length setting of the current field * * @return the input with the max length limitation of the current field applied */ protected String applyLengthRestriction( CmsObject cms, I_CmsXmlContentValue xmlContentValue, String value, int maxLength) { // assume default "text/plain" as value String result = value; if (xmlContentValue instanceof CmsXmlHtmlValue) { // the content is HTML result = xmlContentValue.getPlainText(cms); } if (value.length() <= maxLength) { // value is shorter than maximum length, no trimming needed return result; } else { // value is too long, apply limitation return CmsStringUtil.trimToSize(result, maxLength); } }
result = CmsStringUtil.trimToSize(result, maxLength);
public static String formatContentValueForDiffTable( CmsObject cms, CmsElementComparison comparison, String origValue) { String result = CmsStringUtil.escapeHtml( CmsStringUtil.substitute( CmsStringUtil.trimToSize(origValue, CmsPropertyComparisonList.TRIM_AT_LENGTH), "\n", "")); // formatting DateTime if (comparison instanceof CmsXmlContentElementComparison) { if (((CmsXmlContentElementComparison)comparison).getType().equals(CmsXmlDateTimeValue.TYPE_NAME)) { if (CmsStringUtil.isNotEmpty(result)) { result = CmsDateUtil.getDateTime( new Date(Long.parseLong(result)), DateFormat.SHORT, cms.getRequestContext().getLocale()); } } } return result; }
/** * Formats an xml content value string for display in the value comparison table.<p> * * @param cms the CMS context * @param comparison the element comparison * @param origValue the XML content value as a string * * @return the formatted string */ public static String formatContentValueForDiffTable( CmsObject cms, CmsElementComparison comparison, String origValue) { String result = CmsStringUtil.substitute(CmsStringUtil.trimToSize(origValue, 60), "\n", ""); // formatting DateTime if (comparison instanceof CmsXmlContentElementComparison) { if (((CmsXmlContentElementComparison)comparison).getType().equals(CmsXmlDateTimeValue.TYPE_NAME)) { if (CmsStringUtil.isNotEmpty(result)) { result = CmsDateUtil.getDateTime( new Date(Long.parseLong(result)), DateFormat.SHORT, cms.getRequestContext().getLocale()); } } } return result; }
val = CmsStringUtil.trimToSize(val, 1000, 50, "");
CmsListItem item = getList().newItem(comparison.getName()); item.set(LIST_COLUMN_PROPERTY_NAME, comparison.getName()); item.set(LIST_COLUMN_VERSION_1, CmsStringUtil.trimToSize(comparison.getVersion1(), TRIM_AT_LENGTH)); item.set(LIST_COLUMN_VERSION_2, CmsStringUtil.trimToSize(comparison.getVersion2(), TRIM_AT_LENGTH)); if (CmsResourceComparison.TYPE_ADDED.equals(comparison.getStatus())) { item.set(LIST_COLUMN_TYPE, key(Messages.GUI_COMPARE_ADDED_0));
CmsListItem item = getList().newItem(comparison.getName()); item.set(LIST_COLUMN_PROPERTY_NAME, comparison.getName()); item.set(LIST_COLUMN_VERSION_1, CmsStringUtil.trimToSize(comparison.getVersion1(), TRIM_AT_LENGTH)); item.set(LIST_COLUMN_VERSION_2, CmsStringUtil.trimToSize(comparison.getVersion2(), TRIM_AT_LENGTH)); if (CmsResourceComparison.TYPE_ADDED.equals(comparison.getStatus())) { item.set(LIST_COLUMN_TYPE, key(Messages.GUI_COMPARE_ADDED_0));
CmsListItem item = getList().newItem(comparison.getName()); item.set(LIST_COLUMN_PROPERTY_NAME, key(comparison.getName())); item.set(LIST_COLUMN_VERSION_1, CmsStringUtil.trimToSize(comparison.getVersion1(), TRIM_AT_LENGTH)); item.set(LIST_COLUMN_VERSION_2, CmsStringUtil.trimToSize(comparison.getVersion2(), TRIM_AT_LENGTH)); if (CmsResourceComparison.TYPE_ADDED.equals(comparison.getStatus())) { item.set(LIST_COLUMN_TYPE, key(Messages.GUI_COMPARE_ADDED_0));
textValue = CmsStringUtil.trimToSize(textValue, 250); textValue += "<a href=\"" + m_jspActionElement.link(m_content.getStringValue(
CmsListItem item = getList().newItem(comparison.getName()); item.set(LIST_COLUMN_PROPERTY_NAME, key(comparison.getName())); item.set(LIST_COLUMN_VERSION_1, CmsStringUtil.trimToSize(comparison.getVersion1(), TRIM_AT_LENGTH)); item.set(LIST_COLUMN_VERSION_2, CmsStringUtil.trimToSize(comparison.getVersion2(), TRIM_AT_LENGTH)); if (CmsResourceComparison.TYPE_ADDED.equals(comparison.getStatus())) { item.set(LIST_COLUMN_TYPE, key(Messages.GUI_COMPARE_ADDED_0));
String value1 = CmsStringUtil.escapeHtml(CmsStringUtil.substitute(CmsStringUtil.trimToSize( comparison.getVersion1(), CmsPropertyComparisonList.TRIM_AT_LENGTH), "\n", "")); String value2 = CmsStringUtil.escapeHtml(CmsStringUtil.substitute(CmsStringUtil.trimToSize( comparison.getVersion2(), CmsPropertyComparisonList.TRIM_AT_LENGTH), "\n", ""));
CmsStringUtil.trimToSize(comparison.getVersion1(), CmsPropertyComparisonList.TRIM_AT_LENGTH), "\n", ""));