Esempio n. 1
0
  /**
   * Gets the permalink for a blog entry.
   *
   * @return a URI as a String
   */
  public synchronized String getPermalink(BlogEntry blogEntry) {
    if (blogEntry.getTitle() == null || blogEntry.getTitle().length() == 0) {
      return buildPermalink(blogEntry) + ".html";
    } else {
      BlogService service = new BlogService();
      Day day = getBlog().getBlogForDay(blogEntry.getDate());
      List entries = day.getBlogEntries();
      int count = 0;
      for (int i = entries.size() - 1; i > entries.indexOf(blogEntry.getId()); i--) {
        try {
          BlogEntry entry = service.getBlogEntry(getBlog(), (String) entries.get(i));
          if (entry.getTitle().equals(blogEntry.getTitle())) {
            count++;
          }
        } catch (BlogServiceException e) {
          // do nothing
        }
      }

      if (count == 0) {
        return buildPermalink(blogEntry) + ".html";
      } else {
        return buildPermalink(blogEntry) + "_" + blogEntry.getId() + ".html";
      }
    }
  }
Esempio n. 2
0
  /**
   * Gets the blog entry referred to by the specified URI.
   *
   * @param uri a relative URI
   * @return a BlogEntry instance, or null if one can't be found
   */
  public BlogEntry getBlogEntry(String uri) {
    BlogService service = new BlogService();
    Day day = getDay(uri);

    Iterator it = day.getBlogEntries().iterator();
    while (it.hasNext()) {
      try {
        BlogEntry blogEntry = service.getBlogEntry(getBlog(), (String) it.next());
        // use the local permalink, just in case the entry has been aggregated
        // and an original permalink assigned
        if (blogEntry.getLocalPermalink().endsWith(uri)) {
          return blogEntry;
        }
      } catch (BlogServiceException e) {
        // do nothing
      }
    }

    return null;
  }