public abstract class AbstractPdfView extends AbstractView
このビューの実装では、Bruno Lowagie の iText API を使用します。オリジナルの iText 2.1.7 とそのフォークである OpenPDF で動作することが知られています。OpenPDF は積極的にメンテナンスされており、信頼できない PDF コンテンツに対する重要な脆弱性を修正しているため、強くお勧めします。
メモ: Internet Explorer は、宣言されたコンテンツ型を常に考慮するとは限らないため、".pdf" 拡張子が必要です。
AbstractPdfStamperView
DEFAULT_CONTENT_TYPE
logger
PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
コンストラクターと説明 |
---|
AbstractPdfView() このコンストラクターは、適切なコンテンツ型 "application/pdf" を設定します。 |
修飾子と型 | メソッドと説明 |
---|---|
protected abstract void | buildPdfDocument(MapSE<StringSE, ObjectSE> model, com.lowagie.text.Document document, com.lowagie.text.pdf.PdfWriter writer, HttpServletRequestEE request, HttpServletResponseEE response) サブクラスは、モデルに基づいて iText PDF ドキュメントを構築するためにこのメソッドを実装する必要があります。 |
protected void | buildPdfMetadata(MapSE<StringSE, ObjectSE> model, com.lowagie.text.Document document, HttpServletRequestEE request) iText ドキュメントのメタフィールド (作成者、タイトルなど) を入力します。 |
protected boolean | generatesDownloadContent() このビューがダウンロードコンテンツ(通常は PDF ファイルや Excel ファイルなどのバイナリコンテンツ)を生成するかどうかを返します。 |
protected int | getViewerPreferences() PDF ファイルのビューアー設定を返します。 |
protected com.lowagie.text.Document | newDocument() PDF コンテンツを保持する新しいドキュメントを作成します。 |
protected com.lowagie.text.pdf.PdfWriter | newWriter(com.lowagie.text.Document document, OutputStreamSE os) 指定された iText ドキュメントに対して新しい PdfWriter を作成します。 |
protected void | prepareWriter(MapSE<StringSE, ObjectSE> model, com.lowagie.text.pdf.PdfWriter writer, HttpServletRequestEE request) 指定された PdfWriter を準備します。 |
protected void | renderMergedOutputModel(MapSE<StringSE, ObjectSE> model, HttpServletRequestEE request, HttpServletResponseEE response) ビューを実際にレンダリングするには、サブクラスでこのメソッドを実装する必要があります。 |
addStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, formatViewName, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestToExpose, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setRequestContextAttribute, setResponseContentType, toString, writeToResponse
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, waitSE, waitSE, waitSE
public AbstractPdfView()
protected boolean generatesDownloadContent()
AbstractView
デフォルトの実装は false
を返します。通常、レスポンス OutputStream を介して、クライアント側で一時キャッシュを必要とするダウンロードコンテンツを生成していることがわかっている場合、サブクラスはここで true
を返すことが推奨されます。
protected final void renderMergedOutputModel(MapSE<StringSE,ObjectSE> model, HttpServletRequestEE request, HttpServletResponseEE response) throws ExceptionSE
AbstractView
最初のステップは、リクエストの準備です。JSP の場合、これはモデルオブジェクトをリクエスト属性として設定することを意味します。2 番目のステップは、たとえば RequestDispatcher を介した JSP を含む、実際のビューのレンダリングです。
AbstractView
の renderMergedOutputModel
model
- 静的な属性よりも動的な値が優先される、結合された出力マップ(非 null
)request
- 現在の HTTP リクエスト response
- 現在の HTTP レスポンス ExceptionSE
- レンダリングに失敗した場合 protected com.lowagie.text.Document newDocument()
デフォルトでは A4 ドキュメントを返しますが、サブクラスは任意のドキュメントを指定できます。場合によっては、ビューで定義された Bean プロパティによってパラメーター化されます。
Document.Document(com.lowagie.text.Rectangle)
protected com.lowagie.text.pdf.PdfWriter newWriter(com.lowagie.text.Document document, OutputStreamSE os) throws com.lowagie.text.DocumentException
document
- iText ドキュメントを作成するためのライター os
- 書き込む OutputStreamcom.lowagie.text.DocumentException
- ライターの作成中にスローされた場合 protected void prepareWriter(MapSE<StringSE,ObjectSE> model, com.lowagie.text.pdf.PdfWriter writer, HttpServletRequestEE request) throws com.lowagie.text.DocumentException
Document.open()
を呼び出す前に呼び出されます。 たとえば、ページイベントリスナーの登録に役立ちます。デフォルトの実装では、このクラスの getViewerPreferences()
メソッドによって返されるビューアー設定を設定します。
model
- メタ情報を入力する必要がある場合のモデル writer
- 準備する PdfWriterrequest
- ロケールなどが必要な場合に備えて。属性を見てはいけません。com.lowagie.text.DocumentException
- ライターの準備中にスローされた場合 Document.open()
、PdfWriter.setPageEvent(com.lowagie.text.pdf.PdfPageEvent)
、PdfWriter.setViewerPreferences(int)
, getViewerPreferences()
protected int getViewerPreferences()
デフォルトでは AllowPrinting
および PageLayoutSinglePage
を返しますが、サブクラス化することもできます。サブクラスは、設定を固定するか、ビューで定義された Bean プロパティから取得することができます。
PdfWriter.AllowPrinting
, PdfWriter.PageLayoutSinglePage
protected void buildPdfMetadata(MapSE<StringSE,ObjectSE> model, com.lowagie.text.Document document, HttpServletRequestEE request)
document.open()
を呼び出す前に呼び出されます。model
- メタ情報を入力する必要がある場合のモデル document
- iText ドキュメントが入力 request
- ロケールなどが必要な場合に備えて。属性を見てはいけません。Document.addTitle(java.lang.String)
、Document.addSubject(java.lang.String)
、Document.addKeywords(java.lang.String)
、Document.addAuthor(java.lang.String)
、Document.addCreator(java.lang.String)
、Document.addProducer()
、Document.addCreationDate()
、Document.addHeader(java.lang.String, java.lang.String)
protected abstract void buildPdfDocument(MapSE<StringSE,ObjectSE> model, com.lowagie.text.Document document, com.lowagie.text.pdf.PdfWriter writer, HttpServletRequestEE request, HttpServletResponseEE response) throws ExceptionSE
Document.open()
呼び出しと Document.close()
呼び出しの間で呼び出されます。渡された HTTP レスポンスは、Cookie またはその他の HTTP ヘッダーを設定するために使用されることに注意してください。ビルドされた PDF ドキュメント自体は、このメソッドが返された後、自動的にレスポンスに書き込まれます。
model
- モデルマップ document
- iText ドキュメントに要素を追加する writer
- 使用する PdfWriterrequest
- ロケールなどが必要な場合に備えて。属性を見てはいけません。response
- クッキーを設定する必要がある場合に備えて。書いてはいけません。ExceptionSE
- ドキュメントの構築中に発生した例外 Document.open()
, Document.close()