01: package org.geotools.catalog.styling;
02:
03: import java.io.File;
04: import java.io.FileFilter;
05: import java.net.URI;
06: import java.util.HashMap;
07: import java.util.Map;
08:
09: import org.geotools.catalog.Catalog;
10: import org.geotools.catalog.Service;
11: import org.geotools.catalog.ServiceFactory;
12:
13: public class SLDServiceFactory implements ServiceFactory {
14:
15: static String SLD_NAMESPACE = "http://www.opengis.net/sld";
16:
17: static String KEY = "sldFile";
18:
19: public Service createService(Catalog parent, URI id, Map params) {
20: return new SLDService(parent, new File(id));
21: }
22:
23: public boolean canProcess(URI uri) {
24: File file = new File(uri);
25: if (!file.exists())
26: return false;
27:
28: if (file.isDirectory()) {
29: File[] files = file.listFiles(new FileFilter() {
30:
31: public boolean accept(File pathname) {
32: return isSLDFile(pathname);
33: }
34:
35: });
36: return files.length > 0;
37: } else {
38: return isSLDFile(file);
39: }
40:
41: }
42:
43: public Map createParams(URI uri) {
44: if (canProcess(uri)) {
45: HashMap map = new HashMap();
46: map.put(KEY, uri);
47: return map;
48: }
49:
50: return null;
51: }
52:
53: static boolean isSLDFile(File file) {
54: String filename = file.getName();
55:
56: if (filename.length() > 3) {
57: String ext = filename.substring(filename.length() - 4);
58: return ext.equalsIgnoreCase(".sld")
59: || ext.equalsIgnoreCase(".xml");
60: }
61:
62: return false;
63: }
64:
65: }
|