|
28 | 28 | import com.jcabi.xml.Sources;
|
29 | 29 | import com.jcabi.xml.StrictXML;
|
30 | 30 | import com.jcabi.xml.XML;
|
| 31 | +import com.jcabi.xml.XMLDocument; |
31 | 32 | import com.jcabi.xml.XSD;
|
32 | 33 | import com.jcabi.xml.XSDDocument;
|
33 | 34 | import com.jcabi.xml.XSL;
|
|
39 | 40 | import java.util.HashMap;
|
40 | 41 | import java.util.Map;
|
41 | 42 | import org.cactoos.collection.CollectionOf;
|
42 |
| -import org.cactoos.io.InputOf; |
43 | 43 | import org.cactoos.io.LengthOf;
|
44 | 44 | import org.cactoos.io.TeeInput;
|
45 |
| -import org.cactoos.map.MapEntry; |
46 |
| -import org.cactoos.map.MapOf; |
47 | 45 | import org.cactoos.text.TextOf;
|
48 |
| -import org.cactoos.text.UncheckedText; |
| 46 | +import org.xembly.Directives; |
| 47 | +import org.xembly.Xembler; |
49 | 48 |
|
50 | 49 | /**
|
51 | 50 | * Single report.
|
@@ -139,37 +138,16 @@ final class Report {
|
139 | 138 | * @param mean Mean
|
140 | 139 | * @param sigma Sigma
|
141 | 140 | * @checkstyle ParameterNumberCheck (10 lines)
|
142 |
| - * @todo #135:30min The current solution to add the reference to |
143 |
| - * 'metric.xsd' in the generated 'metric.xml' is too complex for |
144 |
| - * the task at hand. Refactor towards a simpler solution that |
145 |
| - * ideally would just require one or two Xembly instructions to |
146 |
| - * add the required attribute. |
147 | 141 | */
|
148 | 142 | @SuppressWarnings("unchecked")
|
149 | 143 | Report(final XML xml, final String name,
|
150 | 144 | final Map<String, Object> args,
|
151 | 145 | final double mean, final double sigma) {
|
152 | 146 | this.skeleton = xml;
|
153 | 147 | this.metric = name;
|
154 |
| - this.params = new MapOf<>( |
155 |
| - args, |
156 |
| - new MapEntry<>("schemaLocation", Report.SCHEMA_FILE) |
157 |
| - ); |
| 148 | + this.params = args; |
158 | 149 | this.post = new XSLChain(
|
159 | 150 | new CollectionOf<>(
|
160 |
| - new XSLDocument( |
161 |
| - new UncheckedText( |
162 |
| - new TextOf( |
163 |
| - new InputOf( |
164 |
| - Report.class.getResourceAsStream( |
165 |
| - "xsl/metric-post-schemaloc.xsl" |
166 |
| - ) |
167 |
| - ) |
168 |
| - ) |
169 |
| - ).asString(), |
170 |
| - Sources.DUMMY, |
171 |
| - this.params |
172 |
| - ), |
173 | 151 | new XSLDocument(
|
174 | 152 | Report.class.getResourceAsStream(
|
175 | 153 | "xsl/metric-post-colors.xsl"
|
@@ -237,11 +215,23 @@ private XML xml() throws IOException {
|
237 | 215 | String.format("XSL not found: %s", name)
|
238 | 216 | );
|
239 | 217 | }
|
240 |
| - return new XSLDocument( |
241 |
| - new TextOf(res).asString(), |
242 |
| - Sources.DUMMY, |
243 |
| - this.params |
244 |
| - ).transform(this.skeleton); |
| 218 | + return new XMLDocument( |
| 219 | + new Xembler( |
| 220 | + new Directives().xpath("metric").attr( |
| 221 | + "xmlns:xsi", |
| 222 | + "http://www.w3.org/2001/XMLSchema-instance" |
| 223 | + ).attr( |
| 224 | + "xsi:noNamespaceSchemaLocation", |
| 225 | + Report.SCHEMA_FILE |
| 226 | + ) |
| 227 | + ).applyQuietly( |
| 228 | + new XSLDocument( |
| 229 | + new TextOf(res).asString(), |
| 230 | + Sources.DUMMY, |
| 231 | + this.params |
| 232 | + ).transform(this.skeleton).node() |
| 233 | + ) |
| 234 | + ); |
245 | 235 | }
|
246 | 236 |
|
247 | 237 | }
|
0 commit comments