Java Example
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import com.filenet.api.admin.CmSearchFunctionDefinition;
// Custom search function implementation that converts a Date value to a Calendar value.
// All of the following methods must be implemented.
public class DateConversionFunctionHandler implements com.filenet.api.engine.SearchFunctionHandler
{
// Return the name of the function as it must be entered in SQL.
public String getFunctionName()
{
return "SCF::DateConversionFunctionHandler";
}
// Indicates whether the function needs to be executed in a distributed transaction by the server.
public boolean requiresTransaction()
{
return false;
}
// Validates the number and datatypes for the parameters and identifies the return value type.
public Class validate(CmSearchFunctionDefinition definition, Class[] parameterTypes)
{
if ( parameterTypes == null || parameterTypes.length != 2 )
{
throw new RuntimeException("ParameterTypes must consist of two entries, a Date and a String.");
}
if (parameterTypes[0] != Date.class || parameterTypes[1] != String.class)
{
throw new RuntimeException("ParameterTypes must consist of two entries of class Date and String.");
}
return String.class;
}
/* Evaluate the function for each search result row.
* If the String parameter specifies "Year", then the function returns the current year.
* If the String parameter specifies "Month", then the function returns the current month and year.
*/
public Object evaluate(CmSearchFunctionDefinition definition, Object[] parameters)
{
Date date = (Date) parameters[0];
String strType = (String) parameters[1];
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int year = calendar.get(Calendar.YEAR);
String retString = Integer.toString(year);
if (strType.equalsIgnoreCase("Month"))
{
String month = new SimpleDateFormat("MMMM").format(calendar.getTime());
retString = month + " " + retString;
}
// else default to Year
System.out.println("retString: " + retString);
return retString;
}
}
JavaScript Example
importPackage(Packages.java.lang);
importPackage(Packages.java.util);
importPackage(Packages.java.text);
importClass(Packages.com.filenet.api.admin.CmSearchFunctionDefinition);
// Custom search function implementation that converts a Date value to a Calendar value.
// All of the following functions must be implemented.
// Return the name of the function as it must be entered in SQL.
function getFunctionName()
{
return "SCF_Javascript::DateConversionFunctionHandler";
}
// Indicates whether the function needs to be executed in a distributed transaction by the server.
function requiresTransaction()
{
return false;
}
// Validates the number and datatypes for the parameters and identifies the return value type.
function validate(definition, paramTypes)
{
if (paramTypes == null || paramTypes.length != 2 )
{
throw Exception("ParameterTypes must consist of two entries, a Date and a String.");
}
if (paramTypes[0] != java.util.Date || paramTypes[1] != java.lang.String)
{
throw Exception("ParameterTypes must consist of two entries of class Date and String.");
}
return java.lang.String;
}
/* Evaluate the function for each search result row.
* If the String parameter specifies "Year", then the function returns the current year.
* If the String parameter specifies "Month", then the function returns the current month and year.
*/
function evaluate(definition, parameters)
{
var CalType = java.util.Calendar;
var calendar = CalType.getInstance();
calendar.setTime(parameters[0]);
var IntType = Integer;
var year = calendar.get(Calendar.YEAR);
var retString = IntType.toString(year);
var SDFType = SimpleDateFormat;
if (parameters[1].equalsIgnoreCase("Month"))
{
var month = new SDFType("MMMM").format(calendar.getTime());
retString = month + " " + retString;
}
return retString;
}