1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 IBM Corporation - Initial implementation
10 Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpeclipse.actions;
14 import java.io.InputStream;
15 import java.util.Iterator;
17 import net.sourceforge.phpeclipse.phpeditor.phpparser.PHPParser;
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.core.resources.IResource;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.jface.action.IAction;
22 import org.eclipse.jface.viewers.ISelection;
23 import org.eclipse.jface.viewers.ISelectionProvider;
24 import org.eclipse.jface.viewers.StructuredSelection;
25 import org.eclipse.ui.IObjectActionDelegate;
26 import org.eclipse.ui.IWorkbenchPart;
27 import org.w3c.tidy.Configuration;
28 import org.w3c.tidy.Tidy;
30 public class HTMLParserAction implements IObjectActionDelegate {
32 private IWorkbenchPart workbenchPart;
34 * Constructor for Action1.
36 public HTMLParserAction() {
41 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
43 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
44 workbenchPart = targetPart;
47 // public static void open(final URL url, final Shell shell, final String dialogTitle) {
48 // IHelp help= WorkbenchHelp.getHelpSupport();
49 // if (help != null) {
50 // WorkbenchHelp.getHelpSupport().displayHelpResource(url.toExternalForm());
52 // showMessage(shell, dialogTitle, ActionMessages.getString("OpenBrowserUtil.help_not_available"), false); //$NON-NLS-1$
56 public void run(IAction action) {
57 Tidy tidy = new Tidy();
58 Configuration conf = tidy.getConfiguration();
60 ISelectionProvider selectionProvider = null;
61 selectionProvider = workbenchPart.getSite().getSelectionProvider();
63 StructuredSelection selection = null;
64 selection = (StructuredSelection) selectionProvider.getSelection();
67 Iterator iterator = null;
68 iterator = selection.iterator();
69 while (iterator.hasNext()) {
70 // obj => selected object in the view
71 Object obj = iterator.next();
74 if (obj instanceof IResource) {
75 IResource resource = (IResource) obj;
77 // check if it's a file resource
78 switch (resource.getType()) {
82 IFile file = (IFile) resource;
85 in = file.getContents();
86 tidy.parse(file, in, null);
87 } catch (CoreException e) {
95 * @see IActionDelegate#selectionChanged(IAction, ISelection)
97 public void selectionChanged(IAction action, ISelection selection) {