Modify Link Action

Post here questions and problems related to editing and publishing DITA content.
mu258770
Posts: 157
Joined: Mon Aug 18, 2014 4:11 pm

Modify Link Action

Post by mu258770 »

Hi Alex,

We are working in one more functionality as "Modify inserted Link" in oxygen eclipse. What is required is if user select a link and by selecting "Modify Link" option from menu or toolbar, he should get the link in the proper text box and he should be able to edit it. This is similar to "Edit Attributes", but difference is our link is a mixture of many fields.

For eg :- Consider the link is as below,

<xref topicname#sectionname>

Now user selects Modify Link from toolbar (this we have done using framework changes), then we need to get 'topicname' in one field and 'sectionname' in another.

How can we do this. How can we read character from the editor using java code.

Regards,
Shabeer
alex_jitianu
Posts: 1008
Joined: Wed Nov 16, 2005 11:11 am

Re: Modify Link Action

Post by alex_jitianu »

Hi,

I suspect that there is an href attribute there, that contains the topicName#sectionName value, right? You can get it and set it back like this:

Code: Select all

int caretOffset = authorAccess.getEditorAccess().getCaretOffset();
AuthorNode xrefNode = authorAccess.getDocumentController().getNodeAtOffset(caretOffset);
if (xrefNode.getType() == AuthorNode.NODE_TYPE_ELEMENT) {
AuthorElement authorElement = (AuthorElement) xrefNode;

// How to get/set an attribute value
AttrValue attribute = authorElement.getAttribute("href");

String[] topicNameAndSection = attribute.getValue().split("#");
// TODO ......
// To set the value back you must use the controller
authorAccess.getDocumentController().setAttribute("href", new AttrValue("newValue"), authorElement);
}
You can learn more about the Author document model by reading about the AuthorNode and AuthorElement.

best regards,
Alex
Post Reply