Skip to content

Commit

Permalink
MediaTypes::getMultiPartRelatedType: merge parameters of passed Media…
Browse files Browse the repository at this point in the history
…Type to returned MediaType fix #308
  • Loading branch information
gunterze committed Jun 21, 2018
1 parent c510616 commit 8e179b8
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions dcm4che-ws-rs/src/main/java/org/dcm4che3/ws/rs/MediaTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
* @author Gunter Zeilinger <gunterze@gmail.com>
Expand Down Expand Up @@ -84,6 +85,17 @@ public class MediaTypes {
public final static MediaType APPLICATION_DICOM_JSON_TYPE =
new MediaType("application", "dicom+json");

/**
* "image/*"
*/
public final static String IMAGE_WILDCARD = "image/*";

/**
* "image/*"
*/
public final static MediaType IMAGE_WILDCARD_TYPE =
new MediaType("image", "*");

/**
* "image/gif"
*/
Expand Down Expand Up @@ -162,6 +174,17 @@ public class MediaTypes {
public final static MediaType IMAGE_X_DICOM_RLE_TYPE =
new MediaType("image", "x-dicom+rle");

/**
* "video/*"
*/
public final static String VIDEO_WILDCARD = "video/*";

/**
* "video/*"
*/
public final static MediaType VIDEO_WILDCARD_TYPE =
new MediaType("video", "*");

/**
* "video/mpeg"
*/
Expand Down Expand Up @@ -346,11 +369,24 @@ public static boolean equalsIgnoreParameters(MediaType type1, MediaType type2) {
&& type1.getSubtype().equalsIgnoreCase(type2.getSubtype());
}


public static MediaType getMultiPartRelatedType(MediaType type) {
return equalsIgnoreParameters(MULTIPART_RELATED_TYPE, type)
? MediaType.valueOf(type.getParameters().get("type"))
: null;
public static MediaType getMultiPartRelatedType(MediaType mediaType) {
if (mediaType.isWildcardType()) {
return MediaType.WILDCARD_TYPE;
}
if (!equalsIgnoreParameters(MULTIPART_RELATED_TYPE, mediaType)) {
return null;
}
String type = mediaType.getParameters().get("type");
if (type == null) {
return MediaType.WILDCARD_TYPE;
}
MediaType partType = MediaType.valueOf(type);
if (mediaType.getParameters().size() > 1) {
Map<String, String> params = new HashMap<>(mediaType.getParameters());
params.remove("type");
partType = new MediaType(mediaType.getType(), mediaType.getSubtype(), params);
}
return partType;
}

public static String getTransferSyntax(MediaType type) {
Expand Down

0 comments on commit 8e179b8

Please sign in to comment.