Skip to content

Instantly share code, notes, and snippets.

@eugenp
Created January 5, 2014 15:58
Show Gist options
  • Save eugenp/8269915 to your computer and use it in GitHub Desktop.
Save eugenp/8269915 to your computer and use it in GitHub Desktop.
Extracting Link rel values
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();
}
@eugenp
Copy link
Author

eugenp commented Jan 5, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment