|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2017 the original author or authors. |
|
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -319,7 +319,7 @@ public class MimeType implements Comparable<MimeType>, Serializable {
@@ -319,7 +319,7 @@ public class MimeType implements Comparable<MimeType>, Serializable {
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
if (this.isWildcardSubtype()) { |
|
|
|
|
// wildcard with suffix, e.g. application/*+xml
|
|
|
|
|
// Wildcard with suffix, e.g. application/*+xml
|
|
|
|
|
int thisPlusIdx = getSubtype().lastIndexOf('+'); |
|
|
|
|
if (thisPlusIdx == -1) { |
|
|
|
|
return true; |
|
|
|
@ -361,22 +361,18 @@ public class MimeType implements Comparable<MimeType>, Serializable {
@@ -361,22 +361,18 @@ public class MimeType implements Comparable<MimeType>, Serializable {
|
|
|
|
|
if (getSubtype().equals(other.getSubtype())) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
// wildcard with suffix? e.g. application/*+xml
|
|
|
|
|
// Wildcard with suffix? e.g. application/*+xml
|
|
|
|
|
if (this.isWildcardSubtype() || other.isWildcardSubtype()) { |
|
|
|
|
|
|
|
|
|
int thisPlusIdx = getSubtype().lastIndexOf('+'); |
|
|
|
|
int otherPlusIdx = other.getSubtype().lastIndexOf('+'); |
|
|
|
|
|
|
|
|
|
if (thisPlusIdx == -1 && otherPlusIdx == -1) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
else if (thisPlusIdx != -1 && otherPlusIdx != -1) { |
|
|
|
|
String thisSubtypeNoSuffix = getSubtype().substring(0, thisPlusIdx); |
|
|
|
|
String otherSubtypeNoSuffix = other.getSubtype().substring(0, otherPlusIdx); |
|
|
|
|
|
|
|
|
|
String thisSubtypeSuffix = getSubtype().substring(thisPlusIdx + 1); |
|
|
|
|
String otherSubtypeSuffix = other.getSubtype().substring(otherPlusIdx + 1); |
|
|
|
|
|
|
|
|
|
if (thisSubtypeSuffix.equals(otherSubtypeSuffix) && |
|
|
|
|
(WILDCARD_TYPE.equals(thisSubtypeNoSuffix) || WILDCARD_TYPE.equals(otherSubtypeNoSuffix))) { |
|
|
|
|
return true; |
|
|
|
@ -417,7 +413,6 @@ public class MimeType implements Comparable<MimeType>, Serializable {
@@ -417,7 +413,6 @@ public class MimeType implements Comparable<MimeType>, Serializable {
|
|
|
|
|
if (!other.parameters.containsKey(key)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (PARAM_CHARSET.equals(key)) { |
|
|
|
|
if (!ObjectUtils.nullSafeEquals(getCharset(), other.getCharset())) { |
|
|
|
|
return false; |
|
|
|
@ -481,12 +476,14 @@ public class MimeType implements Comparable<MimeType>, Serializable {
@@ -481,12 +476,14 @@ public class MimeType implements Comparable<MimeType>, Serializable {
|
|
|
|
|
if (comp != 0) { |
|
|
|
|
return comp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TreeSet<String> thisAttributes = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); |
|
|
|
|
thisAttributes.addAll(getParameters().keySet()); |
|
|
|
|
TreeSet<String> otherAttributes = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); |
|
|
|
|
otherAttributes.addAll(other.getParameters().keySet()); |
|
|
|
|
Iterator<String> thisAttributesIterator = thisAttributes.iterator(); |
|
|
|
|
Iterator<String> otherAttributesIterator = otherAttributes.iterator(); |
|
|
|
|
|
|
|
|
|
while (thisAttributesIterator.hasNext()) { |
|
|
|
|
String thisAttribute = thisAttributesIterator.next(); |
|
|
|
|
String otherAttribute = otherAttributesIterator.next(); |
|
|
|
@ -494,6 +491,23 @@ public class MimeType implements Comparable<MimeType>, Serializable {
@@ -494,6 +491,23 @@ public class MimeType implements Comparable<MimeType>, Serializable {
|
|
|
|
|
if (comp != 0) { |
|
|
|
|
return comp; |
|
|
|
|
} |
|
|
|
|
if (PARAM_CHARSET.equals(thisAttribute)) { |
|
|
|
|
Charset thisCharset = getCharset(); |
|
|
|
|
Charset otherCharset = other.getCharset(); |
|
|
|
|
if (thisCharset != otherCharset) { |
|
|
|
|
if (thisCharset == null) { |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
if (otherCharset == null) { |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
comp = thisCharset.compareTo(otherCharset); |
|
|
|
|
if (comp != 0) { |
|
|
|
|
return comp; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
String thisValue = getParameters().get(thisAttribute); |
|
|
|
|
String otherValue = other.getParameters().get(otherAttribute); |
|
|
|
|
if (otherValue == null) { |
|
|
|
@ -504,6 +518,8 @@ public class MimeType implements Comparable<MimeType>, Serializable {
@@ -504,6 +518,8 @@ public class MimeType implements Comparable<MimeType>, Serializable {
|
|
|
|
|
return comp; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -557,7 +573,7 @@ public class MimeType implements Comparable<MimeType>, Serializable {
@@ -557,7 +573,7 @@ public class MimeType implements Comparable<MimeType>, Serializable {
|
|
|
|
|
protected int compareParameters(T mimeType1, T mimeType2) { |
|
|
|
|
int paramsSize1 = mimeType1.getParameters().size(); |
|
|
|
|
int paramsSize2 = mimeType2.getParameters().size(); |
|
|
|
|
return (paramsSize2 < paramsSize1 ? -1 : (paramsSize2 == paramsSize1 ? 0 : 1)); // audio/basic;level=1 < audio/basic
|
|
|
|
|
return Integer.compare(paramsSize2, paramsSize1); // audio/basic;level=1 < audio/basic
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|