setHTMLDescription with line breaks
I am programmatically creating work items, and in my HTMLSummary, I want to have multiple lines/paragraphs. I am loading the information from a file into an ArrayList with 1 row in the array per line of text. Then I want to put all of the rows together with "line breaks" to preserve the formatting of the original Summary.
I have tried to string them together:
String allText = "";
for (int i=0;i<myArray.size();i++) {
allText = allText + "\\n" + myArray.get(i);
}
Trying to put a \n new line into the plain text, and then use
XMLString description = XMLSTring.createFrom PlainText(allText);
but that, as you can imagine, just uses \n in the text itself.
Is there a way to do this using createFromPlainText? Or does createfromXMLText(String xmlText) understand HTML-type items like <p>?
Thanks,
Susan
I have tried to string them together:
String allText = "";
for (int i=0;i<myArray.size();i++) {
allText = allText + "\\n" + myArray.get(i);
}
Trying to put a \n new line into the plain text, and then use
XMLString description = XMLSTring.createFrom PlainText(allText);
but that, as you can imagine, just uses \n in the text itself.
Is there a way to do this using createFromPlainText? Or does createfromXMLText(String xmlText) understand HTML-type items like <p>?
Thanks,
Susan
3 answers
Investigating the code we see:
A little deeper, we can see this:
So, I guess if you change your code, replacing "\\n" with just "\n", it might works.
String allText = "";
for (int i=0;i<myArray.size();i++) {
allText = allText + "\n" + myArray.get(i);
}
public static XMLString createFromPlainText(String plainText) {
if (plainText == null)
plainText= "null"; //$NON-NLS-1$
HTMLOutputHandler handler= new HTMLOutputHandler();
handler.beginDocument();
handler.text(plainText);
handler.endDocument();
return handler.getHTML();
}
A little deeper, we can see this:
private static class LineDelimiterRule implements IInternalRule {
private static final String BREAK_TAG= "<br>"; //$NON-NLS-1$
public String evaluate(InternalScanner scanner) {
int ch= scanner.read();
if (ch == '\n')
return BREAK_TAG;
if (ch == '\r') {
ch= scanner.read();
if (ch != '\n')
scanner.unread();
return BREAK_TAG;
}
scanner.unread();
return null;
}
}
So, I guess if you change your code, replacing "\\n" with just "\n", it might works.
String allText = "";
for (int i=0;i<myArray.size();i++) {
allText = allText + "\n" + myArray.get(i);
}
A little deeper, we can see this:
private static class LineDelimiterRule implements IInternalRule {
private static final String BREAK_TAG= "<br>"; //$NON-NLS-1$
public String evaluate(InternalScanner scanner) {
int ch= scanner.read();
if (ch == '\n')
return BREAK_TAG;
if (ch == '\r') {
ch= scanner.read();
if (ch != '\n')
scanner.unread();
return BREAK_TAG;
}
scanner.unread();
return null;
}
}
So, I guess if you change your code, replacing "\\n" with just "\n", it might works.
Thanks
P.S. Where could we find the source code of those classes?