Revision 1207 org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.impl/src/main/java/org/gvsig/scripting/swing/impl/composer/JNewScriptModel.java

View differences:

JNewScriptModel.java
2 2

  
3 3
import java.io.File;
4 4
import javax.swing.tree.TreePath;
5
import org.apache.commons.io.FilenameUtils;
6
import org.apache.commons.lang3.StringUtils;
5 7

  
6 8
import org.gvsig.scripting.ScriptingFolder;
7 9
import org.gvsig.scripting.ScriptingManager;
......
27 29
	}
28 30
	
29 31
	public void validate() throws Exception{
30
		if(this.getName().length()==0){
32
    String theName = this.getName();
33
		if( StringUtils.isBlank(theName) ){
31 34
			throw new Exception( "Name must not be empty.");
32 35
		}
33
		
36
		if( StringUtils.equalsIgnoreCase(this.getType(), ScriptingManager.UNIT_SCRIPT) ) {
37
      String ext = FilenameUtils.getExtension(theName);
38
      if( StringUtils.isBlank(ext) ) {
39
        this.setName(theName+"."+this.getExtension());
40
      } else if( !StringUtils.equalsIgnoreCase(ext, this.getExtension()) ) {
41
  			throw new Exception( "Invalid extension '"+ext+"' for type '"+this.getType()+"', expected '"+this.getExtension()+"'.");
42
      }
43
    }
34 44
		ScriptingFolder folder = manager.getFolder(this.getPath());
35 45
		if(!manager.validateUnitId(folder,this.getName())){
36 46
			throw new Exception("This file already exists.\nWrite another name for the script");

Also available in: Unified diff