Revision 590 org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/src/main/java/org/gvsig/scripting/impl/DefaultScriptingScript.java

View differences:

DefaultScriptingScript.java
178 178

  
179 179
    @Override
180 180
    public void save() {
181
        this.saveInfo();
182
        // Guardo el codigo en el fichero
183
        File fcode = this.getFileResource(this.getExtension());
184
        try {
185
            FileUtils.write(fcode, this.getCode());
186
        } catch (Exception e) {
187
            logger.warn("Can't write code to file '" + fcode.getAbsolutePath() + "'.", e);
188
        }
189
        this.setSaved(true);
190
    }
191

  
192
    private void saveInfo() {
181 193
        File f = getFileResource(".inf");
182 194
        if (!f.isFile()) {
183 195
            try {
......
193 205
            logger.warn("Can't load 'inf' file '" + f.getAbsolutePath() + "'.", e);
194 206
        }
195 207
        save(prefs);
196
        // Guardo el codigo en el fichero
197
        File fcode = this.getFileResource(this.getExtension());
198
        try {
199
            FileUtils.write(fcode, this.getCode());
200
        } catch (Exception e) {
201
            logger.warn("Can't write code to file '" + fcode.getAbsolutePath() + "'.", e);
202
        }
203
        this.setSaved(true);
204 208
    }
205

  
209
    
206 210
    @Override
207 211
    protected void save(Ini prefs) {
208 212
        super.save(prefs);
......
523 527
    public ScriptingUnit get(File file) {
524 528
        return this.manager.getScript(file);
525 529
    }
530

  
531
    @Override
532
    public boolean move(ScriptingFolder target) {
533
        if (! manager.validateUnitId(target, this.getId()) ) {
534
            logger.info("Can't move script '"+this.getId()+"' to '"+target.getFile().getAbsolutePath()+"', is not valid.");
535
            return false;
536
        }
537
        if( !this.isSaved() ) {
538
            logger.info("Can't move script '"+this.getId()+"', is not saved.");
539
            return false;
540
        }
541
        try {
542
            File codefile = this.getFileResource(this.extension);
543
            FileUtils.moveFileToDirectory(this.getFile(), target.getFile(),true);
544
            FileUtils.moveFileToDirectory(codefile, target.getFile(), true);
545
            this.parent = target;
546
            this.load(target, id);
547
        } catch (IOException ex) {
548
            logger.info("Can't move script '"+this.getId()+"' to '"+target.getFile().getAbsolutePath()+"', "+ex.getMessage(),ex);
549
            return false;
550
        }
551
        return true;
552
    }
553

  
554
    @Override
555
    public boolean rename(String newId) {
556
        if (! manager.validateUnitId(this.getParent(), newId) ) {
557
            logger.info("Can't rename script '"+this.getId()+"', target id '"+newId+"' is not valid.");
558
            return false;
559
        }
560
        if( !this.isSaved() ) {
561
            logger.info("Can't rename script '"+this.getId()+"', is not saved.");
562
            return false;
563
        }
564
        try {
565
            ScriptingFolder target = this.getParent();
566
            File codefile = this.getFileResource(this.extension);
567
            FileUtils.moveFile(this.getFile(),  new File(target.getFile(),newId+".inf") );
568
            FileUtils.moveFile(codefile, new File(target.getFile(),newId+this.extension));
569
            this.setId(newId);
570
            this.saveInfo();
571
            this.load(target, id);
572
        } catch (IOException ex) {
573
            logger.info("Can't rename script '"+this.getId()+"' to '"+newId+"', "+ex.getMessage(),ex);
574
            return false;
575
        }        
576
        return true;
577
    }
578

  
526 579
}

Also available in: Unified diff