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 **/
019package lucee.runtime.tag;
020
021import lucee.runtime.op.Caster;
022import lucee.runtime.op.Duplicator;
023import lucee.runtime.type.Collection;
024import lucee.runtime.type.KeyImpl;
025import lucee.runtime.type.Struct;
026import lucee.runtime.type.util.StructUtil;
027
028public class FeedProperties {
029        private static final Collection.Key ITEM = KeyImpl.intern("ITEM");
030        private static final Collection.Key ITEMS = KeyImpl.intern("ITEMS");
031        private static final Collection.Key ENTRY = KeyImpl.intern("ENTRY");
032        private static final Collection.Key RDF = KeyImpl.intern("RDF");
033        private static final Collection.Key RSS = KeyImpl.intern("RSS");
034        private static final Collection.Key CHANNEL = KeyImpl.intern("channel");
035        
036        
037        public static Struct toProperties(Struct data) {
038                data=(Struct) Duplicator.duplicate(data,true);
039                
040                
041
042                Struct rdf = Caster.toStruct(data.removeEL(RDF),null,false);
043                if(rdf==null)rdf = Caster.toStruct(data.removeEL(RSS),null,false);
044                if(rdf!=null){
045                        rdf.removeEL(ITEM);
046                        Struct channel = Caster.toStruct(rdf.get(CHANNEL,null),null,false);
047                        if(channel!=null){
048                                channel.removeEL(ITEMS);
049                                StructUtil.copy(channel, data, true);
050                                
051                        }
052                }
053                
054
055                data.removeEL(ITEM);
056                data.removeEL(ENTRY);
057                
058                return data;
059        }
060}