entrytopdfdecorator.java

### File Source: entrytopdfdecorator.java

             /*
        P/P   *  Method: net.sourceforge.pebble.decorator.EntryToPdfDecorator__static_init
              */
         1  package net.sourceforge.pebble.decorator;
         2
         3  import net.sourceforge.pebble.domain.Blog;
         4  import net.sourceforge.pebble.domain.BlogEntry;
         5  import net.sourceforge.pebble.domain.StaticPage;
         6  import net.sourceforge.pebble.api.decorator.ContentDecoratorContext;
         7
         8  import java.util.ResourceBundle;
         9
        10  /**
        11   * Allow to export current blog entry as PDF document
        12   *
        13   * @author Alexander Zagniotov
        14   */
             /*
        P/P   *  Method: void net.sourceforge.pebble.decorator.EntryToPdfDecorator()
              */
        15  public class EntryToPdfDecorator extends ContentDecoratorSupport {
        16
        17  	private static final String PDF_IMG = "<img src=\"common/images/pdf_logo.gif\" alt=\"Export this post as PDF document\" align=\"bottom\" border=\"0\" />";
        18
        19  	/**
        20  	 * Decorates the specified blog entry.
        21  	 *
        22  	 * @param context
        23  	 *            the context in which the decoration is running
        24  	 * @param blogEntry
        25  	 *            the blog entry to be decorated
        26  	 */
        27  	public void decorate(ContentDecoratorContext context, BlogEntry blogEntry) {
        28
            		 /*
        P/P 		  *  Method: void decorate(ContentDecoratorContext, BlogEntry)
            		  *
            		  *  Preconditions:
            		  *    blogEntry != null
            		  *
            		  *  Test Vectors:
            		  *    java.lang.String:length(...)@30: {0}, {1..232-1}
            		  *
            		  *  Preconditions:
            		  *    init'ed(blogEntry.body)
            		  *    (soft) blogEntry.blog != null
            		  *    (soft) init'ed(blogEntry.id)
            		  *    (soft) blogEntry.propertyChangeSupport != null
            		  *    (soft) init'ed(blogEntry.subtitle)
            		  *    (soft) init'ed(blogEntry.title)
            		  *
            		  *  Postconditions:
            		  *    init'ed(blogEntry.body)
            		  *
            		  *  Preconditions:
            		  *    (soft) init'ed(blogEntry.blog.id)
            		  *
            		  *  Test Vectors:
            		  *    blogEntry.body: Addr_Set{null}, Inverse{null}
            		  *
            		  *  Preconditions:
            		  *    (soft) net/sourceforge/pebble/domain/BlogManager.instance != null
            		  *    (soft) init'ed(net/sourceforge/pebble/domain/BlogManager.instance.multiBlog)
            		  */
        29  		String body = blogEntry.getBody();
        30  		if (body != null && body.trim().length() > 0) {
        31
        32  			String html = generateDecorationHtml(blogEntry);
        33  			blogEntry.setBody(body + html);
        34  		}
        35
        36  //		String excerpt = blogEntry.getExcerpt();
        37  //
        38  //		if (excerpt != null && excerpt.trim().length() > 0) {
        39  //			String html = generateDecorationHtml(blogEntry);
        40  //			blogEntry.setExcerpt(excerpt + html);
        41  //		}
        42  	}
        43
        44  	private String generateDecorationHtml(BlogEntry blogEntry) {
        45
            			 /*
        P/P 			  *  Method: String generateDecorationHtml(BlogEntry)
            			  *
            			  *  Preconditions:
            			  *    blogEntry != null
            			  *
            			  *  Postconditions:
            			  *    return_value != null
            			  *
            			  *  Preconditions:
            			  *    blogEntry.blog != null
            			  *    init'ed(blogEntry.id)
            			  *    init'ed(blogEntry.subtitle)
            			  *    init'ed(blogEntry.title)
            			  *    (soft) init'ed(blogEntry.blog.id)
            			  *    (soft) net/sourceforge/pebble/domain/BlogManager.instance != null
            			  *    (soft) init'ed(net/sourceforge/pebble/domain/BlogManager.instance.multiBlog)
            			  */
        46  			StringBuffer buf = new StringBuffer();
        47  			String title = blogEntry.getTitle();
        48  			String subtitle = blogEntry.getSubtitle();
        49
        50  			buf.append("<p>");
        51  			buf.append("<a href=\"" + blogEntry.getBlog().getUrl() + "entryToPDF.action?entry=" + blogEntry.getId() + "\" title=\"Export " + title + " - " + subtitle + " as PDF document\">");
        52  			buf.append(PDF_IMG);
        53  			buf.append("</a>&nbsp;&nbsp;Export this post to PDF document</p>");
        54
        55  			return buf.toString();
        56  	}
        57
        58  }

SofCheck Inspector Build Version : 2.22510

entrytopdfdecorator.java | 2010-Jun-25 19:40:32
entrytopdfdecorator.class | 2010-Jul-19 20:23:40