[java] Java and Scripting

Started by
3 comments, last by sakky 21 years, 10 months ago
I want to know how I can get Java to write and read HTML files. I know this probebly has something to do with java.io right? What I want to do is make a form of markup language with XML and embed it in Java. So I have sort of a scripting engine. I want to make swing componets and other classes that can be scripted. So I can change there actions and look. This will be part of a skinning package made for Java, that I want to make. I want a Java application to be able to read the XML markup I make. So how do I do this? I''m going to have to make a few classes that implement this, so I can use it in different thangs. Dose any one have a clue on how this is done?
Take back the internet with the most awsome browser around, FireFox
Advertisement
You''ll have to look up java io stuff if you want to read in xml files etc.

But I''m writing just to let you know that Java can be it''s own scripting language. Someone could write a java class, and you can load it dynamically and execute it''s code. Look up dynamic class loaders if you want to know.
He''s a bad motha - Shut yo mouth.
You should check out the new Preferences API in 1.4.
Its perfect if you just want to store application settings, like button colors, fontsm, window positions,etc. You might not really need a full scripting language.

If you want to assign actions to buttons you could name the action listener in the Preferences, and do Class.forName(actionListenerName), so you could change the actions with xml files( preferences uses xml file as the default data store).

You could implement it all you self, and parse xml files, but using Preferences is so much easier. Thanks SUN.
You might want to check out the Xerces XML parser (http://xml.apache.org/).

As for writing and reading HTML, you should check out the Java API docs -- there''s a ton of stuff in there pertaining to writing/reading HTML. On a side-note, I find it humorous that the HTML stuff in Java is actually under the Swing toolset, which limits programs made to handle HTML with the default Java stuff to only working where a GUI is available (I think.. I haven''t verified this experimentally).

-pirate_dau
I''m working on a piece for my website that uses the SAX parser to configure servlets with an XML script. SAX works good for parsing an XML file as a script because it runs through the document linearly, calling into callback methods you define every time it finds the beginning of an element, end of an element, textual data, etc; kind of like single-pass compiling. My servlets compile the script into an in-memory model that helps the servlets process requests.

If you want, there is a massive amount of info on XML parsing in Java here.
"There is no reason good should not triumph at least as often as evil. The triumph of anything is a matter of organization. If there are such things as angels, I hope that they're organized along the lines of the mafia." -Kurt Vonnegut

This topic is closed to new replies.

Advertisement