1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.officeimporter.document; |
21 |
|
|
22 |
|
import java.util.Map; |
23 |
|
|
24 |
|
import org.apache.commons.lang3.StringUtils; |
25 |
|
import org.xwiki.component.manager.ComponentLookupException; |
26 |
|
import org.xwiki.component.manager.ComponentManager; |
27 |
|
import org.xwiki.rendering.block.Block; |
28 |
|
import org.xwiki.rendering.block.HeaderBlock; |
29 |
|
import org.xwiki.rendering.block.SectionBlock; |
30 |
|
import org.xwiki.rendering.block.XDOM; |
31 |
|
import org.xwiki.rendering.renderer.BlockRenderer; |
32 |
|
import org.xwiki.rendering.renderer.printer.DefaultWikiPrinter; |
33 |
|
import org.xwiki.rendering.renderer.printer.WikiPrinter; |
34 |
|
|
35 |
|
|
36 |
|
@link@link |
37 |
|
|
38 |
|
@version |
39 |
|
@since |
40 |
|
|
|
|
| 86% |
Uncovered Elements: 7 (50) |
Complexity: 15 |
Complexity Density: 0.47 |
|
41 |
|
public class XDOMOfficeDocument implements OfficeDocument |
42 |
|
{ |
43 |
|
|
44 |
|
@link |
45 |
|
|
46 |
|
private XDOM xdom; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
private Map<String, byte[]> artifacts; |
52 |
|
|
53 |
|
|
54 |
|
@link |
55 |
|
|
56 |
|
private ComponentManager componentManager; |
57 |
|
|
58 |
|
|
59 |
|
@link |
60 |
|
|
61 |
|
@param@link |
62 |
|
@param |
63 |
|
@param@link |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
65 |
17 |
public XDOMOfficeDocument(XDOM xdom, Map<String, byte[]> artifacts, ComponentManager componentManager)... |
66 |
|
{ |
67 |
17 |
this.xdom = xdom; |
68 |
17 |
this.artifacts = artifacts; |
69 |
17 |
this.componentManager = componentManager; |
70 |
|
} |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
8 |
@Override... |
73 |
|
public XDOM getContentDocument() |
74 |
|
{ |
75 |
8 |
return this.xdom; |
76 |
|
} |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
1 |
@Override... |
79 |
|
public String getContentAsString() |
80 |
|
{ |
81 |
1 |
return getContentAsString("xwiki/2.0"); |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
@param |
88 |
|
@return |
89 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
90 |
1 |
public String getContentAsString(String syntaxId)... |
91 |
|
{ |
92 |
1 |
try { |
93 |
1 |
WikiPrinter printer = new DefaultWikiPrinter(); |
94 |
1 |
BlockRenderer renderer = this.componentManager.getInstance(BlockRenderer.class, syntaxId); |
95 |
1 |
renderer.render(this.xdom, printer); |
96 |
1 |
return printer.toString(); |
97 |
|
} catch (ComponentLookupException ex) { |
98 |
|
|
99 |
|
} |
100 |
0 |
return null; |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
5 |
@Override... |
104 |
|
public Map<String, byte[]> getArtifacts() |
105 |
|
{ |
106 |
5 |
return this.artifacts; |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
@link |
111 |
|
|
112 |
|
|
113 |
|
@return |
114 |
|
|
|
|
| 70% |
Uncovered Elements: 3 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
115 |
6 |
public String getTitle()... |
116 |
|
{ |
117 |
6 |
String title = getTitle(this.xdom); |
118 |
6 |
if (null != title) { |
119 |
|
|
120 |
6 |
title = title.replaceAll("[\n\r]", ""); |
121 |
|
|
122 |
6 |
if (title.length() > 255) { |
123 |
0 |
title = title.substring(0, 255); |
124 |
|
} |
125 |
|
} |
126 |
6 |
return title; |
127 |
|
} |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
@param |
133 |
|
@return |
134 |
|
|
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
135 |
27 |
private String getTitle(Block parent)... |
136 |
|
{ |
137 |
27 |
for (Block block : parent.getChildren()) { |
138 |
33 |
if (block instanceof HeaderBlock) { |
139 |
6 |
String title = renderTitle((HeaderBlock) block); |
140 |
6 |
if (!StringUtils.isBlank(title)) { |
141 |
6 |
return title; |
142 |
|
} |
143 |
27 |
} else if (block instanceof SectionBlock) { |
144 |
21 |
return getTitle(block); |
145 |
|
} |
146 |
|
} |
147 |
0 |
return null; |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
@param |
154 |
|
@return |
155 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
156 |
6 |
private String renderTitle(HeaderBlock header)... |
157 |
|
{ |
158 |
6 |
try { |
159 |
6 |
WikiPrinter printer = new DefaultWikiPrinter(); |
160 |
6 |
BlockRenderer renderer = this.componentManager.getInstance(BlockRenderer.class, "plain/1.0"); |
161 |
6 |
renderer.render(header, printer); |
162 |
6 |
return printer.toString(); |
163 |
|
} catch (ComponentLookupException ex) { |
164 |
|
|
165 |
|
} |
166 |
0 |
return null; |
167 |
|
} |
168 |
|
} |