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
020package lucee.runtime.functions.other;
021
022
023import lucee.runtime.PageContext;
024import lucee.runtime.config.ConfigImpl;
025import lucee.runtime.config.ConfigWeb;
026import lucee.runtime.config.ConfigWebImpl;
027import lucee.runtime.exp.PageException;
028import lucee.runtime.ext.function.Function;
029import lucee.runtime.op.Caster;
030import lucee.runtime.type.Collection;
031import lucee.runtime.type.KeyImpl;
032import lucee.runtime.type.Struct;
033import lucee.runtime.type.StructImpl;
034import lucee.runtime.type.util.KeyConstants;
035
036/**
037 * Implements the CFML Function createGuid
038 */
039public final class GetId implements Function {
040
041        private static final Collection.Key SECURITY_KEY = KeyImpl.intern("securityKey");
042        private static final Collection.Key ID_PRO = KeyImpl.intern("idPro");
043
044        public static Struct call(PageContext pc ) throws PageException {
045                Struct sct=new StructImpl();
046            Struct web=new StructImpl();
047            Struct server=new StructImpl();
048            ConfigWeb config = pc.getConfig();
049        
050                web.set(SECURITY_KEY, ((ConfigImpl)config).getSecurityKey());
051                web.set(KeyConstants._id, config.getId());
052                sct.set(KeyConstants._web, web);
053        
054        if(config instanceof ConfigWebImpl){
055                ConfigWebImpl cwi = (ConfigWebImpl)config;
056                server.set(SECURITY_KEY, cwi.getServerSecurityKey());
057                server.set(KeyConstants._id, cwi.getServerId());
058                server.set(ID_PRO, cwi.getServerIdPro());
059                sct.set(KeyConstants._server, server);
060        }
061        
062        sct.set(KeyConstants._request, Caster.toString(pc.getId()));
063        return  sct;
064    }
065    
066}