Sorry, didn't read the entire message. Passing the script source as a string has obvious limitations, as you have discovered. Processing from standard in might be a good enhancement. At one point we actually did support local files but that code was removed. There was some issue with it, though I don't remember exactly what it was at the moment.
> On Nov 22, 2010, at 7:59 AM, Jacques Granduel wrote: > >> Thanks for your remark and I had indeed seen I could use "Pivot scripting", >> but I want to dynamically shape my view from the outside, according to some >> input. >> >> What could be the best way to send this object (as a String or >> ByteArrayInputStream ?) to BXMLSerializer as the actual API seems to be >> >> java.lang.Object readObject(java.net.URL) >> java.lang.Object readObject(java.io.InputStream) >> java.lang.Object readObject(java.lang.Class,java.lang.String,boolean) >> java.lang.Object readObject(java.lang.Class,java.lang.String) >> java.lang.Object readObject(java.net.URL,org.apache.pivot.util.Resources). >> >> I modified the ScriptApplication.java for allowing path/to/file.bxml to be >> accepted beside classpath resource using File(...).toURI().toURL(). >> >> As for the String, I wanted the equivalent, say (example in JS/Rhino) >> JS>var win = <Window title="Hello BXML!" maximized="true" >> xmlns:bxml="http://pivot.apache.org/bxml" >> xmlns="org.apache.pivot.wtk"> >> <Label text="Hello BXML!" >> styles="{font:'Arial bold 24', color:'#ff0000', >> horizontalAlignment:'center', verticalAlignment:'center'}"/> >> </Window> >> JS>ScriptApplication.main(["--src=" + win]); >> The latest crashed because DesktopApplicationContext.java splits args this >> way: >> if (arg.startsWith("--")) { >> String[] property = arg.split("="); >> and my bxml snippet is full of "=" due to the attribute values! >> So, as a quick workaround, I kept the first element of the property table, >> and joined back the rest. >> >> ScriptApplication.java: >> String src = properties.get(SRC_KEY); >> InputStream ins = new ByteArrayInputStream(src.getBytes()); >> BXMLSerializer bxmlSerializer = new BXMLSerializer(); >> window = (Window)bxmlSerializer.readObject(ins); >> window.open(display); >> >> This way it seems to work nicely. >> >> So... may I suggest adding loading bxml from File and String also? >> >> Thanks once again for your help, >> jqg >> >> >> 2010/11/22 Greg Brown <[email protected]> >> > So my reasons for doing that kind of stuff, well, er, curiosity? learning >> > and playing Pivot from a tiny environment, manipulating the bxml xml with >> > E4X and dynamically injecting js code in the GUI ?... I have to learn how >> > to directly pass a bxml String or E4X/XML object to ScriptApplication and >> > to manipulate objects from the rhino shell, as it's doable in Swing. >> >> OK. Just in case you were not aware, BXML allows you to embed script code >> directly within your markup, and will invoke the appropriate script engine >> as needed. So don't necessarily need to launch Pivot from within Rhino to >> use Rhino. >> >> G >> >> >
