/** * Compares two MediaRanges for equality. * * <p> * The values are first compared according to <code>qValue</code> values. * Should those values be equal, the <code>type</code> is then lexicographically compared (case-insensitive) in * ascending order, with the <js>"*"</js> type demoted last in that order. * <code>MediaRanges</code> with the same type but different sub-types are compared - a more specific subtype is * promoted over the 'wildcard' subtype. * <code>MediaRanges</code> with the same types but with extensions are promoted over those same types with no * extensions. * * @param o The range to compare to. Never <jk>null</jk>. */ @Override /* Comparable */ public int compareTo(MediaTypeRange o) { // Compare q-values. int qCompare = Float.compare(o.qValue, qValue); if (qCompare != 0) return qCompare; // Compare media-types. // Note that '*' comes alphabetically before letters, so just do a reverse-alphabetical comparison. int i = o.mediaType.toString().compareTo(mediaType.toString()); return i; } }
/** * Same as {@link #getParserMatch(String)} but matches using a {@link MediaType} instance. * * @param mediaType The HTTP <l>Content-Type</l> header value as a media type. * @return The parser and media type that matched the media type, or <jk>null</jk> if no match was made. */ public ParserMatch getParserMatch(MediaType mediaType) { return getParserMatch(mediaType.toString()); }
/** * Same as {@link #getSerializerMatch(MediaType)} but returns just the matched serializer. * * @param mediaType The HTTP media type. * @return The serializer that matched the accept header, or <jk>null</jk> if no match was made. */ public Serializer getSerializer(MediaType mediaType) { if (mediaType == null) return null; return getSerializer(mediaType.toString()); }
/** * Same as {@link #getSerializerMatch(String)} but matches using a {@link MediaType} instance. * * @param mediaType The HTTP media type. * @return The serializer and media type that matched the media type, or <jk>null</jk> if no match was made. */ public SerializerMatch getSerializerMatch(MediaType mediaType) { return getSerializerMatch(mediaType.toString()); }
/** * Same as {@link #getSerializerMatch(String)} but matches using a {@link MediaType} instance. * * @param mediaType The HTTP media type. * @return The serializer and media type that matched the media type, or <jk>null</jk> if no match was made. */ public SerializerMatch getSerializerMatch(MediaType mediaType) { return getSerializerMatch(mediaType.toString()); }
/** * Same as {@link #getParserMatch(String)} but matches using a {@link MediaType} instance. * * @param mediaType The HTTP <l>Content-Type</l> header value as a media type. * @return The parser and media type that matched the media type, or <jk>null</jk> if no match was made. */ public ParserMatch getParserMatch(MediaType mediaType) { return getParserMatch(mediaType.toString()); }
/** * Same as {@link #getSerializerMatch(MediaType)} but returns just the matched serializer. * * @param mediaType The HTTP media type. * @return The serializer that matched the accept header, or <jk>null</jk> if no match was made. */ public Serializer getSerializer(MediaType mediaType) { if (mediaType == null) return null; return getSerializer(mediaType.toString()); }
/** * Same as {@link #getSerializerMatch(String)} but matches using a {@link MediaType} instance. * * @param mediaType The HTTP media type. * @return The serializer and media type that matched the media type, or <jk>null</jk> if no match was made. */ public SerializerMatch getSerializerMatch(MediaType mediaType) { return getSerializerMatch(mediaType.toString()); }
/** * Same as {@link #getSerializerMatch(MediaType)} but returns just the matched serializer. * * @param mediaType The HTTP media type. * @return The serializer that matched the accept header, or <jk>null</jk> if no match was made. */ public Serializer getSerializer(MediaType mediaType) { if (mediaType == null) return null; return getSerializer(mediaType.toString()); }
/** * Same as {@link #getParserMatch(String)} but matches using a {@link MediaType} instance. * * @param mediaType The HTTP <l>Content-Type</l> header value as a media type. * @return The parser and media type that matched the media type, or <jk>null</jk> if no match was made. */ public ParserMatch getParserMatch(MediaType mediaType) { return getParserMatch(mediaType.toString()); }
/** * Returns <jk>true</jk> if this parser can handle the specified content type. * * @param contentType The content type to test. * @return <jk>true</jk> if this parser can handle the specified content type. */ public boolean canHandle(String contentType) { if (contentType != null) for (MediaType mt : getMediaTypes()) if (contentType.equals(mt.toString())) return true; return false; }
/** * Returns <jk>true</jk> if this parser can handle the specified content type. * * @param contentType The content type to test. * @return <jk>true</jk> if this parser can handle the specified content type. */ public boolean canHandle(String contentType) { if (contentType != null) for (MediaType mt : getMediaTypes()) if (contentType.equals(mt.toString())) return true; return false; }
/** * Returns <jk>true</jk> if this parser can handle the specified content type. * * @param contentType The content type to test. * @return <jk>true</jk> if this parser can handle the specified content type. */ public boolean canHandle(String contentType) { if (contentType != null) for (MediaType mt : getMediaTypes()) if (contentType.equals(mt.toString())) return true; return false; }
/** * Constructor. * * @param input The POJO to serialize. Can also be a {@link Reader} or {@link InputStream}. * @param serializer The serializer to use to serialize this response. * @param schema The optional schema information about the serialized part. */ public RestRequestEntity(Object input, Serializer serializer, HttpPartSchema schema) { this.output = input; this.serializer = serializer; this.schema = schema; if (serializer != null && serializer.getResponseContentType() != null) setContentType(new BasicHeader("Content-Type", serializer.getResponseContentType().toString())); }
/** * Constructor. * * @param input The POJO to serialize. Can also be a {@link Reader} or {@link InputStream}. * @param serializer The serializer to use to serialize this response. * @param schema The optional schema information about the serialized part. */ public RestRequestEntity(Object input, Serializer serializer, HttpPartSchema schema) { this.output = input; this.serializer = serializer; this.schema = schema; if (serializer != null && serializer.getResponseContentType() != null) setContentType(new BasicHeader("Content-Type", serializer.getResponseContentType().toString())); }
/** * Constructor. * * @param input The POJO to serialize. Can also be a {@link Reader} or {@link InputStream}. * @param serializer The serializer to use to serialize this response. * @param schema The optional schema information about the serialized part. */ public RestRequestEntity(Object input, Serializer serializer, HttpPartSchema schema) { this.output = input; this.serializer = serializer; this.schema = schema; if (serializer != null && serializer.getResponseContentType() != null) setContentType(new BasicHeader("Content-Type", serializer.getResponseContentType().toString())); }
@Override /* MenuItemWidget */ public Div getContent(RestRequest req) { Div div = div(); Set<MediaType> l = new TreeSet<>(); for (Serializer s : req.getSerializers().getSerializers()) l.add(s.getPrimaryMediaType()); for (MediaType mt : l) { URI uri = req.getUri(true, new AMap<String,String>().append("plainText","true").append("Accept",mt.toString())); div.children(a(uri, mt), br()); } return div; } }
@Override /* MenuItemWidget */ public Div getContent(RestRequest req) { Div div = div(); Set<MediaType> l = new TreeSet<>(); for (Serializer s : req.getSerializers().getSerializers()) l.add(s.getPrimaryMediaType()); for (MediaType mt : l) { URI uri = req.getUri(true, new AMap<String,String>().append("plainText","true").append("Accept",mt.toString())); div.children(a(uri, mt), br()); } return div; } }
@Override /* MenuItemWidget */ public Div getContent(RestRequest req) { Div div = div(); Set<MediaType> l = new TreeSet<>(); for (Serializer s : req.getSerializers().getSerializers()) l.add(s.getPrimaryMediaType()); for (MediaType mt : l) { URI uri = req.getUri(true, new AMap<String,String>().append("plainText","true").append("Accept",mt.toString())); div.children(a(uri, mt), br()); } return div; } }
@Test public void testToWritable() throws Exception { Config cf = init("a = b"); StringWriter sw = new StringWriter(); cf.writeTo(sw); assertTextEquals("a = b|", sw); assertEquals("text/plain", cf.getMediaType().toString()); }