Skip to content

Commit 69637dc

Browse files
committed
(cqfn#227) Refactor setting schema reference attribute
1 parent c3d214e commit 69637dc

File tree

2 files changed

+21
-71
lines changed

2 files changed

+21
-71
lines changed

src/main/java/org/jpeek/Report.java

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.jcabi.xml.Sources;
2929
import com.jcabi.xml.StrictXML;
3030
import com.jcabi.xml.XML;
31+
import com.jcabi.xml.XMLDocument;
3132
import com.jcabi.xml.XSD;
3233
import com.jcabi.xml.XSDDocument;
3334
import com.jcabi.xml.XSL;
@@ -39,13 +40,11 @@
3940
import java.util.HashMap;
4041
import java.util.Map;
4142
import org.cactoos.collection.CollectionOf;
42-
import org.cactoos.io.InputOf;
4343
import org.cactoos.io.LengthOf;
4444
import org.cactoos.io.TeeInput;
45-
import org.cactoos.map.MapEntry;
46-
import org.cactoos.map.MapOf;
4745
import org.cactoos.text.TextOf;
48-
import org.cactoos.text.UncheckedText;
46+
import org.xembly.Directives;
47+
import org.xembly.Xembler;
4948

5049
/**
5150
* Single report.
@@ -139,37 +138,16 @@ final class Report {
139138
* @param mean Mean
140139
* @param sigma Sigma
141140
* @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.
147141
*/
148142
@SuppressWarnings("unchecked")
149143
Report(final XML xml, final String name,
150144
final Map<String, Object> args,
151145
final double mean, final double sigma) {
152146
this.skeleton = xml;
153147
this.metric = name;
154-
this.params = new MapOf<>(
155-
args,
156-
new MapEntry<>("schemaLocation", Report.SCHEMA_FILE)
157-
);
148+
this.params = args;
158149
this.post = new XSLChain(
159150
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-
),
173151
new XSLDocument(
174152
Report.class.getResourceAsStream(
175153
"xsl/metric-post-colors.xsl"
@@ -237,11 +215,23 @@ private XML xml() throws IOException {
237215
String.format("XSL not found: %s", name)
238216
);
239217
}
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+
);
245235
}
246236

247237
}

src/main/resources/org/jpeek/xsl/metric-post-schemaloc.xsl

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)