1 19 20 package org.netbeans.modules.tasklist.html; 21 22 23 import javax.swing.text.*; 24 import javax.swing.event.*; 25 import java.awt.*; 26 import java.awt.event.*; 27 import javax.swing.*; 28 import java.io.*; 29 import java.util.List ; 30 import java.util.ArrayList ; 31 import org.openide.ErrorManager; 32 import org.openide.explorer.view.*; 33 import org.openide.util.Utilities; 34 35 import org.openide.loaders.DataObject; 36 import org.openide.loaders.DataObjectNotFoundException; 37 import org.openide.text.Line; 38 39 import org.netbeans.modules.html.*; 40 41 import org.w3c.tidy.*; 42 43 import org.netbeans.modules.tasklist.core.TLUtils; 44 import org.netbeans.modules.tasklist.client.Suggestion; 45 import org.netbeans.modules.tasklist.client.SuggestionManager; 46 import org.netbeans.modules.tasklist.client.SuggestionPriority; 47 import org.netbeans.modules.tasklist.client.SuggestionAgent; 48 import org.netbeans.modules.tasklist.providers.DocumentSuggestionProvider; 49 import org.netbeans.modules.tasklist.providers.SuggestionContext; 50 51 52 59 public class TidySuggester extends DocumentSuggestionProvider 60 implements ErrorReporter { 61 62 final private static String TYPE = "nb-html-errors"; private SuggestionContext env; 64 65 public String getType() { 66 return TYPE; 67 } 68 69 static boolean isHTML(DataObject dobj) { 70 return dobj instanceof HtmlDataObject; 74 } 75 76 static boolean isJSP(DataObject dobj) { 77 String file = dobj.getPrimaryFile().getNameExt(); 78 return file.endsWith(".jsp") || file.endsWith(".JSP") || (dobj.getClass().getName().indexOf("jsploader") != -1); } 85 86 static boolean isXML(DataObject dobj) { 87 String file = dobj.getPrimaryFile().getNameExt(); 88 return file.endsWith(".xml") || file.endsWith(".XML") || (dobj.getClass().getName().indexOf("XMLDataObject") != -1); } 92 93 public List scan(SuggestionContext env) { 94 95 DataObject dobj = null; 96 try { 97 dobj = DataObject.find(env.getFileObject()); 98 } catch (DataObjectNotFoundException e) { 99 return null; 100 } 101 102 boolean isHTML = isHTML(dobj); 106 boolean isJSP = false; 107 boolean isXML = false; 108 if (!isHTML) { 109 isJSP = isJSP(dobj); 110 if (!isJSP) { 111 isXML = isXML(dobj); 112 } 113 } 114 if (!(isHTML || isJSP || isXML)) { 115 return null; 116 } 117 SuggestionManager manager = SuggestionManager.getDefault(); 118 119 parseTasks = null; 120 parseObject = dobj; 121 if (manager.isEnabled(TYPE)) { 122 InputStream input = null; 123 try { 124 input = env.getFileObject().getInputStream(); 125 } catch (FileNotFoundException e) { 126 return null; 127 } 128 129 if (tidy == null) { 130 tidy = new Tidy(); 131 } 132 tidy.setOnlyErrors(true); 133 tidy.setShowWarnings(true); 134 tidy.setQuiet(true); 135 tidy.setXmlTags(isXML || isJSP); 138 139 PrintWriter output = new ReportWriter(this); 140 tidy.setErrout(output); 141 tidy.parse(input, System.err); 144 } 145 return parseTasks; 146 } 147 148 149 private List showingTasks = null; 150 151 152 private List parseTasks = null; 153 private DataObject parseObject = null; 154 155 public void reportError(int line, int col, boolean error, String message) { 156 158 SuggestionManager manager = SuggestionManager.getDefault(); 159 SuggestionAgent s = manager.createSuggestion(TYPE, 160 message, 161 null, 162 this); 163 if (line != -1) { 164 Line l = TLUtils.getLineByNumber(parseObject, line); 165 s.setLine(l); 166 } 167 if (error) { 168 Image taskIcon = Utilities.loadImage("org/netbeans/modules/tasklist/html/error.gif"); s.setIcon(taskIcon); 170 s.setPriority(SuggestionPriority.HIGH); 171 } 172 if (parseTasks == null) { 173 parseTasks = new ArrayList (30); 174 } 175 parseTasks.add(s.getSuggestion()); 176 } 177 178 private Object request = null; 179 private Tidy tidy = null; 180 } 181 | Popular Tags |