This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 41506
Collapse All | Expand All

(-)src/org/openide/filesystems/FileUtil.java (-25 / +14 lines)
Lines 273-278 Link Here
273
    }
273
    }
274
    /** Finds appropriate FileObjects to java.io.File if possible.
274
    /** Finds appropriate FileObjects to java.io.File if possible.
275
     * If not possible then null is returned.
276
     * @param file File whose coresponding FileObjects will be looked for
277
     * @return corresponding FileObject or null
278
     * @since X.XX
279
     */
280
    public static FileObject toFileObject (File file) {
281
        FileObject[] fileObjects = fromFile (file);
282
        return (fileObjects != null && fileObjects.length > 0) ? fileObjects[0] : null;
283
    }
284
285
    /** Finds appropriate FileObjects to java.io.File if possible.
275
     * If not possible then empty array is returned. More FileObjects may
286
     * If not possible then empty array is returned. More FileObjects may
276
     * correspond to one java.io.File that`s why array is returned.
287
     * correspond to one java.io.File that`s why array is returned.
277
     * @param file File whose coresponding FileObjects will be looked for.
288
     * @param file File whose coresponding FileObjects will be looked for.
Lines 281-286 Link Here
281
     * @return corresponding FileObjects or empty array  if no
292
     * @return corresponding FileObjects or empty array  if no
282
     * corresponding FileObject exists.
293
     * corresponding FileObject exists.
283
     * @since 1.29
294
     * @since 1.29
295
     * @deprecated Use method {@link #toFileObject toFileObject}
284
     */
296
     */
285
    public static FileObject[] fromFile (File file) {
297
    public static FileObject[] fromFile (File file) {
286
        if (!file.equals(normalizeFile(file))) {
298
        if (!file.equals(normalizeFile(file))) {
Lines 826-854 Link Here
826
    }
838
    }
827
    /**
839
    /**
828
     * This method is very similar to URLMapper.findFileObjects(URL) with
829
     * difference that it returns just one file object and that it knows
830
     * which file object must be used from available ones.
831
     *
832
     * @param url url to be converted to file object
833
     * @return file object corresponding to url or null if no one was found
834
     * @since XXX
835
     */
836
    public static FileObject findFileObject(URL url) {
837
        FileObject fos[] = URLMapper.findFileObjects(url);
838
        if (fos.length == 0) {
839
            return null;
840
        }
841
        // prefer file object from master filesystem
842
        for (int i=0; i<fos.length; i++) {
843
            if (fos[i].getClass().getName().indexOf("masterfs") != -1) {        //NOI18N
844
                return fos[i];
845
            }
846
        }
847
        return fos[0];
848
    }
849
850
    /**
851
     * Returns a FileObject of the root of an jar/zip archive
840
     * Returns a FileObject of the root of an jar/zip archive
852
     * given be an argument.
841
     * given be an argument.
853
     * @param fo FileObject of the zip/jar archive file
842
     * @param fo FileObject of the zip/jar archive file
Lines 860-866 Link Here
860
        if (archiveURL == null) {
849
        if (archiveURL == null) {
861
            return null;
850
            return null;
862
        }
851
        }
863
        return findFileObject(getArchiveRoot(archiveURL));
852
        return URLMapper.findFileObject(getArchiveRoot(archiveURL));
864
    }
853
    }
865
    /**
854
    /**
Lines 968-974 Link Here
968
     * @since XXX
957
     * @since XXX
969
     */
958
     */
970
    public static boolean isArchiveFile (URL url) {
959
    public static boolean isArchiveFile (URL url) {
971
        FileObject fo = findFileObject(url);
960
        FileObject fo = URLMapper.findFileObject(url);
972
        if (fo!=null) {
961
        if (fo!=null) {
973
            return isArchiveFile(fo);
962
            return isArchiveFile(fo);
974
        }
963
        }
(-)src/org/openide/filesystems/URLMapper.java (-3 / +34 lines)
Lines 111-117 Link Here
111
     * <code> findURL(FileObject fo, int type) </code>.
111
     * <code> findURL(FileObject fo, int type) </code>.
112
     * @param url to wanted FileObjects
112
     * @param url to wanted FileObjects
113
     * @return a suitable arry of FileObjects, or empty array if not successful
113
     * @return a suitable arry of FileObjects, or empty array if not successful
114
     * @since  2.22*/
114
     * @since  2.22
115
     * @deprecated use method {@link #findFileObject findFileObject}
116
     */
115
    public static FileObject[] findFileObjects (URL url) {
117
    public static FileObject[] findFileObjects (URL url) {
116
        /** first basic implementation */
118
        /** first basic implementation */
117
        Set retSet = new HashSet ();
119
        Set retSet = new HashSet ();
Lines 131-139 Link Here
131
        return retVal;
133
        return retVal;
132
    }
134
    }
133
    /** Get an array of FileObjects for this url
135
    /** Find an appropiate instance of FileObject that addresses this url
136
     *
137
     * @param url url to be converted to file object
138
     * @return file object corresponding to url or null if no one was found
139
     * @since  X.XX
140
     */
141
    public static FileObject findFileObject (URL url) {
142
        FileObject[] results  = null;
143
144
        Iterator instances = getInstances().iterator();
145
        while (instances.hasNext() && results  ==  null) {
146
            URLMapper mapper = (URLMapper) instances.next();
147
            if (mapper == getDefault ()) continue;
148
            results  = mapper.getFileObjects (url);
149
        }
150
151
        /** first basic implementation */
152
        if (results == null) {
153
            results = getDefault ().getFileObjects (url);
154
        }
155
156
        return (results != null && results.length > 0) ? results[0] : null;
157
    }
158
159
160
    /** Get an array of FileObjects for this url. There is no reason to return array
161
     * with size greater than one because method {@link #findFileObject findFileObject}
162
     * uses just first element (next elements won't be accepted anyway).
163
     * <p class="nonnormative"> There isn't necessary to return array here.
164
     * The only one reason is just backward compatibility.</p>
134
     * @param url to wanted FileObjects
165
     * @param url to wanted FileObjects
135
     * @return a suitable arry of FileObjects, or null
166
     * @return an array of FileObjects with size no greater than one, or null
136
     * @since  2.22*/
167
     * @since  2.22*/
137
    public abstract FileObject[] getFileObjects (URL url);
168
    public abstract FileObject[] getFileObjects (URL url);
(-)test/unit/src/org/openide/filesystems/FileUtilTestHidden.java (+19 lines)
Lines 51-54 Link Here
51
        assertNotNull(testFile);
51
        assertNotNull(testFile);
52
        assertTrue(testFile.exists());
52
        assertTrue(testFile.exists());
53
    }
53
    }
54
55
    public void testToFileObject () throws Exception {
56
        assertNotNull(root);
57
        FileObject testFo = root.getFileObject("fileutildir/tofileobject.txt");
58
        assertNotNull(testFo);
59
60
        File rootFile = FileUtil.toFile(root);
61
        assertNotNull(rootFile);
62
        assertTrue(rootFile.exists());
63
64
        File testFile = new File (rootFile, "fileutildir/tofileobject.txt");
65
        assertNotNull(testFile);
66
        assertTrue(testFile.exists());
67
68
        FileObject testFo2 = FileUtil.toFileObject(testFile);
69
        assertNotNull(testFo2);
70
        assertEquals(testFo2, testFo);
71
    }
72
54
}
73
}
(-)test/unit/src/org/openide/filesystems/URLMapperTestHidden.java (+23 lines)
Lines 94-99 Link Here
94
        }
94
        }
95
    }
95
    }
96
    public void testConversions2 () throws Exception {
97
        assertNotNull(root);
98
        implTestConversions2(root);
99
100
101
        Enumeration en = root.getChildren(true);
102
        while (en.hasMoreElements()) {
103
            FileObject fileObject = (FileObject) en.nextElement();
104
            implTestConversions2(fileObject);
105
        }
106
107
    }
108
109
    private void implTestConversions2 (FileObject fo)  {
110
        URL urlFromMapper = URLMapper.findURL(fo, getURLType());
111
        if (isNullURLExpected(urlFromMapper, fo)) return;
112
113
        assertNotNull(urlFromMapper);
114
115
        FileObject fileObject = URLMapper.findFileObject(urlFromMapper);
116
        assertEquals(fo, fileObject);
117
    }
118
96
    private void implTestIfReachable(FileObject fo) throws Exception {
119
    private void implTestIfReachable(FileObject fo) throws Exception {
97
        URL urlFromMapper = URLMapper.findURL(fo, getURLType());
120
        URL urlFromMapper = URLMapper.findURL(fo, getURLType());

Return to bug 41506