Reputation: 163
I am trying to make JSON that I would save as domino document. Everything works fine, except when handling rich text format field. The problem is this: my html editor puts newline and tabs after every html beginning tag, so when I try to get rtf in which that html is saved, it also contains newlines, tabs etc. I tried replacing them, but nothing happened.
This is how rtf looks like (and can not be changed):
<p>
some sample text</p>
This is how I'm trying to get data from rtf:
somestring = viewdata.getDocument().getMimeEntity("myField").getContentAsText();
How I tried replacing newline:
somestring.replaceAll("\n", "");
somestring.replaceAll("\\n", "");
somestring.replaceAll("\\\n", "");
I would like to get something like
<p>some sample text</p>
I also tryed approach where jsonGenerator would hadle this for me. It returns json full of /t and /n chars. And also I had some other problems with jsonGenerator because my JSON has more than one level in depth. So returning string without newline and tab would probably be the simpliest solution.
Does anyone have any idea how to solve this problem?
Upvotes: 0
Views: 565
Reputation: 4471
I can imagine there might be a few things involved.
I suspect the first one is that replaceAll
interprets the string as a regular expression. Using just replace
is safer in this situation; in spite of the name, it also replaces all occurrences, but instead treats the contents as a literal string.
Another could be that the string contains the two-character Windows CRLF. I'm less sure about this, but you could also do a .replace("\r", "")
to be sure.
Finally, are you assigning the result of the replace
call back to the String variable? It doesn't modify the String in-place, so that's a common pitfall.
As an aside, be wary about the way you're getting the content of the MIME RT field. That will work when the content is text-only, but, when attachments or embedded images are added, the MIME structure changes and the top level becomes a multipart/related
or multipart/mixed
entity and the content is moved to a child. The safest way to seek the body content is to do a depth-first recursive search for the first MIMEEntity
where getContentType()
is text
and getContentSubType()
is html
.
Upvotes: 3