Class LargeTextHelper

java.lang.Object
fr.becpg.repo.helper.LargeTextHelper

public class LargeTextHelper extends Object

LargeTextHelper class.

Version:
$Id: $Id
Author:
matthieu
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final int
    Overhead kept when shortening a value to leave room for the ellipsis suffix.
    static final int
    Maximum size of a single locale value, in UTF-8 bytes.
    static final int
    Constant TEXT_SIZE_LIMIT=50000
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Constructor for LargeTextHelper.
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.alfresco.util.Pair<String,String>
    createTextDiffs(String string1, String string2)
    createTextDiffs.
    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.
    static final String
    elipse(String textBefore)
    elipse.
    static final String
    elipse(String textBefore, int textLength)
    elipse.
    static org.alfresco.service.cmr.repository.MLText
    elipse(org.alfresco.service.cmr.repository.MLText mlText)
    elipse.
    static final String
    elipseHtml(String value, int textLength)
    HTML-aware truncation.
    static boolean
    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 String
    htmlDiff(String text1, String text2)
    htmlDiff.
    private static int
    totalLength(org.alfresco.service.cmr.repository.MLText mlText)
     
    private static int
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TEXT_SIZE_LIMIT

      public static final int TEXT_SIZE_LIMIT
      Constant TEXT_SIZE_LIMIT=50000
      See Also:
    • MAX_LOCALE_SIZE_BYTES

      public static final int MAX_LOCALE_SIZE_BYTES
      Maximum size of a single locale value, in UTF-8 bytes. Alfresco keys alf_node_properties on the locale, so every language of a d:mltext property lands in its own string_value row. On MySQL that column is a TEXT, capped at 65535 bytes, and the InnoDB dialect never spills strings to serializable_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_OVERHEAD
      Overhead 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

      public static final String elipse(String textBefore)

      elipse.

      Parameters:
      textBefore - a String object
      Returns:
      a String object
    • elipse

      public static final String elipse(String textBefore, int textLength)

      elipse.

      Parameters:
      textBefore - a String object
      textLength - a int
      Returns:
      a String object
    • elipseHtml

      public static final String elipseHtml(String value, int textLength)

      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).

      Parameters:
      value - a String object
      textLength - a int
      Returns:
      a String object
    • createTextDiffs

      public static org.alfresco.util.Pair<String,String> createTextDiffs(String string1, String string2)

      createTextDiffs.

      Parameters:
      string1 - a String object
      string2 - a String object
      Returns:
      a Pair object
    • elipse

      public static org.alfresco.service.cmr.repository.MLText elipse(org.alfresco.service.cmr.repository.MLText mlText)

      elipse.

      Returns a copy of the given MLText whose values are shortened so that the total length (all locales combined) stays under TEXT_SIZE_LIMIT. The budget is shared between locales proportionally to their actual content, empty locales are ignored, and the source MLText is left untouched.
      Parameters:
      mlText - a MLText object
      Returns:
      a new MLText object
    • 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_properties row, so one oversized language never penalises the others.

      Parameters:
      mlText - a MLText object
      noticeProvider - supplies the replacement notice for a dropped locale
      Returns:
      a new MLText object, the source is left untouched
    • fitsInProperty

      public static boolean fitsInProperty(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.

      Parameters:
      value - a String object
      Returns:
      true when the value fits MAX_LOCALE_SIZE_BYTES
    • valueLength

      private static int valueLength(String value)
    • totalLength

      private static int totalLength(org.alfresco.service.cmr.repository.MLText mlText)
    • htmlDiff

      public static String htmlDiff(String text1, String text2)

      htmlDiff.

      Parameters:
      text1 - a String object
      text2 - a String object
      Returns:
      a String object
      Since:
      23.2.1.26