/** * Create a new {@link MimeMappings} from the specified mappings. * @param mappings the source mappings with extension as the key and mime-type as the * value */ public MimeMappings(Map<String, String> mappings) { Assert.notNull(mappings, "Mappings must not be null"); this.map = new LinkedHashMap<String, MimeMappings.Mapping>(); for (Map.Entry<String, String> entry : mappings.entrySet()) { add(entry.getKey(), entry.getValue()); } }
/** * Internal constructor. * @param mappings source mappings * @param mutable if the new object should be mutable. */ private MimeMappings(MimeMappings mappings, boolean mutable) { Assert.notNull(mappings, "Mappings must not be null"); this.map = (mutable ? new LinkedHashMap<String, MimeMappings.Mapping>(mappings.map) : Collections.unmodifiableMap(mappings.map)); }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (obj instanceof Mapping) { Mapping other = (Mapping) obj; return this.extension.equals(other.extension) && this.mimeType.equals(other.mimeType); } return false; }
@Override protected Collection<Mapping> getExpectedMimeMappings() { // Unlike Tomcat and Jetty, Undertow performs a case-sensitive match on file // extension so it has a mapping for "z" and "Z". Set<Mapping> expectedMappings = new HashSet<Mapping>( super.getExpectedMimeMappings()); expectedMappings.add(new Mapping("Z", "application/x-compress")); return expectedMappings; }
/** * Create a new empty {@link MimeMappings} instance. */ public MimeMappings() { this.map = new LinkedHashMap<String, MimeMappings.Mapping>(); }
@Override public Iterator<Mapping> iterator() { return getAll().iterator(); }
public Mapping(String extension, String mimeType) { Assert.notNull(extension, "Extension must not be null"); Assert.notNull(mimeType, "MimeType must not be null"); this.extension = extension; this.mimeType = mimeType; }
private void configureMimeMappings(DeploymentInfo servletBuilder) { for (Mapping mimeMapping : getMimeMappings()) { servletBuilder.addMimeMapping(new MimeMapping(mimeMapping.getExtension(), mimeMapping.getMimeType())); } }
/** * Returns all defined mappings. * @return the mappings. */ public Collection<Mapping> getAll() { return this.map.values(); }
/** * Add a new mime mapping. * @param extension the file extension (excluding '.') * @param mimeType the mime type to map * @return any previous mapping or {@code null} */ public String add(String extension, String mimeType) { Mapping previous = this.map.put(extension, new Mapping(extension, mimeType)); return (previous == null ? null : previous.getMimeType()); }
/** * Get a mime mapping for the given extension. * @param extension the file extension (excluding '.') * @return a mime mapping or {@code null} */ public String get(String extension) { Mapping mapping = this.map.get(extension); return (mapping == null ? null : mapping.getMimeType()); }
/** * Remove an existing mapping. * @param extension the file extension (excluding '.') * @return the removed mime mapping or {@code null} if no item was removed */ public String remove(String extension) { Mapping previous = this.map.remove(extension); return (previous == null ? null : previous.getMimeType()); }