Created
January 5, 2014 15:58
-
-
Save eugenp/8269915 to your computer and use it in GitHub Desktop.
Extracting Link rel values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String extractURIByRel(final String linkHeader, final String rel) { | |
if (linkHeader == null) { | |
return null; | |
} | |
String uriWithSpecifiedRel = null; | |
final String[] links = linkHeader.split(", "); | |
String linkRelation = null; | |
for (final String link : links) { | |
final int positionOfSeparator = link.indexOf(';'); | |
linkRelation = link.substring(positionOfSeparator + 1, link.length()).trim(); | |
if (extractTypeOfRelation(linkRelation).equals(rel)) { | |
uriWithSpecifiedRel = link.substring(1, positionOfSeparator - 1); | |
break; | |
} | |
} | |
return uriWithSpecifiedRel; | |
} | |
static Object extractTypeOfRelation(final String linkRelation) { | |
final int positionOfEquals = linkRelation.indexOf('='); | |
return linkRelation.substring(positionOfEquals + 2, linkRelation.length() - 1).trim(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is used in:
http://www.baeldung.com/2012/01/18/rest-pagination-in-spring/