Exemple #1
0
  /**
   * Linkのアンマーシャラー
   *
   * @param str このオブジェクトの文字列表現
   * @return Linkオブジェクト
   */
  public static Link valueOf(String str) {

    Matcher matcher = parse.matcher(str);
    if (!matcher.matches()) throw new RuntimeException("Failed to parse link : " + str);
    Link link = new Link();
    link.href = matcher.group(1);
    String[] props = matcher.group(2).split(";");
    for (String prop : props) {
      String[] keyVal = prop.split("=");
      String key = keyVal[0];
      String val = keyVal[1];

      switch (key) {
        case "rel":
          link.relationship = val;
          break;
        case "type":
          link.type = val;
          break;
        default:
          break;
      }
    }
    return link;
  }
 @XmlTransient
 public String getPrevious() {
   if (links == null) return null;
   for (Link link : links) {
     if ("previous".equals(link.getRelationship())) return link.getHref();
   }
   return null;
 }