Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions ua/org.eclipse.help/src/org/eclipse/help/internal/Topic.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
*******************************************************************************/
package org.eclipse.help.internal;

import java.util.Arrays;

import org.eclipse.help.ICriteria;
import org.eclipse.help.ITopic;
import org.eclipse.help.ITopic2;
import org.eclipse.help.IUAElement;
import org.w3c.dom.Element;

public class Topic extends UAElement implements ITopic2 {
Expand All @@ -24,7 +27,7 @@ public class Topic extends UAElement implements ITopic2 {
public static final String ATTRIBUTE_HREF = "href"; //$NON-NLS-1$
public static final String ATTRIBUTE_LABEL = "label"; //$NON-NLS-1$
public static final String ATTRIBUTE_ICON = "icon"; //$NON-NLS-1$
public static final String ATTRIBUTE_SORT= "sort"; //$NON-NLS-1$
public static final String ATTRIBUTE_SORT = "sort"; //$NON-NLS-1$

public Topic() {
super(NAME);
Expand All @@ -34,16 +37,19 @@ public Topic(ITopic src) {
super(NAME, src);
setHref(src.getHref());
setLabel(src.getLabel());
appendChildren(src.getChildren());
IUAElement[] copiedChildren = Arrays.stream(src.getChildren()).map(UAElementFactory::newElement)
.toArray(IUAElement[]::new);

appendChildren(copiedChildren);
}

@Override
public String getIcon(){
public String getIcon() {
return getAttribute(ATTRIBUTE_ICON);
}

@Override
public boolean isSorted(){
public boolean isSorted() {
return "true".equalsIgnoreCase(getAttribute(ATTRIBUTE_SORT)); //$NON-NLS-1$
}

Expand Down
44 changes: 23 additions & 21 deletions ua/org.eclipse.help/src/org/eclipse/help/internal/UAElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/*
* Base class for UA model elements.
*/
Expand All @@ -59,6 +60,7 @@ public Filter(String name, String value, boolean isNegated) {
this.value = value;
this.isNegated = isNegated;
}

String name;
String value;
boolean isNegated;
Expand All @@ -82,7 +84,7 @@ public UAElement(String name, IUAElement src) {
}

private void copyFilters(IUAElement src) {
UAElement sourceElement = (UAElement)src;
UAElement sourceElement = (UAElement) src;
String filter = sourceElement.getAttribute(ATTRIBUTE_FILTER);
if (filter != null && filter.length() > 0) {
this.setAttribute(ATTRIBUTE_FILTER, filter);
Expand All @@ -101,15 +103,14 @@ private Filter[] getFilterElements() {
if (node.getNodeType() == Node.ELEMENT_NODE) {
String elementKind = node.getNodeName();
if (ExpressionTagNames.ENABLEMENT.equals(elementKind)) {
Element enablement = (Element)node;
Element enablement = (Element) node;
try {
enablementExpression = ExpressionConverter.getDefault().perform(enablement);
}
catch (CoreException e) {
} catch (CoreException e) {

}
} else if (ELEMENT_FILTER.equals(elementKind)) {
Element filter = (Element)node;
Element filter = (Element) node;
String filterName = filter.getAttribute(ATTRIBUTE_NAME);
String value = filter.getAttribute(ATTRIBUTE_VALUE);
if (filterName.length() > 0 && value.length() > 0) {
Expand Down Expand Up @@ -146,14 +147,15 @@ public void appendChildren(IUAElement[] children) {
if (this.children == null && children.length > 0) {
this.children = new ArrayList<>(4);
}
for (int i=0;i<children.length;i++) {
appendChild(children[i] instanceof UAElement ? (UAElement)children[i] : UAElementFactory.newElement(children[i]));
for (IUAElement child : children) {
appendChild(child instanceof UAElement ? (UAElement) child : UAElementFactory.newElement(child));
}
}

/*
* This method is synchronized to fix Bug 232169. When modifying this source be careful not
* to introduce any logic which could possibly cause this thread to block.
* This method is synchronized to fix Bug 232169. When modifying this source
* be careful not to introduce any logic which could possibly cause this
* thread to block.
*/
synchronized public String getAttribute(String name) {
String value = element.getAttribute(name);
Expand All @@ -164,9 +166,10 @@ synchronized public String getAttribute(String name) {
}

/*
* This method is synchronized to fix Bug 230037. A review of the code indicated that there was no
* path which could get blocked and cause deadlock. When modifying this source be careful not
* to introduce any logic which could possibly cause this thread to block.
* This method is synchronized to fix Bug 230037. A review of the code
* indicated that there was no path which could get blocked and cause
* deadlock. When modifying this source be careful not to introduce any
* logic which could possibly cause this thread to block.
*/
@Override
public synchronized IUAElement[] getChildren() {
Expand All @@ -176,7 +179,7 @@ public synchronized IUAElement[] getChildren() {
Node node = element.getFirstChild();
while (node != null) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
UAElement uaElement = UAElementFactory.newElement((Element)node);
UAElement uaElement = UAElementFactory.newElement((Element) node);
if (uaElement != null) {
uaElement.parent = this;
children.add(uaElement);
Expand All @@ -196,8 +199,7 @@ public <T> T[] getChildren(Class<T> clazz) {
IUAElement[] children = getChildren();
if (children.length > 0) {
List<Object> list = new ArrayList<>();
for (int i=0;i<children.length;++i) {
IUAElement child = children[i];
for (IUAElement child : children) {
if (clazz.isAssignableFrom(child.getClass())) {
list.add(child);
}
Expand Down Expand Up @@ -256,8 +258,8 @@ public boolean isEnabled(IEvaluationContext context) {
return isEnabledByFilterAttribute(filter);
}
Filter[] filterElements = getFilterElements();
for (int i = 0; i < filterElements.length; i++) {
if (!isFilterEnabled(filterElements[i])) {
for (Filter filterElement : filterElements) {
if (!isFilterEnabled(filterElement)) {
return false;
}
}
Expand Down Expand Up @@ -291,12 +293,12 @@ public void setAttribute(String name, String value) {
private void importElement(UAElement uaElementToImport) {
Element elementToImport = uaElementToImport.element;
Document ownerDocument = element.getOwnerDocument();
if (!ownerDocument.equals(elementToImport.getOwnerDocument()) ) {
elementToImport = (Element)ownerDocument.importNode(elementToImport, true);
if (!ownerDocument.equals(elementToImport.getOwnerDocument())) {
elementToImport = (Element) ownerDocument.importNode(elementToImport, true);
uaElementToImport.children = null;
} else {
} else {
if (elementToImport.getParentNode() != null) {
elementToImport = (Element)ownerDocument.importNode(elementToImport, true);
elementToImport = (Element) ownerDocument.importNode(elementToImport, true);
uaElementToImport.children = null;
} else {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class UAElementFactory {
{ ICriteria.class, Criteria.class },
{ ICriteriaDefinition.class, CriteriaDefinition.class },
{ ICriterionDefinition.class, CriterionDefinition.class },
{ ICriterionValueDefinition.class, CriterionValueDefinition.class },
{ ICriterionValueDefinition.class, CriterionValueDefinition.class }
};

private static final Map<String, Class<?>> classByElementName;
Expand Down Expand Up @@ -119,9 +119,9 @@ public static UAElement newElement(Element element) {
}

public static UAElement newElement(IUAElement src) {
for (int i=0;i<interfaceTable.length;++i) {
Class<?> interfaze = interfaceTable[i][0];
Class<?> clazz = interfaceTable[i][1];
for (Class<?>[] element : interfaceTable) {
Class<?> interfaze = element[0];
Class<?> clazz = element[1];
if (interfaze.isAssignableFrom(src.getClass())) {
try {
Constructor<?> constructor = clazz.getConstructor(interfaze);
Expand All @@ -132,6 +132,9 @@ public static UAElement newElement(IUAElement src) {
ILog.of(UAContentFilter.class).error(msg, e);
}
}
if (src instanceof UAElement uaElement) {
return new UAElement(uaElement.getElementName(), uaElement);
}
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ public void testCopyTopicWithChild() {
assertThat(topic2.getSubtopics()).hasSize(1);
}

/*
* Disabled, see Bug 210024 [Help] Topic element problems constructing from an ITopic
@Test
public void testCopyTopicWithChildRemoveChild() {
Topic topic1;
topic1 = createTopic(TOPIC_WITH_CHILD);
Expand All @@ -142,14 +141,12 @@ public void testCopyTopicWithChildRemoveChild() {
assertEquals(0, topic1.getSubtopics().length);
assertEquals(1, topic2.getSubtopics().length);
}
*/

/*
* Test the assumption that when a topic is created from another topic not only
* the topic but all the children are recursively copied
*/
/*
* Disabled, see Bug 210024 [Help] Topic element problems constructing from an ITopic
@Test
public void testCopyTopicWithChildCheckParents() {
Topic topic1;
topic1 = createTopic(TOPIC_WITH_CHILD);
Expand All @@ -158,14 +155,14 @@ public void testCopyTopicWithChildCheckParents() {
assertEquals(ECLIPSE_HREF, topic1.getHref());
assertEquals(1, topic1.getSubtopics().length);
Topic child1 = (Topic)topic1.getSubtopics()[0];
assertTrue(child1.getParentElement() == topic1);
assertEquals(child1.getParentElement(), topic1);
assertEquals(ECLIPSE, topic2.getLabel());
assertEquals(ECLIPSE_HREF, topic2.getHref());
assertEquals(1, topic2.getSubtopics().length);
Topic child2 = (Topic)topic1.getSubtopics()[0];
assertTrue(child2.getParentElement() == topic2);
Topic child2 = (Topic) topic2.getSubtopics()[0];
assertEquals(child2.getParentElement(), topic2);
}
*/

@Test
public void testEnabledTopic() {
Topic topic = createTopic(TOPIC_WITH_ENABLEMENT);
Expand Down
Loading