com.xpn.xwiki.pdf.impl
Class PdfExportImpl

java.lang.Object
  extended by com.xpn.xwiki.pdf.impl.PdfExportImpl
All Implemented Interfaces:
PdfExport

public class PdfExportImpl
extends Object
implements PdfExport

Default implementation for the PDF Export process, which uses XSLT transformations and Apache FOP to convert a Document into PDF, passing through HTML, valid XHTML, styled XHTML, and XSL-FO.

Version:
$Id: e2ee9cf98ade6ee72bed5e6ba36fdf7c7f87b814 $

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.xpn.xwiki.pdf.api.PdfExport
PdfExport.ExportType
 
Constructor Summary
PdfExportImpl()
          Default constructor.
 
Method Summary
protected  String applyXSLT(String xml, InputStream xslt)
          Applies an XSLT transformation to an XML document.
 void export(XWikiDocument doc, OutputStream out, PdfExport.ExportType type, XWikiContext context)
          Export a wiki Document into PDF or RTF.
 void exportHtml(String html, OutputStream out, PdfExport.ExportType type, XWikiContext context)
          Convert an HTML document to PDF.
 void exportToPDF(XWikiDocument doc, OutputStream out, XWikiContext context)
          Export a wiki Document into PDF.
protected  void exportXHTML(String xhtml, OutputStream out, PdfExport.ExportType type, XWikiContext context)
          Convert a valid XHTML document into PDF.
protected  InputStream getXslt(String propertyName, String fallbackFile, XWikiContext context)
          Get an XSLT file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PdfExportImpl

public PdfExportImpl()
Default constructor.

Method Detail

exportToPDF

public void exportToPDF(XWikiDocument doc,
                        OutputStream out,
                        XWikiContext context)
                 throws XWikiException
Description copied from interface: PdfExport
Export a wiki Document into PDF. See PdfExport.export(XWikiDocument, OutputStream, ExportType, XWikiContext) for more details about the conversion process.

Specified by:
exportToPDF in interface PdfExport
Parameters:
doc - the document to export
out - where to write the resulting document
context - the current request context
Throws:
XWikiException - if the conversion fails for any reason
See Also:
PdfExport.export(XWikiDocument, OutputStream, ExportType, XWikiContext)

export

public void export(XWikiDocument doc,
                   OutputStream out,
                   PdfExport.ExportType type,
                   XWikiContext context)
            throws XWikiException
Description copied from interface: PdfExport
Export a wiki Document into PDF or RTF. The content of the document is rendered into HTML using the pdf.vm template, the resulting HTML is cleaned up into valid XHTML using JTidy, and custom CSS is applied to it. The XHTML document is transformed into an XSL-FO document, which is finally processed using Apache FOP.

Specified by:
export in interface PdfExport
Parameters:
doc - the document to export
out - where to write the resulting document
type - the type of the output: PDF or RTF
context - the current request context
Throws:
XWikiException - if the conversion fails for any reason

exportHtml

public void exportHtml(String html,
                       OutputStream out,
                       PdfExport.ExportType type,
                       XWikiContext context)
                throws XWikiException
Description copied from interface: PdfExport
Convert an HTML document to PDF. The HTML is cleaned up, and CSS style is applied to it.

Specified by:
exportHtml in interface PdfExport
Parameters:
html - the source document to transform
out - where to write the resulting document
type - the type of the output: PDF or RTF
context - the current request context
Throws:
XWikiException - if the conversion fails for any reason

exportXHTML

protected void exportXHTML(String xhtml,
                           OutputStream out,
                           PdfExport.ExportType type,
                           XWikiContext context)
                    throws XWikiException
Convert a valid XHTML document into PDF. No further processing of the XHTML occurs.

Note: This method is protected just allow other exporters to hook their code and use the PDF export infrastructure. This is just a temporary solution. The PDF export code needs to be redesigned because it has parts than can be reused for other export formats.

Parameters:
xhtml - the source document to transform
out - where to write the resulting document
type - the type of the output: PDF or RTF
context - the current request context
Throws:
XWikiException - if the conversion fails for any reason

applyXSLT

protected String applyXSLT(String xml,
                           InputStream xslt)
                    throws XWikiException
Applies an XSLT transformation to an XML document.

Parameters:
xml - the XML document to convert
xslt - the XSLT to apply
Returns:
the converted document
Throws:
XWikiException - if the transformation fails for any reason

getXslt

protected InputStream getXslt(String propertyName,
                              String fallbackFile,
                              XWikiContext context)
Get an XSLT file. The content is searched in:
  1. the fopxsl property of the current PDFTemplate
  2. the fop.xsl resource (usually a file inside xwiki-core-*.jar)

Parameters:
propertyName - the name of the XWiki.PDFClass property to read from the current PDFTemplate document
fallbackFile - the name of a resource file to use when the PDFTemplate does not contain an override
context - the current request context
Returns:
the content of the XSLT as a byte stream


Copyright © 2004-2013 XWiki. All Rights Reserved.