Revision 9331 branches/v10/extensions/extScripting/src/org/gvsig/scripting/ScriptingExtension.java
ScriptingExtension.java | ||
---|---|---|
1 | 1 |
package org.gvsig.scripting; |
2 | 2 |
|
3 |
import java.io.File; |
|
4 |
import java.io.FileReader; |
|
3 | 5 |
import java.io.IOException; |
4 | 6 |
import java.net.URLDecoder; |
5 | 7 |
import java.util.Hashtable; |
... | ... | |
8 | 10 |
import org.apache.bsf.BSFEngine; |
9 | 11 |
import org.apache.bsf.BSFException; |
10 | 12 |
import org.apache.bsf.BSFManager; |
13 |
import org.gvsig.scripting.xul.XULInfoToolSupport; |
|
14 |
import org.gvsig.scripting.xul.XULScriptablePanel; |
|
11 | 15 |
|
12 | 16 |
import thinlet.script.ScriptableThinlet; |
13 | 17 |
|
14 | 18 |
import com.iver.andami.PluginServices; |
15 | 19 |
import com.iver.andami.plugins.Extension; |
16 | 20 |
import com.iver.andami.ui.mdiManager.IWindow; |
21 |
import com.iver.cit.gvsig.project.documents.view.info.gui.InfoToolViewer; |
|
17 | 22 |
|
18 | 23 |
public class ScriptingExtension extends Extension { |
19 | 24 |
private static BSFManager bsfManager; |
... | ... | |
77 | 82 |
// TODO Auto-generated catch block |
78 | 83 |
e.printStackTrace(); |
79 | 84 |
} |
80 |
|
|
85 |
|
|
81 | 86 |
return bsfManager; |
82 | 87 |
} |
83 | 88 |
|
84 | 89 |
public void initialize() { |
85 |
// TODO Recivirlo como paramentro |
|
86 |
//this.scriptFileName = "./centerToPoint.xml"; |
|
87 |
|
|
88 |
|
|
90 |
XULScriptablePanel.setBSFManager( getBSFManager() ); |
|
91 |
InfoToolViewer.XULPanelClass = XULInfoToolSupport.class; |
|
89 | 92 |
} |
90 | 93 |
|
91 | 94 |
public void execute(String actionCommand) { |
... | ... | |
122 | 125 |
} |
123 | 126 |
} |
124 | 127 |
|
128 |
private void runStartupScripJython() { |
|
129 |
BSFEngine bsfEngine; |
|
130 |
try { |
|
131 |
bsfEngine = getBSFManager().loadScriptingEngine(JYTHON); |
|
132 |
String startUpFileName = ScriptingExtension.getScriptingAppAccesor().getScriptsDirectory(); |
|
133 |
startUpFileName = startUpFileName + File.separatorChar+ "jython"+ File.separatorChar+"startup.py"; |
|
134 |
File startupFile = new File(startUpFileName); |
|
135 |
|
|
136 |
if (!startupFile.exists()) { |
|
137 |
//throw new IOException("Startup File "+startUpFileName+" not found"); |
|
138 |
return; |
|
139 |
} |
|
140 |
String startupCode = readFile(startupFile); |
|
141 |
bsfEngine.exec(startUpFileName, -1, -1, startupCode); |
|
142 |
} catch (BSFException e) { |
|
143 |
// TODO Auto-generated catch block |
|
144 |
e.printStackTrace(); |
|
145 |
} catch (IOException e) { |
|
146 |
// TODO Auto-generated catch block |
|
147 |
e.printStackTrace(); |
|
148 |
} |
|
149 |
} |
|
150 |
|
|
151 |
private String readFile(File aFile) throws IOException { |
|
152 |
StringBuffer fileContents = new StringBuffer(); |
|
153 |
FileReader fileReader = new FileReader(aFile); |
|
154 |
int c; |
|
155 |
while ((c = fileReader.read()) > -1) { |
|
156 |
fileContents.append((char)c); |
|
157 |
} |
|
158 |
fileReader.close(); |
|
159 |
return fileContents.toString(); |
|
160 |
} |
|
161 |
|
|
125 | 162 |
public static Object show(Map params) { |
126 | 163 |
DefaultThinlet.setBSFManager(getBSFManager()); |
127 | 164 |
ScriptPanel panel; |
Also available in: Unified diff