1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.filter.xar.internal.input; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.io.InputStream; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
|
27 |
|
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; |
28 |
|
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; |
29 |
|
import org.apache.commons.lang3.exception.ExceptionUtils; |
30 |
|
import org.slf4j.Logger; |
31 |
|
import org.xwiki.component.annotation.Component; |
32 |
|
import org.xwiki.component.annotation.InstantiationStrategy; |
33 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
34 |
|
import org.xwiki.filter.FilterEventParameters; |
35 |
|
import org.xwiki.filter.FilterException; |
36 |
|
import org.xwiki.filter.event.model.WikiDocumentFilter; |
37 |
|
import org.xwiki.filter.input.InputSource; |
38 |
|
import org.xwiki.filter.input.InputStreamInputSource; |
39 |
|
import org.xwiki.filter.xar.input.XARInputProperties; |
40 |
|
import org.xwiki.logging.marker.TranslationMarker; |
41 |
|
import org.xwiki.model.reference.EntityReference; |
42 |
|
import org.xwiki.xar.XarPackage; |
43 |
|
import org.xwiki.xar.internal.model.XarModel; |
44 |
|
|
45 |
|
|
46 |
|
@version |
47 |
|
@since |
48 |
|
|
49 |
|
@Component(roles = WikiReader.class) |
50 |
|
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) |
|
|
| 68.5% |
Uncovered Elements: 17 (54) |
Complexity: 18 |
Complexity Density: 0.6 |
|
51 |
|
public class WikiReader |
52 |
|
{ |
53 |
|
private static final TranslationMarker LOG_DOCUMENT_SKIPPED = new TranslationMarker( |
54 |
|
"filter.xar.log.document.skipped", WikiDocumentFilter.LOG_DOCUMENT_SKIPPED); |
55 |
|
|
56 |
|
private static final TranslationMarker LOG_DOCUMENT_FAILREAD = new TranslationMarker( |
57 |
|
"filter.xar.log.document.failread", WikiDocumentFilter.LOG_DOCUMENT_ERROR); |
58 |
|
|
59 |
|
private static final TranslationMarker LOG_DESCRIPTOR_FAILREAD = new TranslationMarker( |
60 |
|
"filter.xar.log.descriptor.failread"); |
61 |
|
|
62 |
|
@Inject |
63 |
|
private DocumentLocaleReader documentReader; |
64 |
|
|
65 |
|
@Inject |
66 |
|
private Logger logger; |
67 |
|
|
68 |
|
private XARInputProperties properties; |
69 |
|
|
70 |
|
private XarPackage xarPackage = new XarPackage(); |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
72 |
7 |
public void setProperties(XARInputProperties properties)... |
73 |
|
{ |
74 |
7 |
this.properties = properties; |
75 |
|
|
76 |
7 |
this.documentReader.setProperties(properties); |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0 |
public XarPackage getXarPackage()... |
80 |
|
{ |
81 |
0 |
return this.xarPackage; |
82 |
|
} |
83 |
|
|
|
|
| 70% |
Uncovered Elements: 6 (20) |
Complexity: 5 |
Complexity Density: 0.42 |
|
84 |
7 |
public void read(Object filter, XARInputFilter proxyFilter) throws IOException, FilterException... |
85 |
|
{ |
86 |
7 |
InputStream stream; |
87 |
|
|
88 |
7 |
InputSource source = this.properties.getSource(); |
89 |
7 |
if (source instanceof InputStreamInputSource) { |
90 |
7 |
stream = ((InputStreamInputSource) source).getInputStream(); |
91 |
|
} else { |
92 |
0 |
throw new FilterException("Unsupported source type [" + source.getClass() + "]"); |
93 |
|
} |
94 |
|
|
95 |
7 |
read(stream, filter, proxyFilter); |
96 |
|
|
97 |
|
|
98 |
7 |
if (this.documentReader.getSentSpaceReference() != null) { |
99 |
14 |
for (EntityReference space = this.documentReader.getSentSpaceReference(); space != null; space = |
100 |
|
space.getParent()) { |
101 |
7 |
proxyFilter.endWikiSpace(space.getName(), FilterEventParameters.EMPTY); |
102 |
|
} |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
7 |
if (this.xarPackage.getPackageExtensionId() != null) { |
107 |
0 |
proxyFilter.beginExtension(this.xarPackage.getPackageExtensionId(), this.xarPackage.getPackageVersion(), |
108 |
|
FilterEventParameters.EMPTY); |
109 |
0 |
proxyFilter.endExtension(this.xarPackage.getPackageExtensionId(), this.xarPackage.getPackageVersion(), |
110 |
|
FilterEventParameters.EMPTY); |
111 |
|
} |
112 |
|
} |
113 |
|
|
|
|
| 66.7% |
Uncovered Elements: 9 (27) |
Complexity: 11 |
Complexity Density: 0.73 |
|
114 |
7 |
public void read(InputStream stream, Object filter, XARInputFilter proxyFilter) throws IOException... |
115 |
|
{ |
116 |
7 |
ZipArchiveInputStream zis = new ZipArchiveInputStream(stream, "UTF-8", false); |
117 |
|
|
118 |
28 |
for (ZipArchiveEntry entry = zis.getNextZipEntry(); entry != null; entry = zis.getNextZipEntry()) { |
119 |
21 |
if (entry.isDirectory() || entry.getName().startsWith("META-INF")) { |
120 |
|
|
121 |
|
|
122 |
3 |
continue; |
123 |
18 |
} else if (entry.getName().equals(XarModel.PATH_PACKAGE)) { |
124 |
|
|
125 |
7 |
try { |
126 |
7 |
this.xarPackage.readDescriptor(zis); |
127 |
|
} catch (Exception e) { |
128 |
0 |
if (this.properties.isVerbose()) { |
129 |
0 |
this.logger.warn(LOG_DESCRIPTOR_FAILREAD, "Failed to read XAR descriptor from entry [{}]: {}", |
130 |
|
entry.getName(), ExceptionUtils.getRootCauseMessage(e)); |
131 |
|
} |
132 |
|
} |
133 |
|
} else { |
134 |
11 |
try { |
135 |
11 |
this.documentReader.read(zis, filter, proxyFilter); |
136 |
|
} catch (SkipEntityException skip) { |
137 |
2 |
if (this.properties.isVerbose()) { |
138 |
2 |
this.logger.info(LOG_DOCUMENT_SKIPPED, "Skipped document [{}]", skip.getEntityReference()); |
139 |
|
} |
140 |
|
} catch (Exception e) { |
141 |
0 |
if (this.properties.isVerbose()) { |
142 |
0 |
this.logger.warn(LOG_DOCUMENT_FAILREAD, "Failed to read XAR XML document from entry [{}]: {}", |
143 |
|
entry.getName(), ExceptionUtils.getRootCauseMessage(e), e); |
144 |
|
} |
145 |
|
} |
146 |
|
} |
147 |
|
} |
148 |
|
} |
149 |
|
} |