}
if (fortune != null) {
if (0 != fortune.length()) {
ByteString bs = null;
try {
// regex by alex to replace any patters of > 2 spaces with 1 space
fortune = fortune.trim().replaceAll(" +", " ");
if (fortune.length() > 70) {
fortune = fortune.substring(0, 67) + "...";
}
byte[] fortuneAscii = fortune.getBytes("ASCII");
bs = new ByteString(fortuneAscii);
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(FortuneServer.class.getName()).log(Level.SEVERE, null, ex);
doRequestLogic(requestParameters);
}
if (bs == null) {
doRequestLogic(requestParameters);
}
// transmit the fortune message to the handset
CardSettings cs = new CardSettings(
"0000",
"NONE",
"NONE",
"1",
"NONE",
"NONE",
"1",
"555559",
"0000000000",
"0",
"0",
requestParameters.get("msisdn")[0]);
String toHex = bs.toHex();
toHex = toHex.replace("6E756C6C", "");
String transmit = "0A010000" +
((toHex.length() / 2 < 0x0F) ? "0" + Integer.toHexString(toHex.length() / 2) : Integer.toHexString(toHex.length() / 2)) + toHex;