Revision: 1684 http://svn.sourceforge.net/vexi/?rev=1684&view=rev Author: mkpg2 Date: 2007-02-17 08:09:22 -0800 (Sat, 17 Feb 2007)
Log Message: ----------- Added stream.write.xml && stream.write.utf8 Modified Paths: -------------- core/trunk/org.vexi.core/src/org/vexi/core/Resources.java core/trunk/org.vexi.core/src/org/vexi/core/Vexi.jpp Modified: core/trunk/org.vexi.core/src/org/vexi/core/Resources.java =================================================================== --- core/trunk/org.vexi.core/src/org/vexi/core/Resources.java 2007-02-17 16:03:34 UTC (rev 1683) +++ core/trunk/org.vexi.core/src/org/vexi/core/Resources.java 2007-02-17 16:09:22 UTC (rev 1684) @@ -8,6 +8,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.net.InetAddress; @@ -23,9 +24,11 @@ import org.ibex.js.JSExn; import org.ibex.js.JSU; import org.ibex.js.Thread; +import org.ibex.util.Basket; import org.ibex.util.Callable; import org.ibex.util.Encode; import org.ibex.util.Log; +import org.ibex.util.Basket.Stack; import org.vexi.plat.Platform; /** @@ -473,5 +476,101 @@ } } - + + /* + public static class Stream extends JS.Immutable{ + + public JS get(JS key) throws JSExn { + String keyStr = JSU.toString(key); + // TODO preprocess... + if("".equals(keyStr)){ + + return super.get(key); + } + + }*/ + + + public static JS loadFile(JS[] args) throws JSExn { + + String s = Platform.fileDialog("", false); + return new Fountain.File(s); + } + + + public static JS saveFile(JS[] args) throws JSExn { + String s = Platform.fileDialog("", true); + return new Fountain.File(s); + } + + public static void writeUTF8(JS[] args) throws JSExn { + try{ + OutputStream out = Fountain.getOutputStream(args[0]); + try{ + out.write(JSU.toString(args[1]).getBytes()); + }finally{ + out.close(); + } + }catch(IOException e){ + throw new JSExn(e.getMessage()); + } + } + public static JS writeXML(JS f) throws JSExn { + try{ + final BufferedWriter out = new BufferedWriter( + new OutputStreamWriter(Fountain.getOutputStream(f))); + JS writer = new JS.Immutable(){ + Stack stack = new Basket.Array(); + + public JS get(JS arg) throws JSExn { + String key = JSU.toString(arg); + if(key.equals("startElement") || + key.equals("endElement") || + key.equals("characters")) + return METHOD; + return super.get(arg); + } + + public JS call(JS method, JS[] args) throws JSExn { + String key = JSU.toString(method); + try{ + if(key.equals("startElement")){ + String name = JSU.toString(args[0]); + stack.push(name); + + JS attrs = args[1]; + out.write("<" + name); + Enumeration E = attrs.keys(); + while(E.hasNext()){ + JS attrName = E.next(); + JS attrVal = attrs.get(attrName); + out.write(" "+ attrName+"=\""+attrVal+"\""); + } + out.write(">"); + return null; + }else if(key.equals("endElement")){ + String name = (String) stack.pop(); + out.write("</"+name+">"); + if(stack.size()==0){ + out.close(); + } + return null; + }else if(key.equals("characters")){ + String chars = JSU.toString(args[0]); + out.write(chars); + return null; + } + }catch(IOException e){ + throw new JSExn(e.getMessage()); + } + return super.call(method, args); + } + }; + return writer; + }catch(IOException e){ + throw new JSExn(e.getMessage()); + } + + } + } Modified: core/trunk/org.vexi.core/src/org/vexi/core/Vexi.jpp =================================================================== --- core/trunk/org.vexi.core/src/org/vexi/core/Vexi.jpp 2007-02-17 16:03:34 UTC (rev 1683) +++ core/trunk/org.vexi.core/src/org/vexi/core/Vexi.jpp 2007-02-17 16:09:22 UTC (rev 1684) @@ -134,9 +134,16 @@ case "stream.uncab": return METHOD; case "stream.cache": return METHOD; case "stream.url": return METHOD; + case "stream.parse": return getSub(name); case "stream.parse.html": return METHOD; case "stream.parse.xml": return METHOD; case "stream.parse.utf8": return METHOD; + case "stream.write": return getSub(name); + case "stream.write.xml": return METHOD; + case "stream.write.utf8": return METHOD; + case "stream.file": return getSub(name); + case "stream.file.load": return METHOD; + case "stream.file.save": return METHOD; case "net": return getSub(name); case "net.rpc": return getSub(name); case "net.rpc.xml": return METHOD; @@ -186,6 +193,8 @@ case "log.warn": if(args.length<1) JSU.warn("**null**"); else JSU.warn(args[0]); return null; case "log.error": if(args.length<1) JSU.error("**null**"); else JSU.error(args[0]); return null; case "stream.url": return Resources.fountainForNames(args); + case "stream.file.load": return Resources.loadFile(args); + case "stream.file.save": return Resources.saveFile(args); //#end switch (args.length) { @@ -220,6 +229,8 @@ case "stream.cache": //try { return args[0] == null ? null : new Fountain.CachedStream((Stream)args[0], "resources", true); } //catch (Stream.NotCacheableException e) { throw new JSExn("this resource cannot be cached"); } + case "stream.write.xml": + return Resources.writeXML(args[0]); case "thread.sleep": sleep(JSU.toInt(args[0])); return null; case "regexp": return new JSRegexp(args[0], null); case "net.rpc.xml": return new XMLRPC(JSU.toString(args[0]), ""); @@ -228,7 +239,6 @@ case "crypto.sha1": /* FEATURE */ return null; case "crypto.rc4": /* FEATURE */ return null; case "stream.parse.html": throw new JSExn("not implemented yet"); //return null; - case "stream.parse.xml": if(args[0] == null) return null; new XMLHelper(args[1]).doParse(args[0]); return null; // FIXME backgrounding case "stream.parse.utf8": if(args[0] == null) return null; try { return JSU.S(new String(InputStreamToByteArray.convert(JSU.getInputStream(args[0])))); } @@ -246,6 +256,10 @@ return func.call(null, args); } }); + case "stream.write.utf8": + Resources.writeUTF8(args); + return null; + case "stream.parse.xml": if(args[0] == null) return null; new XMLHelper(args[1]).doParse(args[0]); return null; case "regexp": return new JSRegexp(args[0], args[1]); //#end case 3: @@ -414,7 +428,7 @@ public void whitespace(char[] ch, int start, int length) throws XML.Exn { try { callargs1[0] = JSU.S(new String(ch, start, length)); - whitespace.call(null, callargs1); + if(whitespace!=null)whitespace.call(null, callargs1); } catch (JSExn jse) { throw new Wrapper(jse); } finally { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn