001    /**
002     * Implements the CFML Function listcontains
003     */
004    package railo.runtime.functions.arrays;
005    
006    import railo.runtime.PageContext;
007    import railo.runtime.exp.FunctionException;
008    import railo.runtime.exp.PageException;
009    import railo.runtime.functions.BIF;
010    import railo.runtime.op.Caster;
011    import railo.runtime.op.Decision;
012    import railo.runtime.type.Array;
013    import railo.runtime.type.util.ArrayUtil;
014    
015    public final class ArrayContains extends BIF {
016            
017            private static final long serialVersionUID = -5400552848978801342L;
018    
019            public static double call(PageContext pc, Array array, Object value, boolean substringMatch) throws PageException {
020            if (substringMatch) {
021                if (!Decision.isSimpleValue(value))
022                    throw new FunctionException( pc, "ArrayContains", 3, "substringMatch", "substringMatch can not be true when the value that is searched for is a complex object" );
023                return callLegacy( pc, array, value );
024            }
025            return ArrayFind.call( pc, array, value );
026            }
027    
028        public static double call(PageContext pc , Array array, Object value) throws PageException {
029            return call( pc, array, value, false );
030        }
031    
032            @Override
033            public Object invoke(PageContext pc, Object[] args) throws PageException {
034            if ( args.length > 2)
035                    return call( pc, Caster.toArray(args[0]),args[1], Caster.toBoolean( args[2] ) );
036            return call(pc,Caster.toArray(args[0]),args[1]);
037            }
038    
039    
040        /* legacy implementation */
041        static double callLegacy(PageContext pc, Array array, Object value) throws PageException {
042            String str=Caster.toString(value,null);
043            if(str!=null)
044                return ArrayUtil.arrayContainsIgnoreEmpty(array,str,false)+1;
045            return ArrayFind.call(pc, array, value);
046        }
047    
048    }