/** * If client can accept text/html, always prefer it. WebKit-based browsers * claim to want application/xml, but we don't want to give it to them. See * <a href="https://webarchive.jira.com/browse/HER-1603">https://webarchive.jira.com/browse/HER-1603</a> */ public Variant getPreferredVariant() { boolean addExplicitTextHtmlPreference = false; for (Preference<MediaType> mediaTypePreference: getRequest().getClientInfo().getAcceptedMediaTypes()) { if (mediaTypePreference.getMetadata().equals(MediaType.TEXT_HTML)) { mediaTypePreference.setQuality(Float.MAX_VALUE); addExplicitTextHtmlPreference = false; break; } else if (mediaTypePreference.getMetadata().includes(MediaType.TEXT_HTML)) { addExplicitTextHtmlPreference = true; } } if (addExplicitTextHtmlPreference) { List<Preference<MediaType>> acceptedMediaTypes = getRequest().getClientInfo().getAcceptedMediaTypes(); acceptedMediaTypes.add(new Preference<MediaType>(MediaType.TEXT_HTML, Float.MAX_VALUE)); getRequest().getClientInfo().setAcceptedMediaTypes(acceptedMediaTypes); } return super.getPreferredVariant(); }
/** * Indicates if a given media type is included in the current one @see * {@link #includes(Metadata, boolean)}. It ignores the parameters. * * @param included * The media type to test for inclusion. * @return True if the given media type is included in the current one. * @see #isCompatible(Metadata) */ @Override public boolean includes(Metadata included) { return includes(included, true); }
/** * Indicates if a given media type is included in the current one @see * {@link #includes(Metadata, boolean)}. It ignores the parameters. * * @param included * The media type to test for inclusion. * @return True if the given media type is included in the current one. * @see #isCompatible(Metadata) */ @Override public boolean includes(Metadata included) { return includes(included, true); }
/** * Checks if this MediaType is compatible with the given media type. * <p> * Examples: * <ul> * <li>TEXT_ALL.isCompatible(TEXT_PLAIN) -> true</li> * <li>TEXT_PLAIN.isCompatible(TEXT_ALL) -> true</li> * <li>TEXT_PLAIN.isCompatible(APPLICATION_ALL) -> false</li> * </ul> * * @param otherMediaType * The other media type to compare. * @return True if the media types are compatible. * @see #includes(MediaType) */ public boolean isCompatible(MediaType otherMediaType) { return includes(otherMediaType) || otherMediaType.includes(this); }
/** * @param resourceMethod * the resource method to check * @param givenMediaType * the MediaType of the request entity * @return Returns true, if the given MediaType is supported by the method, * or no MediaType is given for the method, otherweise false; */ public boolean isGivenMediaTypeSupported(MediaType givenMediaType) { if (givenMediaType == null) { return true; } for (final MediaType consumedMime : getConsumedMimes()) { if (consumedMime.includes(givenMediaType)) { return true; } } return false; }
void checkPosMediaType(Representation entity) throws GeoWebCacheException { String remoteAdr = getRequest().getClientInfo().getAddress(); if (entity == null || ((!entity.getMediaType().includes(MediaType.APPLICATION_XML)) && (!entity.getMediaType().includes(MediaType.APPLICATION_JSON)))) { String message = "Request from "+ remoteAdr + " did not specify MIME type" + " of the document posted. Please specify application/xml " + " or application/json"; throw new GeoWebCacheException(message); } else { log.info("Received seed request from " + remoteAdr); } }
public Response get(Reference uri, MediaType accepts) throws NotSuccessException, MediaTypeException { Response response = request(Method.GET, uri, null, null, accepts); MediaType mediaType = response.getEntity().getMediaType(); if (!accepts.includes(mediaType)) { throw new MediaTypeException(accepts, mediaType); } return response; }
/** * Scores a media type relatively to enriched client preferences. * * @param mediaType * The media type to score. * @return The score. */ public float scoreMediaType(MediaType mediaType) { float result = -1.0F; float current; if (mediaType != null) { for (Preference<MediaType> pref : getMediaTypePrefs()) { if (pref.getMetadata().includes(mediaType, false)) { current = pref.getQuality(); } else { current = -1.0F; } if (current > result) { result = current; } } } else { result = 0.0F; } return result; }
|| getMediaType().includes(other.getMediaType());
&& !(var.getMediaType().includes(representation.getMediaType()))) { return false;
if (a1.includes(p1)) { m.add(MediaType.getMostSpecific(a1, p1));
/** * Indicates if the current variant includes the given variant. * * @param other * The other variant. * @return True if the current variant includes the other. */ public boolean includes(Variant other) { boolean result = other != null; // Compare the character set if (result) { result = (getCharacterSet() == null) || getCharacterSet().includes(other.getCharacterSet()); } // Compare the media type if (result) { result = (getMediaType() == null) || getMediaType().includes(other.getMediaType()); } // Compare the languages if (result) { result = (getLanguages().isEmpty()) || getLanguages().contains(Language.ALL) || getLanguages().containsAll(other.getLanguages()); } return result; }
/** * If client can accept text/html, always prefer it. WebKit-based browsers * claim to want application/xml, but we don't want to give it to them. See * <a href="https://webarchive.jira.com/browse/HER-1603">https://webarchive.jira.com/browse/HER-1603</a> */ public Variant getPreferredVariant() { boolean addExplicitTextHtmlPreference = false; for (Preference<MediaType> mediaTypePreference: getRequest().getClientInfo().getAcceptedMediaTypes()) { if (mediaTypePreference.getMetadata().equals(MediaType.TEXT_HTML)) { mediaTypePreference.setQuality(Float.MAX_VALUE); addExplicitTextHtmlPreference = false; break; } else if (mediaTypePreference.getMetadata().includes(MediaType.TEXT_HTML)) { addExplicitTextHtmlPreference = true; } } if (addExplicitTextHtmlPreference) { List<Preference<MediaType>> acceptedMediaTypes = getRequest().getClientInfo().getAcceptedMediaTypes(); acceptedMediaTypes.add(new Preference<MediaType>(MediaType.TEXT_HTML, Float.MAX_VALUE)); getRequest().getClientInfo().setAcceptedMediaTypes(acceptedMediaTypes); } return super.getPreferredVariant(); }
.entrySet()) { for (final MediaType methodMediaType : mm.getValue()) { if (accMediaType.includes(methodMediaType)) { final ResourceMethod currentResMethod = mm.getKey(); if (bestResMethod == null) {
if (amt.equals(emt)) { score = 1.0f; } else if (amt.includes(emt)) { score = Math.max(0.8f, score);