001    package railo.runtime.functions.image;
002    
003    import java.util.HashSet;
004    
005    import railo.runtime.PageContext;
006    import railo.runtime.exp.PageException;
007    import railo.runtime.img.ImageUtil;
008    import railo.runtime.type.Collection;
009    import railo.runtime.type.KeyImpl;
010    import railo.runtime.type.Struct;
011    import railo.runtime.type.StructImpl;
012    
013    public class ImageFormats {
014    
015            private static Collection.Key DECODER=KeyImpl.getInstance("decoder");
016            private static Collection.Key ENCODER=KeyImpl.getInstance("encoder");
017            
018            public static Struct call(PageContext pc) throws PageException {
019                    Struct sct=new StructImpl();
020                    sct.set(DECODER, toArray(ImageUtil.getReaderFormatNames()));
021                    sct.set(ENCODER, toArray(ImageUtil.getWriterFormatNames()));
022                    
023                    return sct;
024            }
025    
026            private static Object toArray(String[] arr) {
027                    HashSet set=new HashSet();
028                    for(int i=0;i<arr.length;i++) {
029                            set.add(arr[i].toUpperCase());
030                    }
031                    
032                    return set.toArray(new String[set.size()]);
033            }
034    }