Class RawText

java.lang.Object
org.apache.juneau.bean.html5.RawText
All Implemented Interfaces:
RawContent

public class RawText extends Object implements RawContent
A re-serializable, String-backed raw-content wrapper that the XML and HTML serializers emit verbatim.

This is the reusable analogue of handing the serializer a one-shot Reader: the value is emitted without any XML entity escaping or _x####_ whitespace encoding, and without a wrapping element — but because it is backed by a String it can be serialized any number of times. This makes a bean carrying a RawText value survive a serialize→object→serialize cycle (for the serialize direction), unlike a consumed Reader.

Typical use is embedding pre-built script/style bodies into a Script/Style element:

Example:

// Browser-safe raw JSON sidecar ('<' pre-escaped to \\u003c by the caller). Script s = script("application/json").text(rawText(escapedJson));

Safety: content is emitted verbatim. Because Juneau parses via a StAX XMLStreamReader, a value containing a raw '<' (e.g. a literal </script> sequence) or a bare '&' is browser-correct on serialize but will NOT round-trip back through Juneau's parser. Callers embedding markup-bearing content are responsible for escaping '<' to the JS/CSS unicode escape "\\u003c" before wrapping.

See Also:
  • Constructor Details

    • RawText

      public RawText(String text)
      Constructor.
      Parameters:
      text - The raw, verbatim text content. Can be null (nothing is emitted).
  • Method Details

    • toString

      public String toString()
      Description copied from interface: RawContent
      Returns the raw, verbatim character content to emit.
      Specified by:
      toString in interface RawContent
      Overrides:
      toString in class Object
      Returns:
      The raw content. May be null (nothing is emitted).