code: private String filterWhitespace(String text) {
          text = text.replace("\n", " ");
          text = text.replaceAll(" {2,}", " ");
          text = XmlEscape.escape(text);
          return text.trim();
      }
docs: This method filters out white space characters
  @param text original text
  @return {@code String} filtered text