Skip to content

Commit b666ecd

Browse files
vlaknfedejeanne
authored andcommitted
Implement attribute handling during context merging
Implement attribute handling during context merging and enable the related test Contributes to #525
1 parent 3d75a26 commit b666ecd

File tree

2 files changed

+25
-15
lines changed
  • ua

2 files changed

+25
-15
lines changed

ua/org.eclipse.help/src/org/eclipse/help/internal/context/Context.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.eclipse.help.internal.UAElement;
2828
import org.w3c.dom.Document;
2929
import org.w3c.dom.Element;
30+
import org.w3c.dom.NamedNodeMap;
3031
import org.w3c.dom.Node;
3132

3233
public class Context extends UAElement implements IContext3 {
@@ -53,27 +54,37 @@ public void mergeContext(IContext src) {
5354
if (getText() == null || getText().length() == 0) {
5455
setText(text);
5556
}
56-
if (src instanceof IContext2 && getTitle() == null) {
57-
String title = ((IContext2)src).getTitle();
57+
if (src instanceof IContext2 icontext2 && getTitle() == null) {
58+
String title = icontext2.getTitle();
5859
if (title != null) {
5960
setAttribute(ATTRIBUTE_TITLE, title);
6061
}
6162
}
62-
if (src instanceof IContext3) {
63-
ICommandLink[] commands = ((IContext3)src).getRelatedCommands();
64-
for (int i=0;i<commands.length;++i) {
65-
appendChild(new CommandLink(commands[i]));
63+
if (src instanceof IContext3 icontext3) {
64+
ICommandLink[] commands = icontext3.getRelatedCommands();
65+
for (ICommandLink command : commands) {
66+
appendChild(new CommandLink(command));
6667
}
6768
}
68-
IHelpResource[] topics = src.getRelatedTopics();
69-
for (int i=0;i<topics.length;++i) {
70-
if (topics[i] instanceof ITopic) {
71-
appendChild(new Topic((ITopic)topics[i]));
69+
if (src instanceof UAElement uaelement) {
70+
NamedNodeMap attributes = uaelement.getElement().getAttributes();
71+
for (int i = 0; i < attributes.getLength(); i++) {
72+
Node attribute = attributes.item(i);
73+
String attributeName = attribute.getNodeName();
74+
String attributeValue = attribute.getNodeValue();
75+
if (getAttribute(attributeName) == null) {
76+
setAttribute(attributeName, attributeValue);
77+
}
7278
}
73-
else {
79+
}
80+
IHelpResource[] relatedTopics = src.getRelatedTopics();
81+
for (IHelpResource relatedTopic : relatedTopics) {
82+
if (relatedTopic instanceof ITopic) {
83+
appendChild(new Topic((ITopic) relatedTopic));
84+
} else {
7485
Topic topic = new Topic();
75-
topic.setHref(topics[i].getHref());
76-
topic.setLabel(topics[i].getLabel());
86+
topic.setHref(relatedTopic.getHref());
87+
topic.setLabel(relatedTopic.getLabel());
7788
appendChild(topic);
7889
}
7990
}

ua/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/ContextTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ public void testContextWithoutDescriptionMixedCatenation() {
420420
assertEquals("Context Description", context3.getText());
421421
}
422422

423-
/*
423+
@Test
424424
public void testCopyContextWithAttribute() {
425425
final String contextSource = CONTEXT_HEAD_WITH_ATTRIBUTE +
426426
CONTEXT_DESCRIPTION +
@@ -432,6 +432,5 @@ public void testCopyContextWithAttribute() {
432432
assertEquals("abc", context1.getAttribute("att"));
433433
assertEquals("abc", context2.getAttribute("att"));
434434
}
435-
*/
436435

437436
}

0 commit comments

Comments
 (0)