Revision 15094
import/ext3D/trunk/ext3D/src/com/iver/ai2/gvsig3d/resources/ResourcesFactory.java | ||
---|---|---|
1 |
package com.iver.ai2.gvsig3d.resources; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
|
|
5 |
/** |
|
6 |
* @author julio |
|
7 |
* |
|
8 |
* This class is a factory to find resources in 3D extensions |
|
9 |
* |
|
10 |
*/ |
|
11 |
public class ResourcesFactory { |
|
12 |
|
|
13 |
private static String textPath; |
|
14 |
|
|
15 |
private static String extPath; |
|
16 |
|
|
17 |
static { |
|
18 |
extPath = "/gvSIG/extensiones/com.iver.ai2.gvsig3d/resources/"; |
|
19 |
|
|
20 |
textPath = System.getProperty("user.dir") + extPath; |
|
21 |
} |
|
22 |
|
|
23 |
/** |
|
24 |
* Method to get Path resources directory |
|
25 |
* |
|
26 |
* @return |
|
27 |
*/ |
|
28 |
public static String getResourcesPath() { |
|
29 |
return textPath; |
|
30 |
} |
|
31 |
|
|
32 |
/** |
|
33 |
* Method to get path to specific resource |
|
34 |
* |
|
35 |
* @param name |
|
36 |
* Name of resource |
|
37 |
* @return All path resource |
|
38 |
*/ |
|
39 |
public static String getResourcePath(String name) { |
|
40 |
return textPath + name; |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* Method to get a list of all resources |
|
45 |
* |
|
46 |
* @return String array with all resources |
|
47 |
*/ |
|
48 |
public static String[] getResources() { |
|
49 |
String[] resourcesList; |
|
50 |
|
|
51 |
File dir = new File(ResourcesFactory.getResourcesPath()); |
|
52 |
|
|
53 |
resourcesList = dir.list(); |
|
54 |
if (resourcesList == null) { |
|
55 |
// Either dir does not exist or is not a directory |
|
56 |
} else { |
|
57 |
for (int i = 0; i < resourcesList.length; i++) { |
|
58 |
// Get filename of file or directory |
|
59 |
String filename = resourcesList[i]; |
|
60 |
System.out.println(filename); |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
return resourcesList; |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* Method to verify if this resource exits |
|
69 |
* |
|
70 |
* @param name |
|
71 |
* Name of resource |
|
72 |
* @return True or false |
|
73 |
*/ |
|
74 |
public static boolean exitsResouce(String name) { |
|
75 |
boolean exit = false; |
|
76 |
String[] resourcesList = ResourcesFactory.getResources(); |
|
77 |
|
|
78 |
for (int i = 0; i < resourcesList.length; i++) { |
|
79 |
// Get filename of file or directory |
|
80 |
String filename = resourcesList[i]; |
|
81 |
if (filename.equals(name)) |
|
82 |
return true; |
|
83 |
System.out.println(filename); |
|
84 |
} |
|
85 |
|
|
86 |
return exit; |
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* Method to set the extension path |
|
91 |
* |
|
92 |
* @param extPath |
|
93 |
*/ |
|
94 |
public static void setExtPath(String extPath) { |
|
95 |
ResourcesFactory.extPath = extPath; |
|
96 |
} |
|
97 |
} |
Also available in: Unified diff