Пример #1
0
  public void testEntryCRUD() throws Exception {

    PlanetManager mgr = WebloggerFactory.getWeblogger().getPlanetManager();
    Subscription sub = mgr.getSubscriptionById(testSub.getId());

    SubscriptionEntry testEntry = new SubscriptionEntry();
    testEntry.setPermalink("entryBasics");
    testEntry.setTitle("entryBasics");
    testEntry.setPubTime(new java.sql.Timestamp(System.currentTimeMillis()));
    testEntry.setSubscription(sub);

    // add
    mgr.saveEntry(testEntry);
    TestUtils.endSession(true);

    // verify
    SubscriptionEntry entry = null;
    entry = mgr.getEntryById(testEntry.getId());
    assertNotNull(entry);
    assertEquals("entryBasics", entry.getPermalink());

    // modify
    entry.setTitle("foo");
    mgr.saveEntry(entry);
    TestUtils.endSession(true);

    // verify
    entry = null;
    entry = mgr.getEntryById(testEntry.getId());
    assertNotNull(entry);
    assertEquals("foo", entry.getTitle());

    // remove
    mgr.deleteEntry(entry);
    TestUtils.endSession(true);

    // verify
    entry = null;
    entry = mgr.getEntryById(testEntry.getId());
    assertNull(entry);
  }
Пример #2
0
  // build a SubscriptionEntry from Rome SyndEntry and SyndFeed
  private SubscriptionEntry buildEntry(SyndEntry romeEntry) {

    // if we don't have a permalink then we can't continue
    if (romeEntry.getLink() == null) {
      return null;
    }

    SubscriptionEntry newEntry = new SubscriptionEntry();

    newEntry.setTitle(romeEntry.getTitle());
    newEntry.setPermalink(romeEntry.getLink());

    // Play some games to get the author
    DCModule entrydc = (DCModule) romeEntry.getModule(DCModule.URI);
    if (romeEntry.getAuthor() != null) {
      newEntry.setAuthor(romeEntry.getAuthor());
    } else {
      newEntry.setAuthor(entrydc.getCreator()); // use <dc:creator>
    }

    // Play some games to get the updated date
    if (romeEntry.getUpdatedDate() != null) {
      newEntry.setUpdateTime(new Timestamp(romeEntry.getUpdatedDate().getTime()));
    }
    // TODO: should we set a default update time here?

    // And more games getting publish date
    if (romeEntry.getPublishedDate() != null) {
      newEntry.setPubTime(new Timestamp(romeEntry.getPublishedDate().getTime())); // use <pubDate>
    } else if (entrydc != null && entrydc.getDate() != null) {
      newEntry.setPubTime(new Timestamp(entrydc.getDate().getTime())); // use <dc:date>
    } else {
      newEntry.setPubTime(newEntry.getUpdateTime());
    }

    // get content and unescape if it is 'text/plain'
    if (romeEntry.getContents().size() > 0) {
      SyndContent content = (SyndContent) romeEntry.getContents().get(0);
      if (content != null && content.getType().equals("text/plain")) {
        newEntry.setText(StringEscapeUtils.unescapeHtml(content.getValue()));
      } else if (content != null) {
        newEntry.setText(content.getValue());
      }
    }

    // no content, try summary
    if (newEntry.getText() == null || newEntry.getText().trim().length() == 0) {
      if (romeEntry.getDescription() != null) {
        newEntry.setText(romeEntry.getDescription().getValue());
      }
    }

    // copy categories
    if (romeEntry.getCategories().size() > 0) {
      List list = new ArrayList();
      Iterator cats = romeEntry.getCategories().iterator();
      while (cats.hasNext()) {
        SyndCategory cat = (SyndCategory) cats.next();
        list.add(cat.getName());
      }
      newEntry.setCategoriesString(list);
    }

    return newEntry;
  }