-
Running user entered code
I have an application that allows the user to place boxes of text on a page with special placeholders and then output a pdf where the placeholders are replaced but values from a database. Example: "My name is %NAME%" when composed results in "My name is Bob". Now I need a way to allow the user to enter some form of simple code to create a conditional statement which will be parsed when the document is composed. Example: if (%NAME% == "Joe") { return "Bob" } I have no idea how to even begin to approach this. Does anyone know of a way to turn a user entered string of text into actual Java code that the application will run?
-
there are several possibilities.
one elegant version is using a compiler of Java code at run-time, like http://www.janino.net, which also supports expression evaluation.
another elegant approach would be to include a scripting language, like the ones listed at http://pnuts.org/~tomatsu/embedding.html.
the third elegant approach is writing your own little scripting language with jflex, jcup or antlr. but this will assume knowledge on building languages and compilers.
-
graviton is right, we will need to look into making a compiler, and you need to be able to detect syntax errors. I cant say that this is easy.
Similar Threads
-
By sakatnse in forum Java
Replies: 0
Last Post: 12-06-2005, 12:07 AM
-
By sakatnse in forum Java
Replies: 1
Last Post: 12-01-2005, 11:40 AM
-
By Rob Teixeira in forum .NET
Replies: 5
Last Post: 11-27-2001, 06:12 PM
-
By Danny Bowman in forum .NET
Replies: 152
Last Post: 09-13-2001, 07:23 AM
-
Replies: 3
Last Post: 08-30-2001, 11:45 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks