code: public String getText(boolean preserveWhitespace) throws InvalidInputException, ProcessingException, IllegalStateException {
      if (messageML == null) {
        throw new IllegalStateException("The message hasn't been parsed yet. "
            + "Please call MessageMLContext.parse() first.");
      }
  
      StringBuilder sb = new StringBuilder();
  
      String presentationML = getPresentationML();
      Element doc = messageMLParser.parseDocument(presentationML);
  
      NodeList nodes = doc.getChildNodes();
  
      for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        String text = (preserveWhitespace) ? node.getTextContent() : node.getTextContent().trim();
  
        // Prepend space unless we're at the first node or we trim whitespace and current text is blank
        if (i > 0 && StringUtils.isNotEmpty(text)) {
          sb.append(" ");
        }
  
        sb.append(text);
      }
  
      return sb.toString();
    }
docs: Retrieve a string representation of the message by getting the values of
  its PresentationML elements.
  This method returns {@link Element#getTextContent()} of each individual element of the tree,
  separated by a single space
  @param preserveWhitespace if false, trims the leading and trailing whitespce of each element
  @throws IllegalStateException thrown if the message hasn't been parsed yet