public String createAnchor(WeblogEntryData entry) throws RollerException {
    try {
      // Check for uniqueness of anchor
      String base = entry.createAnchorBase();
      String name = base;
      int count = 0;

      while (true) {
        if (count > 0) {
          name = base + count;
        }

        Session session = ((HibernatePersistenceStrategy) this.strategy).getSession();
        Criteria criteria = session.createCriteria(WeblogEntryData.class);
        criteria.add(Expression.eq("website", entry.getWebsite()));
        criteria.add(Expression.eq("anchor", name));

        List results = criteria.list();

        if (results.size() < 1) {
          break;
        } else {
          count++;
        }
      }
      return name;
    } catch (HibernateException e) {
      throw new RollerException(e);
    }
  }
  public void removeWeblogEntry(WeblogEntryData entry) throws RollerException {

    Session session = ((HibernatePersistenceStrategy) this.strategy).getSession();

    // remove referers
    Criteria refererQuery = session.createCriteria(RefererData.class);
    refererQuery.add(Expression.eq("weblogEntry", entry));
    List referers = refererQuery.list();
    for (Iterator iter = referers.iterator(); iter.hasNext(); ) {
      RefererData referer = (RefererData) iter.next();
      this.strategy.remove(referer);
    }

    // remove comments
    List comments =
        getComments(
            null, // website
            entry, null, // search String
            null, // startDate
            null, // endDate
            null, // pending
            null, // approved
            null, // spam
            true, // reverse chrono order (not that it matters)
            0, // offset
            -1); // no limit
    Iterator commentsIT = comments.iterator();
    while (commentsIT.hasNext()) {
      this.strategy.remove((CommentData) commentsIT.next());
    }

    // remove entry
    this.strategy.remove(entry);

    // update weblog last modified date.  date updated by saveWebsite()
    if (entry.isPublished()) {
      RollerFactory.getRoller().getUserManager().saveWebsite(entry.getWebsite());
    }

    // remove entry from cache mapping
    this.entryAnchorToIdMap.remove(entry.getWebsite().getHandle() + ":" + entry.getAnchor());
  }
  public List getNextPrevEntries(
      WeblogEntryData current, String catName, String locale, int maxEntries, boolean next)
      throws RollerException {

    Junction conjunction = Expression.conjunction();
    conjunction.add(Expression.eq("website", current.getWebsite()));
    conjunction.add(Expression.eq("status", WeblogEntryData.PUBLISHED));

    if (next) {
      conjunction.add(Expression.gt("pubTime", current.getPubTime()));
    } else {
      conjunction.add(Expression.lt("pubTime", current.getPubTime()));
    }

    if (catName != null && !catName.trim().equals("/")) {
      WeblogCategoryData category = getWeblogCategoryByPath(current.getWebsite(), null, catName);
      if (category != null) {
        conjunction.add(Expression.eq("category", category));
      } else {
        throw new RollerException("Cannot find category: " + catName);
      }
    }

    if (locale != null) {
      conjunction.add(Expression.ilike("locale", locale, MatchMode.START));
    }

    try {
      Session session = ((HibernatePersistenceStrategy) this.strategy).getSession();
      Criteria criteria = session.createCriteria(WeblogEntryData.class);
      criteria.addOrder(next ? Order.asc("pubTime") : Order.desc("pubTime"));
      criteria.add(conjunction);
      criteria.setMaxResults(maxEntries);
      List results = criteria.list();
      return results;
    } catch (HibernateException e) {
      throw new RollerException(e);
    }
  }
  // TODO: perhaps the createAnchor() and queuePings() items should go outside this method?
  public void saveWeblogEntry(WeblogEntryData entry) throws RollerException {

    if (entry.getAnchor() == null || entry.getAnchor().trim().equals("")) {
      entry.setAnchor(this.createAnchor(entry));
    }

    this.strategy.store(entry);

    // update weblog last modified date.  date updated by saveWebsite()
    if (entry.isPublished()) {
      RollerFactory.getRoller().getUserManager().saveWebsite(entry.getWebsite());
    }

    if (entry.isPublished()) {
      // Queue applicable pings for this update.
      RollerFactory.getRoller().getAutopingManager().queueApplicableAutoPings(entry);
    }
  }