Revision: 4428 http://vexi.svn.sourceforge.net/vexi/?rev=4428&view=rev Author: mkpg2 Date: 2012-07-23 04:24:55 +0000 (Mon, 23 Jul 2012) Log Message: ----------- Improve vexi.file.temp(). - Take object as argument, can specify name/suffix. - If name specified return file with exactly that name, by creating it inside a sub directory in the tmp dir.
Modified Paths: -------------- trunk/org.vexi-core.main/src/main/java/org/vexi/core/Resources.java trunk/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp trunk/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java Modified: trunk/org.vexi-core.main/src/main/java/org/vexi/core/Resources.java =================================================================== --- trunk/org.vexi-core.main/src/main/java/org/vexi/core/Resources.java 2012-07-23 00:36:30 UTC (rev 4427) +++ trunk/org.vexi-core.main/src/main/java/org/vexi/core/Resources.java 2012-07-23 04:24:55 UTC (rev 4428) @@ -39,11 +39,43 @@ "EEE MMM d HH:mm:ss yyyy" }; - // SHOULD manage temporary files (i.e. make sure they get removed, probably when vexi loads/stops) + static public File createTempDirectory() throws IOException{ + File temp0 = File.createTempFile("vexi", null); + temp0.delete(); + File temp = new File(temp0.getParentFile(), temp0.getName()+".d"); + if(!(temp.mkdir())) + { + throw new IOException("Could not create temp directory: " + temp.getAbsolutePath()); + } + return (temp); + } + + static private File createTempWithSuffix(String suffix) throws IOException{ + return File.createTempFile("vexi", suffix); + } + + static private File createTempFile(JS arg) throws IOException, JSExn{ + if(arg==null || JSU.isString(arg)){ + String suffix = JSU.toString(arg, null); + return createTempWithSuffix(suffix); + }else{ + JS name = arg.get(SC_name); + if(name!=null){ + File dir = createTempDirectory(); + return new File(dir, JSU.toString(name)); + } + + JS suffix = arg.get(JSU.S("suffix")); + return createTempWithSuffix(JSU.toString(suffix, null)); + } + + } + + // MAY manage temporary files (i.e. make sure they get removed, possibly when vexi loads/stops) static public Fountain.File createTempFile(JS[] args) throws JSExn { - String suffix = args.length>0?JSU.toString(args[0]):""; + JS arg = JSU.getArg(args,0); try { - File f = File.createTempFile("vexi", suffix); + File f = createTempFile(arg); return new Fountain.File(f,true); } catch (IOException e) { throw new JSExn(e); Modified: trunk/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp =================================================================== --- trunk/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp 2012-07-23 00:36:30 UTC (rev 4427) +++ trunk/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp 2012-07-23 04:24:55 UTC (rev 4428) @@ -386,9 +386,11 @@ case "file.load": return METHOD; case "file.remove": return METHOD; case "file.save": return METHOD; - case "file.homedir": return VexiJS.fountainForURL("file:" + System.getProperty("user.home")); case "file.temp": return METHOD; + // HACK not proper, should not give access to temp dir, home dir (although vexi + // sandboxing is not a huge concern currently) case "file.tempdir": return VexiJS.fountainForURL("file:" + System.getProperty("java.io.tempdir")); + case "file.homedir": return VexiJS.fountainForURL("file:" + System.getProperty("user.home")); case "global.trace": return VexiJS.script().get(JSU.S("trace")); /* <i>Currently looking for a maintainer</i> Modified: trunk/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java =================================================================== --- trunk/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java 2012-07-23 00:36:30 UTC (rev 4427) +++ trunk/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java 2012-07-23 04:24:55 UTC (rev 4428) @@ -144,10 +144,12 @@ return null; } /** Coerce a JS object to a String. */ - public static String toString(JS o) { - if(o == null) return "null"; + static public String toString(JS o, String default_) { + if(o == null) return default_; return o.coerceToString(); + } + static public String toString(JS o) { return toString(o, "null"); } public static String toString(Object o) { if(o == null) return "null"; else if(o instanceof JS) return ((JS)o).coerceToString(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn