Revision 1993
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/resourcesstorage/URLResource.java | ||
---|---|---|
1 |
package org.gvsig.tools.resourcesstorage; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.io.InputStream; |
|
5 |
import java.io.OutputStream; |
|
6 |
import java.net.URL; |
|
7 |
import org.apache.commons.io.IOUtils; |
|
8 |
|
|
9 |
/** |
|
10 |
* |
|
11 |
* @author jjdelcerro |
|
12 |
*/ |
|
13 |
@SuppressWarnings("UseSpecificCatch") |
|
14 |
public class URLResource implements ResourcesStorage.Resource { |
|
15 |
|
|
16 |
private final URL url; |
|
17 |
private InputStream is; |
|
18 |
|
|
19 |
public URLResource(URL url) { |
|
20 |
this.url = url; |
|
21 |
this.is = null; |
|
22 |
} |
|
23 |
|
|
24 |
@Override |
|
25 |
public boolean isReadOnly() { |
|
26 |
return true; |
|
27 |
} |
|
28 |
|
|
29 |
@Override |
|
30 |
public URL getURL() { |
|
31 |
return this.url; |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
public boolean exists() { |
|
36 |
if( this.is!=null ) { |
|
37 |
return true; |
|
38 |
} |
|
39 |
try { |
|
40 |
this.is = this.url.openStream(); |
|
41 |
return true; |
|
42 |
} catch (Exception ex) { |
|
43 |
return false; |
|
44 |
} |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
public InputStream asInputStream() throws IOException { |
|
49 |
if( this.is!=null ) { |
|
50 |
throw new RuntimeException("Stream already open"); |
|
51 |
} |
|
52 |
this.is = this.url.openStream(); |
|
53 |
return this.is; |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public OutputStream asOutputStream() throws IOException { |
|
58 |
return null; |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public void close() { |
|
63 |
IOUtils.closeQuietly(this.is); |
|
64 |
this.is = null; |
|
65 |
} |
|
66 |
|
|
67 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/resourcesstorage/EmptyResourcesStorage.java | ||
---|---|---|
1 | 1 |
package org.gvsig.tools.resourcesstorage; |
2 | 2 |
|
3 |
import java.io.IOException; |
|
4 |
import java.io.InputStream; |
|
5 |
import java.io.OutputStream; |
|
6 |
import java.net.URL; |
|
3 | 7 |
import java.util.List; |
4 | 8 |
|
5 | 9 |
/** |
... | ... | |
8 | 12 |
*/ |
9 | 13 |
public class EmptyResourcesStorage implements ResourcesStorage { |
10 | 14 |
|
15 |
public static class EmptyResource implements ResourcesStorage.Resource { |
|
16 |
|
|
17 |
@Override |
|
18 |
public boolean isReadOnly() { |
|
19 |
return true; |
|
20 |
} |
|
21 |
|
|
22 |
@Override |
|
23 |
public URL getURL() { |
|
24 |
return null; |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public boolean exists() { |
|
29 |
return false; |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public InputStream asInputStream() throws IOException { |
|
34 |
return null; |
|
35 |
} |
|
36 |
|
|
37 |
@Override |
|
38 |
public OutputStream asOutputStream() throws IOException { |
|
39 |
return null; |
|
40 |
} |
|
41 |
|
|
42 |
@Override |
|
43 |
public void close() { |
|
44 |
} |
|
45 |
|
|
46 |
} |
|
47 |
|
|
11 | 48 |
@Override |
12 | 49 |
public Resource getResource(String name) { |
13 | 50 |
return null; |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/resourcesstorage/ResourcesStorage.java | ||
---|---|---|
4 | 4 |
import java.io.IOException; |
5 | 5 |
import java.io.InputStream; |
6 | 6 |
import java.io.OutputStream; |
7 |
import java.net.URI; |
|
7 | 8 |
import java.net.URL; |
8 | 9 |
import java.util.List; |
9 | 10 |
|
... | ... | |
11 | 12 |
* |
12 | 13 |
* @author jjdelcerro |
13 | 14 |
*/ |
15 |
@SuppressWarnings("UseSpecificCatch") |
|
14 | 16 |
public interface ResourcesStorage { |
15 | 17 |
|
16 | 18 |
public interface Resource extends Closeable { |
... | ... | |
47 | 49 |
return new BaseMultiResourcesStorage(); |
48 | 50 |
} |
49 | 51 |
|
52 |
public static Resource createResource(URL url) { |
|
53 |
try { |
|
54 |
return new URLResource(url); |
|
55 |
} catch (Exception ex) { |
|
56 |
return null; |
|
57 |
} |
|
58 |
} |
|
59 |
|
|
60 |
public static Resource createResource(URI uri) { |
|
61 |
try { |
|
62 |
return new URLResource(uri.toURL()); |
|
63 |
} catch (Exception ex) { |
|
64 |
return null; |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
50 | 68 |
public String getSeparator(); |
51 | 69 |
|
52 | 70 |
public Resource getResource(String resourceName); |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/resourcesstorage/FilesResourcesStorage.java | ||
---|---|---|
125 | 125 |
} |
126 | 126 |
|
127 | 127 |
@Override |
128 |
public String getSeparator() { |
|
129 |
return "."; |
|
130 |
} |
|
131 |
|
|
132 |
@Override |
|
133 | 128 |
public Resource getResource(String resourceName) { |
134 | 129 |
File fres; |
135 | 130 |
for (String pathName : resourcesPaths) { |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/resourcesstorage/AbstractResourcesStorage.java | ||
---|---|---|
12 | 12 |
*/ |
13 | 13 |
public abstract class AbstractResourcesStorage implements ResourcesStorage { |
14 | 14 |
|
15 |
|
|
15 | 16 |
@Override |
17 |
public String getSeparator() { |
|
18 |
return "."; |
|
19 |
} |
|
20 |
|
|
21 |
@Override |
|
16 | 22 |
public boolean isEmpty() { |
17 | 23 |
return false; |
18 | 24 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/script/impl/DummyScriptManager.java | ||
---|---|---|
2 | 2 |
package org.gvsig.tools.script.impl; |
3 | 3 |
|
4 | 4 |
import java.net.URI; |
5 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
|
5 | 6 |
import org.gvsig.tools.script.Script; |
6 | 7 |
import org.gvsig.tools.script.ScriptManager; |
7 | 8 |
|
... | ... | |
26 | 27 |
public Script loadScript(URI location) { |
27 | 28 |
return null; |
28 | 29 |
} |
30 |
|
|
31 |
@Override |
|
32 |
public Script loadScript(ResourcesStorage storage, String name) { |
|
33 |
return null; |
|
34 |
} |
|
29 | 35 |
|
30 | 36 |
} |
Also available in: Unified diff