Exemple #1
0
 public static URI parseLinkRelation(String link, String relation) throws InvalidLinkException {
   Precondition.acceptArgument("link", link, Assertions.notNull());
   Precondition.acceptArgument("relation", relation, Assertions.notNull());
   String suffix = getSuffix(relation);
   String tLink = link.trim();
   if (!(tLink.startsWith(LINK_HEADER_PREFIX) && tLink.endsWith(suffix))) {
     throw new InvalidLinkException(
         "Invalid link header format for relation '" + relation + "'", tLink);
   }
   try {
     String base = tLink.substring(LINK_HEADER_PREFIX.length(), tLink.length() - suffix.length());
     return new URI(base);
   } catch (URISyntaxException e) {
     throw new InvalidLinkException(
         "Could not process link for relation '" + relation + "'", e, tLink);
   }
 }
Exemple #2
0
 public static String create(String link, String relation) {
   Precondition.acceptArgument("link", link, Assertions.notNull());
   Precondition.acceptArgument("relation", relation, Assertions.notNull());
   return String.format("<%s>; rel='%s'", link, relation);
 }
Exemple #3
0
 public static URI parseSelf(String link) throws InvalidLinkException {
   Precondition.acceptArgument("link", link, Assertions.notNull());
   return parseLinkRelation(link, "self");
 }