001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019/** 020 * Implements the CFML Function structappend 021 */ 022package lucee.runtime.functions.struct; 023 024import java.util.Iterator; 025 026import lucee.runtime.PageContext; 027import lucee.runtime.exp.PageException; 028import lucee.runtime.functions.BIF; 029import lucee.runtime.op.Caster; 030import lucee.runtime.type.Collection.Key; 031import lucee.runtime.type.KeyImpl; 032import lucee.runtime.type.Struct; 033 034public final class StructAppend extends BIF { 035 036 private static final long serialVersionUID = 6131382324325758447L; 037 038 public static boolean call(PageContext pc , Struct struct1, Struct struct2) throws PageException { 039 return call(pc , struct1, struct2, true); 040 } 041 public static boolean call(PageContext pc , Struct struct1, Struct struct2, boolean overwrite) throws PageException { 042 Iterator<Key> it = struct2.keyIterator(); 043 Key key; 044 while(it.hasNext()) { 045 key=KeyImpl.toKey(it.next()); 046 if(overwrite || struct1.get(key,null)==null) 047 struct1.setEL(key,struct2.get(key,null)); 048 } 049 return true; 050 } 051 052 @Override 053 public Object invoke(PageContext pc, Object[] args) throws PageException { 054 if(args.length==3) return call(pc,Caster.toStruct(args[0]),Caster.toStruct(args[1]),Caster.toBooleanValue(args[2])); 055 return call(pc,Caster.toStruct(args[0]),Caster.toStruct(args[1])); 056 } 057 058}