ServerBookInfo getInfo() {
   final List<String> hashes = Hashes.getValue();
   if (hashes.size() == 0) {
     return null;
   }
   return new ServerBookInfo(
       hashes,
       Title.getValue(),
       fullUrl(DownloadUrl),
       Mimetype.getValue(),
       fullUrl(ThumbnailUrl),
       Size.getValue());
 }
  public Map<String, Object> data(IBookCollection<Book> collection) {
    final Map<String, Object> map = new HashMap<String, Object>();
    map.put("generation", myGeneration.getValue());
    map.put("timestamp", System.currentTimeMillis());

    final Book currentBook = collection.getRecentBook(0);
    if (currentBook != null) {
      final String oldHash = myCurrentBookHash.getValue();
      final String newHash = collection.getHash(currentBook, true);
      if (newHash != null && !newHash.equals(oldHash)) {
        myCurrentBookHash.setValue(newHash);
        if (oldHash.length() != 0) {
          myCurrentBookTimestamp.setValue(String.valueOf(System.currentTimeMillis()));
          myServerBook.reset();
        }
      }
      final String currentBookHash = newHash != null ? newHash : oldHash;

      final Map<String, Object> currentBookMap = new HashMap<String, Object>();
      currentBookMap.put("hash", currentBookHash);
      currentBookMap.put("title", currentBook.getTitle());
      try {
        currentBookMap.put("timestamp", Long.parseLong(myCurrentBookTimestamp.getValue()));
      } catch (Exception e) {
      }
      map.put("currentbook", currentBookMap);

      final List<Map<String, Object>> lst = new ArrayList<Map<String, Object>>();
      if (positionOption(currentBookHash).getValue().length() == 0) {
        final Map<String, Object> posMap = positionMap(collection, currentBook);
        if (posMap != null) {
          posMap.put("hash", currentBookHash);
          lst.add(posMap);
        }
      }
      if (!currentBookHash.equals(oldHash) && positionOption(oldHash).getValue().length() == 0) {
        final Map<String, Object> posMap =
            positionMap(collection, collection.getBookByHash(oldHash));
        if (posMap != null) {
          posMap.put("hash", oldHash);
          lst.add(posMap);
        }
      }
      if (lst.size() > 0) {
        map.put("positions", lst);
      }
    }

    System.err.println("DATA = " + map);
    return map;
  }
 public ZLTextFixedPosition.WithTimestamp getAndCleanPosition(String hash) {
   final ZLStringOption option = positionOption(hash);
   try {
     return map2Position((Map) JSONValue.parse(option.getValue()));
   } catch (Throwable t) {
     return null;
   } finally {
     option.setValue("");
   }
 }
Ejemplo n.º 4
0
 public String getColorProfileName() {
   return ColorProfileOption.getValue();
 }
 private static String fullUrl(ZLStringOption option) {
   final String value = option.getValue();
   return !"".equals(value) ? SyncOptions.BASE_URL + value : null;
 }