Consider a map as below:
Map("PDF","application/pdf")
Map("XLSX","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
Map("CVS","application/csv")
....
There is an export method which gets the export button name and find the export type and application content type
public void setExport(String exportBtn) {
for (String key : exportTypes.keySet()) {
if (exportBtn.contains(key)) {
this.export = key;
this.exportContentType = exportTypes.get(key);
LOG.debug("Exporting to {} ", this.export);
return ;
}
}
}
This method can be called as
setExport("PDF") >> export=PDF, exportContentType=application/pdf
setExport("Make and PDF") >> PDF, exportContentType=application/pdf
setExport("PDF Maker") >> PDF, exportContentType=application/pdf
I am not feeling good with this approch! At least I think there is some libs, for example in StringUtils, which can do something like:
String keys[]={"PDF","XLSX","CVS"};
String input="Make the PDF";
selectedKey = StringUtils.xxx(input,keys);
This can some how simplify my method.
But I could not find anything. Any comments?!