JTidy integration
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / actions / HTMLParserAction.java
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/HTMLParserAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/HTMLParserAction.java
new file mode 100644 (file)
index 0000000..d55087d
--- /dev/null
@@ -0,0 +1,100 @@
+/**********************************************************************
+Copyright (c) 2000, 2002 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+    IBM Corporation - Initial implementation
+    Klaus Hartlage - www.eclipseproject.de
+**********************************************************************/
+package net.sourceforge.phpeclipse.actions;
+
+import java.io.InputStream;
+import java.util.Iterator;
+
+import net.sourceforge.phpeclipse.phpeditor.phpparser.PHPParser;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.w3c.tidy.Configuration;
+import org.w3c.tidy.Tidy;
+
+public class HTMLParserAction implements IObjectActionDelegate {
+
+  private IWorkbenchPart workbenchPart;
+  /**
+   * Constructor for Action1.
+   */
+  public HTMLParserAction() {
+    super();
+  }
+
+  /**
+   * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
+   */
+  public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+    workbenchPart = targetPart;
+  }
+
+  //  public static void open(final URL url, final Shell shell, final String dialogTitle) {
+  //    IHelp help= WorkbenchHelp.getHelpSupport();
+  //    if (help != null) {
+  //      WorkbenchHelp.getHelpSupport().displayHelpResource(url.toExternalForm());
+  //    } else {
+  //      showMessage(shell, dialogTitle, ActionMessages.getString("OpenBrowserUtil.help_not_available"), false); //$NON-NLS-1$
+  //    }
+  //  }
+
+  public void run(IAction action) {
+    Tidy tidy = new Tidy();
+    Configuration conf = tidy.getConfiguration();
+    
+    ISelectionProvider selectionProvider = null;
+    selectionProvider = workbenchPart.getSite().getSelectionProvider();
+
+    StructuredSelection selection = null;
+    selection = (StructuredSelection) selectionProvider.getSelection();
+
+    //Shell shell = null;
+    Iterator iterator = null;
+    iterator = selection.iterator();
+    while (iterator.hasNext()) {
+      //  obj => selected object in the view
+      Object obj = iterator.next();
+
+      // is it a resource
+      if (obj instanceof IResource) {
+        IResource resource = (IResource) obj;
+
+        // check if it's a file resource
+        switch (resource.getType()) {
+
+          case IResource.FILE :
+            // single file:
+            IFile file = (IFile) resource;
+            InputStream in;
+            try {
+              in = file.getContents();
+              tidy.parse(file, in, null);
+            } catch (CoreException e) {
+            }
+        }
+      }
+    }
+  }
+
+  /**
+   * @see IActionDelegate#selectionChanged(IAction, ISelection)
+   */
+  public void selectionChanged(IAction action, ISelection selection) {
+  }
+
+}