Sunday, May 15, 2016

How to handle Rich Text Item In Cognos

A Rich Text Item allows us to embed some basic XHTML in our reports, and it renders it as a part of the report structure (Meaning it will also render when exporting to Excel or PDF).  We can drag one to any data container, such as list and crosstab like this:
And assign expression from data item, or XHTML element.
Please note that each element only supports the style attribute, which must contain a valid CSS style. In addition, ul and ol elements support list-style attributes. Specifically, the ol element supports decimal, and the ul element supports circle, disc, and square, as well as list-style-image. For example, the following code produces an unordered list entitled List: with three items. Each list item is in a different color, and the list-style attribute used is circle.
<div style="font-size:14pt; text-decoration:underline">List:</div>
<ul style="list-style-type:circle">
<li style="color:green">Item <span style="font-weight:bold">A</span></li>
<li style="color:red">Item B</li>
<li style="color:blue">Item C</li>
</ul>
The text is often saved in database, which are initially from rich text editor from Microsoft word.   The problem is that you cannot simply use the text from database, as many formats and tags are not supported by Cognos Rich Text Item.
The solution is to create a conversion function to convert raw text to normal text that is supported by Cognos Rich Text Item. For example IBM OpenPages provides a function called OP_RICH_TEXT_MGR
   FUNCTION CONVERT_TEXT (inRichText CLOB) RETURN CLOB IS
       outRichText CLOB := inRichText;
       BEGIN
           CONVERT_MISCELLANEOUS (outRichText);
           CONVERT_HEADERS (outRichText);
           CONVERT_BREAKS (outRichText);
           CONVERT_CHARACTER_FORMATTING (outRichText);
           CONVERT_NAMED_CHARACTERS (outRichText);
           CONVERT_TABLES (outRichText);
           CONVERT_IMAGES (outRichText);
           RETURN outRichText;
       END;
END;

There was strange case when line-height is provided as normal:  div { font: 12px/normal Arial, Helvetica, sans-serif; }   this case cause Cognos crash and also cause server shut down, unbelievable!
Two solutions can be applied to resolve this issue:
1) Change function for conversion to cover this case.
2) Change report to replace data item from
div { font: 12px/normal Arial, Helvetica, sans-serif; }   to
div { font: 12px/none Arial, Helvetica, sans-serif; }

The other solution is to leverage function REGEXP_REPLACE to cleanup.
SELECT REGEXP_REPLACE(
'<div><span style="font-size: 10px;"><span style="font-family: arial,helvetica,sans-serif;">ABC</span></span></div>',
'( (font)+([^>]*)+(;))' )
FROM DUAL;

SELECT REGEXP_REPLACE(
'<div><span style="font-size: 10px;"><span style="font-family: arial,helvetica,sans-serif;">ABC</span></span></div>',
'( (style="font-)+([^>]*)+(;"))' )
FROM DUAL;

SELECT REGEXP_REPLACE(
'<div><span class="breakWord" id="display.gor-ov.kpro.8173">Shakedown test</span></div>',
'( (class=")+([^>]*)+("))' )
FROM DUAL;

SELECT REGEXP_REPLACE(
'<div><span class="breakWord" id="display.gor-ov.kpro.8173">Shakedown test</span></div>',
'</?font( [^>]*)?>' )
FROM DUAL

No comments:

Post a Comment