Java Code Examples for org.netbeans.api.java.classpath.ClassPath#findResource()

The following examples show how to use org.netbeans.api.java.classpath.ClassPath#findResource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DBSchemaTableProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static List<DisabledReason> getDisabledReasons(TableElement tableElement, PersistenceGenerator persistenceGen, ClassPath source) {
    List<DisabledReason> result = new ArrayList<DisabledReason>();

    if (tableElement.isTable() && hasNoPrimaryKey(tableElement)) {
        result.add(new NoPrimaryKeyDisabledReason());
    }

    String fqClassName = persistenceGen.getFQClassName(tableElement.getName().getName());
    if (fqClassName != null) {
        if(source == null || source.findResource(fqClassName.replace('.', '/')+".java")!=null) {
            result.add(new ExistingDisabledReason(fqClassName));
        }
        else {
            result.add(new Table.ExistingNotInSourceDisabledReason(fqClassName));
        }
    }

    return result;
}
 
Example 2
Source File: DebugFixHooks.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static String classToSourceURL(FileObject fo, PrintWriter logger) {
    ClassPath cp = ClassPath.getClassPath(fo, ClassPath.EXECUTE);
    if (cp == null) {
        return null;
    }
    FileObject root = cp.findOwnerRoot(fo);
    String resourceName = cp.getResourceName(fo, '/', false);
    if (resourceName == null || root == null) {
        logger.println("Can not find classpath resource for " + fo + ", skipping...");
        return null;
    }
    int i = resourceName.indexOf('$');
    if (i > 0) {
        resourceName = resourceName.substring(0, i);
    }
    FileObject[] sRoots = SourceForBinaryQuery.findSourceRoots(root.toURL()).getRoots();
    ClassPath sourcePath = ClassPathSupport.createClassPath(sRoots);
    FileObject rfo = sourcePath.findResource(resourceName + ".java");
    if (rfo == null) {
        return null;
    }
    return rfo.toURL().toExternalForm();
}
 
Example 3
Source File: ServiceModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public synchronized void addServiceChangeListener(ServiceChangeListener pcl) {
    if (serviceChangeListeners.size()==0) {
        fcl = new AnnotationChangeListener();
        implementationClass.addFileChangeListener(fcl);
        if ( getEndpointInterface() != null ){
            String endpoint = getEndpointInterface();
            ClassPath sourceCP = ClassPath.getClassPath(implementationClass, 
                    ClassPath.SOURCE);
            FileObject endpointFo = sourceCP.findResource(
                    endpoint.replace('.', '/')+".java"); //NOI18N
            if ( endpointFo != null ){
                endpointFo.addFileChangeListener(fcl);
            }
        }
    }
    serviceChangeListeners.add(pcl);
}
 
Example 4
Source File: AntProjectTypeStrategy.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public JUnit findJUnitVersion() {
    final boolean hasJUnit3;
    final boolean hasJUnit4;
    final ClassPath classPath = getTestClassPath(project);
    if (classPath != null) {
        hasJUnit3 = (classPath.findResource(JUNIT3_SPECIFIC) != null);
        hasJUnit4 = (classPath.findResource(JUNIT4_SPECIFIC) != null);
    } else {
        hasJUnit3 = false;
        hasJUnit4 = false;
    }

    if (hasJUnit4) {
        return JUnit.JUNIT4;
    } else if (hasJUnit3) {
        return JUnit.JUNIT3;
    } else {
        return JUnit.NOT_DECLARED;
    }
}
 
Example 5
Source File: WSITRenamePackagePlugin.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private FileObject getJavaFile( String fqn, Project project ) {
    SourceGroup[] sourceGroups = ProjectUtils.getSources(project)
            .getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    if (sourceGroups.length > 0) {
        ClassPath classPath = null;
        for (int i = 0; i < sourceGroups.length; i++) {
            classPath = ClassPath.getClassPath(
                    sourceGroups[i].getRootFolder(), ClassPath.SOURCE);
            if (classPath != null) {
                FileObject javaClass = classPath.findResource(fqn.replace(
                        '.', '/') + ".java"); // NOI18N
                if (javaClass != null) {
                    return javaClass;
                }
            }
        }
    }
    return null;
}
 
Example 6
Source File: SpringBinaryIndexer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String findVersion(FileObject classpathRoot) {
    ClassPath cp = ClassPath.getClassPath(classpathRoot, ClassPath.COMPILE);
    if (cp == null) {
        return null;
    }
    String classRelativePath = SpringUtilities.SPRING_CLASS_NAME.replace('.', '/') + ".class"; //NOI18N
    try {
        FileObject resource = cp.findResource(classRelativePath);  //NOI18N
        if (resource==null) {
            return null;
        }
        FileObject ownerRoot = cp.findOwnerRoot(resource);

        if (ownerRoot !=null) { //NOI18N
            if (ownerRoot.getFileSystem() instanceof JarFileSystem) {
                JarFileSystem jarFileSystem = (JarFileSystem) ownerRoot.getFileSystem();
                return SpringUtilities.getImplementationVersion(jarFileSystem);
            }
        }
    } catch (FileStateInvalidException e) {
        Exceptions.printStackTrace(e);
    }
    return null;
}
 
Example 7
Source File: AbstractTestGenerator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static boolean isClassEjb31Bean(WorkingCopy wc, TypeElement srcClass) {
    ClassPath cp = wc.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.COMPILE);
    if (cp == null || cp.findResource("javax/ejb/embeddable/EJBContainer.class") == null) {
        // if EJBContainer class is not available on classpath then it is not EJB 3.1
        return false;
    }
    List<? extends AnnotationMirror> annotations = wc.getElements().getAllAnnotationMirrors(srcClass);
    for (AnnotationMirror am : annotations) {
        String annotation = ((TypeElement)am.getAnnotationType().asElement()).getQualifiedName().toString();
        if (annotation.equals("javax.ejb.Singleton") || // NOI18N
            annotation.equals("javax.ejb.Stateless") || // NOI18N
            annotation.equals("javax.ejb.Stateful")) { // NOI18N
            // class is an EJB
            return true;
        }
    }
    return false;
}
 
Example 8
Source File: RestSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static ClassPath extendClassPathWithJaxRsApisIfNecessary(ClassPath classPath) {
    if (classPath.findResource("javax/ws/rs/core/Application.class") != null) {
        return classPath;
    }
    File jerseyRoot = InstalledFileLocator.getDefault().locate(JERSEY_API_LOCATION, "org.netbeans.modules.websvc.restlib", false);
    if (jerseyRoot != null && jerseyRoot.isDirectory()) {
        File[] jsr311Jars = jerseyRoot.listFiles(new MiscPrivateUtilities.JerseyFilter(JSR311_JAR_PATTERN));
        if (jsr311Jars != null && jsr311Jars.length>0) {
            FileObject fo = FileUtil.toFileObject(jsr311Jars[0]);
            if (fo != null) {
                fo = FileUtil.getArchiveRoot(fo);
                if (fo != null) {
                    return ClassPathSupport.createProxyClassPath(classPath,
                            ClassPathSupport.createClassPath(fo));
                }
            }
        }
    }
    return classPath;
}
 
Example 9
Source File: J2SEJAXWSVersionProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public String getJAXWSVersion() {
    String version = "2.1.3"; //NOI18N
    SourceGroup[] srcGroups = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    if (srcGroups != null && srcGroups.length > 0) {
        ClassPath classpath = ClassPath.getClassPath(srcGroups[0].getRootFolder(), ClassPath.COMPILE);
        FileObject fo = classpath.findResource("com/sun/xml/ws/util/version.properties"); //NOI18N
        if (fo != null) {
            try {
                InputStream is = fo.getInputStream();
                BufferedReader r = new BufferedReader(new InputStreamReader(is, 
                        Charset.forName("UTF-8")));
                String ln = null;
                String ver = null;
                while ((ln=r.readLine()) != null) {
                    String line = ln.trim();
                    if (line.startsWith("major-version=")) { //NOI18N
                        ver = line.substring(14);
                    }
                }
                r.close();
                version = ver;
            } catch (IOException ex) {
                Logger.getLogger(J2SEJAXWSVersionProvider.class.getName()).log(Level.INFO, 
                        "Failed to detect JKAX-WS version", ex); //NOI18N
            }
        } else {
            WSStack<JaxWs> jdkJaxWsStack = JaxWsStackSupport.getJdkJaxWsStack();
            if (jdkJaxWsStack != null) {
                return jdkJaxWsStack.getVersion().toString();
            }
        }
    }
    return version;
}
 
Example 10
Source File: LibraryUtil.java    From jeddict with Apache License 2.0 5 votes vote down vote up
public static String getLibrary(ClassPath classPath, String resource) {
    // Find as resource as a class
    String classNameAsPath = resource.replace('.', '/') + ".class";
    FileObject classResource = classPath.findResource(classNameAsPath);
    if (classResource == null) {
        // Find as resource as a package
        classNameAsPath = resource.replace('.', '/');
        classResource = classPath.findResource(classNameAsPath);

    }
    if (classResource != null) {
        FileObject archiveFile = FileUtil.getArchiveFile(classResource);
        if (archiveFile != null && FileUtil.isArchiveFile(archiveFile)) {
            File toFile = FileUtil.toFile(archiveFile);
            try {
                JarFile jf = new JarFile(toFile);
                Manifest manifest = jf.getManifest();
                Attributes mainAttributes = manifest.getMainAttributes();

                // Find library version by Bundle information (Eclipse/OSGi)
                if (mainAttributes.containsKey(BUNDLE_NAME) && mainAttributes.containsKey(BUNDLE_VERSION)) {
                    if (!mainAttributes.getValue(BUNDLE_NAME).isEmpty()) {
                        return mainAttributes.getValue(BUNDLE_NAME);
                    }
                }

                // If unsuccessful, try by default Manifest Headers
                if (mainAttributes.containsKey(Name.IMPLEMENTATION_TITLE) && mainAttributes.containsKey(Name.IMPLEMENTATION_VERSION)) {
                    if (!mainAttributes.getValue(Name.IMPLEMENTATION_TITLE).isEmpty()) {
                        return mainAttributes.getValue(Name.IMPLEMENTATION_TITLE);
                    }
                }
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
        }

    }
    return null;
}
 
Example 11
Source File: MultiModuleUnitTestsCompilerOptionsQueryImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private List<Map<String,List<File>>> classifyModules(
        @NonNull final Collection<? extends String> toClassify,
        @NonNull final Set<? super File> moduleInfosToListenOn,
        @NonNull final Collection<? super ClassPath> cpsToListenOn) {
    final Map<String,List<File>> mods = new HashMap<>();
    final Map<String,List<File>> ptchs = new HashMap<>();
    final Map<String,List<File>> invd = new HashMap<>();
    for (String modName : toClassify) {
        ClassPath cp = testModules.getModuleSources(modName);
        if (cp == null) {
            invd.put(modName, Collections.emptyList());
            continue;
        }
        final Map<String,List<File>> into;
        FileObject modInfo;
        if ((modInfo = cp.findResource(MODULE_INFO)) != null && modInfo.isData()) {
            into = mods;
        } else if (sourceModules.getModuleNames().contains(modName)) {
            into = ptchs;
        } else {
            into = invd;
        }
        final List<File> files = cp.entries().stream()
                .map((e) -> FileUtil.archiveOrDirForURL(e.getURL()))
                .filter((f) -> f != null)
                .collect(Collectors.toList());
        into.put(modName, files);
        files.stream()
                .map((f) -> new File(f, MODULE_INFO))
                .forEach(moduleInfosToListenOn::add);
        cpsToListenOn.add(cp);
    }
    return Arrays.asList(mods, ptchs, invd);
}
 
Example 12
Source File: JPDABreakpoint.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static void fillFilesForClass(String className, List<FileObject> files) {
    int innerClassIndex = className.indexOf('$');
    if (innerClassIndex > 0) {
        className = className.substring(0, innerClassIndex);
    }
    String resource = className.replaceAll("\\.", "/")+".java";
    for (ClassPath cp : GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE)) {
        FileObject f = cp.findResource(resource);
        if (f != null) {
            files.add(f);
        }
    }            
}
 
Example 13
Source File: JavacParser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean hasResource(
        @NonNull final String resource,
        @NonNull final ClassPath... cps) {
    for (ClassPath cp : cps) {
       if (cp != null && cp.findResource(resource) != null) {
           return true;
       }
    }
    return false;
}
 
Example 14
Source File: WebProjectJAXWSClientSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void addJaxWs20Library() throws Exception{
    SourceGroup[] sgs = SourceGroups.getJavaSourceGroups(project);
    if (sgs.length > 0) {
        FileObject srcRoot = sgs[0].getRootFolder();

        ClassPath compileClassPath = ClassPath.getClassPath(srcRoot,ClassPath.COMPILE);
        ClassPath bootClassPath = ClassPath.getClassPath(srcRoot,ClassPath.BOOT);
        ClassPath classPath = ClassPathSupport.createProxyClassPath(new ClassPath[]{compileClassPath, bootClassPath});
        FileObject jaxWsClass = classPath.findResource("javax/xml/ws/WebServiceFeature.class"); // NOI18N

        if (jaxWsClass == null) {
            //Add the jaxws21 library to the project to be packed with the archive
            Library MetroLib = LibraryManager.getDefault().getLibrary("metro"); //NOI18N
            if (MetroLib != null) {
                try {
                    ProjectClassPathModifier.addLibraries(new Library[]{MetroLib}, srcRoot, ClassPath.COMPILE);
                } catch(IOException e){
                    throw new Exception("Unable to add Metro library", e);
                }
            } else {
                throw new Exception("Unable to add Metro Library" ); //NOI18N
            }
        }
        // add JAX-WS Endorsed Classpath
        try {
            WSUtils.addJaxWsApiEndorsed(project, srcRoot);
        } catch (IOException ex) {
            Logger.getLogger(WebProjectJAXWSClientSupport.class.getName()).log(Level.FINE, "Cannot add JAX-WS-ENDORSED classpath", ex);
        }
    }
}
 
Example 15
Source File: CustomIconEditor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private FileObject findSourceRootOf(FileObject[] roots, String resName) {
    for (FileObject root : roots) {
        ClassPath resCP = ClassPath.getClassPath(root, ClassPath.SOURCE);
        if (resCP != null) {
            FileObject res = resCP.findResource(resName);
            if (res != null) {
                return res;
            }
        }
    }
    return null;
}
 
Example 16
Source File: J2EEUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Updates project classpath with the EclipseLink library.
 *
 * @param fileInProject file in the project whose classpath should be updated.
 * @return <code>true</code> if the classpath has been updated,
 * returns <code>false</code> otherwise.
 */
public static boolean updateProjectForEclipseLink(FileObject fileInProject) {
    try {
        ClassPath classPath = ClassPath.getClassPath(fileInProject, ClassPath.EXECUTE);
        FileObject fob = classPath.findResource("org/eclipse/persistence/jpa/PersistenceProvider.class"); // NOI18N
        if (fob == null) {
            ClassSource cs = new ClassSource("", // class name is not needed // NOI18N
                    new ClassSourceResolver.LibraryEntry(LibraryManager.getDefault().getLibrary("eclipselink"))); // NOI18N
            return ClassPathUtils.updateProject(fileInProject, cs);
        }
    } catch (IOException ex) {
        Logger.getLogger(J2EEUtils.class.getName()).log(Level.INFO, ex.getMessage(), ex);
    }
    return false;
}
 
Example 17
Source File: ContainerCPModifierImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void extendClasspath(final FileObject file, final String[] symbolicNames) {
    if (symbolicNames == null) {
        return;
    }
    final Boolean[] added = new Boolean[1];
    added[0] = Boolean.FALSE;
    ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {

        @Override
        public void performOperation(POMModel model) {
            Map<String, Item> items = createItemList();
            ProjectSourcesClassPathProvider prv = project.getLookup().lookup(ProjectSourcesClassPathProvider.class);
            ClassPath[] cps = prv.getProjectClassPaths(ClassPath.COMPILE);
            ClassPath cp = ClassPathSupport.createProxyClassPath(cps);
            Profile version = Profile.JAVA_EE_5; //sort of fallback
            WebModule wm = WebModule.getWebModule(file);
            if (wm != null) {
                version = wm.getJ2eeProfile();
            } else {
                EjbJar ejb = EjbJar.getEjbJar(file);
                if (ejb != null) {
                    version = ejb.getJ2eeProfile();
                }
            }

            for (String name : symbolicNames) {
                Item item = items.get(name + ":" + version.toPropertiesString()); //NOI18N
                if (item != null) {
                    if (item.classToCheck != null) {
                        FileObject fo = cp.findResource(item.classToCheck);
                        if (fo != null) {
                            //skip, already on CP somehow..
                            continue;
                        }
                    }
                    Dependency dep = ModelUtils.checkModelDependency(model, item.groupId, item.artifactId, true);
                    dep.setVersion(item.version);
                    dep.setScope(Artifact.SCOPE_PROVIDED);
                    added[0] = Boolean.TRUE;
                } else {
                    LOGGER.log(Level.WARNING, "Cannot process api with symbolic name: {0}. Nothing will be added to project''s classpath.", name);
                }
            }
        }
    };
    FileObject pom = project.getProjectDirectory().getFileObject("pom.xml"); //NOI18N
    Utilities.performPOMModelOperations(pom, Collections.singletonList(operation));
    if (added[0]) {
        if (!SwingUtilities.isEventDispatchThread()) {
            project.getLookup().lookup(NbMavenProject.class).downloadDependencyAndJavadocSource(true);
        }
    }
}
 
Example 18
Source File: SourcePathProviderImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Translates a relative path ("java/lang/Thread.java") to url 
 * ("file:///C:/Sources/java/lang/Thread.java"). Uses GlobalPathRegistry
 * if global == true.
 *
 * @param relativePath a relative path (java/lang/Thread.java)
 * @param global true if global path should be used
 * @return url or <code>null</code>
 */
@Override
public String getURL (String relativePath, boolean global) {    if (verbose) System.out.println ("SPPI: getURL " + relativePath + " global " + global);
    relativePath = normalize(relativePath);
    if (global) {
        synchronized (urlCacheGlobal) {
            if (urlCacheGlobal.containsKey(relativePath)) {
                if (verbose) System.out.println("Have cached global path for '"+relativePath+"' url = "+urlCacheGlobal.get(relativePath));
                return urlCacheGlobal.get(relativePath);    // URL or null
            }
        }
    } else {
        synchronized (urlCache) {
            if (urlCache.containsKey(relativePath)) {
                if (verbose) System.out.println("Have cached path for '"+relativePath+"' url = "+urlCache.get(relativePath));
                return urlCache.get(relativePath);  // URL or null
            }
        }
    }
    FileObject fo;
    ClassPath ss = null;
    ClassPath os = null;
    synchronized (this) {
        if (originalSourcePath != null) {
            ss = smartSteppingSourcePath;
            os = originalSourcePath;
        }
    }
    if (ss != null && os != null) {
        fo = ss.findResource(relativePath);
        if (fo == null && global) {
            fo = os.findResource(relativePath);
        }
        if (fo == null && global) {
            fo = GlobalPathRegistry.getDefault().findResource(relativePath);
        }
    } else {
        fo = GlobalPathRegistry.getDefault().findResource(relativePath);
    }
    if (fo == null && global) {
        Set<ClassPath> cpaths = GlobalPathRegistry.getDefault().getPaths(ClassPath.COMPILE);
        for (ClassPath cp : cpaths) {
            fo = cp.findResource(relativePath);
            if (fo != null) {
                FileObject[] roots = cp.getRoots();
                for (FileObject r : roots) {
                    if (FileUtil.isParentOf(r, fo)) {
                        addToSourcePath(r, false);
                        break;
                    }
                }
                break;
            }
        }
    }
    
    if (verbose) System.out.println ("SPPI:   fo " + fo);

    String url;
    if (fo == null) {
        url = null;
    } else {
        url = fo.toURL ().toString ();
    }
    if (global) {
        synchronized (urlCacheGlobal) {
            if (verbose) System.out.println("Storing path into global cache for '"+relativePath+"' url = "+url);
            urlCacheGlobal.put(relativePath, url);
            if (verbose) System.out.println("  Global cache ("+urlCacheGlobal.size()+") = "+urlCacheGlobal);
        }
    } else {
        synchronized (urlCache) {
            if (verbose) System.out.println("Storing path into cache for '"+relativePath+"' url = "+url);
            urlCache.put(relativePath, url);
            if (verbose) System.out.println("  Cache = ("+urlCache.size()+") "+urlCache);
        }
    }
    return url;
}
 
Example 19
Source File: AddWsOperationHelper.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@org.netbeans.api.annotations.common.SuppressWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
private void executeModificationTask( final FileObject implClassFo,
        final JavaSource targetSource, final ProgressHandle handle,
        final AddOperationTask modificationTask )
{
    try {
        ModificationResult result = targetSource.runModificationTask(modificationTask);
        if ( modificationTask.isIncomplete() && 
                org.netbeans.api.java.source.SourceUtils.isScanInProgress() )
        {
            final Runnable runnable = new Runnable(){

                @Override
                public void run() {
                    executeInRequestProcessor(implClassFo, targetSource, 
                            handle, modificationTask);
                }
                
            };
            SwingUtilities.invokeLater( new Runnable() {

                @Override
                public void run() {
                    ScanDialog.runWhenScanFinished(runnable, getTitle());
                }
            });
        }
        else {
            result.commit();
            // add method to SEI class
            String seiClass = modificationTask.getSeiClass();
            if (seiClass != null) {
                ClassPath sourceCP = ClassPath.getClassPath(implClassFo, 
                        ClassPath.SOURCE);
                FileObject seiFo = sourceCP.findResource(
                        seiClass.replace('.', '/')+".java"); //NOI18N
                if (seiFo != null) {
                    JavaSource seiSource = JavaSource.forFileObject(seiFo);
                    seiSource.runModificationTask(modificationTask).commit();
                    saveFile(seiFo);
                }
            }
            saveFile(implClassFo);
        }
    } catch (IOException ex) {
        ErrorManager.getDefault().notify(ex);
    } finally {
        handle.finish();
    }
}
 
Example 20
Source File: FXMLHyperlinkProvider.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static @CheckForNull
FileObject findFile(FileObject docFO, String path) {
    if (path == null || path.trim().isEmpty()) {
        return null;
    }
    
    Project prj = FileOwnerQuery.getOwner(docFO);
    if (prj == null) {
        return null;
    }
    
    Sources srcs = ProjectUtils.getSources(prj);
    SourceGroup[] grps = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    if (grps.length == 0) {
        return null;
    }

    // XXX other source roots?
    final FileObject rootFolder = grps[0].getRootFolder();
    ClassPath cp = ClassPath.getClassPath(rootFolder, ClassPath.SOURCE);
    if (cp == null) {
        return null;
    }
    
    FileObject fo;
    String rootPath = FileUtil.normalizePath(rootFolder.getPath());
    String docPath = FileUtil.normalizePath(docFO.getParent().getPath());
    if (!docPath.startsWith(rootPath)) {
        // #228262 sanity check, for files which are outside of any source root
        return null;
    }

    // Java Controller
    String javaPath = path.trim().replace("\"", "").replace('.', '/') + ".java"; // NOI18N
    fo = cp.findResource(javaPath);
    if (fo == null) {
        javaPath = docPath.substring(rootPath.length()) + '/' + javaPath; // NOI18N
        fo = cp.findResource(javaPath);
    }
    
    // CSS file
    if (fo == null) {
        // try short path
        String cssPath = path.trim().replace("\"", "").replace("@", ""); // NOI18N
        fo = cp.findResource(cssPath);
        // try full path
        if (fo == null) {
            cssPath = docPath.substring(rootPath.length()) + '/' + cssPath; // NOI18N
            fo = cp.findResource(cssPath);
        }
    }
    return fo;
}