1 24 package org.riotfamily.common.io; 25 26 import javax.activation.MimetypesFileTypeMap ; 27 28 import org.springframework.beans.factory.FactoryBean; 29 import org.springframework.core.io.Resource; 30 31 36 public class MimetypesFileTypeMapFactoryBean implements FactoryBean { 37 38 private Resource location; 39 40 private MimetypesFileTypeMap map; 41 42 private String [] types; 43 44 47 public void setLocation(Resource location) { 48 this.location = location; 49 } 50 51 55 public void setTypes(String [] types) { 56 this.types = types; 57 } 58 59 public Object getObject() throws Exception { 60 if (map == null) { 61 if (location != null) { 62 map = new MimetypesFileTypeMap (location.getInputStream()); 63 } 64 else { 65 map = new MimetypesFileTypeMap (); 66 } 67 if (types != null) { 68 for (int i = 0; i < types.length; i++) { 69 map.addMimeTypes(types[i]); 70 } 71 } 72 } 73 return map; 74 } 75 76 public Class getObjectType() { 77 return MimetypesFileTypeMap .class; 78 } 79 80 public boolean isSingleton() { 81 return true; 82 } 83 84 } 85 | Popular Tags |