private String decorateFormat(int index, List rowData, FieldDecoration decoration, String out)
{
Integer listTypeInteger = new Integer(this.listObject.getParameters().getValueListType());
StringBuffer decoratedField = new StringBuffer();
Date valueDate = null;
Timestamp timeStamp = null;
boolean flagUrl = true;
String valueString = "";
int decorationType = decoration.getFieldDecorationType();
Object content = rowData.get(decoration.getParameter() - 1);
switch (decorationType) {
case FieldDecoration.urlType:
String folderType = "";
if (listTypeInteger.intValue() == ValueListConstants.FILE_LIST_TYPE && this.listObject.getLookupType() != null
&& this.listObject.getLookupType().equals("lookup")) {
folderType = rowData.get(ValueListConstants.KB_FILE_EMAIL_HACK_INDEX - 1).toString();
if (folderType != null && folderType.equals("FILE")) {
flagUrl = false;
}
}
if (flagUrl) {
// display the string in Hyper link format
decoratedField.append(ValueListConstants.ANCHOR_PART_OPEN);
decoratedField.append("class=\"plainLink\" ");
decoratedField.append("href=\"javascript:");
decoratedField.append(decoration.getUrlOpen());
valueString = content.toString();
valueString = valueString.replaceAll("\"", """);
// For file and knowledgebase lists we will append type parameter to
// the url.
if (listTypeInteger.intValue() == ValueListConstants.KNOWLEDGEBASE_LIST_TYPE
|| listTypeInteger.intValue() == ValueListConstants.FILE_LIST_TYPE) {
valueString = valueString.concat("&type=" + rowData.get(ValueListConstants.KB_FILE_EMAIL_HACK_INDEX - 1));
if (this.listObject.isLookup()) {
valueString += ValueListConstants.AMP + "actionType=" + this.listObject.getLookupType();
}
}
decoratedField.append(valueString);
if (this.pageContext.findAttribute("listScope") != null) {
decoratedField.append("&listScope=");
decoratedField.append(this.request.getAttribute("listScope"));
}
if (this.listObject.getCurrentLinkParameters() != null && !this.listObject.getCurrentLinkParameters().equals("")) {
decoratedField.append(this.listObject.getCurrentLinkParameters());
}
decoratedField.append(decoration.getUrlClose());
decoratedField.append("\"");
decoratedField.append(ValueListConstants.CLOSE);
// For completed activities
if (((listTypeInteger.intValue() == ValueListConstants.ACTIVITY_LIST_TYPE)
|| (listTypeInteger.intValue() == ValueListConstants.APPOINTMENT_LIST_TYPE)
|| (listTypeInteger.intValue() == ValueListConstants.CALL_LIST_TYPE)
|| (listTypeInteger.intValue() == ValueListConstants.FORECASTSALES_LIST_TYPE)
|| (listTypeInteger.intValue() == ValueListConstants.MEETING_LIST_TYPE)
|| (listTypeInteger.intValue() == ValueListConstants.NEXTACTION_LIST_TYPE)
|| (listTypeInteger.intValue() == ValueListConstants.TODO_LIST_TYPE) || (listTypeInteger.intValue() == ValueListConstants.TASK_LIST_TYPE))
&& (index == ValueListConstants.ACTIVITY_TITLE_INDEX)) {
Object columnData = rowData.get(ValueListConstants.ACTIVITY_STATUS_INDEX - 1);
if (((String) columnData).indexOf("Completed") != -1) {
decoratedField.append(ValueListConstants.SPAN_PART_OPEN);
decoratedField.append("class=\"completedActivity\" ");
decoratedField.append(ValueListConstants.CLOSE);
decoratedField.append(out);
decoratedField.append(ValueListConstants.SPAN_CLOSE);
} else {
decoratedField.append(out);
decoratedField.append(ValueListConstants.ANCHOR_CLOSE);
}
} else {
decoratedField.append(out);
decoratedField.append(ValueListConstants.ANCHOR_CLOSE);
}
} else {
decoratedField.append(out);
}
break;
case FieldDecoration.dateType: {
// use the standard i18n way of formating these.
// that means using the default formats based on locale.
if (content != null) {
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, this.locale);
if (content instanceof Timestamp) {
timeStamp = (Timestamp) content;
valueDate = new Date(timeStamp.getTime());
valueString = df.format(valueDate);
}
if (content instanceof java.sql.Date) {
java.sql.Date dateStamp = (java.sql.Date) content;
valueString = df.format(dateStamp);
}
if (content instanceof Long) {
Long dateObject = (Long) content;
valueDate = new Date();
valueDate.setTime(dateObject.longValue());
valueString = df.format(valueDate);
}
decoratedField.append(valueString);
}
break;
}
case FieldDecoration.dateTimeType: {
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, this.locale);
timeStamp = (Timestamp) content;
if (timeStamp != null) {
valueDate = new Date(timeStamp.getTime());
valueString = df.format(valueDate);
}
decoratedField.append(valueString);
break;
}
case FieldDecoration.timeType: {
DateFormat df = DateFormat.getTimeInstance(DateFormat.MEDIUM, this.locale);
if (content instanceof Timestamp) {
timeStamp = (Timestamp) content;
valueDate = new Date(timeStamp.getTime());
if (timeStamp != null) {
valueDate = new Date(timeStamp.getTime());
valueString = df.format(valueDate);
}
}
if (content instanceof Long) {
Long dateObject = (Long) content;
if (dateObject != null) {
valueDate = new Date();
valueDate.setTime(dateObject.longValue());
valueString = df.format(dateObject);
}
}
decoratedField.append(valueString);
break;
}
case FieldDecoration.fileSizeType:
// display the string to file Size
// which in byte to GB,MB,KB
float size = (new Float(content.toString())).floatValue();
DecimalFormat df = new DecimalFormat("###.#");
Integer s = new Integer((int) size);
valueString = s.toString();
if (size > 1000000000) {
size /= 1073741824; // 1GB
valueString = df.format(size) + "GB";
} else if (size > 1000000) {
size /= 1048576; // 1MB
valueString = df.format(size) + "MB";
} else if (size > 1000) {
size /= 1024; // 1KB
valueString = df.format(size) + "KB";
}
decoratedField.append(valueString);
break;
case FieldDecoration.moneyType:
// display the string to currency format
NumberFormat numFormatter = NumberFormat.getCurrencyInstance(this.locale);
if (content == null) {
content = "0";
}
valueString = content.toString();
Double doubleValue = new Double(valueString);
if (doubleValue != null) {
String contentFormated = numFormatter.format(doubleValue.doubleValue());
decoratedField.append(contentFormated);
}
break;
case FieldDecoration.hourType:
// We are using the old version of mysql we must have to do this..
// In futher version of mysql 4.1.1 as the datediff function we can use
// that, but now no choice
// we have to do this calculation.
int startTimeIndex = ((Integer) ValueListConstants.timeslipDurationCalc.get("Start")).intValue();
int endTimeIndex = ((Integer) ValueListConstants.timeslipDurationCalc.get("End")).intValue();
Object startTimeObject = rowData.get(startTimeIndex - 1);
Object endTimeObject = rowData.get(endTimeIndex - 1);
long startTime = 0;
long endTime = 0;
if (startTimeObject != null && startTimeObject instanceof Timestamp) {
Timestamp startTimeStamp = (Timestamp) startTimeObject;
if (startTimeStamp != null) {
startTime = startTimeStamp.getTime();
}
}
if (endTimeObject != null && endTimeObject instanceof Timestamp) {
Timestamp endTimeStamp = (Timestamp) endTimeObject;
if (endTimeStamp != null) {
endTime = endTimeStamp.getTime();
}
}
if (startTime != 0 && endTime != 0) {
long diffTime = endTime - startTime;