/** * Determine if the two list of media types share a common * {@link #typeEqual(javax.ws.rs.core.MediaType, javax.ws.rs.core.MediaType) type-equal} * sub-list. * * @param ml1 first media type list. * @param ml2 second media type list. * @return {@code true} if the two media type lists intersect by sharing a * common type-equal sub-list, {@code false} otherwise. */ public static boolean intersect(List<? extends MediaType> ml1, List<? extends MediaType> ml2) { for (MediaType m1 : ml1) { for (MediaType m2 : ml2) { if (MediaTypes.typeEqual(m1, m2)) { return true; } } } return false; }
/** * Determine if the two list of media types share a common * {@link #typeEqual(javax.ws.rs.core.MediaType, javax.ws.rs.core.MediaType) type-equal} * sub-list. * * @param ml1 first media type list. * @param ml2 second media type list. * @return {@code true} if the two media type lists intersect by sharing a * common type-equal sub-list, {@code false} otherwise. */ public static boolean intersect(List<? extends MediaType> ml1, List<? extends MediaType> ml2) { for (MediaType m1 : ml1) { for (MediaType m2 : ml2) { if (MediaTypes.typeEqual(m1, m2)) { return true; } } } return false; }
private int getMediaTypeDistance(final MediaType wanted, final List<MediaType> mtl) { if (wanted == null) { return 0; } int distance = 2; for (final MediaType mt : mtl) { if (MediaTypes.typeEqual(wanted, mt)) { return 0; } if (distance > 1 && MediaTypes.typeEqual(MediaTypes.getTypeWildCart(wanted), mt)) { distance = 1; } } return distance; }
private int getMediaTypeDistance(final MediaType wanted, final List<MediaType> mtl) { if (wanted == null) { return 0; } int distance = 2; for (final MediaType mt : mtl) { if (MediaTypes.typeEqual(wanted, mt)) { return 0; } if (distance > 1 && MediaTypes.typeEqual(MediaTypes.getTypeWildCart(wanted), mt)) { distance = 1; } } return distance; }
/** * Disables changing the media type to anything other than {@code multipart/form-data}. * * @param mediaType the proposed media type. * @throws IllegalArgumentException if the proposed media type is not {@code multipart/form-data}. */ @Override public void setMediaType(MediaType mediaType) { if (!MediaTypes.typeEqual(mediaType, MediaType.MULTIPART_FORM_DATA_TYPE)) { throw new IllegalArgumentException(LocalizationMessages.FORM_DATA_MULTIPART_CANNOT_CHANGE_MEDIATYPE()); } super.setMediaType(mediaType); }
private static ContainerRequest ensureValidRequest(final ContainerRequest request) throws IllegalStateException { if (request.getMethod().equals("GET")) { throw new IllegalStateException( LocalizationMessages.FORM_PARAM_METHOD_ERROR()); } if (!MediaTypes.typeEqual(MediaType.APPLICATION_FORM_URLENCODED_TYPE, request.getMediaType())) { throw new IllegalStateException( LocalizationMessages.FORM_PARAM_CONTENT_TYPE_ERROR()); } return request; }
private static ContainerRequest ensureValidRequest(final ContainerRequest request) throws IllegalStateException { if (request.getMethod().equals("GET")) { throw new IllegalStateException( LocalizationMessages.FORM_PARAM_METHOD_ERROR()); } if (!MediaTypes.typeEqual(MediaType.APPLICATION_FORM_URLENCODED_TYPE, request.getMediaType())) { throw new IllegalStateException( LocalizationMessages.FORM_PARAM_CONTENT_TYPE_ERROR()); } return request; }
@Override public int compare(AcceptableMediaType o1, AcceptableMediaType o2) { // FIXME what is going on here? boolean q_o1_set = false; int q_o1 = 0; boolean q_o2_set = false; int q_o2 = 0; for (QualitySourceMediaType priorityType : priorityMediaTypes) { if (!q_o1_set && MediaTypes.typeEqual(o1, priorityType)) { q_o1 = o1.getQuality() * priorityType.getQuality(); q_o1_set = true; } else if (!q_o2_set && MediaTypes.typeEqual(o2, priorityType)) { q_o2 = o2.getQuality() * priorityType.getQuality(); q_o2_set = true; } } int i = q_o2 - q_o1; if (i != 0) { return i; } i = o2.getQuality() - o1.getQuality(); if (i != 0) { return i; } return MediaTypes.PARTIAL_ORDER_COMPARATOR.compare(o1, o2); } },
@Override public int compare(AcceptableMediaType o1, AcceptableMediaType o2) { // FIXME what is going on here? boolean q_o1_set = false; int q_o1 = 0; boolean q_o2_set = false; int q_o2 = 0; for (QualitySourceMediaType priorityType : priorityMediaTypes) { if (!q_o1_set && MediaTypes.typeEqual(o1, priorityType)) { q_o1 = o1.getQuality() * priorityType.getQuality(); q_o1_set = true; } else if (!q_o2_set && MediaTypes.typeEqual(o2, priorityType)) { q_o2 = o2.getQuality() * priorityType.getQuality(); q_o2_set = true; } } int i = q_o2 - q_o1; if (i != 0) { return i; } i = o2.getQuality() - o1.getQuality(); if (i != 0) { return i; } return MediaTypes.PARTIAL_ORDER_COMPARATOR.compare(o1, o2); } },
@Override public MultivaluedMap<String, String> get() { MultivaluedMap<String, String> params = null; final MediaType mediaType = context.getMediaType(); if (mediaType != null && MediaTypes.typeEqual(mediaType, MediaType.APPLICATION_FORM_URLENCODED_TYPE)) { final ContainerRequest jerseyRequest = (ContainerRequest) context; jerseyRequest.bufferEntity(); final Form form = jerseyRequest.readEntity(Form.class); params = form.asMap(); } return params; } });
if (MediaTypes.typeEqual(MediaType.APPLICATION_FORM_URLENCODED_TYPE, containerRequest.getMediaType()) && !containerRequest.hasEntity()) { final Form form = new Form();
if (MediaTypes.typeEqual(MediaType.APPLICATION_FORM_URLENCODED_TYPE, containerRequest.getMediaType()) && !containerRequest.hasEntity()) { final Form form = new Form();
/** * Gets the field value for this body part. This should be called only on body parts representing simple field values. * * @return the simple field value. * @throws ProcessingException if an IO error arises during reading the value. * @throws IllegalStateException if called on a body part with a media type other than {@code text/plain} */ public String getValue() { if (!MediaTypes.typeEqual(MediaType.TEXT_PLAIN_TYPE, getMediaType())) { throw new IllegalStateException(LocalizationMessages.MEDIA_TYPE_NOT_TEXT_PLAIN()); } if (getEntity() instanceof BodyPartEntity) { return getValueAs(String.class); } else { return (String) getEntity(); } }
private Form getFormParameters(ContainerRequest request) { if (MediaTypes.typeEqual(MediaType.APPLICATION_FORM_URLENCODED_TYPE, request.getMediaType())) { request.bufferEntity(); Form form; if (decode) { form = request.readEntity(Form.class); } else { Annotation[] annotations = new Annotation[1]; annotations[0] = encodedAnnotation; form = request.readEntity(Form.class, annotations); } return (form == null ? new Form() : form); } else { return new Form(); } } }
private Form getFormParameters(ContainerRequest request) { if (MediaTypes.typeEqual(MediaType.APPLICATION_FORM_URLENCODED_TYPE, request.getMediaType())) { request.bufferEntity(); Form form; if (decode) { form = request.readEntity(Form.class); } else { Annotation[] annotations = new Annotation[1]; annotations[0] = encodedAnnotation; form = request.readEntity(Form.class, annotations); } return (form == null ? new Form() : form); } else { return new Form(); } } }
mimeConfig); final boolean formData = MediaTypes.typeEqual(mediaType, MediaType.MULTIPART_FORM_DATA_TYPE); final MultiPart multiPart = formData ? new FormDataMultiPart() : new MultiPart();
private static ContainerRequest ensureValidRequest(final ContainerRequest request) throws IllegalStateException { if (request.getMethod().equals("GET")) { throw new IllegalStateException( LocalizationMessages.FORM_PARAM_METHOD_ERROR()); } if (!MediaTypes.typeEqual(MediaType.APPLICATION_FORM_URLENCODED_TYPE, request.getMediaType())) { throw new IllegalStateException( LocalizationMessages.FORM_PARAM_CONTENT_TYPE_ERROR()); } return request; }
private Form getFormParameters(ContainerRequest request) { if (MediaTypes.typeEqual(MediaType.APPLICATION_FORM_URLENCODED_TYPE, request.getMediaType())) { request.bufferEntity(); Form form; if (decode) { form = request.readEntity(Form.class); } else { Annotation[] annotations = new Annotation[1]; annotations[0] = encodedAnnotation; form = request.readEntity(Form.class, annotations); } return (form == null ? new Form() : form); } else { return new Form(); } } }
private static ContainerRequest ensureValidRequest(final ContainerRequest request) throws IllegalStateException { if (request.getMethod().equals("GET")) { throw new IllegalStateException( LocalizationMessages.FORM_PARAM_METHOD_ERROR()); } if (!MediaTypes.typeEqual(MediaType.APPLICATION_FORM_URLENCODED_TYPE, request.getMediaType())) { throw new IllegalStateException( LocalizationMessages.FORM_PARAM_CONTENT_TYPE_ERROR()); } return request; }
private static ContainerRequest ensureValidRequest(final ContainerRequest request) throws IllegalStateException { if (request.getMethod().equals("GET")) { throw new IllegalStateException( LocalizationMessages.FORM_PARAM_METHOD_ERROR()); } if (!MediaTypes.typeEqual(MediaType.APPLICATION_FORM_URLENCODED_TYPE, request.getMediaType())) { throw new IllegalStateException( LocalizationMessages.FORM_PARAM_CONTENT_TYPE_ERROR()); } return request; }