1 19 package org.netbeans.modules.css.actions; 20 21 import java.awt.datatransfer.StringSelection ; 22 import java.net.*; 23 import java.io.*; 24 25 import org.openide.*; 26 import org.openide.awt.StatusDisplayer; 27 import org.openide.nodes.Node; 28 import org.openide.util.*; 29 import org.openide.util.actions.*; 30 import org.openide.filesystems.*; 31 import org.openide.cookies.*; 32 33 import org.w3c.css.sac.*; 34 35 import org.netbeans.modules.css.*; 36 37 42 public class CheckStyleAction extends CookieAction implements ErrorHandler, DocumentHandler { 43 44 45 private static final long serialVersionUID = -6638807099960633338L; 46 47 private CSSObject csso; private CSSDisplayer disp; 50 private boolean failed; 52 private int warnings; 53 54 57 public int mode() { 58 return MODE_EXACTLY_ONE; 59 } 60 61 64 public Class [] cookieClasses() { 65 return new Class [] {CSSObject.class}; 66 } 67 68 70 protected void performAction(final Node[] nodes) { 71 if (nodes.length != 1) return; 72 if (nodes[0] == null) return; 73 74 failed = false; 75 warnings = 0; 76 77 disp = new CSSDisplayer(); 78 79 Parser parser = new org.w3c.flute.parser.Parser(); 80 parser.setErrorHandler(this); 81 parser.setDocumentHandler(this); 82 83 for (int i=0; i<nodes.length; i++) { 84 csso = (CSSObject) nodes[i].getCookie(CSSObject.class); 85 86 if (csso != null) { 87 try { 88 SaveCookie cake = (SaveCookie) csso.getCookie(SaveCookie.class); 91 if (cake != null) 92 cake.save(); 93 94 String uri = csso.getPrimaryFile().getURL().toExternalForm(); 95 96 parser.parseStyleSheet(uri); 97 } catch (IOException ex) { 98 failed = true; 100 } catch (CSSParseException ex) { 101 failed = true; 103 } 104 } 105 } 106 107 if ( ( failed == true ) || 108 ( warnings > 0 ) ) { 109 disp.moveToFront(); 110 } 111 StatusDisplayer.getDefault().setStatusText(Util.THIS.getString("TEXT_PART_CSS_checking") + getStatus() + "."); } 113 114 115 private String getStatus() { 116 return failed ? Util.THIS.getString("TEXT_PART_failed") : warnings>1 ? Util.THIS.getString("TEXT_PART_finished_with_warnings") : Util.THIS.getString("TEXT_PART_finished"); 117 } 118 119 public String getName() { 120 return Util.THIS.getString("NAME_check_CSS"); 121 } 122 123 protected String iconResource () { 124 return "org/netbeans/modules/css/resources/checkStyleAction.gif"; } 126 127 129 public HelpCtx getHelpCtx() { 130 return new HelpCtx(getClass()); 131 } 132 133 135 public void warning(CSSParseException exception) throws CSSException { 136 disp.display(csso, exception); 137 warnings++; 138 } 139 140 public void error(CSSParseException exception) throws CSSException { 141 disp.display(csso, exception); 142 failed = true; 143 } 144 145 public void fatalError(CSSParseException exception) throws CSSException { 146 disp.display(csso, exception); 147 failed = true; 148 } 149 150 152 public void startDocument(InputSource source) throws CSSException { 153 } 154 155 public void endDocument(InputSource source) throws CSSException { 156 } 157 158 public void comment(String text) throws CSSException { 159 } 160 161 public void ignorableAtRule(String atRule) throws CSSException { 162 } 163 164 public void namespaceDeclaration(String prefix,String uri) throws CSSException { 165 } 166 167 public void importStyle(String uri,SACMediaList media,String defaultNamespaceURI) throws CSSException { 168 } 169 170 public void startMedia(SACMediaList media) throws CSSException { 171 } 172 173 public void endMedia(SACMediaList media) throws CSSException { 174 } 175 176 public void startPage(String name,String pseudo_page) throws CSSException { 177 } 178 179 public void endPage(String name,String pseudo_page) throws CSSException { 180 } 181 182 public void startFontFace() throws CSSException { 183 } 184 185 public void endFontFace() throws CSSException { 186 } 187 188 public void startSelector(SelectorList selectors) throws CSSException { 189 } 190 191 public void endSelector(SelectorList selectors) throws CSSException { 192 } 193 194 public void property(String name,LexicalUnit value,boolean important) throws CSSException { 195 } 196 } 197 | Popular Tags |