My requirement is to replace parameter in rtf template with dynamic values.
I am developing the application in Oracle adf.
Scenario : template file is in arabic with some parameters that need to be replaced at run time and create a send file with updated values.
Solution tried : Method is reading template and generating another .rtf file in Arabic by replacing parameters with dynamic values.
Problem : if parameter value is in Arabic then it's replacing the parameter with some other unicode(unreadable format), where as in case of English value for parameter it's working as expected.
Kindly help me to get it out.
Below is the code that's creating another .rtf file.
sendingFileName = Constants.TEMPLATE_FILE + key + ".rtf";
String str = "";
FileInputStream fi;
try {
fi = new FileInputStream(sendingFileName);
BufferedInputStream bun = new BufferedInputStream(fi);
StringBuilder sbb = new StringBuilder();
int c = 0;
while ((c = bun.read()) != -1) {
sbb.append((char)c);
}
for (String param : (Set<String>)parameters.keySet()) {
String param1 = param +""; //"$" + param + "$";
int index = sbb.indexOf(param1);
String paramValue = (String)parameters.get(param);
if(index>-1) {
sbb.replace(index, index + param1.length(), paramValue);//now run
}
}
str = sbb.toString();
fileName = Constants.SENT_TEMPLATE + key + "_" + new Date().getTime() + ".rtf";
DataOutputStream dos;
File _file = new File(fileName);
dos = new DataOutputStream(new FileOutputStream(_file));
dos.writeBytes(str);
dos.close();
fi.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}