1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.pdf.impl; |
21 |
|
|
22 |
|
import java.io.ByteArrayInputStream; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import javax.xml.transform.Source; |
26 |
|
import javax.xml.transform.TransformerException; |
27 |
|
import javax.xml.transform.URIResolver; |
28 |
|
import javax.xml.transform.stream.StreamSource; |
29 |
|
|
30 |
|
import org.xwiki.formula.ImageData; |
31 |
|
import org.xwiki.formula.ImageStorage; |
32 |
|
import org.xwiki.model.EntityType; |
33 |
|
import org.xwiki.model.reference.AttachmentReference; |
34 |
|
|
35 |
|
import com.xpn.xwiki.XWikiContext; |
36 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
37 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
38 |
|
import com.xpn.xwiki.web.Utils; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
@link |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
@version |
52 |
|
@since |
53 |
|
@deprecated@link |
54 |
|
|
55 |
|
@Deprecated |
|
|
| 63% |
Uncovered Elements: 10 (27) |
Complexity: 7 |
Complexity Density: 0.41 |
|
56 |
|
public class PDFURIResolver implements URIResolver |
57 |
|
{ |
58 |
|
private static final String TEX_ACTION = "/tex/"; |
59 |
|
|
60 |
|
|
61 |
|
@see |
62 |
|
|
63 |
|
private Map<String, AttachmentReference> attachmentMap; |
64 |
|
|
65 |
|
|
66 |
|
@see |
67 |
|
|
68 |
|
private XWikiContext context; |
69 |
|
|
70 |
|
|
71 |
|
@param@link |
72 |
|
|
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
74 |
2 |
public PDFURIResolver(XWikiContext context)... |
75 |
|
{ |
76 |
2 |
this.attachmentMap = (Map<String, AttachmentReference>) context.get(PdfURLFactory.PDF_EXPORT_CONTEXT_KEY); |
77 |
2 |
this.context = context; |
78 |
|
} |
79 |
|
|
|
|
| 56.5% |
Uncovered Elements: 10 (23) |
Complexity: 6 |
Complexity Density: 0.4 |
|
80 |
2 |
@Override... |
81 |
|
public Source resolve(String href, String base) throws TransformerException |
82 |
|
{ |
83 |
2 |
if (this.attachmentMap != null) { |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
1 |
if (href.contains(TEX_ACTION)) { |
92 |
|
|
93 |
0 |
AttachmentReference reference = this.attachmentMap.get(href.replace(TEX_ACTION, "/download/")); |
94 |
0 |
if (reference != null) { |
95 |
|
|
96 |
0 |
ImageStorage storage = Utils.getComponent(ImageStorage.class); |
97 |
0 |
ImageData image = storage.get(reference.getName()); |
98 |
0 |
return new StreamSource(new ByteArrayInputStream(image.getData())); |
99 |
|
} |
100 |
|
} |
101 |
|
|
102 |
|
|
103 |
1 |
AttachmentReference reference = this.attachmentMap.get(href); |
104 |
1 |
if (reference != null) { |
105 |
1 |
try { |
106 |
1 |
XWikiDocument xdoc = this.context.getWiki().getDocument( |
107 |
|
reference.extractReference(EntityType.DOCUMENT), this.context); |
108 |
|
|
109 |
1 |
XWikiAttachment attachment = xdoc.getAttachment( |
110 |
|
reference.extractReference(EntityType.ATTACHMENT).getName()); |
111 |
1 |
return new StreamSource(attachment.getContentInputStream(this.context)); |
112 |
|
} catch (Exception e) { |
113 |
0 |
throw new TransformerException(String.format("Failed to resolve export URI [%s]", href), e); |
114 |
|
} |
115 |
|
} |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
1 |
return null; |
120 |
|
} |
121 |
|
} |