DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2006

    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
    Cologne - Germany
    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
    UK, London
    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

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
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.