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

File OfficeExporterURLFactory.java

 

Coverage histogram

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

Code metrics

4
7
1
1
59
26
5
0.71
7
1
5

Classes

Class Line # Actions
OfficeExporterURLFactory 39 7 0% 5 12
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.internal.export;
21   
22    import java.io.File;
23    import java.net.URISyntaxException;
24    import java.net.URL;
25    import java.util.Map;
26   
27    import com.xpn.xwiki.XWikiContext;
28    import com.xpn.xwiki.pdf.impl.FileSystemURLFactory;
29   
30    /**
31    * URL factory used while exporting a wiki page as an office document.
32    * <p>
33    * Note: We extend {@link FileSystemURLFactory} for convenience. This is just a temporary solution. The entire export
34    * code needs to be redesigned.
35    *
36    * @version $Id: 9a56d13f7d725eca8c8d215f486d1063d755946a $
37    * @since 3.1M1
38    */
 
39    public class OfficeExporterURLFactory extends FileSystemURLFactory
40    {
 
41  0 toggle @Override
42    public String getURL(URL url, XWikiContext context)
43    {
44  0 if (url != null && "file".equals(url.getProtocol())) {
45  0 @SuppressWarnings("unchecked")
46    Map<String, File> fileMapping = (Map<String, File>) context.get("pdfexport-file-mapping");
47  0 try {
48  0 File file = new File(url.toURI());
49  0 if (fileMapping.values().contains(file)) {
50    // Embedded files are placed in the same folder as the HTML input file during office conversion.
51  0 return file.getName();
52    }
53    } catch (URISyntaxException e) {
54    // Shouldn't happen. Ignore.
55    }
56    }
57  0 return super.getURL(url, context);
58    }
59    }