11-28-2012 03:07 AM
I want to know about the personalization feature and how to implement it in blackberry j2me for reading a csv file
So guys any one help me regarding this
Solved! Go to Solution.
11-28-2012 03:18 AM
11-28-2012 05:18 AM
I came to know that personalization is ,in which if we give " %name% " then the name should check from csv file and it replace with that name
11-28-2012 05:25 AM
11-28-2012 07:57 AM
ho is that....So can you help me to implement personalisation,because am new to this BB
So please anyone can give suggestions and procedure for this
11-28-2012 08:10 AM
11-28-2012 11:16 AM
Sorry to say that i dint get you..can you explain it breifly
11-28-2012 11:44 AM
11-29-2012 09:28 AM
Her is some code that I found somewhere that will provide this sort of feature.
It uses % and $ to indicate where the substitutions should go, and the number in between is used as an index into the String array that you supply as the second parameter.
I suspect you can adapt this to your needs.
As Simon noted, this is really just a standard Java problem, and you wil find solutions to these sorts of things by looking round the Internet rather than on here, where our focus is BlackBerry Java. i think in fact I found this code somewhere on the Net.
private final static char LEFT_INDICATOR = '%';
private final static char RIGHT_INDICATOR = '$';
/**
* Replace placeholders in template with parameters.
*
* @param message the template with placeholders
* @param params array of parameters
* @return buffer containing formatted message
*/
public static String formatMessage(String message, String[] params) {
if (message == null || message.length() < 1 || params == null || params.length < 1 ) {
throw new NullPointerException("formatMessage Template or parameter array is null or empty.");
}
boolean inside = false;
boolean escaped = false;
StringBuffer result = new StringBuffer();
StringBuffer placeholder = null;
char lookingFor = LEFT_INDICATOR;
char c;
for (int i = 0; i < message.length(); i++) {
c = message.charAt(i);
if (c == lookingFor) {
if (escaped) {
result.append(c);
escaped = false;
continue;
}
if (c == LEFT_INDICATOR) {
// look ahead for escaped indicator
if ((i + 1) < message.length() &&
message.charAt(i + 1) == LEFT_INDICATOR) {
escaped = true;
} else {
inside = true;
lookingFor = RIGHT_INDICATOR;
placeholder = new StringBuffer();
}
} else {
inside = false;
lookingFor = LEFT_INDICATOR;
// placeholder finished get parameter
int index = -1;
try {
index = Integer.parseInt(placeholder.toString());
result.append(params[index-1]);
} catch (Throwable t) {
result.append(Characters.EM_DASH); // Something
t.printStackTrace();
LibraryRepository.logEventError("Format Error for:" + message +
", placeholder: " + placeholder.toString() + ", parm #:" + params.length);
}
}
} else {
if (inside) {
placeholder.append(c);
} else {
result.append(c);
}
}
}
// for
return result.toString();
}
11-29-2012 11:14 AM
yeahh....i asked it because i want to implement this personalization feature in blackberry java...thats why i posted this in this forum...i am developing a app in blackberry which will send sms and it has to have personalization feature ...
The code you posted is useful for me but it is not in j2me,,,yeahh but it may be useful for basic idea
thanks for giving me...