1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.officeimporter.internal.builder; |
21 |
|
|
22 |
|
import java.io.InputStream; |
23 |
|
import java.io.StringReader; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Named; |
27 |
|
import javax.inject.Singleton; |
28 |
|
|
29 |
|
import org.w3c.dom.Document; |
30 |
|
import org.xwiki.component.annotation.Component; |
31 |
|
import org.xwiki.component.manager.ComponentManager; |
32 |
|
import org.xwiki.model.reference.DocumentReference; |
33 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
34 |
|
import org.xwiki.officeimporter.OfficeImporterException; |
35 |
|
import org.xwiki.officeimporter.builder.XDOMOfficeDocumentBuilder; |
36 |
|
import org.xwiki.officeimporter.builder.XHTMLOfficeDocumentBuilder; |
37 |
|
import org.xwiki.officeimporter.document.XDOMOfficeDocument; |
38 |
|
import org.xwiki.officeimporter.document.XHTMLOfficeDocument; |
39 |
|
import org.xwiki.rendering.block.XDOM; |
40 |
|
import org.xwiki.rendering.listener.MetaData; |
41 |
|
import org.xwiki.rendering.parser.ParseException; |
42 |
|
import org.xwiki.rendering.parser.Parser; |
43 |
|
import org.xwiki.xml.html.HTMLUtils; |
44 |
|
|
45 |
|
|
46 |
|
@link |
47 |
|
|
48 |
|
@version |
49 |
|
@since |
50 |
|
|
51 |
|
@Component |
52 |
|
@Singleton |
|
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 3 |
Complexity Density: 0.3 |
|
53 |
|
public class DefaultXDOMOfficeDocumentBuilder implements XDOMOfficeDocumentBuilder |
54 |
|
{ |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
@Inject |
59 |
|
private XHTMLOfficeDocumentBuilder xhtmlOfficeDocumentBuilder; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@Inject |
65 |
|
@Named("xhtml/1.0") |
66 |
|
private Parser xHtmlParser; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
@Inject |
72 |
|
private ComponentManager componentManager; |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
@Inject |
78 |
|
private EntityReferenceSerializer<String> entityReferenceSerializer; |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
80 |
1 |
@Override... |
81 |
|
public XDOMOfficeDocument build(InputStream officeFileStream, String officeFileName, DocumentReference reference, |
82 |
|
boolean filterStyles) throws OfficeImporterException |
83 |
|
{ |
84 |
1 |
XDOMOfficeDocument xdomOfficeDocument = |
85 |
|
build(this.xhtmlOfficeDocumentBuilder.build(officeFileStream, officeFileName, reference, filterStyles)); |
86 |
|
|
87 |
1 |
xdomOfficeDocument.getContentDocument().getMetaData() |
88 |
|
.addMetaData(MetaData.BASE, entityReferenceSerializer.serialize(reference)); |
89 |
1 |
return xdomOfficeDocument; |
90 |
|
} |
91 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
|
92 |
1 |
@Override... |
93 |
|
public XDOMOfficeDocument build(XHTMLOfficeDocument xhtmlOfficeDocument) throws OfficeImporterException |
94 |
|
{ |
95 |
1 |
Document xhtmlDoc = xhtmlOfficeDocument.getContentDocument(); |
96 |
1 |
HTMLUtils.stripHTMLEnvelope(xhtmlDoc); |
97 |
1 |
XDOM xdom = null; |
98 |
1 |
try { |
99 |
1 |
xdom = this.xHtmlParser.parse(new StringReader(HTMLUtils.toString(xhtmlDoc))); |
100 |
|
} catch (ParseException ex) { |
101 |
0 |
throw new OfficeImporterException("Error: Could not parse xhtml office content.", ex); |
102 |
|
} |
103 |
1 |
return new XDOMOfficeDocument(xdom, xhtmlOfficeDocument.getArtifacts(), this.componentManager); |
104 |
|
} |
105 |
|
} |