0

I am currently working on a customized behavior of how Jasper retrieves values from resource bundle object. As I know, I can pass a resource bundle as REPORT_RESOURCE_BUNDLE and $R{SOME_TEXT} in the report will be replaced as the value of resource bundle.

What I wanna do is doing a customized getString() methods that works like follow:

public String getString(){
    if (map.get("SOME_KEY_A")!=null){
        return map.get("SOME_KEY_A");
    }else{
        return map.get("SOME_KEY");
    }
}

SOME_KEY_A is a specific value, if it is not defined, bundle will return text associates with SOME_KEY (the default value).

I have tried to override getString() or getObject() but they are final and we cannot override it. Both methods of ResourceBundle are calling handleGetObject(), however, adding the above logic to this methods doesn't change the behavior of Jasper report.

Anyone know which method Jasper will be calling to get the localized text? Thanks!

NeoNosliw
  • 111
  • 1
  • 1
  • 7
  • Is `SOME_KEY_A` a translation of `SOME_KEY`? So essentially if there is not a translation you want to use the default value? If so [ResourceBundle](http://docs.oracle.com/javase/7/docs/api/java/util/ResourceBundle.html#containsKey%28java.lang.String%29) already works that way. – Jacob Schoen Nov 19 '12 at 15:41
  • no, SOME_KEY_A is not a translation of SOME_KEY. Take an example, CURRENCY=USD CURRENCY_STORE1=JPY CURRENCY_STORE2=CAD What I want is Jasper is getting JPY if I can pass "store1" into the resource bundle. if the 2nd param is null, USD will be returned. – NeoNosliw Nov 19 '12 at 16:16
  • Okay, then I don't think you want a ResourceBundle. Take a look at [Writing methods in jasper report?](http://stackoverflow.com/questions/1470476/writing-methods-in-jasper-report) as that is probably closer to what you want. – Jacob Schoen Nov 19 '12 at 21:22

0 Answers0