use of org.apache.jena.atlas.web.AcceptList in project jena by apache.
the class ConNeg method match.
/**
* Match a single media type against a header string.
*
* @param headerString HTTP header string
* @param mediaRangeStr Semi-colon separated list of media types
* @return the matched media type or <code>null</code> if there was no match
*/
public static String match(String headerString, String mediaRangeStr) {
AcceptList l = new AcceptList(headerString);
// MediaType
MediaRange aItem = new MediaRange(mediaRangeStr);
MediaType m = l.match(aItem);
if (m == null)
return null;
return m.toHeaderString();
}
use of org.apache.jena.atlas.web.AcceptList in project jena by apache.
the class ConNeg method choose.
/**
* <p>
* This method receives a HTTP header string, an {@link AcceptList} and a default
* {@link MediaType}.
* </p>
* <p>
* If the header string is null, it returns the given default MediaType.
* </p>
* <p>
* Otherwise it builds an {@link AcceptList} object with the header string and
* uses it to match against the given MediaType.
* </p>
*
* @param headerString HTTP header string
* @param myPrefs accept list
* @param defaultMediaType default media type
* @return a media type or <code>null</code> if none matched or if the HTTP
* header string and the default media type are <code>null</code>.
*/
private static MediaType choose(String headerString, AcceptList myPrefs, MediaType defaultMediaType) {
if (headerString == null)
return defaultMediaType;
AcceptList headerList = new AcceptList(headerString);
if (myPrefs == null) {
MediaType i = headerList.first();
if (i == null)
return defaultMediaType;
return i;
}
MediaType i = AcceptList.match(headerList, myPrefs);
if (i == null)
return defaultMediaType;
return i;
}
use of org.apache.jena.atlas.web.AcceptList in project jena by apache.
the class ConNeg method choose.
/**
* <p>This method receives a HTTP header string, an {@link AcceptList} and a
* default {@link MediaType}.</p>
*
* <p>If the header string is null, it returns the given default MediaType.</p>
*
* <p>Otherwise it builds an {@link AcceptList} object with the header string
* and uses it to match against the given MediaType.</p>
*
* @param headerString HTTP header string
* @param myPrefs accept list
* @param defaultMediaType default media type
* @return a media type or <code>null</code> if none matched or if the
* HTTP header string and the default media type are <code>null</code>.
*/
private static MediaType choose(String headerString, AcceptList myPrefs, MediaType defaultMediaType) {
if (headerString == null)
return defaultMediaType;
AcceptList headerList = new AcceptList(headerString);
if (myPrefs == null) {
MediaType i = headerList.first();
if (i == null)
return defaultMediaType;
return i;
}
MediaType i = AcceptList.match(headerList, myPrefs);
if (i == null)
return defaultMediaType;
return i;
}
use of org.apache.jena.atlas.web.AcceptList in project jena by apache.
the class ConNeg method match.
/**
* Match a single media type against a header string.
*
* @param headerString HTTP header string
* @param mediaRangeStr Semi-colon separated list of media types
* @return the matched media type or <code>null</code> if there was no match
*/
public static String match(String headerString, String mediaRangeStr) {
AcceptList l = new AcceptList(headerString);
// MediaType
MediaRange aItem = new MediaRange(mediaRangeStr);
MediaType m = l.match(aItem);
if (m == null)
return null;
return m.toHeaderString();
}
use of org.apache.jena.atlas.web.AcceptList in project jena by apache.
the class TestContentNegotiation method testMatch.
// HTTP: RDF
//See WebContent.defaultGraphAcceptHeader, defaultDatasetAcceptHeader, defaultRDFAcceptHeader
private void testMatch(String header, String offer, String result) {
AcceptList list1 = new AcceptList(header);
AcceptList list2 = new AcceptList(offer);
MediaType matchItem = AcceptList.match(list1, list2);
if (result == null) {
assertNull("Match not null: from " + q(header) + " :: " + q(offer), matchItem);
return;
}
assertNotNull("Match is null: expected " + q(result), matchItem);
assertEquals("Match different", result, matchItem.toHeaderString());
}
Aggregations