01: package net.refractions.udig.style.sld.editor;
02:
03: import java.io.File;
04: import java.io.IOException;
05:
06: import net.refractions.udig.style.sld.SLDPlugin;
07: import net.refractions.udig.style.sld.internal.Messages;
08:
09: import org.eclipse.core.runtime.IProgressMonitor;
10: import org.geotools.styling.SLDParser;
11: import org.geotools.styling.StyleFactory;
12: import org.geotools.styling.StyleFactoryFinder;
13: import org.geotools.styling.StyledLayerDescriptor;
14:
15: public class ImportSLD extends ImportFrom {
16:
17: @Override
18: public boolean canImport(Object target) {
19: return super .canImport(target);
20: }
21:
22: @Override
23: public String defaultName(Object target) {
24: //unused??
25: return null;
26: }
27:
28: @Override
29: public String prompt(Object target) {
30: return Messages.ImportSLD_title;
31: }
32:
33: @Override
34: public String[] getExtentions() {
35: return addTo(new String[] { "sld" }, super .getExtentions()); //$NON-NLS-1$
36: }
37:
38: @Override
39: public Object importFrom(File file, IProgressMonitor monitor)
40: throws Exception {
41: StyleFactory factory = StyleFactoryFinder.createStyleFactory();
42: SLDParser stylereader = new SLDParser(factory, file);
43: StyledLayerDescriptor newSLD = stylereader.parseSLD();
44: //TODO: handle exceptions
45: if (newSLD == null) {
46: //exceptional!
47: SLDPlugin.log("SLD Import returned null", null); //$NON-NLS-1$
48: throw (IOException) new IOException(
49: "SLD import returned null"); //$NON-NLS-1$
50: }
51: return newSLD;
52: }
53:
54: @Override
55: public String[] getFilterNames() {
56: return addTo(
57: new String[] { Messages.ImportExportSLD_document },
58: super.getFilterNames());
59: }
60:
61: }
|