Revision 1221 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
51 51
import org.slf4j.Logger;
52 52
import org.slf4j.LoggerFactory;
53 53

  
54
@SuppressWarnings("EqualsAndHashcode")
54
@SuppressWarnings({"EqualsAndHashcode", "UseSpecificCatch"})
55 55
public class DefaultScriptingScript extends AbstractScript implements
56 56
        ScriptingScript {
57 57

  
58 58
    @SuppressWarnings("FieldNameHidesFieldInSuperclass")
59
    private static final Logger logger = LoggerFactory.getLogger(DefaultScriptingScript.class);
59
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultScriptingScript.class);
60 60
    protected String langName;
61 61
    protected String extension = null;
62 62
    protected String librarySuffix = null;
......
85 85
                byte[] buf = new String(cbuf).getBytes(Charset.forName("UTF-8"));
86 86
                out.write(buf, off, len);
87 87
            } catch (Exception ex) {
88
                logger.warn("Can't output",ex);
88
                LOGGER.warn("Can't output",ex);
89 89
            }
90 90
            for (Writer writer : writers) {
91 91
                try {
92 92
                    writer.write(cbuf, off, len);
93 93
                } catch (Exception ex) {
94
                    logger.warn("Can't output",ex);
94
                    LOGGER.warn("Can't output",ex);
95 95
                }
96 96
            }
97 97
        }
......
101 101
            try {
102 102
                out.flush();
103 103
            } catch (Exception ex) {
104
                logger.warn("Can't flush",ex);
104
                LOGGER.warn("Can't flush",ex);
105 105
            }
106 106
            for (Writer writer : writers) {
107 107
                try {
108 108
                    writer.flush();
109 109
                } catch (Exception ex) {
110
                    logger.warn("Can't flush",ex);
110
                    LOGGER.warn("Can't flush",ex);
111 111
                }
112 112
            }
113 113
        }
......
233 233
                this.code = FileUtils.readFileToString(f, encoding);
234 234
            } catch (IOException e) {
235 235
                String fname = (f == null) ? "(null)" : f.getAbsolutePath();
236
                logger.warn("Can't load code from file '" + fname + "'.");
236
                LOGGER.warn("Can't load code from file '" + fname + "'.");
237 237
            }
238 238
        }
239 239
        return this.code;
......
283 283
            List<String> lines = IOUtils.readLines(template);
284 284
            return StringUtils.join(lines, "\n");
285 285
        } catch (Exception ex) {
286
            logger.warn("Can't load code to initialize the script from '"+initName+".",ex);
286
            LOGGER.warn("Can't load code to initialize the script from '"+initName+".",ex);
287 287
            return null;
288 288
        }
289 289
    }
......
392 392
                    try {
393 393
                        this.engine.eval(theCode);
394 394
                    } catch (Exception ex) {
395
                        logger.warn("Can't initialize engine with the code:\n" + theCode, ex);
395
                        LOGGER.warn("Can't initialize engine with the code:\n" + theCode, ex);
396 396
                    }
397 397
                }
398 398
            }
......
429 429
            try {
430 430
                prefs = new Ini(f);
431 431
            } catch (Exception e) {
432
                logger.warn("Can't load 'inf' file '" + f.getAbsolutePath() + "'.", e);
432
                LOGGER.warn("Can't load 'inf' file '" + f.getAbsolutePath() + "'.", e);
433 433
            }
434 434
            loadInf(prefs);
435 435
        }
......
443 443
        // Guardo el codigo en el fichero
444 444
        File fcode = this.getFileResource(this.getExtension());
445 445
        try {
446
            FileUtils.write(fcode, this.getCode());
446
            String text = this.getCode();
447
            Charset encoding = Charsets.toCharset(EncodingUtils.getEncoding(text));           
448
            FileUtils.write(fcode, text, encoding);
447 449
        } catch (Exception e) {
448
            logger.warn("Can't write code to file '" + fcode.getAbsolutePath() + "'.", e);
450
            LOGGER.warn("Can't write code to file '" + fcode.getAbsolutePath() + "'.", e);
449 451
        }
450 452
        this.setSaved(true);
451 453
    }
......
456 458
            try {
457 459
                f.createNewFile();
458 460
            } catch (Exception e) {
459
                logger.warn("Can't create 'inf' file '" + f.getAbsolutePath() + "'.", e);
461
                LOGGER.warn("Can't create 'inf' file '" + f.getAbsolutePath() + "'.", e);
460 462
            }
461 463
        }
462 464
        Ini prefs = null;
463 465
        try {
464 466
            prefs = new Ini(f);
465 467
        } catch (Exception e) {
466
            logger.warn("Can't load 'inf' file '" + f.getAbsolutePath() + "'.", e);
468
            LOGGER.warn("Can't load 'inf' file '" + f.getAbsolutePath() + "'.", e);
467 469
        }
468 470
        save(prefs);
469 471
    }
......
480 482
            prefs.store();
481 483
        } catch (IOException e) {
482 484
            String fname = (prefs.getFile() == null) ? "(null)" : prefs.getFile().getAbsolutePath();
483
            logger.warn("Can't save inf file (" + fname + ").", e);
485
            LOGGER.warn("Can't save inf file (" + fname + ").", e);
484 486
        }
485 487

  
486 488
    }
......
831 833
        try {
832 834
            FileUtils.forceDelete(f);
833 835
        } catch (IOException e) {
834
            logger.warn("Can't remove inf file '" + f.getAbsolutePath() + "'.", e);
836
            LOGGER.warn("Can't remove inf file '" + f.getAbsolutePath() + "'.", e);
835 837
            r = false;
836 838
        }
837 839
        try {
838 840
            f = new File(folder, this.getId() + this.getExtension());
839 841
            FileUtils.forceDelete(f);
840 842
        } catch (IOException e) {
841
            logger.warn("Can't remove code file '" + f.getAbsolutePath() + "'.", e);
843
            LOGGER.warn("Can't remove code file '" + f.getAbsolutePath() + "'.", e);
842 844
            r = false;
843 845
        }
844 846
        return r;
......
859 861
        try {
860 862
            file.createNewFile();
861 863
        } catch (IOException e) {
862
            logger.warn("Can't create file of the dialog in '" + file.getAbsolutePath() + "'.", e);
864
            LOGGER.warn("Can't create file of the dialog in '" + file.getAbsolutePath() + "'.", e);
863 865
        }
864 866
        File fcode = this.getFileResource(this.getExtension());
865 867
        if( fcode.exists() ) {
......
883 885
            List<String> lines = IOUtils.readLines(template);
884 886
            return StringUtils.join(lines, "\n");
885 887
        } catch (Exception ex) {
886
            logger.warn("Can't load new-template from '"+theTemplateName+"'.",ex);
888
            LOGGER.warn("Can't load new-template from '"+theTemplateName+"'.",ex);
887 889
            return null;
888 890
        }
889 891
    }
......
899 901
    @Override
900 902
    public boolean move(ScriptingFolder target) {
901 903
        if (! manager.validateUnitId(target, this.getId()) ) {
902
            logger.info("Can't move script '"+this.getId()+"' to '"+target.getFile().getAbsolutePath()+"', is not valid.");
904
            LOGGER.info("Can't move script '"+this.getId()+"' to '"+target.getFile().getAbsolutePath()+"', is not valid.");
903 905
            return false;
904 906
        }
905 907
        if( !this.isSaved() ) {
906
            logger.info("Can't move script '"+this.getId()+"', is not saved.");
908
            LOGGER.info("Can't move script '"+this.getId()+"', is not saved.");
907 909
            return false;
908 910
        }
909 911
        try {
......
913 915
            this.parent = target;
914 916
            this.load(target, id);
915 917
        } catch (IOException ex) {
916
            logger.info("Can't move script '"+this.getId()+"' to '"+target.getFile().getAbsolutePath()+"', "+ex.getMessage(),ex);
918
            LOGGER.info("Can't move script '"+this.getId()+"' to '"+target.getFile().getAbsolutePath()+"', "+ex.getMessage(),ex);
917 919
            return false;
918 920
        }
919 921
        return true;
......
922 924
    @Override
923 925
    public boolean rename(String newId) {
924 926
        if (! manager.validateUnitId(this.getParent(), newId) ) {
925
            logger.info("Can't rename script '"+this.getId()+"', target id '"+newId+"' is not valid.");
927
            LOGGER.info("Can't rename script '"+this.getId()+"', target id '"+newId+"' is not valid.");
926 928
            return false;
927 929
        }
928 930
        if( !this.isSaved() ) {
929
            logger.info("Can't rename script '"+this.getId()+"', is not saved.");
931
            LOGGER.info("Can't rename script '"+this.getId()+"', is not saved.");
930 932
            return false;
931 933
        }
932 934
        try {
......
938 940
            this.saveInfo();
939 941
            this.load(target, id);
940 942
        } catch (IOException ex) {
941
            logger.info("Can't rename script '"+this.getId()+"' to '"+newId+"', "+ex.getMessage(),ex);
943
            LOGGER.info("Can't rename script '"+this.getId()+"' to '"+newId+"', "+ex.getMessage(),ex);
942 944
            return false;
943 945
        }        
944 946
        return true;

Also available in: Unified diff