generatetrackbacklinkaction.java

### File Source: generatetrackbacklinkaction.java

             /*
        P/P   *  Method: net.sourceforge.pebble.web.action.GenerateTrackBackLinkAction__static_init
              *
              *  Postconditions:
              *    init'ed(log)
              */
         1  package net.sourceforge.pebble.web.action;
         2
         3  import net.sourceforge.pebble.Constants;
         4  import net.sourceforge.pebble.api.confirmation.TrackBackConfirmationStrategy;
         5  import net.sourceforge.pebble.domain.*;
         6  import net.sourceforge.pebble.web.view.NotFoundView;
         7  import net.sourceforge.pebble.web.view.View;
         8  import net.sourceforge.pebble.web.view.impl.ConfirmTrackBackView;
         9  import net.sourceforge.pebble.web.view.impl.TrackBackLinkView;
        10  import org.apache.commons.logging.Log;
        11  import org.apache.commons.logging.LogFactory;
        12
             /*
        P/P   *  Method: void net.sourceforge.pebble.web.action.GenerateTrackBackLinkAction()
              */
        13  import javax.servlet.ServletException;
        14  import javax.servlet.http.HttpServletRequest;
        15  import javax.servlet.http.HttpServletResponse;
        16
        17  /**
        18   * Generates a TrackBack link for a blog entry.
        19   *
        20   * @author    Simon Brown
        21   */
        22  public class GenerateTrackBackLinkAction extends AbstractTrackBackAction {
        23
        24    /** the log used by this class */
        25    private static Log log = LogFactory.getLog(GenerateTrackBackLinkAction.class);
        26
        27    /**
        28     * Peforms the processing associated with this action.
        29     *
        30     * @param request  the HttpServletRequest instance
        31     * @param response the HttpServletResponse instance
        32     * @return the name of the next view
        33     */
        34    public View process(HttpServletRequest request, HttpServletResponse response) throws ServletException {
                 /*
        P/P       *  Method: View process(HttpServletRequest, HttpServletResponse)
                  *
                  *  Preconditions:
                  *    request != null
                  *    this.model != null
                  *    this.model.data != null
                  *
                  *  Presumptions:
                  *    java.util.HashMap:get(...)@63 != null
                  *    javax.servlet.http.HttpServletRequest:getSession(...)@57 != null
                  *    net.sourceforge.pebble.domain.Blog:getTrackBackConfirmationStrategy(...)@54 != null
                  *
                  *  Postconditions:
                  *    return_value in Addr_Set{&new TrackBackLinkView(process#6),&new ConfirmTrackBackView(process#5),&new NotFoundView(process#4),&new NotFoundView(process#3)}
                  *    new ConfirmTrackBackView(process#5) num objects <= 1
                  *    new NotFoundView(process#3) num objects <= 1
                  *    new NotFoundView(process#4) num objects <= 1
                  *    new TrackBackLinkView(process#6) num objects <= 1
                  *
                  *  Test Vectors:
                  *    net.sourceforge.pebble.api.confirmation.TrackBackConfirmationStrategy:confirmationRequired(...)@56: {0}, {1}
                  *    net.sourceforge.pebble.domain.BlogEntry:isTrackBacksEnabled(...)@49: {1}, {0}
                  *    net.sourceforge.pebble.domain.BlogService:getBlogEntry(...)@41: Inverse{null}, Addr_Set{null}
                  */
        35      Blog blog = (Blog)getModel().get(Constants.BLOG_KEY);
        36      BlogEntry blogEntry;
        37
        38      String entry = request.getParameter("entry");
        39      BlogService service = new BlogService();
        40      try {
        41        blogEntry = service.getBlogEntry(blog, entry);
        42      } catch (BlogServiceException e) {
        43        throw new ServletException(e);
        44      }
        45      if (blogEntry == null) {
        46        // just send back a 404 - this is probably somebody looking for a way
        47        // to send comment spam ;-)
        48        return new NotFoundView();
        49      } else if (!blogEntry.isTrackBacksEnabled()) {
        50        return new NotFoundView();
        51      }
        52      getModel().put(Constants.BLOG_ENTRY_KEY, blogEntry);
        53
        54      TrackBackConfirmationStrategy strategy = blog.getTrackBackConfirmationStrategy();
        55
        56      if (strategy.confirmationRequired(blog)) {
        57        ((LogFactory) request.getSession()).setAttribute(BLOG_ENTRY_ID, blogEntry.getId());
        58        strategy.setupConfirmation(request);
        59        return new ConfirmTrackBackView();
        60      } else {
        61        generateTrackBackLink(blogEntry);
        62        return new TrackBackLinkView();
        63      }
        64    }
        65
        66  }

SofCheck Inspector Build Version : 2.22510

generatetrackbacklinkaction.java | 2010-Jul-19 17:35:50
generatetrackbacklinkaction.class | 2010-Jul-19 20:23:38