Blob Blame History Raw
--- com.redhat.eclipse.cdt.autotools/src/com/redhat/eclipse/cdt/autotools/ui/LibHover.java.fix	2006-08-02 13:34:36.000000000 -0400
+++ com.redhat.eclipse.cdt.autotools/src/com/redhat/eclipse/cdt/autotools/ui/LibHover.java	2006-08-02 13:34:57.000000000 -0400
@@ -15,40 +15,45 @@
 
 package com.redhat.eclipse.cdt.autotools.ui;
 
-import java.util.*;
-import java.net.URL;
-import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-import org.w3c.dom.*;
-
-import org.eclipse.core.runtime.*;
-import com.redhat.eclipse.cdt.autotools.AutotoolsPlugin;
-import org.eclipse.cdt.ui.ICHelpProvider;
-import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
+import org.eclipse.cdt.ui.CUIPlugin;
 import org.eclipse.cdt.ui.ICHelpBook;
+import org.eclipse.cdt.ui.ICHelpProvider;
 import org.eclipse.cdt.ui.ICHelpResourceDescriptor;
 import org.eclipse.cdt.ui.IFunctionSummary;
 import org.eclipse.cdt.ui.IRequiredInclude;
+import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Plugin;
 import org.eclipse.help.IHelpResource;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import com.redhat.eclipse.cdt.autotools.AutotoolsPlugin;
 
 public class LibHover implements ICHelpProvider {
 	
     private static Plugin plugin;
-    private static String docsRootPath = null;
 
     // see comment in initialize()
     // private static String defaultSearchPath = null;
     
     private static Document document;
-    private static String oldpath = null;static final String  constructTypes[] ={
+    static final String  constructTypes[] ={
             "dtype",
 	        "enum",
 	        "function",
@@ -63,70 +68,39 @@ public class LibHover implements ICHelpP
 	    static final int typeIndex          = 4;
 	    static final int unionIndex         = 5;
 
-    private Document getDocument(String path, String name) {
-        Document doc = null;
-
-        String userHome = System.getProperty("user.home");
-        String userDir  = System.getProperty("user.dir");
-
-        if ((null == oldpath) || !oldpath.equals(path)) {
-            StringTokenizer dirs = new StringTokenizer(path, ":", false);
-
-            while((null == doc) && dirs.hasMoreTokens()) {
-                String dir =  dirs.nextToken();
-                if ((null != userHome) && dir.startsWith("~")) {
-                    dir = dir.replaceFirst("~", userHome);
-                }
-                else if ((null != userDir) && dir.startsWith(".")) {
-                    dir = dir.replaceFirst(".", userDir);
-                }
-                else if ((null != docsRootPath) && dir.startsWith("!")) {
-                    dir = dir.replaceFirst("!", docsRootPath);
-                }
-
-                if (!dir.endsWith("/")) dir = dir.concat("/");
-
-                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-                factory.setValidating(true);
-                try {
-                    DocumentBuilder builder = factory.newDocumentBuilder();
-//                    builder.setErrorHandler(new TextHoverErrorHandler());
-                    doc = builder.parse( new File(dir + name) );
-                }
-                catch (SAXParseException saxException) {
-                    doc = null;
-                }
-                catch (SAXException saxEx) {
-                    doc = null;
-                }
-                catch (ParserConfigurationException pce) {
-                    doc = null;
-                }
-                catch (IOException ioe) {
-                    doc = null;
-                }
-            }
-            oldpath = path;
-        }
-
-        return doc;
-    }
-    
-	public void buildDocPath(String root, String path) {
+     
+	public void getLibHoverDocs() {
 		if (null != plugin) {
-			URL homeURL = plugin.find(new Path("."));
+			Document doc = null;
 			try {
-				homeURL = Platform.asLocalURL(homeURL);
-				IPath topPath = (new Path(homeURL.getPath())).removeLastSegments(1);
-				IPath homePath = topPath;
-				if (null != root) homePath = homePath.append(root);
-				if (null != path) homePath = homePath.append(path);
-				homePath = homePath.addTrailingSeparator();
-				docsRootPath = homePath.toOSString();
-
 				// see comment in initialize()
-				// document = getDocument(((null == defaultSearchPath) ? "!" : defaultSearchPath), "glibc.xml");
-				document = getDocument("./libhoverdocs:~/libhoverdocs:/usr/share/eclipse/libhoverdocs:!", "glibc.xml");
+				try {
+					// Use the FileLocator class to open the magic hover doc file
+					// in the plugin's jar.
+					Path p = new Path("libhoverdocs/glibc.xml"); //$NON-NLS-1$
+					InputStream docStream = FileLocator.openStream(AutotoolsPlugin.getDefault().getBundle(), p, false);
+					DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+					factory.setValidating(true);
+					try {
+						DocumentBuilder builder = factory.newDocumentBuilder();
+						doc = builder.parse(docStream);
+					}
+					catch (SAXParseException saxException) {
+						doc = null;
+					}
+					catch (SAXException saxEx) {
+						doc = null;
+					}
+					catch (ParserConfigurationException pce) {
+						doc = null;
+					}
+					catch (IOException ioe) {
+						doc = null;
+					}
+				} catch (MalformedURLException e) {
+					CUIPlugin.getDefault().log(e);
+				}
+				document = doc;
 			}
 			catch (IOException ioe) {
 			}
@@ -135,26 +109,7 @@ public class LibHover implements ICHelpP
 	
 	public void initialize() {
 		plugin = (Plugin)AutotoolsPlugin.getDefault();
-
-		// the getAttribute() isn't working right -- it gets ghost attrs from somwhere rather than from the current fragment.xml --
-		// so to hell with it for the moment.
-		//
-		// String libhoverdocsroot = null;
-		// String libhoverdocspath = null;
-		// IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID,
-		//										   "CCompletionContributor"); //$NON-NLS-1$
-		// if (extensionPoint != null) {
-		// 	IConfigurationElement[] elements = extensionPoint.getConfigurationElements();
-		// 	for (int i = 0; i < elements.length; i++) {
-		// 		libhoverdocsroot  = elements[i].getAttribute("libhoverdocsroot");
-		// 		libhoverdocspath  = elements[i].getAttribute("libhoverdocspath");
-		//		defaultSearchPath = elements[i].getAttribute("defaultsearchpath");
-		//	}
-		// }
-		// buildDocPath(libhoverdocsroot,libhoverdocspath);
-		//
-		// use the following, pro-tem, instead
-		buildDocPath("com.redhat.eclipse.cdt.autotools", "libhoverdocs");
+		getLibHoverDocs();
 	}
 	
 	private class HelpBook implements ICHelpBook {