//# 0 errors, 182 messages
//#
/*
    //#pdfview.java:1:1: class: net.sourceforge.pebble.web.view.PdfView$1
    //#pdfview.java:1:1: method: net.sourceforge.pebble.web.view.PdfView$1.net.sourceforge.pebble.web.view.PdfView$1__static_init
    //#pdfview.java:1:1: class: net.sourceforge.pebble.web.view.PdfView
    //#pdfview.java:1: method: void net.sourceforge.pebble.web.view.PdfView$1.net.sourceforge.pebble.web.view.PdfView$1(PdfView)
    //#input(void net.sourceforge.pebble.web.view.PdfView$1(PdfView)): Param_1
    //#input(void net.sourceforge.pebble.web.view.PdfView$1(PdfView)): this
    //#output(void net.sourceforge.pebble.web.view.PdfView$1(PdfView)): this.this$0
    //#post(void net.sourceforge.pebble.web.view.PdfView$1(PdfView)): this.this$0 == Param_1
    //#post(void net.sourceforge.pebble.web.view.PdfView$1(PdfView)): init'ed(this.this$0)
 * Copyright (c) 2003-2006, Simon Brown
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 *   - Neither the name of Pebble nor the names of its contributors may
 *     be used to endorse or promote products derived from this software
 *     without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package net.sourceforge.pebble.web.view;

import java.io.ByteArrayInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.File;
import java.io.FilenameFilter;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import org.w3c.dom.Document;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import net.sourceforge.pebble.PebbleContext;
import net.sourceforge.pebble.domain.Tag;
import net.sourceforge.pebble.domain.BlogEntry;
import net.sourceforge.pebble.util.StringUtils;
import net.sourceforge.pebble.web.listener.PebblePDFCreationListener;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.Iterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.DocumentException;

import org.xhtmlrenderer.pdf.ITextRenderer;
import org.xhtmlrenderer.pdf.TrueTypeUtil;


/**
 * Represents a binary view component and prepares the model for display.
 *
 * @author    Alexander Zagniotov
 */
public class PdfView extends BinaryView {


  private static Log log = LogFactory.getLog(PdfView.class);
    //#pdfview.java:81: method: net.sourceforge.pebble.web.view.PdfView.net.sourceforge.pebble.web.view.PdfView__static_init
    //#pdfview.java:81: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: net.sourceforge.pebble.web.view.PdfView__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#output(net.sourceforge.pebble.web.view.PdfView__static_init): __Descendant_Table[net/sourceforge/pebble/web/view/PdfView]
    //#output(net.sourceforge.pebble.web.view.PdfView__static_init): __Dispatch_Table.dispatch(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Ljavax/servlet/ServletContext;)V
    //#output(net.sourceforge.pebble.web.view.PdfView__static_init): __Dispatch_Table.getContentLength()J
    //#output(net.sourceforge.pebble.web.view.PdfView__static_init): __Dispatch_Table.getContentType()Ljava/lang/String;
    //#output(net.sourceforge.pebble.web.view.PdfView__static_init): __Dispatch_Table.getModel()Lnet/sourceforge/pebble/web/model/Model;
    //#output(net.sourceforge.pebble.web.view.PdfView__static_init): __Dispatch_Table.getServletContext()Ljavax/servlet/ServletContext;
    //#output(net.sourceforge.pebble.web.view.PdfView__static_init): __Dispatch_Table.prepare()V
    //#output(net.sourceforge.pebble.web.view.PdfView__static_init): __Dispatch_Table.setModel(Lnet/sourceforge/pebble/web/model/Model;)V
    //#output(net.sourceforge.pebble.web.view.PdfView__static_init): __Dispatch_Table.setServletContext(Ljavax/servlet/ServletContext;)V
    //#output(net.sourceforge.pebble.web.view.PdfView__static_init): log
    //#output(net.sourceforge.pebble.web.view.PdfView__static_init): net/sourceforge/pebble/web/view/BinaryView.__Descendant_Table[net/sourceforge/pebble/web/view/PdfView]
    //#output(net.sourceforge.pebble.web.view.PdfView__static_init): net/sourceforge/pebble/web/view/View.__Descendant_Table[net/sourceforge/pebble/web/view/PdfView]
    //#post(net.sourceforge.pebble.web.view.PdfView__static_init): __Descendant_Table[net/sourceforge/pebble/web/view/PdfView] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.web.view.PdfView__static_init): net/sourceforge/pebble/web/view/BinaryView.__Descendant_Table[net/sourceforge/pebble/web/view/PdfView] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.web.view.PdfView__static_init): net/sourceforge/pebble/web/view/View.__Descendant_Table[net/sourceforge/pebble/web/view/PdfView] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.web.view.PdfView__static_init): __Dispatch_Table.dispatch(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Ljavax/servlet/ServletContext;)V == &dispatch
    //#post(net.sourceforge.pebble.web.view.PdfView__static_init): __Dispatch_Table.getContentLength()J == &getContentLength
    //#post(net.sourceforge.pebble.web.view.PdfView__static_init): __Dispatch_Table.getContentType()Ljava/lang/String; == &getContentType
    //#post(net.sourceforge.pebble.web.view.PdfView__static_init): __Dispatch_Table.getModel()Lnet/sourceforge/pebble/web/model/Model; == &net/sourceforge/pebble/web/view/View.getModel
    //#post(net.sourceforge.pebble.web.view.PdfView__static_init): __Dispatch_Table.getServletContext()Ljavax/servlet/ServletContext; == &net/sourceforge/pebble/web/view/View.getServletContext
    //#post(net.sourceforge.pebble.web.view.PdfView__static_init): __Dispatch_Table.prepare()V == &net/sourceforge/pebble/web/view/View.prepare
    //#post(net.sourceforge.pebble.web.view.PdfView__static_init): __Dispatch_Table.setModel(Lnet/sourceforge/pebble/web/model/Model;)V == &net/sourceforge/pebble/web/view/View.setModel
    //#post(net.sourceforge.pebble.web.view.PdfView__static_init): __Dispatch_Table.setServletContext(Ljavax/servlet/ServletContext;)V == &net/sourceforge/pebble/web/view/View.setServletContext
    //#post(net.sourceforge.pebble.web.view.PdfView__static_init): init'ed(log)
    //#pdfview.java:81: end of method: net.sourceforge.pebble.web.view.PdfView.net.sourceforge.pebble.web.view.PdfView__static_init

  private static final String SEP = "/";
  private static final String FONTS_PATH = "fonts";
  private static final String THEMES_PATH = "themes";
  private static final String DEFAULT_ENCODING = "UTF-8";
  private static final String PDF_CSS = "pdf.css";
  private static final String SYSTEM_THEME_PATH = HtmlView.SYSTEM_THEME;

  private String filename = "default.pdf";
  private BlogEntry entry;
  private long length = 0;

  public PdfView(BlogEntry entry, String filename) {
    //#pdfview.java:94: method: void net.sourceforge.pebble.web.view.PdfView.net.sourceforge.pebble.web.view.PdfView(BlogEntry, String)
    //#input(void net.sourceforge.pebble.web.view.PdfView(BlogEntry, String)): entry
    //#input(void net.sourceforge.pebble.web.view.PdfView(BlogEntry, String)): filename
    //#input(void net.sourceforge.pebble.web.view.PdfView(BlogEntry, String)): this
    //#output(void net.sourceforge.pebble.web.view.PdfView(BlogEntry, String)): this.entry
    //#output(void net.sourceforge.pebble.web.view.PdfView(BlogEntry, String)): this.filename
    //#output(void net.sourceforge.pebble.web.view.PdfView(BlogEntry, String)): this.length
    //#post(void net.sourceforge.pebble.web.view.PdfView(BlogEntry, String)): this.entry == entry
    //#post(void net.sourceforge.pebble.web.view.PdfView(BlogEntry, String)): init'ed(this.entry)
    //#post(void net.sourceforge.pebble.web.view.PdfView(BlogEntry, String)): this.filename == filename
    //#post(void net.sourceforge.pebble.web.view.PdfView(BlogEntry, String)): init'ed(this.filename)
    //#post(void net.sourceforge.pebble.web.view.PdfView(BlogEntry, String)): this.length == 0
    //#unanalyzed(void net.sourceforge.pebble.web.view.PdfView(BlogEntry, String)): Effects-of-calling:net.sourceforge.pebble.web.view.View
	this.entry = entry;
    this.filename = filename;
  }
    //#pdfview.java:97: end of method: void net.sourceforge.pebble.web.view.PdfView.net.sourceforge.pebble.web.view.PdfView(BlogEntry, String)

  /**
   * Gets the title of this view.
   *
   * @return the title as a String
   */
  public String getContentType() {
    return "application/pdf";
    //#pdfview.java:105: method: String net.sourceforge.pebble.web.view.PdfView.getContentType()
    //#output(String getContentType()): return_value
    //#post(String getContentType()): return_value == &"application.pdf"
    //#pdfview.java:105: end of method: String net.sourceforge.pebble.web.view.PdfView.getContentType()
  }

  public long getContentLength() {
    return length;
    //#pdfview.java:109: method: long net.sourceforge.pebble.web.view.PdfView.getContentLength()
    //#input(long getContentLength()): this
    //#input(long getContentLength()): this.length
    //#output(long getContentLength()): return_value
    //#pre[2] (long getContentLength()): init'ed(this.length)
    //#post(long getContentLength()): return_value == this.length
    //#post(long getContentLength()): init'ed(return_value)
    //#pdfview.java:109: end of method: long net.sourceforge.pebble.web.view.PdfView.getContentLength()
  }

  /**
   * Dispatches this view.
   *
   * @param request  the HttpServletRequest instance
   * @param response the HttpServletResponse instance
   * @param context
   */
  public void dispatch(HttpServletRequest request, HttpServletResponse response, ServletContext context) throws ServletException {

			try {
				ITextRenderer renderer = new ITextRenderer();
    //#pdfview.java:122: method: void net.sourceforge.pebble.web.view.PdfView.dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#pdfview.java:122: Warning: method not available
    //#    -- call on void org.xhtmlrenderer.pdf.ITextRenderer()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: void org.xhtmlrenderer.pdf.ITextRenderer()
    //#input(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): log
    //#input(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net.sourceforge.pebble.PebbleContext__static_init.new PebbleContext(PebbleContext__static_init#1).__Tag
    //#input(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net.sourceforge.pebble.PebbleContext__static_init.new PebbleContext(PebbleContext__static_init#1).webApplicationRoot
    //#input(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net/sourceforge/pebble/PebbleContext.__Descendant_Table[net/sourceforge/pebble/PebbleContext]
    //#input(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net/sourceforge/pebble/PebbleContext.__Dispatch_Table.getWebApplicationRoot()Ljava/lang/String;
    //#input(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net/sourceforge/pebble/PebbleContext.instance
    //#input(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net/sourceforge/pebble/security/PebbleUserDetails.__Descendant_Table[net/sourceforge/pebble/security/PebbleUserDetails]
    //#input(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net/sourceforge/pebble/security/PebbleUserDetails.__Descendant_Table[others]
    //#input(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net/sourceforge/pebble/security/PebbleUserDetails.__Dispatch_Table.getName()Ljava/lang/String;
    //#input(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net/sourceforge/pebble/util/StringUtils.htmlEntities
    //#input(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net/sourceforge/pebble/web/listener/PebblePDFCreationListener.__Descendant_Table[net/sourceforge/pebble/web/listener/PebblePDFCreationListener]
    //#input(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net/sourceforge/pebble/web/listener/PebblePDFCreationListener.__Dispatch_Table.parseMetaTags(Lorg/w3c/dom/Document;)V
    //#input(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net/sourceforge/pebble/web/listener/PebblePDFCreationListener.log
    //#input(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): response
    //#input(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): this
    //#input(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): this.entry
    //#input(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): this.filename
    //#pre[1] (void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): log != null
    //#pre[2] (void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): (soft) init'ed(net.sourceforge.pebble.PebbleContext__static_init.new PebbleContext(PebbleContext__static_init#1).webApplicationRoot)
    //#pre[3] (void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): (soft) net/sourceforge/pebble/web/listener/PebblePDFCreationListener.log != null
    //#pre[4] (void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): (soft) response != null
    //#pre[6] (void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): (soft) this.entry != null
    //#pre[7] (void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): (soft) init'ed(this.filename)
    //#presumption(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): files[0]@187 != null
    //#presumption(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): java.io.File:listFiles(...)@187 != null
    //#presumption(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): java.util.Iterator:next(...)@157 != null
    //#presumption(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): javax.xml.parsers.DocumentBuilder:parse(...)@234 != null
    //#presumption(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): javax.xml.parsers.DocumentBuilderFactory:newDocumentBuilder(...)@232 != null
    //#presumption(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): javax.xml.parsers.DocumentBuilderFactory:newInstance(...)@232 != null
    //#presumption(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net.sourceforge.pebble.domain.BlogEntry:getAllTags(...)@153 != null
    //#presumption(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net.sourceforge.pebble.domain.BlogEntry:getBlog(...)@134 != null
    //#presumption(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net.sourceforge.pebble.domain.BlogEntry:getBlog(...)@136 != null
    //#presumption(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net.sourceforge.pebble.domain.BlogEntry:getBlog(...)@176 != null
    //#presumption(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net.sourceforge.pebble.domain.BlogEntry:getBody(...)@133 != null
    //#presumption(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net.sourceforge.pebble.domain.BlogEntry:getDate(...)@223 != null
    //#presumption(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net.sourceforge.pebble.domain.BlogEntry:getUser(...).__Tag@130 == net/sourceforge/pebble/security/PebbleUserDetails
    //#presumption(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net.sourceforge.pebble.domain.BlogEntry:getUser(...)@130 != null
    //#presumption(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net.sourceforge.pebble.domain.Tag:getName(...)@158 != null
    //#presumption(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): org.xhtmlrenderer.pdf.ITextRenderer:getFontResolver(...)@199 != null
    //#presumption(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): org.xhtmlrenderer.pdf.TrueTypeUtil:getFamilyName(...)@204 != null
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:java.lang.String:length
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:java.lang.StringBuffer
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:java.lang.String:charAt
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:java.lang.StringBuffer:append
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:java.lang.StringBuffer:toString
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:java.util.Iterator:hasNext
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:java.util.Iterator:next
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:java.lang.String:replaceAll
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:java.util.Map:keySet
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:java.util.Set:iterator
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:java.util.Map:get
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:java.util.Properties
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:org.w3c.dom.Document:getDocumentElement
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:org.w3c.dom.Element:getElementsByTagName
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:org.w3c.dom.NodeList:item
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:org.w3c.dom.NodeList:getLength
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:org.w3c.dom.Element:getAttribute
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:java.util.Properties:setProperty
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:java.lang.StringBuilder
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:java.lang.StringBuilder:append
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:java.lang.StringBuilder:toString
    //#unanalyzed(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): Effects-of-calling:org.apache.commons.logging.Log:warn
    //#test_vector(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): files.length@187: {0}, {1..+Inf}
    //#test_vector(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): java.io.File:isDirectory(...)@186: {0}, {1}
    //#test_vector(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): java.lang.String:equals(...)@158: {1}, {0}
    //#test_vector(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): java.lang.String:equals(...)@206: {1}, {0}
    //#test_vector(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): java.util.Iterator:hasNext(...)@156: {1}, {0}
    //#test_vector(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): java.util.Iterator:hasNext(...)@160: {0}, {1}
    //#test_vector(void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)): net.sourceforge.pebble.domain.Tag:getName(...)@158: Addr_Set{null}, Inverse{null}

				//This will be an attachment
				response.setHeader("Content-Disposition", "attachment; filename=" + filename);
				response.setHeader("Expires", "0");
				response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
				response.setHeader("Pragma", "public");

				String author = entry.getUser().getName();
    //#pdfview.java:130: Warning: method not available
    //#    -- call on PebbleUserDetails net.sourceforge.pebble.domain.BlogEntry:getUser()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: PebbleUserDetails net.sourceforge.pebble.domain.BlogEntry:getUser()
				String title = entry.getTitle();
    //#pdfview.java:131: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.BlogEntry:getTitle()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.BlogEntry:getTitle()
				String subtitle = entry.getSubtitle();
    //#pdfview.java:132: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.BlogEntry:getSubtitle()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.BlogEntry:getSubtitle()
				String body = entry.getBody();
    //#pdfview.java:133: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.BlogEntry:getBody()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.BlogEntry:getBody()
				String blogName = entry.getBlog().getName();
    //#pdfview.java:134: Warning: method not available
    //#    -- call on Blog net.sourceforge.pebble.domain.BlogEntry:getBlog()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: Blog net.sourceforge.pebble.domain.BlogEntry:getBlog()
    //#pdfview.java:134: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.Blog:getName()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.Blog:getName()
				String entryPermalink = entry.getPermalink();
    //#pdfview.java:135: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.BlogEntry:getPermalink()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.BlogEntry:getPermalink()
				String entryDescription = entry.getBlog().getDescription();
    //#pdfview.java:136: Warning: method not available
    //#    -- call on Blog net.sourceforge.pebble.domain.BlogEntry:getBlog()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: Blog net.sourceforge.pebble.domain.BlogEntry:getBlog()
    //#pdfview.java:136: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.Blog:getDescription()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.Blog:getDescription()

				//Some of the HTML entities need to be escaped to Unicode notation \\uXXXX for XHTML markup to validate
				title = StringUtils.transformHTML(title);
				subtitle = StringUtils.transformHTML(subtitle);
				body = StringUtils.unescapeHTMLEntities(body);
				
				//Build absolute path to: <pebble_root>/themes/_pebble/fonts/ 
				String webApplicationRoot = PebbleContext.getInstance().getWebApplicationRoot() + SEP + THEMES_PATH;

				//<pebble_root> + / + themes + / + _pebble + / + fonts 
				String fontDirAbsolutePath = webApplicationRoot + SEP + SYSTEM_THEME_PATH + SEP + FONTS_PATH;
				File fontDir = new File(fontDirAbsolutePath);


				//Get blog entry tags for PDF metadata 'keywords'
				StringBuffer tags = new StringBuffer();
				Iterator<Tag> currentEntryTags = entry.getAllTags().iterator();
    //#pdfview.java:153: Warning: method not available
    //#    -- call on List net.sourceforge.pebble.domain.BlogEntry:getAllTags()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: List net.sourceforge.pebble.domain.BlogEntry:getAllTags()
				
				//Build a string out of blog entry tags and seperate them by comma
				while (currentEntryTags.hasNext()) {
					Tag currentTag = currentEntryTags.next();
					if (currentTag.getName() != null && !currentTag.getName().equals("")) {
    //#pdfview.java:158: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.Tag:getName()
    //#    severity: SUPPRESSED
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.Tag:getName()
						 tags.append(currentTag.getName());
    //#pdfview.java:159: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.Tag:getName()
    //#    severity: SUPPRESSED
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.Tag:getName()
						 if (currentEntryTags.hasNext()) {
							tags.append(",");
						}
					}
				}

				//Build valid XHTML source from blog entry for parsing 
				StringBuffer buf = new StringBuffer();
				buf.append("<html>");
				buf.append("<head>");
				buf.append("<meta name=\"title\" content=\"" + title + " - " + blogName + "\"/>");
				buf.append("<meta name=\"subject\" content=\"" + title + "\"/>");
				buf.append("<meta name=\"keywords\" content=\"" + tags.toString().trim() + "\"/>");
				buf.append("<meta name=\"author\" content=\"" + author + "\"/>");
				buf.append("<meta name=\"creator\" content=\"Pebble (by pebble.sourceforge.net)\"/>");
				buf.append("<meta name=\"producer\" content=\"Flying Saucer (by xhtmlrenderer.dev.java.net)\"/>");
				buf.append("<link rel='stylesheet' type='text/css' href='" + entry.getBlog().getUrl() + 
    //#pdfview.java:176: Warning: method not available
    //#    -- call on Blog net.sourceforge.pebble.domain.BlogEntry:getBlog()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: Blog net.sourceforge.pebble.domain.BlogEntry:getBlog()
    //#pdfview.java:176: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.Blog:getUrl()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.Blog:getUrl()
																			THEMES_PATH + SEP + 
																			SYSTEM_THEME_PATH + SEP + 
																			PDF_CSS + "' media='print' />");
				buf.append("</head>");
				buf.append("<body>");
				buf.append("<div id=\"header\" style=\"\">" + blogName + " - " + entryDescription + "</div>");
				buf.append("<p>");

				//Gets TTF or OTF font file from the font directory in the system theme folder
				 if (fontDir.isDirectory()) {
						File[] files = fontDir.listFiles(new FilenameFilter() {
    //#pdfview.java:187: end of method: void net.sourceforge.pebble.web.view.PdfView$1.net.sourceforge.pebble.web.view.PdfView$1(PdfView)
							public boolean accept(File dir, String name) {
								String lower = name.toLowerCase();
    //#pdfview.java:189: method: bool net.sourceforge.pebble.web.view.PdfView$1.accept(File, String)
    //#input(bool accept(File, String)): name
    //#output(bool accept(File, String)): return_value
    //#pre[1] (bool accept(File, String)): name != null
    //#post(bool accept(File, String)): init'ed(return_value)
    //#test_vector(bool accept(File, String)): java.lang.String:endsWith(...)@192: {1}, {0}

								//Load TTF or OTF files
								return lower.endsWith(".otf") || lower.endsWith(".ttf");
    //#pdfview.java:192: end of method: bool net.sourceforge.pebble.web.view.PdfView$1.accept(File, String)
							}
						});
						
						if (files.length > 0) {
							String fontFamilyName = "";
    //#pdfview.java:197: Warning: unused assignment
    //#    unused assignment into fontFamilyName
    //#    severity: LOW
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
							//You should always embed TrueType fonts.
							renderer.getFontResolver().addFont(files[0].getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    //#pdfview.java:199: Warning: method not available
    //#    -- call on ITextFontResolver org.xhtmlrenderer.pdf.ITextRenderer:getFontResolver()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: ITextFontResolver org.xhtmlrenderer.pdf.ITextRenderer:getFontResolver()
    //#pdfview.java:199: Warning: method not available
    //#    -- call on void org.xhtmlrenderer.pdf.ITextFontResolver:addFont(String, String, bool)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: void org.xhtmlrenderer.pdf.ITextFontResolver:addFont(String, String, bool)
							log.info("Added font: " + files[0].getAbsolutePath());
    //#pdfview.java:200: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:info(Object)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:info(Object)

							//Get font family name from the BaseFont object. All this work just to get font family name
							BaseFont font = BaseFont.createFont(files[0].getAbsolutePath(), BaseFont.IDENTITY_H , BaseFont.NOT_EMBEDDED);
    //#pdfview.java:203: Warning: method not available
    //#    -- call on BaseFont com.lowagie.text.pdf.BaseFont:createFont(String, String, bool)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: BaseFont com.lowagie.text.pdf.BaseFont:createFont(String, String, bool)
							fontFamilyName = TrueTypeUtil.getFamilyName(font);
    //#pdfview.java:204: Warning: method not available
    //#    -- call on String org.xhtmlrenderer.pdf.TrueTypeUtil:getFamilyName(BaseFont)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: String org.xhtmlrenderer.pdf.TrueTypeUtil:getFamilyName(BaseFont)
							
							if (!fontFamilyName.equals("")) {
								//Wrap DIV with font family name around the content of the blog entry
								author = "<div style=\"font-family: " + fontFamilyName + ";\">" + author + "</div>";
								title = "<div style=\"font-family: " + fontFamilyName + ";\">" + title + "</div>";
								subtitle = "<div style=\"font-family: " + fontFamilyName + ";\">" + subtitle + "</div>";
								body = "<div style=\"font-family: " + fontFamilyName + ";\">" + body + "</div>";
								log.info("PDFGenerator - Added font family: '" + fontFamilyName + "' to PDF content");
    //#pdfview.java:212: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:info(Object)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:info(Object)
							}		
						}
				 }

				buf.append("<h1>" + title  + "</h1>");
				buf.append("<h2>" + subtitle + "</h2>");
				buf.append("</p>");
				buf.append("<p>" + body + "</p>");
				buf.append("<p><br /><br /><br />");
				buf.append("<i>Published by " + author + "</i><br />");
				buf.append("<i>" + entry.getDate().toString() + "</i><br />");
    //#pdfview.java:223: Warning: method not available
    //#    -- call on Date net.sourceforge.pebble.domain.BlogEntry:getDate()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: Date net.sourceforge.pebble.domain.BlogEntry:getDate()
				buf.append("<i><a href=\"" + entryPermalink + "\" title=\"" + entryPermalink + "\">" + entryPermalink + "</a></i>");
				buf.append("</p>");
				buf.append("</body>");
				buf.append("</html>");

				byte[] bytes = buf.toString().getBytes(DEFAULT_ENCODING);

				ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
				DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
				InputSource is = new InputSource(bais);
    //#pdfview.java:233: Warning: method not available
    //#    -- call on void org.xml.sax.InputSource(InputStream)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: void org.xml.sax.InputSource(InputStream)
				Document doc = builder.parse(is);

				//Listener that will parse HTML header meta tags, and will set them to PDF document as meta data
				PebblePDFCreationListener pdfListener = new PebblePDFCreationListener();
				pdfListener.parseMetaTags(doc);
				renderer.setListener(pdfListener);
    //#pdfview.java:239: Warning: method not available
    //#    -- call on void org.xhtmlrenderer.pdf.ITextRenderer:setListener(PDFCreationListener)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: void org.xhtmlrenderer.pdf.ITextRenderer:setListener(PDFCreationListener)
				renderer.setDocument(doc, null);
    //#pdfview.java:240: Warning: method not available
    //#    -- call on void org.xhtmlrenderer.pdf.ITextRenderer:setDocument(Document, String)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: void org.xhtmlrenderer.pdf.ITextRenderer:setDocument(Document, String)
				renderer.layout();
    //#pdfview.java:241: Warning: method not available
    //#    -- call on void org.xhtmlrenderer.pdf.ITextRenderer:layout()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: void org.xhtmlrenderer.pdf.ITextRenderer:layout()

				BufferedOutputStream bufferedOutput = new BufferedOutputStream(response.getOutputStream());
				
				renderer.createPDF(bufferedOutput);
    //#pdfview.java:245: Warning: method not available
    //#    -- call on void org.xhtmlrenderer.pdf.ITextRenderer:createPDF(OutputStream)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: void org.xhtmlrenderer.pdf.ITextRenderer:createPDF(OutputStream)
				bufferedOutput.flush();
				bufferedOutput.close();

				log.info("Successfully generated PDF document: " + filename);
    //#pdfview.java:249: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:info(Object)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:info(Object)
			}

			catch (ParserConfigurationException e)  {
				log.error("Could not create PDF, could not get new instance of DocumentBuilder: " + e);
    //#pdfview.java:253: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:error(Object)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:error(Object)
			} 

			catch (SAXException e)  {
				log.error("Could not create PDF, could not parse InputSource: " + e);
    //#pdfview.java:257: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:error(Object)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:error(Object)
			}

			catch (IOException e)  {
				log.error("Could not create PDF: " + e);
    //#pdfview.java:261: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:error(Object)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:error(Object)
			}

			catch (DocumentException e)  {
				log.error("iText could not create PDF document: " + e);
    //#pdfview.java:265: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:error(Object)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:error(Object)
			}

			catch (Exception e)  {
				log.error("Could not create PDF: " + e);
    //#pdfview.java:269: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:error(Object)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.view.PdfView
    //#    method: void dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:error(Object)
			}
		}
    //#pdfview.java:271: end of method: void net.sourceforge.pebble.web.view.PdfView.dispatch(HttpServletRequest, HttpServletResponse, ServletContext)
	}    //#output(net.sourceforge.pebble.web.view.PdfView$1__static_init): __Descendant_Table[net/sourceforge/pebble/web/view/PdfView$1]
    //#output(net.sourceforge.pebble.web.view.PdfView$1__static_init): __Dispatch_Table.accept(Ljava/io/File;Ljava/lang/String;)Z
    //#post(net.sourceforge.pebble.web.view.PdfView$1__static_init): __Descendant_Table[net/sourceforge/pebble/web/view/PdfView$1] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.web.view.PdfView$1__static_init): __Dispatch_Table.accept(Ljava/io/File;Ljava/lang/String;)Z == &accept
    //#pdfview.java:: end of method: net.sourceforge.pebble.web.view.PdfView$1.net.sourceforge.pebble.web.view.PdfView$1__static_init
    //#pdfview.java:: end of class: net.sourceforge.pebble.web.view.PdfView$1
    //#pdfview.java:: end of class: net.sourceforge.pebble.web.view.PdfView
