IBM Support

How to add a clickable hyperlink in the description field using JAVA API in Rational Rhapsody

Question & Answer


Question

How do you add a clickable hyperlink in the description field of an element using JAVA API in IBM Rational Rhapsody?

Cause

You would like to use Java Application Programming Interfaces [API] code to automate the manual task to be performed with in Rational Rhapsody.

Answer

In order to add a clickable hyperlink in the description field of an element in Rational Rhapsody you can use the API method:
setDescriptionAndHyperlinks(String rtfText, IRPCollection targets)


Find below a code snippet for your reference:
Disclaimer

All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.


Adding a single target
 
IRPApplication myApp = RhapsodyAppServer.getActiveRhapsodyApplication();
IRPProject proj = myApp.activeProject();
IRPPackage pkg = proj.addPackage("myPkg");                            
IRPCollection targets = myApp.createNewCollection();

// add one link targets to the collection
targets.setSize(1);
targets.setString(1, "http://www.google.com");

// construct RTF string
String rtfText = "{\\rtf1\\fbidis\\ansi\\ansicpg1255\\deff0\\deflang1037{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}\n{\\colortbl;\\red0\\green0\\blue255;}\n\\viewkind4\\uc1\\pard\\ltrpar\\fs20 This is link to \\cf1\\ul\\protect google\\cf0\\ulnone\\protect0\\par\n}";

// set the description using the RTF string and collection of (one) targets
pkg.setDescriptionAndHyperlinks(rtfText, targets);
Adding multiple targets
The RTF string has to have a equal number of references to match the number of link targets. If you increase the number of link targets without increasing the number of references in the RTF string, the setDescriptionAndHyperlinks operation will fail.
IRPApplication myApp = RhapsodyAppServer.getActiveRhapsodyApplication();
IRPProject proj = myApp.activeProject();
IRPPackage pkg = proj.addPackage("myPkg");                            
IRPCollection targets = myApp.createNewCollection();

// add two link targets to collection
targets.setSize(2);
targets.setString(1, "http://www.google.com");
targets.setString(2, "https://www.duckduckgo.com");

// construct RTF string
String rtfText = "{\\rtf1\\fbidis\\ansi\\ansicpg1255\\deff0\\deflang1037{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}\n{\\colortbl;\\red0\\green0\\blue255;}\n\\viewkind4\\uc1\\pard\\ltrpar\\fs20 This is link to \\cf1\\ul\\protect google\\cf0\\ulnone\\protect0\\par This is link to \\cf1\\ul\\protect duckduckgo\\cf0\\ulnone\\protect0\\par\n}";

// set the description using the RTF string and the collection of (two) targets
pkg.setDescriptionAndHyperlinks(rtfText, targets);

[{"Product":{"code":"SSB2MU","label":"IBM Engineering Systems Design Rhapsody"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"General Information","Platform":[{"code":"PF033","label":"Windows"}],"Version":"7.6.1;7.6.0.1;7.6;7.5.3.2;7.5.3.1;7.5.3;7.5.2.1;7.5.2;7.5.1.1;7.5.1;7.5.0.1;7.5","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21587079