private int addScriptsFromDir ( File dir , ScriptType type , String targetEngineName ) { int addedScripts = 0 ; File typeDir = new File ( dir , type . getName ( ) ) ; if ( typeDir . exists ( ) ) { for ( File f : typeDir . listFiles ( ) ) { String ext = f . getName ( ) . substring ( f . getName ( ) . lastIndexOf ( "." ) + 1 ) ; String engineName = this . getEngineNameForExtension ( ext ) ; if ( engineName != null && ( targetEngineName == null || engineName . equals ( targetEngineName ) ) ) { try { if ( f . canWrite ( ) ) { String scriptName = this . getUniqueScriptName ( f . getName ( ) , ext ) ; logger . debug ( "Loading script " + scriptName ) ; ScriptWrapper sw = new ScriptWrapper ( scriptName , "" , this . getEngineWrapper ( engineName ) , type , false , f ) ; this . loadScript ( sw ) ; this . addScript ( sw , false ) ; } else { // Cant write so add as a template String scriptName = this . getUniqueTemplateName ( f . getName ( ) , ext ) ; logger . debug ( "Loading script " + scriptName ) ; ScriptWrapper sw = new ScriptWrapper ( scriptName , "" , this . getEngineWrapper ( engineName ) , type , false , f ) ; this . loadScript ( sw ) ; this . addTemplate ( sw , false ) ; } addedScripts ++ ; } catch ( Exception e ) { logger . error ( e . getMessage ( ) , e ) ; } } else { logger . debug ( "Ignoring " + f . getName ( ) ) ; } } } return addedScripts ; }
Adds the scripts from the given directory of the given script type and optionally for the engine with the given name .