1 19 20 package org.netbeans.modules.j2ee.refactoring.whereused; 21 22 import java.io.IOException ; 23 import java.text.MessageFormat ; 24 import java.util.Collection ; 25 import java.util.Enumeration ; 26 import javax.jmi.reflect.RefObject; 27 import org.netbeans.modules.j2ee.dd.api.web.Filter; 28 import org.netbeans.modules.j2ee.dd.api.web.Listener; 29 import org.netbeans.modules.j2ee.dd.api.web.Servlet; 30 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 31 import org.netbeans.jmi.javamodel.JavaClass; 32 import org.netbeans.jmi.javamodel.Resource; 33 import org.netbeans.modules.j2ee.refactoring.Utility; 34 import org.netbeans.modules.javacore.api.JavaModel; 35 import org.netbeans.modules.refactoring.api.AbstractRefactoring; 36 import org.netbeans.modules.refactoring.api.Problem; 37 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; 38 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation; 39 import org.netbeans.modules.web.api.webmodule.WebModule; 40 import org.netbeans.modules.web.taglib.TLDDataObject; 41 import org.netbeans.modules.web.taglib.TLDLoader; 42 import org.netbeans.modules.web.taglib.model.FunctionType; 43 import org.netbeans.modules.web.taglib.model.TagType; 44 import org.netbeans.modules.web.taglib.model.Taglib; 45 import org.netbeans.modules.web.taglib.model.ValidatorType; 46 import org.openide.ErrorManager; 47 import org.openide.filesystems.FileObject; 48 import org.openide.loaders.DataObject; 49 import org.openide.loaders.DataObjectNotFoundException; 50 import org.openide.util.NbBundle; 51 52 56 public final class TldWhereUsedRefactoring { 57 58 private static final ErrorManager err = ErrorManager.getDefault().getInstance("org.netbeans.modules.j2ee.refactoring.whereused"); 60 public TldWhereUsedRefactoring() { } 61 62 64 public Problem prepare(AbstractRefactoring refactoring, RefObject refObject, RefactoringElementsBag refactoringElements) { 65 66 Problem problem = null; 67 if (refObject instanceof JavaClass) { 68 69 JavaClass jClass = (JavaClass)refObject; 70 err.log("jClass: " + jClass); 71 72 String name = jClass.getName(); 73 err.log("name: " + name); 74 Resource res = jClass.getResource(); 75 err.log("res: " + res); 76 77 FileObject fo = JavaModel.getFileObject(res); 78 err.log("fo: " + fo); 79 80 WebModule wm = WebModule.getWebModule(fo); 81 if (wm != null) { FileObject webInf = wm.getWebInf(); 83 Enumeration e = null; 84 if (webInf != null) { 85 e = webInf.getChildren(true); 86 } 87 if (e != null) { 88 while (e.hasMoreElements()) { 89 FileObject tld = (FileObject)e.nextElement(); 90 if (isTld(tld)) { 91 DataObject tldData = null; 92 try { 93 tldData = DataObject.find(tld); 94 } catch (DataObjectNotFoundException dne) { 95 } 97 if ((tldData != null) && (tldData instanceof TLDDataObject)) { 98 Taglib taglib = null; 99 try { 100 taglib = ((TLDDataObject)tldData).getTaglib(); 101 } catch (IOException ioe) {} 102 if (taglib != null) { 103 TagType[] tagTypes = taglib.getTag(); 105 if ((tagTypes != null) && (tagTypes.length > 0)) { 106 for (int tt = 0; tt < tagTypes.length; tt++) { 107 TagType tagT = tagTypes[tt]; 108 String tagClass = tagT.getTagClass(); 109 if ((tagClass != null) && (tagClass.equals(name))) { 110 RefactoringElementImplementation elem = new TaglibTagClassWhereUsedRefactoringElement(taglib, name, tld); 111 refactoringElements.add(refactoring, elem); 112 } 113 String teiClass = tagT.getTeiClass(); 114 if ((teiClass != null) && (teiClass.equals(name))) { 115 RefactoringElementImplementation elem = new TaglibTeiClassWhereUsedRefactoringElement(taglib, name, tld); 116 refactoringElements.add(refactoring, elem); 117 } 118 } 119 } 120 121 FunctionType[] functionTypes = taglib.getFunction(); 122 if ((functionTypes != null) && (functionTypes.length > 0)) { 123 for (int tt = 0; tt < functionTypes.length; tt++) { 124 FunctionType functionT = functionTypes[tt]; 125 String functionClass = functionT.getFunctionClass(); 126 if ((functionClass != null) && (functionClass.equals(name))) { 127 RefactoringElementImplementation elem = new TaglibFunctionClassWhereUsedRefactoringElement(taglib, name, tld); 128 refactoringElements.add(refactoring, elem); 129 } 130 } 131 } 132 133 ValidatorType validatorType = taglib.getValidator(); 135 if (validatorType != null) { 136 String validatorClass = validatorType.getValidatorClass(); 137 if ((validatorClass != null) && (validatorClass.equals(name))) { 138 RefactoringElementImplementation elem = new TaglibValidatorClassWhereUsedRefactoringElement(taglib, name, tld); 139 refactoringElements.add(refactoring, elem); 140 } 141 } 142 143 org.netbeans.modules.web.taglib.model.ListenerType[] listenerTypes = taglib.getListener(); 145 if ((listenerTypes != null) && (listenerTypes.length > 0)) { 146 for (int tt = 0; tt < listenerTypes.length; tt++) { 147 org.netbeans.modules.web.taglib.model.ListenerType listenerT = listenerTypes[tt]; 148 String listenerClass = listenerT.getListenerClass(); 149 if ((listenerClass != null) && (listenerClass.equals(name))) { 150 RefactoringElementImplementation elem = new TaglibListenerClassWhereUsedRefactoringElement(taglib, name, tld); 151 refactoringElements.add(refactoring, elem); 152 } 153 } 154 } 155 156 } else { 157 Object [] args = new Object [] {tld.getNameExt()}; 158 String msg = MessageFormat.format(NbBundle.getMessage(TldWhereUsedRefactoring.class, "TXT_TaglibWhereUsedInvalidProblem"), args); 159 Problem newProblem = new Problem(false, msg); 160 problem = Utility.addProblemsToEnd(problem, newProblem); 161 } 162 } 163 } 164 } 165 } 166 } 167 } return problem; 169 } 170 171 private boolean isTld(FileObject fo) { 172 boolean isTld = false; 173 if (fo != null) { 174 String ext = fo.getExt(); 175 if (TLDLoader.tldExt.equalsIgnoreCase(ext)) { 176 isTld = true; 177 } 178 } 179 return isTld; 180 } 181 182 public final class TaglibTagClassWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 183 184 protected Taglib taglib; 185 186 187 public TaglibTagClassWhereUsedRefactoringElement(Taglib taglib, String name, FileObject parentFile) { 188 this.taglib = taglib; 189 this.name = name; 190 this.parentFile = parentFile; 191 } 192 193 196 public String getDisplayText() { 197 Object [] args = new Object [] {name}; 198 return MessageFormat.format(NbBundle.getMessage(TldWhereUsedRefactoring.class, "TXT_TaglibTagClassWhereUsed"), args); 199 } 200 } 201 202 public final class TaglibTeiClassWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 203 204 protected Taglib taglib; 205 206 207 public TaglibTeiClassWhereUsedRefactoringElement(Taglib taglib, String name, FileObject parentFile) { 208 this.taglib = taglib; 209 this.name = name; 210 this.parentFile = parentFile; 211 } 212 213 216 public String getDisplayText() { 217 Object [] args = new Object [] {name}; 218 return MessageFormat.format(NbBundle.getMessage(TldWhereUsedRefactoring.class, "TXT_TaglibTeiClassWhereUsed"), args); 219 } 220 } 221 222 public final class TaglibValidatorClassWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 223 224 protected Taglib taglib; 225 226 227 public TaglibValidatorClassWhereUsedRefactoringElement(Taglib taglib, String name, FileObject parentFile) { 228 this.taglib = taglib; 229 this.name = name; 230 this.parentFile = parentFile; 231 } 232 233 236 public String getDisplayText() { 237 Object [] args = new Object [] {name}; 238 return MessageFormat.format(NbBundle.getMessage(TldWhereUsedRefactoring.class, "TXT_TaglibValidatorClassWhereUsed"), args); 239 } 240 } 241 242 public final class TaglibListenerClassWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 243 244 protected Taglib taglib; 245 246 247 public TaglibListenerClassWhereUsedRefactoringElement(Taglib taglib, String name, FileObject parentFile) { 248 this.taglib = taglib; 249 this.name = name; 250 this.parentFile = parentFile; 251 } 252 253 256 public String getDisplayText() { 257 Object [] args = new Object [] {name}; 258 return MessageFormat.format(NbBundle.getMessage(TldWhereUsedRefactoring.class, "TXT_TaglibListenerClassWhereUsed"), args); 259 } 260 } 261 262 public final class TaglibFunctionClassWhereUsedRefactoringElement extends AbstractWhereUsedRefactoringElement { 263 264 protected Taglib taglib; 265 266 267 public TaglibFunctionClassWhereUsedRefactoringElement(Taglib taglib, String name, FileObject parentFile) { 268 this.taglib = taglib; 269 this.name = name; 270 this.parentFile = parentFile; 271 } 272 273 276 public String getDisplayText() { 277 Object [] args = new Object [] {name}; 278 return MessageFormat.format(NbBundle.getMessage(TldWhereUsedRefactoring.class, "TXT_TaglibFunctionClassWhereUsed"), args); 279 } 280 } 281 282 } 283 | Popular Tags |