Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6007987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:45:38+00:00 2026-05-23T01:45:38+00:00

Im my Java application, users can specify how to name their files from a

  • 0

Im my Java application, users can specify how to name their files from a series of metadata fields. i.e

%artist% - %album% - %disctotal%

My code then parses these fields and renames file accoringly. But I want the user to be able to use an ‘expression languge’ so they can say things like:

$if(%disctotal% >= 01,%discno%) 

Use ifelse, compare length and case and so on.

I dont want to write this from scratch, is there something that offers me this that I can just plugin to my code?

EDIT:I think Ive had some good replies, but my knowledge is letting me down. Lets simplify the issue I want the user to be able to write

$if(%disctotal% >= 01,%discno%)

into a field in a gui.

Then later on in my Java code I want to be able to apply this expression to a set of files, so for each file I have the value of disctotal, and discno but I want to be able to convert the expression into something like

if(discTotal >=1)
{
return discNo
}
else
{
return “”
}

What I dont want to do is have to write the code that recognises the string (”
$if(%disctotal% >= 01,%discno%)” is an if statement because this is akward to do.

Then expanding on this I would like the expression to allow things such as capitalizing oof fields, checking lengths of fields and so on.

Alternatively: Perhaps it should work this way, the user enters the expression, then at a later date for each file the Java code replaces each variable with the real value

i.e
$if(%disctotal% >= 01,%discno%) -> $if(2 >= 01,1)

then this is passed to the exopression language to parse and give a result,

Is this the Javascript idea ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:45:38+00:00Added an answer on May 23, 2026 at 1:45 am

    How about using the JavaScript engine that is bundled with Java 1.6?

    You can see how you would pass in all the parameters:

    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("JavaScript");
    engine.put("artist", artist);
    ...
    

    You would read back the value using

    ScriptEngine.get(...)
    

    The final bit of glue would be to surround the user’s expression with a function declaration, and write an expression that calls the function and assigns the result to a well known variable.

    So to start experimenting, lets have a function to test expressions out:

    private static void printResult(final ScriptEngine jsEngine, String name, String expr) throws ScriptException {
        Object result = jsEngine.eval(expr);
        System.out.println(name + " result: " + result + "; expr: " + expr);
    }
    

    Now let’s call it:

    public static void main(String[] args) throws Exception {
        ScriptEngineManager sem = new ScriptEngineManager();
        ScriptEngine jsEngine = sem.getEngineByName("JavaScript");
        printResult(jsEngine, "Hello World", "'Hello World'");
        printResult(jsEngine, "Simple Math", "123 + 456");
    }
    

    This produces:

    Hello World result: Hello World; expr: 'Hello World'
    Simple Math result: 579.0; expr: 123 + 456
    

    Now lets try with your usecase:

    public static void main(String[] args) throws Exception {
        ScriptEngineManager sem = new ScriptEngineManager();
        ScriptEngine jsEngine = sem.getEngineByName("JavaScript");
    
        String expr = "artist + '-' + album + (disktotal > 1 ? ('-D' + diskno) : '')";
    
        jsEngine.put("artist", "U2");
        jsEngine.put("album", "The Joshua Tree");
        jsEngine.put("disktotal", 1);
        jsEngine.put("diskno", 1);
        printResult(jsEngine, "Single Disk", expr);
    
        jsEngine.put("artist", "Tori Amos");
        jsEngine.put("album", "To Venus and Back");
        jsEngine.put("disktotal", 2);
        jsEngine.put("diskno", 2);
        printResult(jsEngine, "Muti-Disk", expr);
    }
    

    Produces result:

    Single Disk result: U2-The Joshua Tree; expr: ...
    Muti-Disk result: Tori Amos-To Venus and Back-D2; expr: ...
    

    Notice how Tori’s has ‘D2’ at the end.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If an application uses the java.net.* routines, I can set a proxy when invoking
I have a web-application where the users can be sent directly to some specific
My Java application needs to send an email out to all users once per
we got high-load java application which works in clustered mode. I need to add
I am creating a simple MIDI application in C# with an open source library
So I have looked at a couple of related questions, but still can't seem
This is the situation: I'm working on a project where I need to be
I'm having an issue with Lucene's Term [Boosting][1] query syntax, specifically in Ruby on
Hey, I have some trouble using the stream_publish method, more exactly with the attachment
I have an MVC/Nhibernate app that is giving me the below. [WrongClassException: Object with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.