1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.web

File PDFAction.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

0
14
1
1
74
37
2
0.14
14
1
2

Classes

Class Line # Actions
PDFAction 40 14 0% 2 15
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Exports a document as PDF.
35    *
36    * @deprecated Use {@link ExportAction}.
37    * @version $Id: 8c30ca4c09074743bdfb0cdc8d9a69ceef7676a4 $
38    */
39    @Deprecated
 
40    public class PDFAction extends XWikiAction
41    {
 
42  0 toggle @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    // Compute the name of the export. Since it's gong to be saved on the user's file system it needs to be a
56    // valid File name. Thus we use the "path" serializer but replace the "/" separator by "_" since we're not
57    // computing a directory hierarchy but a file name
58  0 EntityReferenceSerializer<String> serializer =
59    Utils.getComponent(EntityReferenceSerializer.TYPE_STRING, "path");
60  0 String filename = serializer.serialize(doc.getDocumentReference()).replaceAll("/", "_");
61    // Make sure we don't go over 255 chars since several filesystems don't support filename longer than that!
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    }