| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.web; |
| 21 |
|
|
| 22 |
|
import java.io.IOException; |
| 23 |
|
|
| 24 |
|
import org.apache.commons.lang3.StringUtils; |
| 25 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
| 26 |
|
|
| 27 |
|
import com.xpn.xwiki.XWikiContext; |
| 28 |
|
import com.xpn.xwiki.XWikiException; |
| 29 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 30 |
|
import com.xpn.xwiki.pdf.api.PdfExport.ExportType; |
| 31 |
|
import com.xpn.xwiki.pdf.impl.PdfExportImpl; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
@deprecated@link |
| 37 |
|
@version |
| 38 |
|
|
| 39 |
|
@Deprecated |
| |
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 2 |
Complexity Density: 0.14 |
|
| 40 |
|
public class PDFAction extends XWikiAction |
| 41 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 2 |
Complexity Density: 0.14 |
|
| 42 |
0 |
@Override... |
| 43 |
|
public String render(XWikiContext context) throws XWikiException |
| 44 |
|
{ |
| 45 |
0 |
XWikiURLFactory urlf = |
| 46 |
|
context.getWiki().getURLFactoryService().createURLFactory(XWikiContext.MODE_PDF, context); |
| 47 |
0 |
context.setURLFactory(urlf); |
| 48 |
0 |
PdfExportImpl pdfexport = new PdfExportImpl(); |
| 49 |
0 |
XWikiDocument doc = context.getDoc(); |
| 50 |
0 |
handleRevision(context); |
| 51 |
|
|
| 52 |
0 |
try { |
| 53 |
0 |
context.getResponse().setContentType(ExportType.PDF.getMimeType()); |
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
0 |
EntityReferenceSerializer<String> serializer = |
| 59 |
|
Utils.getComponent(EntityReferenceSerializer.TYPE_STRING, "path"); |
| 60 |
0 |
String filename = serializer.serialize(doc.getDocumentReference()).replaceAll("/", "_"); |
| 61 |
|
|
| 62 |
0 |
filename = StringUtils.abbreviateMiddle(filename, "__", 255); |
| 63 |
|
|
| 64 |
0 |
context.getResponse().addHeader("Content-disposition", |
| 65 |
|
String.format("inline; filename=%s.%s", filename, ExportType.PDF.getExtension())); |
| 66 |
|
|
| 67 |
0 |
pdfexport.export(doc, context.getResponse().getOutputStream(), ExportType.PDF, context); |
| 68 |
|
} catch (IOException e) { |
| 69 |
0 |
throw new XWikiException(XWikiException.MODULE_XWIKI_APP, |
| 70 |
|
XWikiException.ERROR_XWIKI_APP_SEND_RESPONSE_EXCEPTION, "Exception while sending response", e); |
| 71 |
|
} |
| 72 |
0 |
return null; |
| 73 |
|
} |
| 74 |
|
} |