It's all about the answers!

Ask a question

Line breaks and leading spaces in programmatically created work items


Frederic Mora (13811518) | asked Jun 17 '13, 7:07 p.m.
edited Jun 17 '13, 7:13 p.m.
Hi RTC developers,

We are programmatically creating work items using the Resource Oriented Work Item API. We set up the description using a source text that contains no enrichments, but does contain line breaks and leading blanks forming ASCII indented lists, e.g.:

Items:
 - line 1
  - line 2
    - line 2.1
    - line 2.2

We found that if we PUT a <dc:description> block containing escaped HTML (with br tags and nbsp entities), we get the formatting we want... But only in the web UI.

What we do is this:
  - We insert <BR/> tags for newlines, which, once escaped, give &lt;br/&gt
  - We replaced each leading space with &amp;nbsp;

The resulting XML looks like:
<dc:description>
Items:&lt;br/&gt;
&amp;nbsp;&amp;nbsp;-&amp;nbsp;line&amp;nbsp;1&lt;br/&gt;
...etc...
</dc:description>
(Note: what we submit is actually escaped, so each ampersand within the block is actually replaced by & amp ;)

However, even so, we only see the desired result in the Web UI, and only in preview mode. If we click the Edit button on the description field, we see the unescaped HTML. The Eclipse UI always shows the unescaped HTML.

I understand the restrictions on HTML, but surely there is a way to create a description with blank lines and leading spaces, isn't it? How do you do that?



Accepted answer


permanent link
Christopher Ricci (9815) | answered Jun 18 '13, 1:10 p.m.
That is correct, in both Eclipse and the Web in both Edit or Preview modes.

Attached are the results.

Web Edit Mode
Web Preview Mode Eclipse

Frederic Mora selected this answer as the correct answer

Comments
Frederic Mora commented Jun 18 '13, 6:49 p.m. | edited Jun 18 '13, 6:52 p.m.

Got it. There is a gotcha: the XML quoted by Chris has been unescaped by the forum software.

Summary of solution: We want to create a description with line breaks and leading blanks, e.g.,

Items:
- line 1
- line 2
      - line 2.1
      - line 2.2

Here is the algorithm to apply when you send a <dc:description> block:

   each newline has to be replaced with the sequence & lt;br/& gt; (I am inserting blanks here to avoid the forum software interpreting it).

 
Each space has to be replaced with & #160; (again, mind the extra space), but only from the start of the line until the first non-blank character. Otherwise, you get lines as wide as a paragraph, and you have to scroll horizontally to read the text.


Frederic Mora commented Jun 18 '13, 6:53 p.m.

Here is the corresponding description block (warning: a space has been added after each ampersand to avoid interpretation):

<dc:description>Items:& lt;br/& gt;- line 1& lt;br/& gt;- line 2& lt;br/& gt;& #160;& #160;& #160;& #160;& #160;& #160;- line 2.1& lt;br/& gt;& #160;& #160;& #160;& #160;& #160;& #160;- line 2.2</dc:description>

2 other answers



permanent link
Millard Ellingsworth (2.5k12431) | answered Jun 18 '13, 1:46 p.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER
As Chris shows by example, if you have valid XHTML content, it should work. Here are some possibly useful references:

http://open-services.net/bin/view/Main/CmSpecificationV2
dcterms:description
Value-type: XMLLiteral
Descriptive text (reference: Dublin Core) about resource represented as rich text in XHTML content. SHOULD include only content that is valid and suitable inside an XHTML <div> element.

http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#section-XMLLiteral

http://open-services.net/pipermail/oslc-core_open-services.net/2011-November/001178.html
[this last item includes some discussion about formatted plain text in descriptions]

If there is some sort of defect related to 4.0.1, we should file that, but your fastest relief is likely to move up to 4.0.3 if that is the case.

permanent link
Christopher Ricci (9815) | answered Jun 18 '13, 12:43 p.m.
edited Jun 18 '13, 12:47 p.m.
Hi Fred,

This worked for me:
<?xml version="1.0" encoding="UTF-8"?><oslc_cm:ChangeRequest xmlns:oslc_cm="http://open-services.net/xmlns/cm/1.0/" rdf:about="https://jazz-server:9443/ccm/resource/itemName/com.ibm.team.workitem.WorkItem/60" xmlns:dc="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:calm="http://jazz.net/xmlns/prod/jazz/calm/1.0/" xmlns:rtc_cm="http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/" xmlns:oslc_pl="http://open-services.net/ns/pl#">
<dc:description>Items:&lt;br/&gt;- line 1&lt;br/&gt;- line 2&lt;br/&gt;&amp;#160;&amp;#160;&amp;#160;- line 2.1&lt;br/&gt;&amp;#160;&amp;#160;&amp;#160;- line 2.2</dc:description>
</oslc_cm:ChangeRequest>



Comments
Christopher Ricci commented Jun 18 '13, 12:52 p.m.

By the way, I'm using 4.0.3, not sure if that matters.


Frederic Mora commented Jun 18 '13, 1:04 p.m. | edited Jun 18 '13, 1:33 p.m.

Hi Chris,

When you say "that works", do you mean that you saw the description in the Eclipse client with the correct spacing and the <br/> interpreted correctly?


Your answer


Register or 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.