public static Comparator toComparator(PageContext pc,String sortType, String sortOrder, boolean localeSensitive) throws PageException {
// check sortorder
boolean isAsc=true;
if(sortOrder.equalsIgnoreCase("asc"))isAsc=true;
else if(sortOrder.equalsIgnoreCase("desc"))isAsc=false;
else throw new ExpressionException("invalid sort order type ["+sortOrder+"], sort order types are [asc and desc]");
// text
if(sortType.equalsIgnoreCase("text")) {
if(localeSensitive)return toCollator(pc,Collator.IDENTICAL);
return new TextComparator(isAsc,false);
}
// text no case
else if(sortType.equalsIgnoreCase("textnocase")) {
if(localeSensitive)return toCollator(pc,Collator.TERTIARY);
return new TextComparator(isAsc,true);
}
// numeric
else if(sortType.equalsIgnoreCase("numeric")) {
return new NumberComparator(isAsc);
}
else {
throw new ExpressionException("invalid sort type ["+sortType+"], sort types are [text, textNoCase, numeric]");
}
}