/** * Indicate whether this {@code MediaType} includes the given media type. * <p>For instance, {@code text/*} includes {@code text/plain} and {@code text/html}, * and {@code application/*+xml} includes {@code application/soap+xml}, etc. * This method is <b>not</b> symmetric. * <p>Simply calls {@link #includes(MimeType)} but declared with a * {@code MediaType} parameter for binary backwards compatibility. * @param other the reference media type with which to compare * @return {@code true} if this media type includes the given media type; * {@code false} otherwise */ public boolean includes(@Nullable MediaType other) { return super.includes(other); }
protected boolean isReadableContentType() { MimeType contentType = getContentType(); for (MimeType mimeType : READABLE_MIME_TYPES) { if (mimeType.includes(contentType)) { return true; } } return false; }
/** * Indicate whether this {@code MediaType} includes the given media type. * <p>For instance, {@code text/*} includes {@code text/plain} and {@code text/html}, * and {@code application/*+xml} includes {@code application/soap+xml}, etc. * This method is <b>not</b> symmetric. * <p>Simply calls {@link #includes(MimeType)} but declared with a * {@code MediaType} parameter for binary backwards compatibility. * @param other the reference media type with which to compare * @return {@code true} if this media type includes the given media type; * {@code false} otherwise */ public boolean includes(@Nullable MediaType other) { return super.includes(other); }
@Test public void includes() { MimeType textPlain = MimeTypeUtils.TEXT_PLAIN; assertTrue("Equal types is not inclusive", textPlain.includes(textPlain)); MimeType allText = new MimeType("text"); assertTrue("All subtypes is not inclusive", allText.includes(textPlain)); assertFalse("All subtypes is inclusive", textPlain.includes(allText)); assertTrue("All types is not inclusive", MimeTypeUtils.ALL.includes(textPlain)); assertFalse("All types is inclusive", textPlain.includes(MimeTypeUtils.ALL)); assertTrue("All types is not inclusive", MimeTypeUtils.ALL.includes(textPlain)); assertFalse("All types is inclusive", textPlain.includes(MimeTypeUtils.ALL)); MimeType applicationSoapXml = new MimeType("application", "soap+xml"); MimeType applicationWildcardXml = new MimeType("application", "*+xml"); MimeType suffixXml = new MimeType("application", "x.y+z+xml"); // SPR-15795 assertTrue(applicationSoapXml.includes(applicationSoapXml)); assertTrue(applicationWildcardXml.includes(applicationWildcardXml)); assertTrue(applicationWildcardXml.includes(suffixXml)); assertTrue(applicationWildcardXml.includes(applicationSoapXml)); assertFalse(applicationSoapXml.includes(applicationWildcardXml)); assertFalse(suffixXml.includes(applicationWildcardXml)); assertFalse(applicationWildcardXml.includes(MimeTypeUtils.APPLICATION_JSON)); }
protected boolean isReadableContentType() { MimeType contentType = getContentType(); for (MimeType mimeType : READABLE_MIME_TYPES) { if (mimeType.includes(contentType)) { return true; } } return false; }
/** * Indicate whether this {@code MediaType} includes the given media type. * <p>For instance, {@code text/*} includes {@code text/plain} and {@code text/html}, and {@code application/*+xml} * includes {@code application/soap+xml}, etc. This method is <b>not</b> symmetric. * @param other the reference media type with which to compare * @return {@code true} if this media type includes the given media type; {@code false} otherwise */ public boolean includes(MediaType other) { return super.includes(other); }
/** * Indicate whether this {@code MediaType} includes the given media type. * <p>For instance, {@code text/*} includes {@code text/plain} and {@code text/html}, * and {@code application/*+xml} includes {@code application/soap+xml}, etc. * This method is <b>not</b> symmetric. * <p>Simply calls {@link #includes(MimeType)} but declared with a * {@code MediaType} parameter for binary backwards compatibility. * @param other the reference media type with which to compare * @return {@code true} if this media type includes the given media type; * {@code false} otherwise */ public boolean includes(@Nullable MediaType other) { return super.includes(other); }
/** * Indicate whether this {@code MediaType} includes the given media type. * <p>For instance, {@code text/*} includes {@code text/plain} and {@code text/html}, * and {@code application/*+xml} includes {@code application/soap+xml}, etc. * This method is <b>not</b> symmetric. * <p>Simply calls {@link #includes(MimeType)} but declared with a * {@code MediaType} parameter for binary backwards compatibility. * @param other the reference media type with which to compare * @return {@code true} if this media type includes the given media type; * {@code false} otherwise */ public boolean includes(@Nullable MediaType other) { return super.includes(other); }
protected boolean isReadableContentType() { MimeType contentType = getContentType(); for (MimeType mimeType : READABLE_MIME_TYPES) { if (mimeType.includes(contentType)) { return true; } } return false; }
protected boolean isReadableContentType() { MimeType contentType = getContentType(); for (MimeType mimeType : READABLE_MIME_TYPES) { if (mimeType.includes(contentType)) { return true; } } return false; }
/** * Get the java Object type for the MimeType X_JAVA_OBJECT * * @return the class for the content type */ public static Class<?> getJavaTypeForJavaObjectContentType(MimeType contentType) { Assert.isTrue(X_JAVA_OBJECT.includes(contentType), "Content type must be " + X_JAVA_OBJECT.toString() + ", or " + "included in it"); if (contentType.getParameter("type") != null) { try { return ClassUtils.forName(contentType.getParameter("type"), null); } catch (Exception e) { throw new ConversionException(e.getMessage(), e); } } return Object.class; }
if (converter instanceof AbstractMessageConverter) { for (MimeType type : ((AbstractMessageConverter) converter).getSupportedMimeTypes()) { if (type.includes(mimeType)) { converters.add(converter);
@Override protected boolean supportsMimeType(MessageHeaders headers) { if (super.supportsMimeType(headers)) { return true; } MimeType mimeType = getContentTypeResolver().resolve(headers); return DEFAULT_AVRO_MIME_TYPE.includes(mimeType); }
@Override protected boolean supportsMimeType(MessageHeaders headers) { if (super.supportsMimeType(headers)) { return true; } MimeType mimeType = getContentTypeResolver().resolve(headers); return DEFAULT_AVRO_MIME_TYPE.includes(mimeType); }
@Override public boolean canConvert(String fromMimeType, String toMimeType) { for (RenditionProvider provider : providers) { if (MimeType.valueOf(fromMimeType) .includes(MimeType.valueOf(provider.consumes()))) { for (String produce : provider.produces()) { if (MimeType.valueOf(toMimeType) .includes(MimeType.valueOf(produce))) { return true; } } } } return false; }
@Override public InputStream convert(String fromMimeType, InputStream fromInputSource, String toMimeType) { for (RenditionProvider provider : providers) { if (MimeType.valueOf(fromMimeType) .includes(MimeType.valueOf(provider.consumes()))) { for (String produce : provider.produces()) { if (MimeType.valueOf(toMimeType) .includes(MimeType.valueOf(produce))) { return provider.convert(fromInputSource, toMimeType); } } } } return null; }
/** * Convert message body to text if possible, otherwise throw exception. * @param body * @return */ public static String toPlainText(MailBody body) throws MailBadMessageException { MimeType mimeType = body.getMimeType(); boolean containsMime = false; for (MimeType type : mimeTypeSet) { containsMime = containsMime || type.includes(mimeType); } if(!containsMime) { throw new MailBadMessageException("Message contains body with unsupported contentType: " + mimeType); } try(Reader r = body.getReader()) { return IOUtils.toString(r); } catch (IOException e) { throw new MailBadMessageException(e); } } }