public URL getIndexURL()

in remoting/ide/downloadable/src/org/netbeans/modules/jackpot30/remoting/downloadable/IndexDownloaderImpl.java [46:86]


    public URL getIndexURL(URL sourceRoot) {
        FileObject sourceRootFO = URLMapper.findFileObject(sourceRoot);

        if (sourceRootFO == null) return null;

        for (RemoteIndex ri : RemoteIndex.loadIndices()) {
            URL localFolderURL = ri.getLocalFolder();
            FileObject indexRootFO = localFolderURL != null ? URLMapper.findFileObject(localFolderURL) : null;

            if (indexRootFO == null) continue;

            if (FileUtil.isParentOf(indexRootFO, sourceRootFO) || indexRootFO == sourceRootFO) {
                String relativePath = FileUtil.getRelativePath(indexRootFO, sourceRootFO);
                InputStream in = null;

                try {
                    URL result = new URL(ri.remote.toExternalForm() + "/downloadable/netbeans?path=" + WebUtilities.escapeForQuery(ri.remoteSegment) + "&root=" + WebUtilities.escapeForQuery(relativePath));
                    HttpURLConnection c = (HttpURLConnection) result.openConnection();

                    if (c.getResponseCode() / 100 == 2 && (in = c.getInputStream()).read() != (-1)) //XXX: because the RepUp would currently throw an exception!
                        return result;
                } catch (MalformedURLException ex) {
                    Logger.getLogger(IndexDownloaderImpl.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(IndexDownloaderImpl.class.getName()).log(Level.SEVERE, null, ex);
                } catch (URISyntaxException ex) {
                    Logger.getLogger(IndexDownloaderImpl.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                    if (in != null) {
                        try {
                            in.close();
                        } catch (IOException ex) {
                            Logger.getLogger(IndexDownloaderImpl.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                }
            }
        }

        return null;
    }