Class GenericContent


  • public class GenericContent
    extends Object
    Handles the conversion between a coded text object and a generic markup string.
    • Constructor Detail

      • GenericContent

        public GenericContent()
      • GenericContent

        public GenericContent​(TextFragment content)
    • Method Detail

      • printSegmentedContent

        public String printSegmentedContent​(TextContainer container,
                                            boolean showSegments)
        Prints a generic string representation of a given segmented text, with optional markers to indicate the segments boundaries.
        Parameters:
        container - The container to output.
        showSegments - True if segment boundaries should be shown.
        Returns:
        A string with the segmented text output.
      • printSegmentedContent

        public String printSegmentedContent​(TextContainer container,
                                            boolean showSegments,
                                            boolean normalText)
        Prints a string representation of a given segmented text, with optional markers to indicate the segments boundaries.
        Parameters:
        container - the container to output.
        showSegments - true if segment boundaries should be shown.
        normalText - true to show in-line real data instead of generic codes.
        Returns:
        a string with the segmented text output.
      • printMarkerIndexes

        public String printMarkerIndexes()
        Generates a coded string containing code indexes in place of two-char code markers.
        Returns:
        The coded string.
      • toString

        public String toString()
        Generates an generic coded string from the content.
        Overrides:
        toString in class Object
        Returns:
        The generic string.
      • toString

        public String toString​(boolean normalText)
        Generates a generic coded string or an normal output from the content.
        Parameters:
        normalText - True to show in-line real data instead of generic codes.
        Returns:
        The output string.
      • getCodedTextPosition

        public Range getCodedTextPosition​(Range position)
        Gets the matching position in the coded text string of a given position in the generic text output.
        Parameters:
        position - Generic text position to convert to coded text position.
        Returns:
        Calculated coded text position.
      • updateFragment

        public static void updateFragment​(String genericText,
                                          TextFragment fragment,
                                          boolean allowCodeDeletion)
        Updates a text fragment from a generic representation.
        Parameters:
        genericText - The generic text to use to update the fragment.
        fragment - The text fragment to update.
        allowCodeDeletion - True when missing in-line codes in the generic text means the corresponding codes should be deleted from the fragment.
        Throws:
        InvalidContentException - When the generic text is not valid, or does not correspond to the existing codes.
      • fromLetterCodedToFragment

        public static TextFragment fromLetterCodedToFragment​(String text,
                                                             TextFragment fragment,
                                                             boolean reuseCodes,
                                                             boolean decodeEncodedLetterCodes)
        Converts a letter-coded text to a fragment.

        A letter-coded text is like "<g1>text<x2/></g1><b3/>".

        Parameters:
        text - the text to convert.
        fragment - optional existing fragment where to set the converted data, or null to create a new fragment. If an existing fragment is provided, no existing code is preserved: all codes are coming from the parsing of the input text, except if reuseCodes is set to true.
        reuseCodes - true to re-use the codes of the provided text fragment. If a code is not found in the provided text fragment, one is created for the output.
        decodeEncodedLetterCodes - true to reverse previous tag escaping, this should match the value of encodeExistingLetterCodes when the text was tag encoded
        Returns:
        the new fragment created from the text.
      • fromFragmentToLetterCoded

        public static String fromFragmentToLetterCoded​(TextFragment fragment,
                                                       boolean encodeExistingLetterCodes)
        Converts a text fragment into a letter-coded text, optionally escaping tags that will interfere with conversion back to a fragment. Use fromLetterCodedToFragment(String, TextFragment, boolean, boolean) to convert back to a fragment.
        Parameters:
        fragment - the fragment to convert.
        encodeExistingLetterCodes - escape the tags.
        Returns:
        the resulting letter-coded text.