Revision 1090

View differences:

org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>org.gvsig.scripting package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>TODO: Example library description.</p>
11
	
12
	<p>See the <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#packagecomment">Javadoc Tool documentation about the package file</a></p>
13

  
14
</body>
15
</html>
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/CompileErrorException.java
1
package org.gvsig.scripting;
2

  
3
import java.io.File;
4

  
5
public class CompileErrorException extends ScriptingErrorException {
6

  
7
	/**
8
	 * 
9
	 */
10
	private static final long serialVersionUID = -7829204331513125285L;
11

  
12
	public CompileErrorException(String msg, File name, int line, int column) {
13
		super(msg, name, line, column);
14
	}
15
	
16
	public CompileErrorException(String msg, File name, int line, int column, Throwable cause) {
17
		this(msg, name, line, column);
18
		this.initCause(cause);
19
	}
20
	
21
	public CompileErrorException(String msg, File name, Throwable cause) {
22
		this(msg, name, -1, -1);
23
		this.initCause(cause);
24
	}
25
}
0 26

  
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingBaseScript.java
1
package org.gvsig.scripting;
2

  
3
import java.io.File;
4
import java.io.Writer;
5

  
6
import org.gvsig.tools.observer.WeakReferencingObservable;
7

  
8
/**
9
 * <p>
10
 * Interface that represents Scripting elements.</p>
11
 *
12
 * @see ScriptingUnit
13
 *
14
 * @see ScriptingScript
15
 * @see ScriptingDialog
16
 * @see ScriptingProject
17
 */
18
public interface ScriptingBaseScript extends ScriptingUnit, WeakReferencingObservable {
19

  
20
    public static final int ISOLATION_LOW = 0;
21
    public static final int ISOLATION_HIGH = 10;
22
    
23
    /**
24
     * Check if the script execution is enabled.
25
     *
26
     * @return if the script is enabled.
27
     */
28
    public boolean isEnabled();
29

  
30
    /**
31
     * Enable or disable the sript execution.
32
     *
33
     * @param enabled
34
     */
35
    public void setEnabled(boolean enabled);
36

  
37
    /**
38
     * Executes the code of a ScriptBaseScript.
39
     *
40
     * @return
41
     */
42
    public Object run();
43

  
44
    /**
45
     * Executes the code of a ScriptBaseScript.
46
     *
47
     * @param args Contains the input parameters to run the ScriptBaseScript.
48
     * @return
49
     */
50
    public Object run(Object args[]);
51

  
52
    /**
53
     * Executes the code of a ScriptBaseScript in a separated thread
54
     *
55
     * @param args Contains the input parameters to run the ScriptBaseScript.
56
     */
57
    public void runAsTask(Object args[]);
58

  
59
    public void compile() throws ScriptingRunningException;
60

  
61
    public void put(String name, Object value);
62

  
63
    /**
64
     * Return a resource File that is beside this script.
65
     *
66
     * @param filename
67
     * @return the file which is beside this script
68
     */
69
    public File getResource(String filename);
70

  
71
    public File getScriptFile();
72
  
73
    public String getLibrarySuffix();
74

  
75
    public void setLibrarySuffix(String librarySuffix);    
76
    
77
    public void addStdoutWriter(Writer out);
78
    
79
    public void addStderrWriter(Writer err);
80
    
81
    public void removeStdoutWriter(Writer out);
82
    
83
    public void removeStderrWriter(Writer err);
84
    
85
    public void setIsolationGroup(String group);
86
    
87
    public String getIsolationGroup();
88
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingDialog.java
1
package org.gvsig.scripting;
2

  
3
import java.io.File;
4

  
5
/**
6
 * <p> Interface that represents a single script with window dialog.</p>
7
 * 
8
 * @see ScriptingUnit
9
 * @see ScriptingBaseScript
10
 */
11
public interface ScriptingDialog extends ScriptingScript{
12

  
13
	public static final int MODE_DIALOG=1;
14
	public static final int MODE_WINDOW=2;
15
	public static final int MODE_TOOL=3;
16
	
17
	/**
18
	 * Returns the file where is the window dialog's gui.  
19
	 * 
20
	 * @return a File with the code of the window dialog.
21
	 */
22
	public File getDialogFile();
23

  
24
	/**
25
	 * Returns the type of the window dialog associated with the ScriptingDialog.  
26
	 * 
27
	 * @return an int with the window mode.
28
	 */
29
	public int getShowMode();
30
	
31
	/**
32
	 * Sets the window mode associated with a ScriptingDialog.
33
	 *
34
	 * @param mode
35
	 *            int that contains the window mode.
36
	 */
37
	public void setShowMode(int mode);
38
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingRunningException.java
1
package org.gvsig.scripting;
2

  
3
public class ScriptingRunningException extends Exception {
4

  
5
	/**
6
	 * 
7
	 */
8
	private static final long serialVersionUID = 4327337186862453971L;
9

  
10
	private String message;
11
	private String fileName;
12
	private int lineNunber;
13
	private int columnNumber;
14

  
15
	public ScriptingRunningException(String message, String fileName,
16
			int lineNumber, int columnNumber) {
17
		this.message = message;
18
		this.fileName = fileName;
19
		this.lineNunber = lineNumber;
20
		this.columnNumber = columnNumber;
21
	}
22

  
23
	public ScriptingRunningException(String message, String fileName) {
24
		this(message, fileName, -1, -1);
25
	}
26

  
27
	public int getLineNumber() {
28
		return this.lineNunber;
29
	}
30

  
31
	public int getColumnNumber() {
32
		return this.columnNumber;
33
	}
34

  
35
	public String getFileName() {
36
		return this.fileName;
37
	}
38

  
39
	public String getMessage() {
40
		return this.message;
41
	}
42
}
0 43

  
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingLocator.java
1
package org.gvsig.scripting;
2

  
3
import org.gvsig.tools.locator.BaseLocator;
4
import org.gvsig.tools.locator.Locator;
5
import org.gvsig.tools.locator.LocatorException;
6

  
7
public class ScriptingLocator extends BaseLocator {
8

  
9
	private static final String LOCATOR_NAME = "ScriptingLocator";
10

  
11
	public static final String MANAGER_NAME = "scriptinglocator.manager";
12

  
13
	public static final String MANAGER_DESCRIPTION = "Scripting Manager";
14

  
15
	/**
16
	 * Unique instance.
17
	 */
18
	private static final ScriptingLocator instance = new ScriptingLocator();
19

  
20
	/**
21
	 * Return the singleton instance.
22
	 *
23
	 * @return the singleton instance
24
	 */
25
	public static ScriptingLocator getInstance() {
26
		return instance;
27
	}
28

  
29
	/**
30
	 * Return the Locator's name
31
	 *
32
	 * @return a String with the Locator's name
33
	 */
34
	@Override
35
    public String getLocatorName() {
36
		return LOCATOR_NAME;
37
	}
38

  
39
    /**
40
     * Return a reference to ScriptManager.
41
     * 
42
     * @return a reference to ScriptManager
43
     * @throws LocatorException
44
     *             if there is no access to the class or the class cannot be
45
     *             instantiated
46
     * @see Locator#get(String)
47
     */
48
	public static ScriptingManager getManager() throws LocatorException {
49
		return (ScriptingManager) getInstance().get(MANAGER_NAME);
50
	}
51

  
52
    /**
53
     * Registers the Class implementing the ScriptManager interface.
54
     * 
55
     * @param clazz
56
     *            implementing the ScriptManager interface
57
     */
58
    public static void registerManager(Class<? extends ScriptingManager> clazz) {
59
		getInstance().register(MANAGER_NAME, MANAGER_DESCRIPTION, clazz);
60
	}
61
	
62
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingLibrary.java
1
package org.gvsig.scripting;
2

  
3
import org.gvsig.tools.library.AbstractLibrary;
4
import org.gvsig.tools.library.LibraryException;
5
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
6

  
7
public class ScriptingLibrary extends AbstractLibrary {
8

  
9
    @Override
10
    public void doRegistration() {
11
        registerAsAPI(ScriptingLibrary.class);
12
    }
13

  
14
    @Override
15
    protected void doInitialize() throws LibraryException {
16
        // Nothing to do
17
    }
18

  
19
    @Override
20
    protected void doPostInitialize() throws LibraryException {
21
        // Validate there is any implementation registered.
22
        ScriptingManager manager = ScriptingLocator.getManager();
23

  
24
        if (manager == null) {
25
            throw new ReferenceNotRegisteredException(
26
                ScriptingLocator.MANAGER_NAME, ScriptingLocator.getInstance());
27
        }
28
    }
29

  
30
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingScript.java
1
package org.gvsig.scripting;
2

  
3
import org.gvsig.tools.script.Script;
4

  
5

  
6
/**
7
 * <p> Interface that represents a single script without window dialog.</p>
8
 * 
9
 * @see ScriptingUnit
10
 * @see ScriptingBaseScript
11
 */
12
public interface ScriptingScript extends ScriptingBaseScript, Script {
13

  
14
	/**
15
	 * Returns the languange in which the ScriptingScript is written.
16
	 * 
17
	 * @return a String containing the name of the language
18
	 */
19
	public String getLangName();
20

  
21
	/**
22
	 * Returns the ScriptingScript's code.
23
	 * 
24
	 * @return a String with the code of the script.
25
	 */
26
        @Override
27
	public String getCode();
28

  
29
	/**
30
	 * Sets a the code associated with a ScriptingScript.
31
	 *
32
	 * @param code
33
	 *            String that contains the new code.
34
	 */
35
	public void setCode(String code);
36

  
37
	/**
38
	 * Returns the name of the main function in the ScriptingScript's code
39
	 * 
40
	 * @return a String with main function (default main name is 'main').
41
	 */
42
	public String getMainName();
43

  
44
	/**
45
	 * Stablishes a new main main function in the ScriptingScript's code.
46
	 *
47
	 * @param mainName
48
	 *            String that contains the new main function name.
49
	 */
50
	public void setMainName(String mainName);
51

  
52
	/**
53
	 * Persists the current status of a ScriptingScript with the content associated.
54
	 */
55
	public void save();
56
	
57
	/**
58
	 * Executes a method from the Script's code
59
	 * 
60
	 * @param obj this Object represents the script's code
61
	 * @param name method's name to execute
62
	 * @param args input parameters of the method 
63
	 * 
64
	 * @return An Object that represents the execution
65
	 * 
66
	 * @throws NoSuchMethodException If there isn't a main function to begin the execution
67
	 */
68
	public Object invokeMethod(Object obj, String name, Object[] args) throws NoSuchMethodException;
69
	
70
	/**
71
	 * Executes a function from the Script's code
72
	 * 
73
	 * @param name method's name to execute
74
	 * @param args input parameters of the method 
75
	 * 
76
	 * @return An Object that represents the execution
77
	 * 
78
	 * @throws NoSuchMethodException If there isn't a main function to begin the execution
79
	 */
80
        @Override
81
	public Object invokeFunction(String name, Object[] args) throws NoSuchMethodException;
82
	
83
        public String getMimeType();
84
        
85
        public void registerDataFolder(String id);
86
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ExecuteErrorException.java
1
package org.gvsig.scripting;
2

  
3
import java.io.File;
4

  
5
public class ExecuteErrorException extends ScriptingErrorException {
6

  
7
	/**
8
	 * 
9
	 */
10
	private static final long serialVersionUID = 3733567933742742587L;
11

  
12
	public ExecuteErrorException(String msg, File name, int line, int column) {
13
		super(msg, name, line, column);
14
	}
15
	
16
	public ExecuteErrorException(String msg, File name, int line, int column, Throwable cause) {
17
		this(msg, name, line, column);
18
		this.initCause(cause);
19
	}
20
	
21
	public ExecuteErrorException(String msg, File name, Throwable cause) {
22
		this(msg, name, -1, -1);
23
		this.initCause(cause);
24
	}
25
	
26
}
0 27

  
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingErrorException.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.scripting;
7

  
8
import java.io.File;
9
import org.apache.commons.io.FilenameUtils;
10

  
11
/**
12
 *
13
 * @author jjdelcerro
14
 */
15
public class ScriptingErrorException extends RuntimeException {
16
    private static final long serialVersionUID = -3489829775437358107L;
17
    private final File name;
18
    private final int line;
19
    private final int column;
20

  
21
    public ScriptingErrorException(String msg, File name, int line, int column) {
22
        super(msg);
23
        this.name = name;
24
        this.line = line;
25
        this.column = column;
26
    }
27

  
28
    public int getLineNumber() {
29
        return this.line;
30
    }
31

  
32
    public int getColumnNumber() {
33
        return this.column;
34
    }
35

  
36
    public String getScriptName() {
37
        return FilenameUtils.getBaseName(this.name.getName());
38
    }
39
   
40
    public File getScriptFile() {
41
        return this.name;
42
    }
43
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingManager.java
1
package org.gvsig.scripting;
2

  
3
import java.io.File;
4
import java.util.List;
5
import java.util.Map;
6
import java.util.Set;
7
import org.gvsig.tools.packageutils.Version;
8
import org.gvsig.tools.service.spi.ProviderFactory;
9
import org.gvsig.tools.script.ScriptManager;
10
import org.gvsig.tools.util.FolderSet;
11

  
12
/**
13
 * There are two top level management roles within ScriptingFramework: logical
14
 * and User's Interface (UI) management.
15
 *
16
 * This class is responsible of the logical role. It provides all the services
17
 * to manage the information used in ScriptingFramework.
18
 */
19
public interface ScriptingManager extends ScriptManager {
20

  
21
    public static final String INSTALLER_PROVIDER_NAME = "Script";
22
    public static final String INSTALLER_PROVIDER_DESCRIPTION = "Provider to install scripts";
23

  
24
    public static final String PYTHON_LANGUAGE_NAME = "python";
25
//    public static final String SCALA_LANGUAGE_NAME = "scala";
26
    public static final String DEFAULT_ISOLATION_GROUP = "default";
27
    
28
    public static final String UNIT_SCRIPT = "Script";
29
    public static final String UNIT_DIALOG = "Dialog";
30
    public static final String UNIT_FOLDER = "Folder";
31
    public static final String UNIT_EXTERNALFILE = "ExternalFile";
32

  
33
    public void setHomeFolder(File home);
34

  
35
    public File getHomeFolder();
36

  
37
    public File getDataFolder(String id);
38
    
39
    public void registerDataFolder(ScriptingFolder folderScript, String id);
40
    
41
    public List<DataFolderFound> searchOldVersions(Version currentVersion, FolderSet folder);
42
    
43
    /**
44
     * Returns the System's Folder
45
     *
46
     * @return a {@link ScriptingFolder} with the System's Folder.
47
     */
48
    public ScriptingFolder getSystemFolder();
49

  
50
    /**
51
     * Returns the User's Folder
52
     *
53
     * @return a {@link ScriptingFolder} with the User's Folder.
54
     */
55
    public ScriptingFolder getUserFolder();
56

  
57
    public List<ScriptingFolder> getAlternativeUserFolders();
58

  
59
    public void addAlternativeUserFolder(File f, String name, String description);
60

  
61
    public ScriptingUnit createUnit(String unitType, ScriptingFolder folder, String id);
62

  
63
    public ScriptingUnit createUnit(String unitType, ScriptingFolder folder, String id, String language);
64
    
65
    public List<String> getUnitTypes();
66

  
67
    /**
68
     * Returns the {@link ScriptingBaseScript} associated with the file
69
     * specified
70
     *
71
     * @param file File where is contained the {@link ScriptingBaseScript}'s
72
     * information
73
     *
74
     * @return {@link ScriptingBaseScript}
75
     */
76
    public ScriptingBaseScript getScript(File file);
77

  
78
    public ScriptingBaseScript getScript(String name);
79

  
80
    /**
81
     * Returns the {@link ScriptingFolder} associated with the file specified
82
     *
83
     * @param file File where is contained the {@link ScriptingFolder}'s
84
     * information
85
     *
86
     * @return {@link ScriptingFolder}
87
     */
88
    public ScriptingFolder getFolder(File file);
89
    
90
    /**
91
     * Return the {@link ScriptingUnit} associated with the path specified.
92
     * 
93
     * the path should start with "User" or "System".
94
     * 
95
     * @param pathName
96
     * 
97
     * @return the required {@link ScriptingUnit}
98
     */
99
    public ScriptingUnit getUnit(String pathName);
100

  
101

  
102
    /**
103
     * Returns the path of the User's Folder
104
     *
105
     * @return a String with the path of the User's Folder
106
     */
107
//    public String getRootUserFolder();
108
    /**
109
     * Registers a File System with {@link ScriptingUnit}s in the SystemFolder
110
     *
111
     * @param name String with the identificator name of the File System
112
     * registered
113
     * @param folder File with the root of the File System to register
114
     */
115
    public void registerSystemFolder(String name, File folder);
116

  
117
    public List<String> getSupportedLanguages();
118

  
119
    public String getExtensionOfLanguage(String language);
120

  
121
    public String getEngineNameByLanguage(String langName);
122
    
123
    public Set<String> getEnginesIsolationGroups();
124

  
125
    /**
126
     * Checks if an id is unique in a determinate folder
127
     *
128
     * @param folder {
129
     * @ScriptingFolder} with the directory to verify the id
130
     * @param id String with the id to validate
131
     *
132
     * @return true if there isn't another {@link ScriptingUnit} with the same
133
     * id, and false in the other case
134
     */
135
    public boolean validateUnitId(ScriptingFolder folder, String id);
136

  
137
    /**
138
     * Sets a key/value pair in the state of the ScriptingManager that may
139
     * either create a Java Language Binding to be used in the execution of
140
     * scripts
141
     *
142
     * @param key The name of named value to add
143
     * @param value The value of named value to add.
144
     */
145
    public void put(String key, Object value);
146

  
147
    /**
148
     * Retrieves a value set in the state of this ScriptingManager
149
     *
150
     * @param key The key whose value is to be returned
151
     *
152
     * @return an Object with the value corresponding to the key
153
     */
154
    public Object get(String key);
155

  
156
    public void addLibFolder(File lib);
157

  
158
    public File getRootUserFolder();
159
    
160
    public ProviderFactory getInstallerFactory();
161
    
162
    /**
163
     * Devuelbe la carpeta en la que se encuentran los paquetes
164
     * de la aplicacion.
165
     * 
166
     * @return 
167
     */
168
    public File getPackagesFolder();
169
    
170
    /**
171
     * Establece la carpeta en la que se encuentran los paquetes
172
     * de la aplicacion.
173
     * @param folder 
174
     */
175
    public void setPackagesFolder(File folder);
176
    
177
    /**
178
     * Search the available engines and initialize the manager.
179
     */
180
    public void loadEngines();
181
    
182
    public List<File> getLibFolders();
183
    
184
    /**
185
     * Return a map with the label and suffix of the library versions.
186
     * 
187
     * For each value of map, the value is the name of the version (a label) and
188
     * the key is the suffix for that version.
189
     * 
190
     * @return a map with suffix and labels of library versions. 
191
     */
192
    public Map<String,String> getLibFoldersVersions();
193
    
194
    /**
195
     * <p>
196
     * Returns a reference to an object (property) associated to this layer.</p>
197
     *
198
     * <p>
199
     * For example, you can attach a network definition to key "network" and
200
     * check
201
     * if a layer has a network loaded using
202
     * <i>getAssociatedObject("network")</i> and
203
     * that it's not null.</p>
204
     *
205
     * @param key the key associated to the property
206
     *
207
     * @return <code>null</code> if key is not found
208
     *
209
     * @see #getExtendedProperties()
210
     * @see #setProperty(Object, Object)
211
     */
212
    public Object getProperty(Object key);
213

  
214
    /**
215
     * Inserts an object as a property to this layer.
216
     *
217
     * @param key the key associated to the property
218
     * @param obj the property
219
     *
220
     * @see #getProperty(Object)
221
     * @see #getExtendedProperties()
222
     */
223
    public void setProperty(Object key, Object obj);
224

  
225
    /**
226
     * Returns a hash map with all new properties associated to this layer.
227
     *
228
     * @return hash table with the added properties
229
     *
230
     * @see #getProperty(Object)
231
     * @see #setProperty(Object, Object)
232
     */
233
    public Map getExtendedProperties();   
234
    
235
    public ScriptingFolder createLink(String name, File link, String targetPathName);
236

  
237
    public ScriptingFolder createLink(String name, ScriptingFolder link, String targetPathName);
238
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingFolder.java
1
package org.gvsig.scripting;
2

  
3
import java.io.File;
4
import java.io.IOException;
5
import java.util.List;
6
import java.util.function.Predicate;
7
import org.gvsig.tools.exception.BaseException;
8
import org.gvsig.tools.visitor.Visitable;
9
import org.gvsig.tools.visitor.Visitor;
10

  
11
/**
12
 * <p>
13
 * Interface that represents a directory in the ScriptingFramework.</p>
14
 *
15
 * @see ScriptingUnit
16
 */
17
public interface ScriptingFolder extends ScriptingUnit, Visitable {
18

  
19
    /**
20
     * Adds a {@link ScriptingUnit} to the ScriptingFolder.
21
     *
22
     * @param unit {@link ScriptingUnit} to include.
23
     */
24
    public void add(ScriptingUnit unit);
25

  
26
    /**
27
     * Removes a {@link ScriptingUnit} from the ScriptingFolder.
28
     *
29
     * @param unit {@link ScriptingUnit} to delete.
30
     */
31
    public void remove(ScriptingUnit unit);
32

  
33
    /**
34
     * Returns the {@link ScriptingUnit} associated with a File.
35
     *
36
     * @param file File of the data origin.
37
     *
38
     * @return a {@link ScriptingUnit} with the content extracted from the file.
39
     */
40
    public ScriptingUnit getUnit(File file);
41
    
42
    public ScriptingUnit getUnit(String path);
43

  
44
    /**
45
     * Gets all the {@link ScriptingUnit}s contained in a ScriptingFolder.
46
     *
47
     * @return a List with the {@link ScriptingUnit}s.
48
     *
49
     */
50
    public List<ScriptingUnit> getUnits();
51

  
52
    public List<ScriptingFolder> getUnitFolders();
53

  
54
    public boolean isLink();
55

  
56
    public void accept(Visitor visitor, Predicate<ScriptingUnit> includeFilter) throws BaseException;
57

  
58
    public void save();
59

  
60
    public String getRawInf();
61

  
62
    public void setRawInf(String rawInf);
63

  
64
    public String getProperty(String group, String name);
65

  
66
    public void setProperty(String group, String name, String value);
67
    
68
    public void setIconNames(String iconName, String iconNameOpen);
69
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/DataFolderFound.java
1
package org.gvsig.scripting;
2

  
3
import java.io.File;
4
import org.gvsig.tools.packageutils.Version;
5

  
6
/**
7
 *
8
 * @author jjdelcerro
9
 */
10
public interface DataFolderFound {
11

  
12
    ScriptingFolder getApplicationFolder();
13

  
14
    String getApplicationName();
15

  
16
    String getDataFolderId();
17

  
18
    File getNewDataFolder();
19

  
20
    File getOldDataFolder();
21

  
22
    Version getOldDataFolderVersion();
23

  
24
    void leave();
25

  
26
    void restore();
27

  
28
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingUnit.java
1
package org.gvsig.scripting;
2

  
3
import java.beans.PropertyChangeListener;
4
import java.io.File;
5
import java.util.List;
6
import java.util.Map;
7

  
8
/**
9
 * <p> Interface that represents the elements used in the ScriptingFramework.</p>
10
 * 
11
 * @see ScriptingBaseScript
12
 * @see ScriptingFolder
13
 */
14
public interface ScriptingUnit {
15
	
16
	/**
17
	 * Returns the ScriptingUnit's ID
18
	 * 
19
	 * @return a String containing the ScriptingUnit's ID
20
	 */
21
	public String getId();
22
	
23
	/**
24
	 * Returns the ScriptingUnit's name
25
	 * 
26
	 * @return a String containing the ScriptingUnit's name
27
	 */
28
	public String getName();
29
	
30
	/**
31
	 * Returns the ScriptingUnit's description
32
	 * 
33
	 * @return a String containing the ScriptingUnit's description
34
	 */
35
	public String getDescription();
36
	
37
	/**
38
	 * Returns information about the ScriptingUnit's creator
39
	 * 
40
	 * @return a String containing the ScriptingUnit's creator
41
	 */
42
	public String getCreatedBy();
43
	
44
	/**
45
	 * Returns the ScriptingUnit's version
46
	 * 
47
	 * @return a String containing the ScriptingUnit's version
48
	 */
49
	public String getVersion();
50
	
51
	/**
52
	 * Returns the ScriptingUnit's parent
53
	 * 
54
	 * @return a {@link ScriptingFolder} where is contained the ScriptingUnit
55
	 */
56
	public ScriptingFolder getParent();
57
	
58
    public String getUserPath();
59
	/**
60
	 * Sets a new name to the ScriptingUnit.
61
	 *
62
	 * @param name
63
	 *            String that contains the new name.
64
	 */
65
	public void setName(String name);
66
	
67
	/**
68
	 * Sets a new description to the ScriptingUnit.
69
	 *
70
	 * @param description
71
	 *            String that contains the new description.
72
	 */
73
	public void setDescription(String description);
74
	
75
	/**
76
	 * Sets a new information about the ScriptingUnit's creator.
77
	 *
78
	 * @param createdBy
79
	 *            String that contains the new creator's information.
80
	 */
81
	public void setCreatedBy(String createdBy);
82
	
83
	/**
84
	 * Sets a new version value to the ScriptingUnit.
85
	 *
86
	 * @param version
87
	 *            String that contains the new version.
88
	 */
89
	public void setVersion(String version);
90
        
91
    public void reload();
92
    
93
	/**
94
	 * Changes the ID of a ScriptingUnit and the name of the files and/or directories associated
95
	 *
96
	 * @param newId
97
	 *            String that contains the new Id.
98
	 *            
99
	 * @return true if it's succesful, false if not.
100
	 */
101
	public boolean rename(String newId);
102
	
103
	public boolean remove();
104
	
105
	/**
106
	 * Moves a ScriptingUnitfrom the current directory to the new location.
107
	 *
108
	 * @param target
109
	 *            {@link ScriptingFolder} that represents the destination..
110
	 *            
111
	 * @return true if it's succesful, false if not.
112
	 */
113
	public boolean move(ScriptingFolder target);
114
	
115
	/**
116
	 * Gets the name of the icons associated to the ScriptingUnit type.
117
	 *            
118
	 * @return a String array with the identificators of the icons associated.
119
	 */
120
	public String[] getIconNames();
121
	
122
	public String getTypeName();
123
	
124
	/**
125
	 * Gets a File with the ScriptUnit path name.
126
	 *
127
	 * @return a string with the path name of the ScriptUnit (inf/folder).
128
	 */
129
	public File getFile();
130
        
131
        /**
132
         * Return a list of the files that use this unit with out the inf file.
133
         * @return list of files of the unit.
134
         */
135
        public List<File> getFiles();
136
        
137
        public void addPropertyChangeListener(PropertyChangeListener listener);
138

  
139
        /**
140
         * Sets the unit current status with the saved version.
141
         *
142
         * @param saved Indicate if the unit is up-to-date or not.
143
         */
144
        public void setSaved(boolean saved);
145
        
146
        /**
147
         * Indicates if the ScriptBaseScript is modified from last saved version.
148
         *
149
         * @return true if current version is up-to-date, false if not.
150
         */
151
        public boolean isSaved();     
152
        
153
        public String getProperty(String name);
154
        
155
        public void setProperty(String name, String value);
156
        
157
        public Map<String,String> getProperties();
158
        
159
        public boolean isASystemUnit();
160
        
161
        public File getFileResource(String extension);
162
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingExternalFile.java
1
package org.gvsig.scripting;
2

  
3
import java.io.File;
4

  
5

  
6
public interface ScriptingExternalFile extends ScriptingUnit {
7
    
8
    public File getExternalFile();
9

  
10
    public String getMimeType();
11

  
12
    public void setContents(String text);
13

  
14
    public String getContentsAsText();
15
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/java/org/gvsig/scripting/ScriptingNotification.java
1
package org.gvsig.scripting;
2

  
3
/**
4
 * Interface to support the notifications in the application 
5
 *
6
 */
7
public interface ScriptingNotification {
8

  
9
	/**
10
	 * Gets the type of ScriptingNotification
11
	 * 
12
	 * @return An integer with the type.
13
	 */
14
	public int getType();
15
	
16
	/**
17
	 * Gets the ScriptingNotification's id
18
	 * 
19
	 * @return a String with the id
20
	 */
21
	public String getId();
22
	
23
	/**
24
	 * Get the {@link ScriptingUnit} which send the notification
25
	 * 
26
	 * @return {@link ScriptingUnit
27
	 */
28
	public ScriptingUnit getUnit();
29
	
30
	/**
31
	 * Gets the cause of the ScriptingNotification
32
	 * 
33
	 * @return Exception
34
	 */
35
	public Exception getException();
36
	
37

  
38
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/javadoc/overview.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>org.gvsig.scripting package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>TODO: Example library overview.</p>
11
	
12
	<p>See the <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#overviewcomment">Javadoc Tool documentation about the overview file</a></p>
13

  
14
</body>
15
</html>
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/resources/org/gvsig/scripting/i18n/text.properties
1
# Resource bundle texts for the Spanish language locale (es)
2
Example.returns_value=devuelve el valor
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/resources/org/gvsig/scripting/i18n/text_en.properties
1
# Resource bundle texts for the English language locale (en)
2
Example.returns_value=returns value
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/resources/overview.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>org.gvsig.scripting package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>TODO: Example library overview.</p>
11
	
12
	<p>See the <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#overviewcomment">Javadoc Tool documentation about the overview file</a></p>
13

  
14
</body>
15
</html>
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/resources/README.txt
1
Put into this folder the resources needed by your library classes.
2

  
3
This folder is added to the runtime classpath, so you can load any resources 
4
through the ClassLoader.
5

  
6
By default, into this folder you can find some examples of resource bundle 
7
property files that may be used by your library classes.
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.scripting.ScriptingLibrary
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

  
4
<!-- 
5
Log4J configuration file for unit tests execution.
6
 -->
7
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
8

  
9
	<!-- Appender configuration to show logging messages through the console -->
10
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
11
		<layout class="org.apache.log4j.PatternLayout">
12
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
13
		</layout>
14
	</appender>
15

  
16
	<!-- 
17
	Activate logging messages of DEBUG level of higher only for the
18
	DefaultExampleManager class.
19
	You can put full classes names or packages instead, to configure
20
	logging for all the classes and subpackages of the package.
21
	-->
22
	<category name="org.gvsig.scripting.impl.DefaultExampleManager">
23
		<priority value="DEBUG" />
24
	</category>
25

  
26
	<!-- 
27
	By default, show only logging messages of INFO level or higher, 
28
	through the previously configured CONSOLE appender. 
29
	-->
30
	<root>
31
		<priority value="INFO" />
32
		<appender-ref ref="CONSOLE" />
33
	</root>
34
</log4j:configuration>
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/test/resources/README.txt
1
#set( $symbol_pound = '#' )
2
#set( $symbol_dollar = '$' )
3
#set( $symbol_escape = '\' )
4
Put into this folder the resources needed by your test classes.
5

  
6
This folder is added to the Tests classpath, so you can load any resources 
7
through the ClassLoader.
8

  
9
By default, in this folder you can find an example of log4j configuration,
10
prepared to log messages through the console, so logging works when you
11
run your tests classes.
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/test/java/README.txt
1
#set( $symbol_pound = '#' )
2
#set( $symbol_dollar = '$' )
3
#set( $symbol_escape = '\' )
4
For each class you are going to test, create one Test class with the same
5
name as the class to test, ending with Test.
6

  
7
For example, the unit tests of the "ExampleLibrary" class are performed
8
by the "ExampleLibraryTest" class.
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/test/java/org/gvsig/scripting/TestManager.java
1
package org.gvsig.scripting;
2

  
3
import java.io.File;
4
import java.util.Iterator;
5
import java.util.List;
6
import java.util.Map;
7
import java.util.Set;
8

  
9
import junit.framework.Assert;
10

  
11
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
12

  
13
public abstract class TestManager extends AbstractLibraryAutoInitTestCase {
14

  
15
	protected ScriptingManager manager;
16
	
17
	@Override
18
	protected void doSetUp() throws Exception {
19
		manager = ScriptingLocator.getManager();
20
	}
21
	
22
	public void setWorkingFolder(){
23
		File file =new File(this.getClass().getClassLoader().getResource("org/gvsig/scripting/home").getFile());
24
//		FIXME: hay que sustituirlo por manager.setHomeFolder(home) 
25
//		manager.setRootUserFolder(file.getAbsolutePath());
26
	}
27
	
28
	public void deleteFolderContent(ScriptingFolder folder){
29
		List<ScriptingUnit> units = folder.getUnits();
30
        Iterator<ScriptingUnit> it = units.iterator();
31
		while(it.hasNext()){
32
			ScriptingUnit unit = it.next();
33
			if(unit instanceof ScriptingFolder){
34
				deleteFolderContent((ScriptingFolder)unit);
35
				folder.remove(unit);
36
			}else{
37
				folder.remove(unit);
38
			}
39
		}
40
	}
41
	
42
	public void deleteWorkingFolderContent(){
43
		setWorkingFolder();
44
		ScriptingFolder folder = manager.getUserFolder();
45
		deleteFolderContent(folder);
46
	}
47
	
48
	public void testUserFolderPath(){
49
		setWorkingFolder();
50
		Assert.assertEquals(manager.getRootUserFolder().getAbsolutePath(), manager.getUserFolder().getFile().getAbsolutePath());
51
	}
52
	
53
	public void testExistsScriptId(){
54
		setWorkingFolder();
55
		manager.createUnit(ScriptingManager.UNIT_SCRIPT,manager.getUserFolder(),"test_script.py");
56
		
57
		Assert.assertEquals(false, manager.validateUnitId(manager.getUserFolder(),"test_script"));
58
		Assert.assertEquals(true, manager.validateUnitId(manager.getUserFolder(),"test_script2"));
59
		deleteWorkingFolderContent();
60
	}
61

  
62

  
63
	public void checkUnitValues(ScriptingUnit unit1, ScriptingUnit unit2){
64
		Assert.assertEquals(unit1.getId(),unit2.getId());
65
		Assert.assertEquals(unit1.getName(),unit2.getName());
66
	}
67
	
68
	public void testRegisteringSystemFolders(){
69
		ScriptingFolder folder_parent = (ScriptingFolder) manager.createUnit(ScriptingManager.UNIT_FOLDER,manager.getUserFolder(), "test");
70
		ScriptingFolder folder = (ScriptingFolder) manager.createUnit(ScriptingManager.UNIT_FOLDER,folder_parent, "test");
71
		ScriptingScript script = (ScriptingScript)manager.createUnit(ScriptingManager.UNIT_SCRIPT,folder, "test_script.py");
72
		
73
		manager.registerSystemFolder("test", folder.getFile());
74
		
75
		List<ScriptingUnit> units = manager.getSystemFolder().getUnits();
76

  
77
        Iterator<ScriptingUnit> it = units.iterator();
78
		ScriptingUnit unit = null;
79
		while(it.hasNext()){
80
			unit = it.next();
81
			checkUnitValues(unit, folder);
82
		}
83
		Assert.assertNotNull(unit);
84
		
85
		ScriptingScript script2 = (ScriptingScript) manager.getScript(new File(((ScriptingFolder)unit).getFile(),script.getId()+".py"));
86
		checkUnitValues(script,script2);
87
		deleteWorkingFolderContent();
88
	}
89

  
90

  
91
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/test/java/org/gvsig/scripting/TestFolder.java
1
package org.gvsig.scripting;
2

  
3
import java.io.File;
4
import java.util.Iterator;
5
import java.util.List;
6

  
7
import junit.framework.Assert;
8

  
9
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
10

  
11
public abstract class TestFolder extends AbstractLibraryAutoInitTestCase {
12

  
13
	protected ScriptingManager manager;
14
	
15
	@Override
16
	protected void doSetUp() throws Exception {
17
		manager = ScriptingLocator.getManager();
18
	}
19
	
20
	public void setWorkingFolder(){
21
		File file =new File(this.getClass().getClassLoader().getResource("org/gvsig/scripting/home").getFile());
22
		if(file.exists()){
23
			file.mkdir();
24
		}
25
//		FIXME: hay que sustituirlo por manager.setHomeFolder(home) 
26
//		manager.setRootUserFolder(file.getAbsolutePath());
27
	}
28
	
29
	public void deleteFolderContent(ScriptingFolder folder){
30
		List<ScriptingUnit> units = folder.getUnits();
31
        Iterator<ScriptingUnit> it = units.iterator();
32
		while(it.hasNext()){
33
			ScriptingUnit unit = it.next();
34
			if(unit instanceof ScriptingFolder){
35
				deleteFolderContent((ScriptingFolder)unit);
36
				folder.remove(unit);
37
			}else{
38
				folder.remove(unit);
39
			}
40
		}
41
	}
42
	
43
	public void deleteWorkingFolderContent(){
44
		setWorkingFolder();
45
		ScriptingFolder folder = manager.getUserFolder();
46
		deleteFolderContent(folder);
47
	}
48
	
49
	public File getFile(ScriptingFolder folder, String name){
50
		return new File(folder.getFile(),name);
51
	}
52
	
53
	public void checkFolder(ScriptingFolder folder, String fName){
54
		File ffolder = getFile(folder, fName);
55
		Assert.assertTrue(ffolder.exists());
56
		Assert.assertTrue(ffolder.isDirectory());
57
	}
58
	
59
	public void checkScriptDefaultValues(ScriptingScript script){
60
		Assert.assertEquals("test_script", script.getId());
61
		Assert.assertEquals("test_script", script.getName());
62
		Assert.assertEquals("python", script.getLangName());
63
		Assert.assertEquals("main", script.getMainName());
64
	}
65

  
66
	public void testCreation(){
67
		deleteWorkingFolderContent();
68
		ScriptingFolder folder = (ScriptingFolder) manager.createUnit(ScriptingManager.UNIT_FOLDER,manager.getUserFolder(),"test_folder");
69
		
70
		checkFolder(manager.getUserFolder(),folder.getId());
71
	}
72

  
73
	public void testList(){
74
		testCreation();
75
		ScriptingFolder folder = manager.getFolder(getFile(manager.getUserFolder(),"test_folder"));
76

  
77
		ScriptingScript script = (ScriptingScript) manager.createUnit(ScriptingManager.UNIT_SCRIPT,folder, "test_script.py");
78
		
79
        List<ScriptingUnit> units = folder.getUnits();
80
        Iterator<ScriptingUnit> it = units.iterator();
81
		while(it.hasNext()){
82
			ScriptingUnit unit = it.next();
83
			checkScriptDefaultValues((ScriptingScript) unit);
84
		}
85
		
86
		folder.remove(script);
87
		Assert.assertTrue(folder.getUnits().isEmpty());
88
	}
89
	
90
	public void testRename(){
91
		testCreation();
92
		ScriptingFolder folder = manager.getFolder(getFile(manager.getUserFolder(),"test_folder"));
93
		
94
		Assert.assertFalse(folder.rename("test_folder"));
95
		Assert.assertTrue(folder.rename("test_folder2"));
96
		
97
		Assert.assertEquals("test_folder2", folder.getName());
98
		deleteWorkingFolderContent();
99
	}
100
	
101
	public void testMove(){
102
		testCreation();
103
		ScriptingScript script = (ScriptingScript) manager.createUnit(ScriptingManager.UNIT_SCRIPT,manager.getUserFolder(), "test_script.py");	
104
		ScriptingFolder folder = manager.getFolder(getFile(manager.getUserFolder(),"test_folder"));
105
		Assert.assertEquals(script.getParent().getFile().getAbsolutePath(),manager.getUserFolder().getFile().getAbsolutePath());
106
		
107
		folder.add(script);
108
		Assert.assertEquals(script.getParent(),folder);
109
		deleteWorkingFolderContent();
110
	}
111

  
112

  
113
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.70/org.gvsig.scripting.lib/org.gvsig.scripting.lib.api/src/test/java/org/gvsig/scripting/TestDialog.java
1
package org.gvsig.scripting;
2

  
3
import java.io.BufferedWriter;
4
import java.io.File;
5
import java.io.FileWriter;
6
import java.io.IOException;
7
import java.util.Iterator;
8
import java.util.List;
9

  
10
import junit.framework.Assert;
11

  
12
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
13

  
14
public abstract class TestDialog extends AbstractLibraryAutoInitTestCase {
15

  
16
	protected ScriptingManager manager;
17
	
18
	@Override
19
	protected void doSetUp() throws Exception {
20
		manager = ScriptingLocator.getManager();
21
	}
22
	
23
	public void setWorkingFolder(){
24
		File file =new File(this.getClass().getClassLoader().getResource("org/gvsig/scripting/home").getFile());
25
		
26
//		FIXME: hay que sustituirlo por manager.setHomeFolder(home) 
27
//		manager.setRootUserFolder(file.getAbsolutePath());
28
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff