Class MjmlParser
java.lang.Object
dev.jcputney.mjml.parser.MjmlParser
Parses preprocessed MJML source into an MjmlDocument. Uses the JDK DOM parser to build a DOM
tree, then converts it to our lightweight MjmlNode tree.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcleanUp()Removes the thread-localDocumentBuilderfor the current thread.static MjmlDocumentParses raw MJML source into an MjmlDocument using the default maximum nesting depth.static MjmlDocumentParses raw MJML source into an MjmlDocument with a configurable maximum nesting depth.
-
Method Details
-
cleanUp
public static void cleanUp()Removes the thread-localDocumentBuilderfor the current thread. Call this in application-server environments where threads are recycled (e.g., in a servlet filter'sdestroy()or a thread-pool shutdown hook) to avoid retaining ~50-100KB of XML parser infrastructure per thread.Not required in short-lived applications or environments with fixed thread pools, where keeping the DocumentBuilder warm avoids repeated construction overhead.
-
parse
Parses raw MJML source into an MjmlDocument using the default maximum nesting depth. The source is preprocessed (CDATA wrapping, entity replacement) before XML parsing.- Parameters:
mjmlSource- the raw MJML markup to parse- Returns:
- the parsed
MjmlDocument
-
parse
Parses raw MJML source into an MjmlDocument with a configurable maximum nesting depth. The source is preprocessed (CDATA wrapping, entity replacement) before XML parsing.- Parameters:
mjmlSource- the raw MJML markupmaxNestingDepth- maximum allowed element nesting depth- Returns:
- the parsed
MjmlDocument
-