KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > loaders > TestUtilHid


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.loaders;
21
22 import java.io.File JavaDoc;
23 import java.io.FileOutputStream JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.io.PrintWriter JavaDoc;
26 import java.net.URL JavaDoc;
27 import java.text.DecimalFormat JavaDoc;
28 import java.text.NumberFormat JavaDoc;
29 import java.util.Arrays JavaDoc;
30 import java.util.Enumeration JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.StringTokenizer JavaDoc;
35
36 import org.openide.filesystems.*;
37
38 /** Copy of TestUtilHid from filesystems tests.
39  * @author rm111737
40  */

41 public class TestUtilHid {
42     public static FileSystem createLocalFileSystem(String JavaDoc name, String JavaDoc[] resources) throws IOException JavaDoc {
43         File JavaDoc f = File.createTempFile (name, ".tmp");
44         f.delete ();
45         f = new File JavaDoc (f.getParent (), name);
46         f.mkdirs ();
47         return createLocalFileSystem (f, resources);
48     }
49
50     public static FileSystem createLocalFileSystem(File JavaDoc mountPoint, String JavaDoc[] resources) throws IOException JavaDoc {
51         mountPoint.mkdir();
52         
53         for (int i = 0; i < resources.length; i++) {
54             File JavaDoc f = new File JavaDoc (mountPoint,resources[i]);
55             if (f.isDirectory() || resources[i].endsWith("/")) {
56                 f.mkdirs();
57             }
58             else {
59                 f.getParentFile().mkdirs();
60                 try {
61                     f.createNewFile();
62                 } catch (IOException JavaDoc iex) {
63                     throw new IOException JavaDoc ("While creating " + resources[i] + " in " + mountPoint.getAbsolutePath() + ": " + iex.toString() + ": " + f.getAbsolutePath() + " with resource list: " + Arrays.asList(resources));
64                 }
65             }
66         }
67         
68         LocalFileSystem lfs = new StatusFileSystem();
69         try {
70         lfs.setRootDirectory(mountPoint);
71         } catch (Exception JavaDoc ex) {}
72         
73         return lfs;
74     }
75
76     public final static void destroyLocalFileSystem (String JavaDoc testName) throws IOException JavaDoc {
77     }
78
79     static class StatusFileSystem extends LocalFileSystem {
80         Status status = new Status () {
81             public String JavaDoc annotateName (String JavaDoc name, java.util.Set JavaDoc files) {
82                 return name;
83             }
84
85             public java.awt.Image JavaDoc annotateIcon (java.awt.Image JavaDoc icon, int iconType, java.util.Set JavaDoc files) {
86                 return icon;
87             }
88         };
89         
90         public org.openide.filesystems.FileSystem.Status getStatus() {
91             return status;
92         }
93         
94     }
95 }
96
Popular Tags