Interface ContentTypeAdapter


  • public interface ContentTypeAdapter

    Provides a format adapter.

    Implementations of this interface are used to convert a certain text format from and to HTML.

    By contract, the conversion to HTML must be as precise as possible, as it is used for render the fragment. I.e., the HTML created by toHTML(String) is eventually displayed to the end user.

    While it is recommended to provide an "as precise as possible" conversion from HTML to the target format as well, it is not absolutely required: fromHTML(String) is only used for manual format changes where it is assumed that the author has to tweak the results manually anyway.

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.lang.String fromHTML​(java.lang.String html)
      Converts the given HTML text into the represented text format.
      java.lang.String getContentType()
      Returns the MIME type the adapter is responsible for.
      java.lang.String toHTML​(java.lang.String formattedText)
      Converts the given text that is assumed to be in the adapter's format into a valid HTML fragment.
    • Method Detail

      • getContentType

        java.lang.String getContentType()
        Returns the MIME type the adapter is responsible for.
        Returns:
        The content type
      • fromHTML

        java.lang.String fromHTML​(java.lang.String html)
                           throws ContentFragmentException
        Converts the given HTML text into the represented text format.
        Parameters:
        html - The HTML text to convert
        Returns:
        The provided HTML, converted into the adapter's text format
        Throws:
        ContentFragmentException - if the conversion fails
      • toHTML

        java.lang.String toHTML​(java.lang.String formattedText)
                         throws ContentFragmentException

        Converts the given text that is assumed to be in the adapter's format into a valid HTML fragment.

        The returned HTML fragment must not have a root tag (like <html>, <body> or <div>).

        Note that "is assumed to be in the transformer's format" means that you can't rely on the input being syntactically correct (unless the editor implementation ensures it in the UI). Hence the implementation should handle syntactical errors gracefully. In a worst case scenario, the original text should be treated as plain text.

        Parameters:
        formattedText - The text to be converted to HTML; supposed to be in the adapter's format
        Returns:
        The converted text
        Throws:
        ContentFragmentException - if the conversion fails