Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

0 votes



3 answers

Permanent link
Investigating the code we see:


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);
}

0 votes


Permanent link
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 bello, your post was precious!

P.S. Where could we find the source code of those classes?

0 votes


Permanent link
Davide,
you can find them on SDK. In version 3.x they are provided by zip files but in version 2.x was provided by jar (search for those with .source.). You only have to unzip them.

Michele.

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938

Question asked: Feb 03 '11, 2:19 p.m.

Question was seen: 5,934 times

Last updated: Feb 03 '11, 2:19 p.m.

Confirmation Cancel Confirm