Archived

This topic is now archived and is closed to further replies.

[java] Java and Scripting

This topic is 5674 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites