/** * <p>Creates a {@link AcceptList} with the given HTTP header string and * uses the {@link AcceptList#match(MediaType)} method to decide which * media type matches the HTTP header string.</p> * * <p>The <em>q</em> quality factor is used to decide which choice is the best * match.</p> * * @param headerString HTTP header string * @param offerList accept list * @return matched media type */ static public MediaType match(String headerString, AcceptList offerList) { AcceptList l = new AcceptList(headerString) ; return AcceptList.match(l, offerList) ; }
return defaultMediaType ; AcceptList headerList = new AcceptList(headerString) ; MediaType i = headerList.first() ; if ( i == null ) return defaultMediaType ; return i ; MediaType i = AcceptList.match(headerList, myPrefs) ; if ( i == null ) return defaultMediaType ;
/** * Create a list of accept items from strings. * @param acceptStrings */ public static AcceptList create(String... acceptStrings) { AcceptList accepList = new AcceptList(); for ( String acceptString : acceptStrings ) { accepList.ranges.add(new MediaRange(acceptString)); } return accepList; }
private /* public */ boolean accepts(MediaRange aItem) { return match(aItem) != null; }
/** * Parse an HTTP Accept (or etc) header string. * @param headerString */ public AcceptList(String headerString) { try { ranges = stringToAcceptList(headerString); } catch (Exception ex) { ex.printStackTrace(System.err); Log.warn(this, "Unrecognized accept string (ignored): " + headerString); ranges = new ArrayList<>(); } }
/** * Create a list of accept items from the give MediaTypes. * @param acceptItems */ public static AcceptList create(MediaType... acceptItems) { AcceptList accepList = new AcceptList(); for ( MediaType mtype : acceptItems ) accepList.ranges.add(new MediaRange(mtype)); return accepList; }
private /*public*/ boolean accepts(MediaRange aItem) { return match(aItem) != null ; }
/** * Parse an HTTP Accept (or etc) header string. * @param headerString */ public AcceptList(String headerString) { try { ranges = stringToAcceptList(headerString) ; } catch (Exception ex) { ex.printStackTrace(System.err) ; Log.warn(this, "Unrecognized accept string (ignored): "+headerString) ; ranges = new ArrayList<MediaRange>() ; } }
/** * <p>Creates a {@link AcceptList} with the given HTTP header string and * uses the {@link AcceptList#match(MediaType)} method to decide which * media type matches the HTTP header string.</p> * * <p>The <em>q</em> quality factor is used to decide which choice is the best * match.</p> * * @param headerString HTTP header string * @param offerList accept list * @return matched media type */ static public MediaType match(String headerString, AcceptList offerList) { AcceptList l = new AcceptList(headerString) ; return AcceptList.match(l, offerList) ; }
return defaultMediaType ; AcceptList headerList = new AcceptList(headerString) ; MediaType i = headerList.first() ; if ( i == null ) return defaultMediaType ; return i ; MediaType i = AcceptList.match(headerList, myPrefs) ; if ( i == null ) return defaultMediaType ;
/** * Create a list of accept items from strings. * @param acceptStrings */ public static AcceptList create(String... acceptStrings) { AcceptList accepList = new AcceptList() ; for ( int i = 0 ; i < acceptStrings.length ; i++ ) accepList.ranges.add(new MediaRange(acceptStrings[i])) ; return accepList ; }
/** * 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) ; MediaRange aItem = new MediaRange(mediaRangeStr) ; // MediaType MediaType m = l.match(aItem) ; if ( m == null ) return null ; return m.toHeaderString() ; }
/** * Create a list of accept items from the give MediaTypes. * @param acceptItems */ public static AcceptList create(MediaType...acceptItems) { AcceptList accepList = new AcceptList() ; for ( MediaType mtype : acceptItems ) accepList.ranges.add(new MediaRange(mtype)) ; return accepList ; }
/** * 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) ; MediaRange aItem = new MediaRange(mediaRangeStr) ; // MediaType MediaType m = l.match(aItem) ; if ( m == null ) return null ; return m.toHeaderString() ; }
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()) ; }