Class LargeTextHelper
LargeTextHelper class.
- Version:
- $Id: $Id
- Author:
- matthieu
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intOverhead kept when shortening a value to leave room for the ellipsis suffix.static final intMaximum size of a single locale value, in UTF-8 bytes.static final intConstantTEXT_SIZE_LIMIT=50000 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateTextDiffs(String string1, String string2) createTextDiffs.static org.alfresco.service.cmr.repository.MLTextdropOversizedLocales(org.alfresco.service.cmr.repository.MLText mlText, Function<Locale, String> noticeProvider) Replaces the locale values that cannot be persisted by the notice supplied for that locale, without ever cutting a value in the middle.static final Stringelipse.static final Stringelipse.static org.alfresco.service.cmr.repository.MLTextelipse(org.alfresco.service.cmr.repository.MLText mlText) elipse.static final StringelipseHtml(String value, int textLength) HTML-aware truncation.static booleanfitsInProperty(String value) Tells whether a single locale value can be persisted, measured in UTF-8 bytes rather than in characters: the underlying column is capped in bytes, and a character weighs from one byte (markup, digits) to four, so a limit counted in characters would be either too lax for Chinese or needlessly strict for Latin scripts.static StringhtmlDiff.private static inttotalLength(org.alfresco.service.cmr.repository.MLText mlText) private static intvalueLength(String value)
-
Field Details
-
TEXT_SIZE_LIMIT
public static final int TEXT_SIZE_LIMITConstantTEXT_SIZE_LIMIT=50000- See Also:
-
MAX_LOCALE_SIZE_BYTES
public static final int MAX_LOCALE_SIZE_BYTESMaximum size of a single locale value, in UTF-8 bytes. Alfresco keysalf_node_propertieson the locale, so every language of a d:mltext property lands in its ownstring_valuerow. On MySQL that column is aTEXT, capped at 65535 bytes, and the InnoDB dialect never spills strings toserializable_value(SchemaBootstrap sets its threshold to Integer.MAX_VALUE), so the column is the hard wall. The margin absorbs the encoding of the notice replacing an oversized value.- See Also:
-
ELLIPSIS_OVERHEAD
private static final int ELLIPSIS_OVERHEADOverhead kept when shortening a value to leave room for the ellipsis suffix.- See Also:
-
-
Constructor Details
-
LargeTextHelper
private LargeTextHelper()Constructor for LargeTextHelper.
-
-
Method Details
-
elipse
elipse.
-
elipse
elipse.
-
elipseHtml
HTML-aware truncation. When the value is an HTML table, the cut is done after the last complete row (</tr>) and the table is closed, so the rendered output stays valid instead of being broken mid-tag. Otherwise falls back to
elipse(String, int). -
createTextDiffs
createTextDiffs.
-
elipse
public static org.alfresco.service.cmr.repository.MLText elipse(org.alfresco.service.cmr.repository.MLText mlText) elipse.
Returns a copy of the givenMLTextwhose values are shortened so that the total length (all locales combined) stays underTEXT_SIZE_LIMIT. The budget is shared between locales proportionally to their actual content, empty locales are ignored, and the sourceMLTextis left untouched.- Parameters:
mlText- aMLTextobject- Returns:
- a new
MLTextobject
-
dropOversizedLocales
public static org.alfresco.service.cmr.repository.MLText dropOversizedLocales(org.alfresco.service.cmr.repository.MLText mlText, Function<Locale, String> noticeProvider) Replaces the locale values that cannot be persisted by the notice supplied for that locale, without ever cutting a value in the middle. A partially cut value carries wrong data and is never usable, whereas an explicit notice tells the user what happened.
Each locale is weighed on its own: Alfresco stores every locale of a d:mltext property in its own
alf_node_propertiesrow, so one oversized language never penalises the others.- Parameters:
mlText- aMLTextobjectnoticeProvider- supplies the replacement notice for a dropped locale- Returns:
- a new
MLTextobject, the source is left untouched
-
fitsInProperty
Tells whether a single locale value can be persisted, measured in UTF-8 bytes rather than in characters: the underlying column is capped in bytes, and a character weighs from one byte (markup, digits) to four, so a limit counted in characters would be either too lax for Chinese or needlessly strict for Latin scripts.
- Parameters:
value- aStringobject- Returns:
- true when the value fits
MAX_LOCALE_SIZE_BYTES
-
valueLength
-
totalLength
private static int totalLength(org.alfresco.service.cmr.repository.MLText mlText) -
htmlDiff
htmlDiff.
-