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