Class ContentManager

java.lang.Object
com.wontlost.ckeditor.internal.ContentManager

public class ContentManager extends Object
Internal class for managing editor content. Handles content retrieval, setting, sanitization, and transformation.

This class is an internal API and should not be used directly by external code.

  • Constructor Details

    • ContentManager

      public ContentManager(HtmlSanitizer htmlSanitizer)
      Create a content manager.
      Parameters:
      htmlSanitizer - HTML sanitizer, may be null
  • Method Details

    • getSanitizedValue

      public String getSanitizedValue(String html)
      Get sanitized HTML content.

      null 语义:本方法对 null/空串原样透传(null in → null out),不归一为 ""; 这与 getSanitizedHtml(java.lang.String)/sanitizeHtml(java.lang.String, org.jsoup.safety.Safelist)/getPlainText(java.lang.String)(对 null 返回 "") 不同,是有意的契约差异——本方法保留输入值的 null 语义。调用方若需要空串,应自行归一。

      Parameters:
      html - raw HTML(可为 null)
      Returns:
      sanitized HTML;无 sanitizer 时原样返回;null/空串原样返回
    • getPlainText

      public String getPlainText(String html)
      Convert HTML to plain text.
      Parameters:
      html - HTML content
      Returns:
      plain text content
    • getSanitizedHtml

      public String getSanitizedHtml(String html)
      Sanitize HTML using relaxed rules.
      Parameters:
      html - HTML content
      Returns:
      sanitized HTML
    • sanitizeHtml

      public String sanitizeHtml(String html, org.jsoup.safety.Safelist safelist)
      Sanitize HTML using custom rules.
      Parameters:
      html - HTML content
      safelist - sanitization rules
      Returns:
      sanitized HTML
    • normalizeForComparison

      public String normalizeForComparison(String html)
      Normalize HTML content for comparison.
      Parameters:
      html - HTML content
      Returns:
      normalized HTML
    • isContentEmpty

      public boolean isContentEmpty(String html)
      Check whether the content is empty.
      Parameters:
      html - HTML content
      Returns:
      true if the content is empty or contains only whitespace tags
    • getCharacterCount

      public int getCharacterCount(String html)
      Estimate the character count of the content (excluding HTML tags).
      Parameters:
      html - HTML content
      Returns:
      character count
    • getWordCount

      public int getWordCount(String html)
      Estimate the word count of the content.
      Parameters:
      html - HTML content
      Returns:
      word count
    • getContentStats

      public ContentManager.ContentStats getContentStats(String html)
      一次解析同时计算字符数与词数(review 发现:分别调用 getCharacterCount/getWordCount 会对同一 HTML 重复 Jsoup.parse)。需要同时展示字/词数时用本方法避免重复解析。
      Parameters:
      html - HTML content
      Returns:
      字符数与词数
    • countWords

      public static int countWords(String text)
      从纯文本计算词数(纯函数,便于单测;不触碰 HTML 解析)。

      分词规则保持不变:按空白切分;CJK(Character.UnicodeScript.HAN)字符每个计一词, 词内非 CJK 部分整体再计一词。CJK 判定刻意沿用 UnicodeScript.HAN 以保持既有计数行为, 不改用 isIdeographic(二者结果不同,会改变用户的词数)。

      Parameters:
      text - 纯文本
      Returns:
      词数