svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / ext3D / src / com / iver / ai2 / gvsig3d / resources / ResourcesFactory.java @ 15441
History | View | Annotate | Download (2.21 KB)
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.gvsig3dgui/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 |
} |
61 |
} |
62 |
|
63 |
return resourcesList;
|
64 |
} |
65 |
|
66 |
/**
|
67 |
* Method to verify if this resource exits
|
68 |
*
|
69 |
* @param name
|
70 |
* Name of resource
|
71 |
* @return True or false
|
72 |
*/
|
73 |
public static boolean exitsResouce(String name) { |
74 |
boolean exit = false; |
75 |
String[] resourcesList = ResourcesFactory.getResources(); |
76 |
if (resourcesList != null) { |
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 |
} |
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 |
textPath = System.getProperty("user.dir") + extPath; |
97 |
} |
98 |
|
99 |
/**
|
100 |
* Method to get the extension path
|
101 |
*
|
102 |
* @param extPath
|
103 |
*/
|
104 |
public static String getExtPath() { |
105 |
return ResourcesFactory.extPath;
|
106 |
} |
107 |
} |