changed the "description" attribute in phpsyntax.xml into multi-line text between...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / actions / HTMLParserAction.java
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
7
8 Contributors:
9     IBM Corporation - Initial implementation
10     Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpeclipse.actions;
13
14 import java.io.InputStream;
15 import java.util.Iterator;
16
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 net.sourceforge.phpdt.tidy.Configuration;
28 import net.sourceforge.phpdt.tidy.Tidy;
29
30 public class HTMLParserAction implements IObjectActionDelegate {
31
32   private IWorkbenchPart workbenchPart;
33   /**
34    * Constructor for Action1.
35    */
36   public HTMLParserAction() {
37     super();
38   }
39
40   /**
41    * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
42    */
43   public void setActivePart(IAction action, IWorkbenchPart targetPart) {
44     workbenchPart = targetPart;
45   }
46
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());
51   //    } else {
52   //      showMessage(shell, dialogTitle, ActionMessages.getString("OpenBrowserUtil.help_not_available"), false); //$NON-NLS-1$
53   //    }
54   //  }
55
56   public void run(IAction action) {
57     Tidy tidy = new Tidy();
58     Configuration conf = tidy.getConfiguration();
59     
60     ISelectionProvider selectionProvider = null;
61     selectionProvider = workbenchPart.getSite().getSelectionProvider();
62
63     StructuredSelection selection = null;
64     selection = (StructuredSelection) selectionProvider.getSelection();
65
66     //Shell shell = null;
67     Iterator iterator = null;
68     iterator = selection.iterator();
69     while (iterator.hasNext()) {
70       //  obj => selected object in the view
71       Object obj = iterator.next();
72
73       // is it a resource
74       if (obj instanceof IResource) {
75         IResource resource = (IResource) obj;
76
77         // check if it's a file resource
78         switch (resource.getType()) {
79
80           case IResource.FILE :
81             // single file:
82             IFile file = (IFile) resource;
83             InputStream in;
84             try {
85               in = file.getContents();
86               tidy.parse(file, in, null);
87             } catch (CoreException e) {
88             }
89         }
90       }
91     }
92   }
93
94   /**
95    * @see IActionDelegate#selectionChanged(IAction, ISelection)
96    */
97   public void selectionChanged(IAction action, ISelection selection) {
98   }
99
100 }