Initial import of the phpmanual plugin
authorscorphus <scorphus>
Tue, 20 Nov 2007 01:53:37 +0000 (01:53 +0000)
committerscorphus <scorphus>
Tue, 20 Nov 2007 01:53:37 +0000 (01:53 +0000)
net.sourceforge.phpeclipse.phpmanual/.classpath [new file with mode: 0644]
net.sourceforge.phpeclipse.phpmanual/.project [new file with mode: 0644]
net.sourceforge.phpeclipse.phpmanual/META-INF/MANIFEST.MF [new file with mode: 0644]
net.sourceforge.phpeclipse.phpmanual/build.properties [new file with mode: 0644]
net.sourceforge.phpeclipse.phpmanual/icons/phpmanual.png [new file with mode: 0644]
net.sourceforge.phpeclipse.phpmanual/plugin.properties [new file with mode: 0644]
net.sourceforge.phpeclipse.phpmanual/plugin.xml [new file with mode: 0644]
net.sourceforge.phpeclipse.phpmanual/src/net/sourceforge/phpeclipse/phpmanual/PHPManualUIPlugin.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phpmanual/src/net/sourceforge/phpeclipse/phpmanual/views/PHPManualView.java [new file with mode: 0644]
net.sourceforge.phpeclipse.phpmanual/templates/refpage.html [new file with mode: 0644]

diff --git a/net.sourceforge.phpeclipse.phpmanual/.classpath b/net.sourceforge.phpeclipse.phpmanual/.classpath
new file mode 100644 (file)
index 0000000..751c8f2
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/net.sourceforge.phpeclipse.phpmanual/.project b/net.sourceforge.phpeclipse.phpmanual/.project
new file mode 100644 (file)
index 0000000..6c598df
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>net.sourceforge.phpeclipse.phpmanual</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.ManifestBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.SchemaBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
diff --git a/net.sourceforge.phpeclipse.phpmanual/META-INF/MANIFEST.MF b/net.sourceforge.phpeclipse.phpmanual/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..e8aa1da
--- /dev/null
@@ -0,0 +1,17 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: net.sourceforge.phpeclipse.phpmanual; singleton:=true
+Bundle-Version: 0.0.0
+Bundle-Activator: net.sourceforge.phpeclipse.phpmanual.PHPManualUIPlugin
+Bundle-Vendor: %providerName
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.jface.text,
+ org.eclipse.ui,
+ org.eclipse.ui.editors,
+ org.eclipse.ui.workbench.texteditor,
+ net.sourceforge.phpeclipse,
+ net.sourceforge.phpeclipse.phphelp,
+ net.sourceforge.phpeclipse.phpmanual.htmlparser
+Eclipse-LazyStart: true
diff --git a/net.sourceforge.phpeclipse.phpmanual/build.properties b/net.sourceforge.phpeclipse.phpmanual/build.properties
new file mode 100644 (file)
index 0000000..0d3d3a7
--- /dev/null
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = plugin.xml,\
+               META-INF/,\
+               .,\
+               icons/
diff --git a/net.sourceforge.phpeclipse.phpmanual/icons/phpmanual.png b/net.sourceforge.phpeclipse.phpmanual/icons/phpmanual.png
new file mode 100644 (file)
index 0000000..9159c3d
Binary files /dev/null and b/net.sourceforge.phpeclipse.phpmanual/icons/phpmanual.png differ
diff --git a/net.sourceforge.phpeclipse.phpmanual/plugin.properties b/net.sourceforge.phpeclipse.phpmanual/plugin.properties
new file mode 100644 (file)
index 0000000..84f29a9
--- /dev/null
@@ -0,0 +1,7 @@
+#########################################
+#
+#########################################
+pluginName=PHP Manual
+providerName=PHPEclipse project team
+viewCategoryName=PHPeclipse Web Development
+phpManualViewName=PHP Manual
diff --git a/net.sourceforge.phpeclipse.phpmanual/plugin.xml b/net.sourceforge.phpeclipse.phpmanual/plugin.xml
new file mode 100644 (file)
index 0000000..526f24f
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+
+   <extension
+         point="org.eclipse.ui.views">
+      <category
+            name="%viewCategoryName"
+            id="net.sourceforge.phpeclipse.views.category">
+      </category>
+      <view
+            name="%phpManualViewName"
+            icon="icons/phpmanual.png"
+            category="net.sourceforge.phpeclipse.views.category"
+            class="net.sourceforge.phpeclipse.phpmanual.views.PHPManualView"
+            id="net.sourceforge.phpeclipse.phpmanual.views.PHPManualViewz">
+      </view>
+   </extension>
+   <extension
+         point="org.eclipse.ui.perspectiveExtensions">
+      <perspectiveExtension
+            targetID="org.eclipse.ui.resourcePerspective">
+         <view
+               ratio="0.5"
+               relative="org.eclipse.ui.views.TaskList"
+               relationship="right"
+               id="net.sourceforge.phpeclipse.phpmanual.views.PHPManualView">
+         </view>
+      </perspectiveExtension>
+   </extension>
+
+</plugin>
diff --git a/net.sourceforge.phpeclipse.phpmanual/src/net/sourceforge/phpeclipse/phpmanual/PHPManualUIPlugin.java b/net.sourceforge.phpeclipse.phpmanual/src/net/sourceforge/phpeclipse/phpmanual/PHPManualUIPlugin.java
new file mode 100644 (file)
index 0000000..81e4e8b
--- /dev/null
@@ -0,0 +1,61 @@
+package net.sourceforge.phpeclipse.phpmanual;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class PHPManualUIPlugin extends AbstractUIPlugin {
+
+       // The plug-in ID
+       public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.phpmanual";
+
+       // The shared instance
+       private static PHPManualUIPlugin plugin;
+       
+       /**
+        * The constructor
+        */
+       public PHPManualUIPlugin() {
+               plugin = this;
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+        */
+       public void start(BundleContext context) throws Exception {
+               super.start(context);
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+        */
+       public void stop(BundleContext context) throws Exception {
+               plugin = null;
+               super.stop(context);
+       }
+
+       /**
+        * Returns the shared instance
+        *
+        * @return the shared instance
+        */
+       public static PHPManualUIPlugin getDefault() {
+               return plugin;
+       }
+
+       /**
+        * Returns an image descriptor for the image file at the given
+        * plug-in relative path
+        *
+        * @param path the path
+        * @return the image descriptor
+        */
+       public static ImageDescriptor getImageDescriptor(String path) {
+               return imageDescriptorFromPlugin(PLUGIN_ID, path);
+       }
+}
diff --git a/net.sourceforge.phpeclipse.phpmanual/src/net/sourceforge/phpeclipse/phpmanual/views/PHPManualView.java b/net.sourceforge.phpeclipse.phpmanual/src/net/sourceforge/phpeclipse/phpmanual/views/PHPManualView.java
new file mode 100644 (file)
index 0000000..fe2cace
--- /dev/null
@@ -0,0 +1,319 @@
+package net.sourceforge.phpeclipse.phpmanual.views;
+
+
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import net.sourceforge.phpdt.internal.ui.text.JavaWordFinder;
+import net.sourceforge.phpdt.internal.ui.viewsupport.ISelectionListenerWithAST;
+import net.sourceforge.phpdt.internal.ui.viewsupport.SelectionListenerWithASTManager;
+import net.sourceforge.phpdt.phphelp.PHPHelpPlugin;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
+import net.sourceforge.phpeclipse.phpmanual.PHPManualUIPlugin;
+
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.ViewPart;
+import org.htmlparser.Node;
+import org.htmlparser.Parser;
+import org.htmlparser.tags.Div;
+import org.htmlparser.util.ParserException;
+import org.htmlparser.visitors.TagFindingVisitor;
+import org.osgi.framework.Bundle;
+
+/**
+ * This sample class demonstrates how to plug-in a new
+ * workbench view. The view shows data obtained from the
+ * model. The sample creates a dummy model on the fly,
+ * but a real implementation would connect to the model
+ * available either in this or another plug-in (e.g. the workspace).
+ * The view is connected to the model using a content provider.
+ * <p>
+ * The view uses a label provider to define how model
+ * objects should be presented in the view. Each
+ * view can present the same model objects using
+ * different labels and icons, if needed. Alternatively,
+ * a single label provider can be shared between views
+ * in order to ensure that objects of the same type are
+ * presented in the same way everywhere.
+ * <p>
+ */
+
+public class PHPManualView extends ViewPart implements ISelectionListenerWithAST {
+       private Browser browser;
+       private Action action1;
+       private Action action2;
+       private PHPEditor phpEditor;
+       private final Path docPath = new Path("doc.zip"); 
+
+       /**
+        * The constructor.
+        */
+       public PHPManualView() {
+       }
+
+       /**
+        * This is a callback that will allow us
+        * to create the viewer and initialize it.
+        */
+       public void createPartControl(Composite parent) {
+               browser = new Browser(parent, SWT.NONE);
+               parent.pack();
+               phpEditor = getJavaEditor();
+               makeActions();
+               hookContextMenu();
+               SelectionListenerWithASTManager.getDefault().addListener(phpEditor, this);
+               if (phpEditor.getSelectionProvider() != null) {
+                       ISelection its = phpEditor.getSelectionProvider().getSelection();
+                       SelectionListenerWithASTManager.getDefault().forceSelectionChange(
+                                       phpEditor, (ITextSelection) its);
+               }
+       }
+
+       /* (non-Javadoc)
+        * @see net.sourceforge.phpdt.internal.ui.viewsupport.ISelectionListenerWithAST#selectionChanged()
+        */
+       public void selectionChanged(IEditorPart part, ITextSelection selection) {
+               if (getJavaEditor() != null) {
+                       phpEditor = getJavaEditor();
+               }
+               IDocument document = phpEditor.getViewer().getDocument();
+               int offset = selection.getOffset();
+               IRegion iRegion = JavaWordFinder.findWord(document, offset);
+               try {
+                       final String wordStr = document.get(iRegion.getOffset(),
+                                       iRegion.getLength());
+                       showReference(wordStr);
+               } catch (Exception e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+       }
+
+       private void showReference(final String occurrence) {
+               System.out.println("Show reference for " + occurrence);
+               new Thread(new Runnable() {
+                       public void run() {
+                               Display.getDefault().asyncExec(new Runnable() {
+                                       public void run() {
+                                               String html = getHtmlSource(occurrence);
+                                               browser.setText(html);
+                                       }
+                               });
+                       }
+               }).start();
+       }
+
+       private void hookContextMenu() {
+               MenuManager menuMgr = new MenuManager("#PopupMenu");
+               menuMgr.setRemoveAllWhenShown(true);
+               menuMgr.addMenuListener(new IMenuListener() {
+                       public void menuAboutToShow(IMenuManager manager) {
+                               PHPManualView.this.fillContextMenu(manager);
+                       }
+               });
+//             Menu menu = menuMgr.createContextMenu(viewer.getControl());
+//             viewer.getControl().setMenu(menu);
+//             getSite().registerContextMenu(menuMgr, viewer);
+       }
+
+       private void fillContextMenu(IMenuManager manager) {
+               manager.add(action1);
+               manager.add(action2);
+               // Other plug-ins can contribute there actions here
+               manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+       }
+
+       private void makeActions() {
+               action1 = new Action() {
+                       public void run() {
+                               showMessage("Action 1 executed");
+                       }
+               };
+               action1.setText("Action 1");
+               action1.setToolTipText("Action 1 tooltip");
+               action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+                       getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
+               
+               action2 = new Action() {
+                       public void run() {
+                               showMessage("Action 2 executed");
+                       }
+               };
+               action2.setText("Action 2");
+               action2.setToolTipText("Action 2 tooltip");
+               action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+                               getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
+       }
+
+       private void showMessage(String message) {
+//             MessageDialog.openInformation(
+//                     viewer.getControl().getShell(),
+//                     "%phpManualView",
+//                     message);
+       }
+
+       /**
+        * Looks for the function's reference page inside the doc.zip file and
+        * returns a filtered HTML source of it
+        * @param funcName Function name
+        * @return HTML source of reference page
+        */
+       private String filterHtmlSource(String source) {
+               try {
+                       Parser parser = new Parser(source);
+                       String [] tagsToBeFound = {"DIV"};
+                       ArrayList<String> classList = new ArrayList<String>(6);
+                       classList.add("refnamediv");
+                       classList.add("refsect1 description");
+                       classList.add("refsect1 parameters");
+                       classList.add("refsect1 returnvalues");
+                       classList.add("refsect1 examples");
+                       classList.add("refsect1 seealso");
+                       classList.add("refsect1 u");
+                       TagFindingVisitor visitor = new TagFindingVisitor(tagsToBeFound);
+                       parser.visitAllNodesWith(visitor);
+                       Node [] allPTags = visitor.getTags(0);
+                       StringBuilder output = new StringBuilder();
+                       for (int i = 0; i < allPTags.length; i++) {
+                               String tagClass = ((Div)allPTags[i]).getAttribute("class");
+                               if (classList.contains(tagClass)) {
+                                       output.append(allPTags[i].toHtml());
+                               }
+                       }
+                       return output.toString().replace("—", "-");
+                       //.replace("<h3 class=\"title\">Description</h3>", " ");
+               } catch (ParserException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+               return "";
+       }
+
+       /**
+        * Looks for the function's reference page inside the doc.zip file and
+        * returns a filtered HTML source of it
+        * @param funcName Function name
+        * @return HTML source of reference page
+        */
+       public String getRefPageTemplate() {
+               Bundle bundle = Platform.getBundle(PHPManualUIPlugin.PLUGIN_ID);
+               URL fileURL = Platform.find(bundle, new Path("templates"));
+               StringBuffer contents = new StringBuffer();
+               BufferedReader input = null;
+               try {
+                       URL resolve = Platform.resolve(fileURL);
+                       input = new BufferedReader(new FileReader(resolve.getPath()+"/refpage.html"));
+                       String line = null;
+                       while ((line = input.readLine()) != null){
+                               contents.append(line);
+                       }
+               }
+               catch (FileNotFoundException e) {
+                       e.printStackTrace();
+               } catch (IOException e) {
+                       e.printStackTrace();
+               }
+               finally {
+                       try {
+                               if (input!= null) {
+                                       input.close();
+                               }
+                       }
+                       catch (IOException ex) {
+                               ex.printStackTrace();
+                       }
+               }
+               return contents.toString();
+       }
+
+       /**
+        * Looks for the function's reference page inside the doc.zip file and
+        * returns a filtered HTML source of it
+        * @param funcName Function name
+        * @return HTML source of reference page
+        */
+       public String getHtmlSource(String funcName) {
+               Bundle bundle = Platform.getBundle(PHPHelpPlugin.PLUGIN_ID);
+               URL fileURL = Platform.find(bundle, docPath);
+               byte[] b = null;
+               try {
+                       URL resolve = Platform.resolve(fileURL);
+                       ZipFile docFile = new ZipFile(resolve.getPath());
+                       ZipEntry entry = docFile.getEntry("doc/function."+funcName.replace('_', '-')+".html");
+                       InputStream ref = docFile.getInputStream(entry);
+                       b = new byte[(int)entry.getSize()];
+                       ref.read(b, 0, (int)entry.getSize());
+               } catch (IOException e) {
+                       return "<html></html>";
+               }
+               if (b != null) {
+                       String reference = filterHtmlSource(new String(b));
+                       String refPageTpl = getRefPageTemplate();
+                       refPageTpl = refPageTpl.replace("{title}", funcName);
+                       refPageTpl = refPageTpl.replace("{reference}", reference);
+                       return refPageTpl;
+               }
+               return "<html></html>";
+       }
+
+       /**
+        * Passing the focus request to the viewer's control.
+        */
+       public void setFocus() {
+//             viewer.getControl().setFocus();
+       }
+
+       /**
+        * Returns the currently active java editor, or <code>null</code> if it
+        * cannot be determined.
+        * 
+        * @return the currently active java editor, or <code>null</code>
+        */
+       private PHPEditor getJavaEditor() {
+               try {
+                       IEditorPart part = PHPeclipsePlugin.getActivePage().getActiveEditor();
+                       if (part instanceof PHPEditor)
+                               return (PHPEditor) part;
+                       else
+                               return null;
+               } catch (Exception e) {
+                       e.printStackTrace();
+                       return null;
+               }
+       }
+
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.phpmanual/templates/refpage.html b/net.sourceforge.phpeclipse.phpmanual/templates/refpage.html
new file mode 100644 (file)
index 0000000..67bf007
--- /dev/null
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<title>{title}</title>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+<style>
+body {
+       background-color: #F5F5B5;
+       padding: 0px 0px 0px 0px;
+       margin: 0px 0px 0px 0px;
+}
+body, h1, h2, h3, h4, p, div code, pre {
+       font-size: small;
+}
+p, div, h1, h2 {
+       padding: 0px 0px 0px 0px;
+       margin: 5px 1px 1px 1px;
+}
+</style>
+</head>
+<body>
+{reference}
+</body>
+</html>
\ No newline at end of file