diff options
author | Alexander Kurtakov | 2012-04-19 20:58:16 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2012-04-19 20:58:16 +0000 |
commit | b15459e5f9da531eca4ecd18804cc7bf6be0eba4 (patch) | |
tree | 888fda4ee6be9878d6bd915fee7b07612b6a977f | |
parent | ad4735fb7d4d0987c2c2adef61346715d5bfe572 (diff) | |
download | org.eclipse.linuxtools-b15459e5f9da531eca4ecd18804cc7bf6be0eba4.tar.gz org.eclipse.linuxtools-b15459e5f9da531eca4ecd18804cc7bf6be0eba4.tar.xz org.eclipse.linuxtools-b15459e5f9da531eca4ecd18804cc7bf6be0eba4.zip |
Use title from the devhelp2 file.
It is way more informative than the directory name.
-rw-r--r-- | libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/DevHelpTopic.java | 76 |
1 files changed, 75 insertions, 1 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 ea1406128d..77705b3280 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 @@ -10,17 +10,91 @@ *******************************************************************************/ package org.eclipse.linuxtools.internal.cdt.libhover.devhelp; +import java.io.File; +import java.io.IOException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; import org.eclipse.help.ITopic; import org.eclipse.help.IUAElement; +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.xml.sax.SAXException; public class DevHelpTopic implements ITopic { private String name; + private XPath xpath; + private String label; DevHelpTopic(String name) { this.name = name; + xpath = XPathFactory.newInstance().newXPath(); + init(); + } + + private void init() { + IPreferenceStore ps = DevHelpPlugin.getDefault().getPreferenceStore(); + IPath devhelpLocation = new Path( + ps.getString(PreferenceConstants.DEVHELP_DIRECTORY)).append( + name).append(name + ".devhelp2"); + File devhelpFile = devhelpLocation.toFile(); + if (devhelpFile.exists()) { + DocumentBuilderFactory docfactory = DocumentBuilderFactory + .newInstance(); + docfactory.setValidating(false); + try { + docfactory.setFeature("http://xml.org/sax/features/namespaces", + false); + docfactory.setFeature("http://xml.org/sax/features/validation", + false); + docfactory + .setFeature( + "http://apache.org/xml/features/nonvalidating/load-dtd-grammar", + false); + docfactory + .setFeature( + "http://apache.org/xml/features/nonvalidating/load-external-dtd", + false); + + DocumentBuilder docbuilder = docfactory.newDocumentBuilder(); + Document docroot = docbuilder.parse(devhelpLocation.toFile()); + + label = xpathEval("/book/@title", docroot); + if (label.equals("")) { + label = name; + } + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } catch (SAXException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + label = name; + } + + } + + private String xpathEval(String path, Document docroot) { + String result = ""; + try { + result = xpath.evaluate(path, docroot); + } catch (XPathExpressionException e) { + e.printStackTrace(); + } + return result; } @Override @@ -41,7 +115,7 @@ public class DevHelpTopic implements ITopic { @Override public String getLabel() { - return name; + return label; } @Override |