net.sf.okapi.common.filterwriter

## Class GenericContent

- java.lang.Object
- - net.sf.okapi.common.filterwriter.GenericContent

-     public class GenericContent
      extends java.lang.Object

  Handles the conversion between a coded text object and a generic markup string.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `GenericContent()`
    `GenericContent(TextFragment content)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `fromFragmentToLetterCoded(TextFragment fragment)` Deprecated.
    `static java.lang.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.
    `static TextFragment` | `fromLetterCodedToFragment(java.lang.String text, TextFragment fragment, boolean reuseCodes)` Deprecated.
    `static TextFragment` | `fromLetterCodedToFragment(java.lang.String text, TextFragment fragment, boolean reuseCodes, boolean decodeEncodedLetterCodes)` Converts a letter-coded text to a fragment.
    `Range` | `getCodedTextPosition(Range position)` Gets the matching position in the coded text string of a given position in the generic text output.
    `java.lang.String` | `printMarkerIndexes()` Generates a coded string containing code indexes in place of two-char code markers.
    `java.lang.String` | `printSegmentedContent(TextContainer container, boolean showSegments)` Prints a generic string representation of a given segmented text, with optional markers to indicate the segments boundaries.
    `java.lang.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.
    `GenericContent` | `setContent(TextFragment content)`
    `java.lang.String` | `toString()` Generates an generic coded string from the content.
    `java.lang.String` | `toString(boolean normalText)` Generates a generic coded string or an normal output from the content.
    `static void` | `updateFragment(java.lang.String genericText, TextFragment fragment, boolean allowCodeDeletion)` Updates a text fragment from a generic representation.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### GenericContent

          public GenericContent()

    - #### GenericContent

          public GenericContent(TextFragment content)

  - ### Method Detail

    - #### setContent

          public GenericContent setContent(TextFragment content)

    - #### printSegmentedContent

          public java.lang.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 java.lang.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 java.lang.String printMarkerIndexes()

      Generates a coded string containing code indexes in place of two-char code markers.
      Returns:
        The coded string.

    - #### toString

          public java.lang.String toString()

      Generates an generic coded string from the content.
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        The generic string.

    - #### toString

          public java.lang.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(java.lang.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

          @Deprecated
          public static TextFragment fromLetterCodedToFragment(java.lang.String text,
                                                          TextFragment fragment,
                                                          boolean reuseCodes)

      Deprecated.
      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.
      Returns:
        the new fragment created from the text.

    - #### fromLetterCodedToFragment

          public static TextFragment fromLetterCodedToFragment(java.lang.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

          @Deprecated
          public static java.lang.String fromFragmentToLetterCoded(TextFragment fragment)

      Deprecated.
      Converts a text fragment into a letter-coded text. Use `fromLetterCodedToFragment(String, TextFragment, boolean)` to convert back to a fragment.
      Parameters:
        `fragment` - the fragment to convert.
      Returns:
        the resulting letter-coded text.

    - #### fromFragmentToLetterCoded

          public static java.lang.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.
      Returns:
        the resulting letter-coded text.