Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2012-04-19 18:30:19 -0400
committerAlexander Kurtakov2012-04-19 18:30:19 -0400
commitbc3d823a422f95921155c07616d5675d60466532 (patch)
tree572e2850fff50e9c7abd4caa954ed5b207824d19 /libhover
parentb15459e5f9da531eca4ecd18804cc7bf6be0eba4 (diff)
downloadorg.eclipse.linuxtools-bc3d823a422f95921155c07616d5675d60466532.tar.gz
org.eclipse.linuxtools-bc3d823a422f95921155c07616d5675d60466532.tar.xz
org.eclipse.linuxtools-bc3d823a422f95921155c07616d5675d60466532.zip
Create full toc.
The toc is recursively created now by parsing the devhelp2 files and using the sub elements to make topics for.
Diffstat (limited to 'libhover')
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/DevHelpTopic.java36
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/SimpleTopic.java101
2 files changed, 131 insertions, 6 deletions
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/DevHelpTopic.java b/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/DevHelpTopic.java
index 77705b3280..16345f5c21 100644
--- a/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/DevHelpTopic.java
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/DevHelpTopic.java
@@ -12,11 +12,14 @@ package org.eclipse.linuxtools.internal.cdt.libhover.devhelp;
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
@@ -29,6 +32,8 @@ import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.linuxtools.cdt.libhover.devhelp.DevHelpPlugin;
import org.eclipse.linuxtools.internal.cdt.libhover.devhelp.preferences.PreferenceConstants;
import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class DevHelpTopic implements ITopic {
@@ -36,10 +41,13 @@ public class DevHelpTopic implements ITopic {
private String name;
private XPath xpath;
private String label;
+ private List<ITopic> subTopics;
DevHelpTopic(String name) {
this.name = name;
xpath = XPathFactory.newInstance().newXPath();
+ subTopics = new ArrayList<ITopic>();
+ label = name;
init();
}
@@ -69,11 +77,19 @@ public class DevHelpTopic implements ITopic {
DocumentBuilder docbuilder = docfactory.newDocumentBuilder();
Document docroot = docbuilder.parse(devhelpLocation.toFile());
-
+
+ // set label
label = xpathEval("/book/@title", docroot);
if (label.equals("")) {
label = name;
}
+
+ // set subtopics
+ NodeList nodes = xpathEvalNodes("/book/chapters/sub", docroot);
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node node = nodes.item(i);
+ subTopics.add(new SimpleTopic(name, node));
+ }
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
@@ -81,10 +97,7 @@ public class DevHelpTopic implements ITopic {
} catch (IOException e) {
e.printStackTrace();
}
- } else {
- label = name;
}
-
}
private String xpathEval(String path, Document docroot) {
@@ -97,6 +110,17 @@ public class DevHelpTopic implements ITopic {
return result;
}
+ private NodeList xpathEvalNodes(String path, Document docroot) {
+ NodeList result = null;
+ try {
+ result = (NodeList) xpath.evaluate(path, docroot,
+ XPathConstants.NODESET);
+ } catch (XPathExpressionException e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+
@Override
public boolean isEnabled(IEvaluationContext context) {
return true;
@@ -104,7 +128,7 @@ public class DevHelpTopic implements ITopic {
@Override
public IUAElement[] getChildren() {
- return new IUAElement[0];
+ return getSubtopics();
}
@Override
@@ -120,6 +144,6 @@ public class DevHelpTopic implements ITopic {
@Override
public ITopic[] getSubtopics() {
- return null;
+ return subTopics.toArray(new ITopic[subTopics.size()]);
}
} \ No newline at end of file
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/SimpleTopic.java b/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/SimpleTopic.java
new file mode 100644
index 0000000000..bb66af9783
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/SimpleTopic.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexander Kurtakov - Initial implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.cdt.libhover.devhelp;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.help.ITopic;
+import org.eclipse.help.IUAElement;
+import org.eclipse.linuxtools.cdt.libhover.devhelp.DevHelpPlugin;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class SimpleTopic implements ITopic {
+
+ private String bookName;
+ private Node node;
+ private XPath xpath;
+ private List<ITopic> subTopics;
+
+ public SimpleTopic(String bookName, Node node) {
+ this.bookName = bookName;
+ this.node = node;
+ xpath = XPathFactory.newInstance().newXPath();
+ subTopics = new ArrayList<ITopic>();
+ initSubtopics();
+ }
+
+ private void initSubtopics() {
+ NodeList nodes = xpathEvalNodes("sub", node);
+ if (nodes != null) {
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node innerNode = nodes.item(i);
+ subTopics.add(new SimpleTopic(bookName, innerNode));
+ }
+ }
+
+ }
+
+ private NodeList xpathEvalNodes(String path, Node docroot) {
+ NodeList result = null;
+ try {
+ result = (NodeList) xpath.evaluate(path, docroot,
+ XPathConstants.NODESET);
+ } catch (XPathExpressionException e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+
+ @Override
+ public boolean isEnabled(IEvaluationContext context) {
+ return true;
+ }
+
+ @Override
+ public IUAElement[] getChildren() {
+ return getSubtopics();
+ }
+
+ @Override
+ public String getHref() {
+ String link = "";
+ try {
+ link = xpath.evaluate("@link", node);
+ } catch (XPathExpressionException e) {
+ e.printStackTrace();
+ }
+ return "/" + DevHelpPlugin.PLUGIN_ID + "/" + bookName + "/" + link;
+ }
+
+ @Override
+ public String getLabel() {
+ try {
+ return xpath.evaluate("@name", node);
+ } catch (XPathExpressionException e) {
+ e.printStackTrace();
+ }
+ return "";
+ }
+
+ @Override
+ public ITopic[] getSubtopics() {
+ return subTopics.toArray(new ITopic[subTopics.size()]);
+ }
+
+}

Back to the top