コード例 #1
0
 static Session sessionFromElement(DomElement element, String apiKey, String secret) {
   if (element == null) return null;
   String user = element.getChildText("name");
   String key = element.getChildText("key");
   boolean subsc = element.getChildText("subscriber").equals("1");
   return createSession(apiKey, secret, key, user, subsc);
 }
コード例 #2
0
  public static <T> PaginatedResult<T> buildPaginatedResult(
      DomElement contentElement, DomElement childElement, ItemFactory<T> factory) {
    Collection<T> items = buildCollection(childElement, factory);

    String totalPagesAttribute = contentElement.getAttribute("totalPages");
    if (totalPagesAttribute == null)
      totalPagesAttribute = contentElement.getAttribute("totalpages");

    int page = Integer.parseInt(contentElement.getAttribute("page"));
    int totalPages = Integer.parseInt(totalPagesAttribute);

    return new PaginatedResult<T>(page, totalPages, items);
  }
コード例 #3
0
 public static <T> Collection<T> buildCollection(DomElement element, ItemFactory<T> factory) {
   if (element == null) return Collections.emptyList();
   Collection<DomElement> children = element.getChildren();
   Collection<T> items = new ArrayList<T>(children.size());
   for (DomElement child : children) {
     items.add(factory.createItemFromElement(child));
   }
   return items;
 }