1 19 20 package org.netbeans.modules.ruby.railsprojects; 21 22 import java.io.File ; 23 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 import org.netbeans.modules.ruby.rubyproject.api.RubyInstallation; 28 import org.netbeans.api.project.Project; 29 import org.openide.filesystems.FileObject; 30 import org.openide.filesystems.FileUtil; 31 32 36 public class RailsProjectUtil { 37 private RailsProjectUtil () {} 38 39 47 public static Object getEvaluatedProperty(Project p, String value) { 48 if (value == null) { 49 return null; 50 } 51 RailsProject j2seprj = (RailsProject) p.getLookup().lookup(RailsProject.class); 52 if (j2seprj != null) { 53 return j2seprj.evaluator().evaluate(value); 54 } else { 55 return null; 56 } 57 } 58 59 public static void getAllScripts(String prefix, FileObject sourcesRoot, List result) { 60 FileObject children[] = sourcesRoot.getChildren(); 61 if (!"".equals(prefix)) { 62 prefix += "/"; 63 } 65 for (int i = 0; i < children.length; i++) { 66 if (children[i].isData()) { 67 if (children[i].getMIMEType().equals(RubyInstallation.RUBY_MIME_TYPE)) { 68 result.add(prefix + children[i].getNameExt()); 69 } 70 } 71 if (children[i].isFolder()) { 72 getAllScripts(prefix + children[i].getNameExt(), children[i], result); 73 } 74 } 75 } 76 77 78 88 public static URL getRootURL (File root, String offset) throws MalformedURLException { 89 URL url = root.toURI().toURL(); 90 if (FileUtil.isArchiveFile(url)) { 91 url = FileUtil.getArchiveRoot(url); 92 } else if (!root.exists()) { 93 url = new URL (url.toExternalForm() + "/"); } 95 if (offset != null) { 96 assert offset.endsWith("/"); url = new URL (url.toExternalForm() + offset); } 99 return url; 100 } 101 } 102 | Popular Tags |