Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_914 / extensions / extScripting / src / org / gvsig / scripting / DefaultThinlet.java @ 12200

History | View | Annotate | Download (3.25 KB)

1 5565 jmvivo
package org.gvsig.scripting;
2
3
import java.awt.Container;
4
import java.io.BufferedReader;
5
import java.io.File;
6
import java.io.FileInputStream;
7
import java.io.IOException;
8
import java.io.InputStream;
9
import java.io.InputStreamReader;
10
import java.io.LineNumberReader;
11
import java.net.MalformedURLException;
12
import java.net.URL;
13
14
import javax.swing.JDialog;
15
16 5741 jmvivo
import org.apache.bsf.BSFDeclaredBean;
17 5565 jmvivo
import org.apache.bsf.BSFException;
18 5741 jmvivo
import org.apache.bsf.BSFManager;
19 5565 jmvivo
20
import thinlet.script.ScriptableThinlet;
21
22
import com.iver.andami.PluginServices;
23 6877 cesar
import com.iver.andami.ui.mdiManager.IWindow;
24 5565 jmvivo
25
public class DefaultThinlet extends ScriptableThinlet {
26
27
        public DefaultThinlet() throws BSFException {
28
                super();
29
        }
30
31
        public DefaultThinlet(String scriptLanguage) throws BSFException {
32
                super(scriptLanguage);
33
        }
34 5741 jmvivo
35
        public static void setBSFManager(BSFManager bsfManager) {
36
                fbsfManager = bsfManager;
37
        }
38 5565 jmvivo
39
        /**
40
         *
41
         */
42
        private static final long serialVersionUID = 8042912379044685040L;
43
44 5596 jmvivo
    public Object parse(File file) throws IOException {
45
        return parse(file, this);
46
    }
47 5565 jmvivo
48 5596 jmvivo
49 5565 jmvivo
    public Object parse(String path, Object handler) throws IOException {
50
        ffilename = path;
51
        InputStream inputstream = null;
52
        try {
53
            inputstream = getClass().getResourceAsStream(path);
54
            if (inputstream == null) {
55
56
                try {
57
                    inputstream = new URL(path).openStream();
58
                } catch (MalformedURLException mfe) {
59
                        try {
60
                                File file = new File(path);
61
                                inputstream = new FileInputStream(file);
62
                        } catch (Exception e) {
63
                                /* thows nullpointerexception*/
64
                        }
65
                }
66
67
            }
68
            fin = new LineNumberReader(new BufferedReader(new InputStreamReader(inputstream)));
69
            fin.setLineNumber(1);
70
            Object ret = parse(fin, true, false, handler);
71
            return ret;
72
        } finally{
73
            fin = null;
74
            if(inputstream != null) try{inputstream.close();}catch(IOException ignore){}
75
        }
76
    }
77
78 5596 jmvivo
    public Object parse(File file, Object handler) throws IOException {
79
        ffilename = file.getAbsolutePath();
80
        InputStream inputstream = null;
81
82
        try {
83
                try {
84
                        inputstream = new FileInputStream(file);
85
                } catch (Exception e) {
86
                        /* thows nullpointerexception*/
87
                }
88
                fin = new LineNumberReader(new BufferedReader(new InputStreamReader(inputstream)));
89
                fin.setLineNumber(1);
90
                Object ret = parse(fin, true, false, handler);
91
                return ret;
92
        } finally{
93
            fin = null;
94
            if(inputstream != null) try{inputstream.close();}catch(IOException ignore){}
95
        }
96
    }
97 5565 jmvivo
98
        public void closeWindow() {
99
        if (PluginServices.getMainFrame() == null) {
100
                Container dialog = this.getParent();
101
                int i=0;
102
                while (i < 150) {
103
                        if (dialog instanceof JDialog) {
104
                                ((JDialog)dialog).dispose();
105
                                break;
106
                        }
107
                                dialog = dialog.getParent();
108
                                i++;
109
                        }
110
        } else {
111 6880 cesar
            PluginServices.getMDIManager().closeWindow((IWindow)this.getParent());
112 5565 jmvivo
        }
113
        }
114 5741 jmvivo
115
116 5565 jmvivo
}