MessageML parse ( String message , String entityJson , String version ) throws InvalidInputException , ProcessingException , IOException { this . index = 0 ; String expandedMessage ; if ( StringUtils . isBlank ( message ) ) { throw new InvalidInputException ( "Error parsing message: the message cannot be null or empty" ) ; } if ( StringUtils . isNotBlank ( entityJson ) ) { try { this . entityJson = ( ObjectNode ) MAPPER . readTree ( entityJson ) ; } catch ( JsonProcessingException e ) { throw new InvalidInputException ( "Error parsing EntityJSON: " + e . getMessage ( ) ) ; } } else { this . entityJson = new ObjectNode ( JsonNodeFactory . instance ) ; } try { expandedMessage = expandTemplates ( message , this . entityJson ) ; } catch ( IOException e ) { throw new InvalidInputException ( "Error parsing EntityJSON: " + e . getMessage ( ) ) ; } catch ( TemplateException e ) { throw new InvalidInputException ( String . format ( "Error parsing Freemarker template: invalid input at line %s, " + "column %s" , e . getLineNumber ( ) , e . getColumnNumber ( ) ) ) ; } this . messageML = parseMessageML ( expandedMessage , version ) ; if ( this . messageML != null ) { this . entityJson = this . messageML . asEntityJson ( this . entityJson ) ; return this . messageML ; } throw new ProcessingException ( "Internal error. Generated null MessageML from valid input" ) ; }
Parse the text contents of the message and optionally EntityJSON into a MessageMLV2 message . Expands Freemarker templates and generates a MessageML document tree .