001 package railo.runtime.functions.image; 002 003 import java.util.Iterator; 004 import java.util.List; 005 import java.util.Map; 006 import java.util.Map.Entry; 007 008 import railo.runtime.PageContext; 009 import railo.runtime.exp.PageException; 010 import railo.runtime.img.Image; 011 import railo.runtime.op.Caster; 012 import railo.runtime.type.Struct; 013 import railo.runtime.type.StructImpl; 014 015 public class ImageGetEXIFMetadata { 016 017 public static Struct call(PageContext pc, Object name) throws PageException { 018 if(name instanceof String) name=pc.getVariable(Caster.toString(name)); 019 Image img = Image.toImage(name); 020 return getData(img); 021 } 022 023 public static Struct getData(Image img) throws PageException { 024 Struct sct = img.info(),data=new StructImpl(); 025 Iterator it = sct.entrySet().iterator(); 026 Map.Entry entry; 027 while(it.hasNext()){ 028 entry=(Entry) it.next(); 029 if(entry.getValue() instanceof Map) 030 fill(data,(Map)entry.getValue()); 031 else if(entry.getValue() instanceof List) 032 fill(data,entry.getKey(),(List)entry.getValue()); 033 else 034 data.put(entry.getKey(),entry.getValue()); 035 } 036 037 return data; 038 } 039 040 private static void fill(Struct data, Map map) throws PageException { 041 Iterator it = map.entrySet().iterator(); 042 Map.Entry entry; 043 while(it.hasNext()){ 044 entry=(Entry) it.next(); 045 if(entry.getValue() instanceof Map) 046 fill(data,(Map)entry.getValue()); 047 else if(entry.getValue() instanceof List) 048 fill(data,entry.getKey(),(List)entry.getValue()); 049 else 050 data.put(entry.getKey(),entry.getValue()); 051 } 052 } 053 054 private static void fill(Struct data, Object key, List list) throws PageException { 055 data.put( 056 key, 057 railo.runtime.type.List.listToList(list, ",")); 058 } 059 }