DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2006
    Posts
    16

    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?

  2. #2
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    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.

  3. #3
    Join Date
    Mar 2005
    Location
    UK, London
    Posts
    150
    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

  1. Replies: 0
    Last Post: 12-06-2005, 12:07 AM
  2. Replies: 1
    Last Post: 12-01-2005, 11:40 AM
  3. Code security
    By Rob Teixeira in forum .NET
    Replies: 5
    Last Post: 11-27-2001, 06:12 PM
  4. Brain Washing
    By Danny Bowman in forum .NET
    Replies: 152
    Last Post: 09-13-2001, 07:23 AM
  5. Script for scrolling
    By Mark in forum Web
    Replies: 3
    Last Post: 08-30-2001, 11:45 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links