/** Convenience method to load the trackbacks for this blog entry. */
 public void loadTrackbacks() {
   String trackbacksDirectoryPath;
   if (_source.getParent() == null) {
     trackbacksDirectoryPath =
         File.separator + _trackbacksDirectory + File.separator + _source.getName();
   } else {
     trackbacksDirectoryPath =
         _source.getParent()
             + File.separator
             + _trackbacksDirectory
             + File.separator
             + _source.getName();
   }
   File trackbacksDirectory = new File(trackbacksDirectoryPath);
   File[] trackbacks =
       trackbacksDirectory.listFiles(BlojsomUtils.getExtensionFilter(TRACKBACK_EXTENSION));
   if ((trackbacks != null) && (trackbacks.length > 0)) {
     _logger.debug("Adding " + trackbacks.length + " trackbacks to blog entry: " + getPermalink());
     Arrays.sort(trackbacks, BlojsomUtils.FILE_TIME_ASCENDING_COMPARATOR);
     _trackbacks = new ArrayList(trackbacks.length);
     for (int i = 0; i < trackbacks.length; i++) {
       File trackbackFile = trackbacks[i];
       _trackbacks.add(loadTrackback(trackbackFile));
     }
   }
 }
 /** Convenience method to load the comments for this blog entry. A blog entry can have */
 public void loadComments() {
   if (supportsComments()) {
     String commentsDirectoryPath;
     if (_source.getParent() == null) {
       commentsDirectoryPath =
           File.separator + _commentsDirectory + File.separator + _source.getName();
     } else {
       commentsDirectoryPath =
           _source.getParent()
               + File.separator
               + _commentsDirectory
               + File.separator
               + _source.getName();
     }
     File commentsDirectory = new File(commentsDirectoryPath);
     File[] comments =
         commentsDirectory.listFiles(BlojsomUtils.getExtensionFilter(COMMENT_EXTENSION));
     if ((comments != null) && (comments.length > 0)) {
       _logger.debug("Adding " + comments.length + " comments to blog entry: " + getPermalink());
       Arrays.sort(comments, BlojsomUtils.FILE_TIME_ASCENDING_COMPARATOR);
       _comments = new ArrayList(comments.length);
       for (int i = 0; i < comments.length; i++) {
         File comment = comments[i];
         _comments.add(loadComment(comment));
       }
     }
   } else {
     _logger.debug("Blog entry does not support comments");
   }
 }
  /**
   * Send Trackback Email to Blog Author
   *
   * @param entryTitle Blog Entry title for this Trackback
   * @param title title of trackback entry
   * @param category catagory for trackbacked entry
   * @param permalink permalink for trackbacked entry
   * @param url URL of site tracking back
   * @param excerpt excerpt of trackback post
   * @param blogName Title of trackbacking blog
   * @param context Context
   */
  private synchronized void sendTrackbackEmail(
      String entryTitle,
      String title,
      String category,
      String permalink,
      String url,
      String excerpt,
      String blogName,
      Map context) {

    StringBuffer _trackback = new StringBuffer();
    _trackback
        .append("Trackback on: ")
        .append(_blogUrlPrefix)
        .append(BlojsomUtils.removeInitialSlash(category));
    _trackback.append("?permalink=").append(permalink).append("&page=comments").append("\n");

    _trackback
        .append("\n==[ Trackback ]==========================================================")
        .append("\n\n");

    if (title == null && !title.equals("")) {
      _trackback.append("Title    : ").append(title).append("\n");
    }
    if (url != null && !url.equals("")) {
      _trackback.append("Url      : ").append(url).append("\n");
    }
    if (blogName == null && !blogName.equals("")) {
      _trackback.append("Blog Name: ").append(blogName).append("\n");
    }
    if (excerpt != null && !excerpt.equals("")) {
      _trackback.append("Excerpt  : ").append(excerpt).append("\n");
    }

    EmailUtils.notifyBlogAuthor(
        "[blojsom] Trackback on: " + entryTitle, _trackback.toString(), context);
  }
  /**
   * @param category
   * @param permalink
   * @param title
   * @param excerpt
   * @param url
   * @param blogName
   */
  private synchronized Integer addTrackback(
      Map context,
      String category,
      String permalink,
      String title,
      String excerpt,
      String url,
      String blogName) {
    Trackback trackback = new Trackback();
    excerpt = BlojsomUtils.escapeMetaAndLink(excerpt);
    trackback.setTitle(title);
    trackback.setExcerpt(excerpt);
    trackback.setUrl(url);
    trackback.setBlogName(blogName);
    trackback.setTrackbackDateLong(new Date().getTime());

    StringBuffer trackbackDirectory = new StringBuffer();
    String permalinkFilename = BlojsomUtils.getFilenameForPermalink(permalink, _blogFileExtensions);
    permalinkFilename = BlojsomUtils.urlDecode(permalinkFilename);
    if (permalinkFilename == null) {
      _logger.debug("Invalid permalink trackback for: " + permalink);
      context.put(BLOJSOM_TRACKBACK_MESSAGE, "Invalid permalink trackback for: " + permalink);
      return new Integer(1);
    }

    trackbackDirectory.append(_blogHome);
    trackbackDirectory.append(BlojsomUtils.removeInitialSlash(category));
    File blogEntry = new File(trackbackDirectory.toString() + File.separator + permalinkFilename);
    if (!blogEntry.exists()) {
      _logger.error("Trying to create trackback for invalid blog entry: " + permalink);
      context.put(BLOJSOM_TRACKBACK_MESSAGE, "Trying to create trackback for invalid permalink");
      return new Integer(1);
    }
    trackbackDirectory.append(_blogTrackbackDirectory);
    trackbackDirectory.append(File.separator);
    trackbackDirectory.append(permalinkFilename);
    trackbackDirectory.append(File.separator);
    String trackbackFilename =
        trackbackDirectory.toString()
            + trackback.getTrackbackDateLong()
            + BlojsomConstants.TRACKBACK_EXTENSION;
    File trackbackDir = new File(trackbackDirectory.toString());
    if (!trackbackDir.exists()) {
      if (!trackbackDir.mkdirs()) {
        _logger.error("Could not create directory for trackbacks: " + trackbackDirectory);
        context.put(BLOJSOM_TRACKBACK_MESSAGE, "Could not create directory for trackbacks");
        return new Integer(1);
      }
    }

    File trackbackEntry = new File(trackbackFilename);
    try {
      BufferedWriter bw = new BufferedWriter(new FileWriter(trackbackEntry));
      bw.write(trackback.getTitle());
      bw.newLine();
      bw.write(trackback.getExcerpt());
      bw.newLine();
      bw.write(trackback.getUrl());
      bw.newLine();
      bw.write(trackback.getBlogName());
      bw.newLine();
      bw.close();
      _logger.debug("Added trackback: " + trackbackFilename);
    } catch (IOException e) {
      _logger.error(e);
      context.put(BLOJSOM_TRACKBACK_MESSAGE, "I/O error on trackback write.");
      return new Integer(1);
    }

    return new Integer(0);
  }
 /**
  * Return an RFC 822 style date
  *
  * @return Date formatted in RFC 822 format
  */
 public String getRFC822Date() {
   return BlojsomUtils.getRFC822Date(_entryDate);
 }
 /**
  * Escaped description of the blog entry This method would be used for generating RSS feeds where
  * the &lt;, &gt;, and &amp; characters are escaped
  *
  * @return Blog entry description where &amp;, &lt;, and &gt; have been escaped
  */
 public String getEscapedDescription() {
   return BlojsomUtils.escapeString(_description);
 }
 /**
  * Permalink for the blog entry where the &lt;, &gt;, and &amp; characters are escaped
  *
  * @return Blog entry permalink which has been escaped
  */
 public String getEscapedLink() {
   return BlojsomUtils.escapeString(_link);
 }
 /**
  * Title for the entry where the &lt;, &gt;, and &amp; characters are escaped
  *
  * @return Escaped entry title
  */
 public String getEscapedTitle() {
   return BlojsomUtils.escapeString(_title);
 }
 /**
  * Return an ISO 8601 style date http://www.w3.org/TR/NOTE-datetime
  *
  * @return Date formatted in ISO 8601 format
  */
 public String getISO8601Date() {
   return BlojsomUtils.getISO8601Date(_entryDate);
 }