1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.hivemind.util; |
16 |
| |
17 |
| import java.io.IOException; |
18 |
| import java.io.InputStream; |
19 |
| import java.net.MalformedURLException; |
20 |
| import java.net.URL; |
21 |
| import java.util.Locale; |
22 |
| |
23 |
| import org.apache.hivemind.ApplicationRuntimeException; |
24 |
| import org.apache.hivemind.Resource; |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| public class URLResource extends AbstractResource |
33 |
| { |
34 |
| private URL _url; |
35 |
| |
36 |
278
| public URLResource( URL url )
|
37 |
| { |
38 |
278
| super( url.toString() );
|
39 |
278
| _url = url;
|
40 |
| } |
41 |
| |
42 |
17
| public URLResource( String path )
|
43 |
| { |
44 |
17
| super( path );
|
45 |
| } |
46 |
| |
47 |
67
| public String toString()
|
48 |
| { |
49 |
67
| return getPath();
|
50 |
| } |
51 |
| |
52 |
17
| protected Resource newResource( String path )
|
53 |
| { |
54 |
17
| return new URLResource( path );
|
55 |
| } |
56 |
| |
57 |
293
| public URL getResourceURL()
|
58 |
| { |
59 |
293
| if( _url == null )
|
60 |
| { |
61 |
17
| try
|
62 |
| { |
63 |
17
| URL test = new URL( getPath() );
|
64 |
17
| InputStream stream = test.openStream();
|
65 |
7
| if( stream != null )
|
66 |
| { |
67 |
7
| stream.close();
|
68 |
7
| _url = test;
|
69 |
| } |
70 |
| } |
71 |
| catch( MalformedURLException ex ) |
72 |
| { |
73 |
0
| throw new ApplicationRuntimeException( ex );
|
74 |
| } |
75 |
| catch( IOException ex ) |
76 |
| { |
77 |
| |
78 |
| |
79 |
| } |
80 |
| } |
81 |
293
| return _url;
|
82 |
| } |
83 |
| |
84 |
| |
85 |
| |
86 |
| |
87 |
0
| public Resource getLocalization( Locale locale )
|
88 |
| { |
89 |
0
| return this;
|
90 |
| } |
91 |
| } |