Skip to content

Commit

Permalink
(cqfn#227) Refactor setting schema reference attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
gsnoff committed Apr 27, 2019
1 parent c3d214e commit 69637dc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 71 deletions.
52 changes: 21 additions & 31 deletions src/main/java/org/jpeek/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.jcabi.xml.Sources;
import com.jcabi.xml.StrictXML;
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import com.jcabi.xml.XSD;
import com.jcabi.xml.XSDDocument;
import com.jcabi.xml.XSL;
Expand All @@ -39,13 +40,11 @@
import java.util.HashMap;
import java.util.Map;
import org.cactoos.collection.CollectionOf;
import org.cactoos.io.InputOf;
import org.cactoos.io.LengthOf;
import org.cactoos.io.TeeInput;
import org.cactoos.map.MapEntry;
import org.cactoos.map.MapOf;
import org.cactoos.text.TextOf;
import org.cactoos.text.UncheckedText;
import org.xembly.Directives;
import org.xembly.Xembler;

/**
* Single report.
Expand Down Expand Up @@ -139,37 +138,16 @@ final class Report {
* @param mean Mean
* @param sigma Sigma
* @checkstyle ParameterNumberCheck (10 lines)
* @todo #135:30min The current solution to add the reference to
* 'metric.xsd' in the generated 'metric.xml' is too complex for
* the task at hand. Refactor towards a simpler solution that
* ideally would just require one or two Xembly instructions to
* add the required attribute.
*/
@SuppressWarnings("unchecked")
Report(final XML xml, final String name,
final Map<String, Object> args,
final double mean, final double sigma) {
this.skeleton = xml;
this.metric = name;
this.params = new MapOf<>(
args,
new MapEntry<>("schemaLocation", Report.SCHEMA_FILE)
);
this.params = args;
this.post = new XSLChain(
new CollectionOf<>(
new XSLDocument(
new UncheckedText(
new TextOf(
new InputOf(
Report.class.getResourceAsStream(
"xsl/metric-post-schemaloc.xsl"
)
)
)
).asString(),
Sources.DUMMY,
this.params
),
new XSLDocument(
Report.class.getResourceAsStream(
"xsl/metric-post-colors.xsl"
Expand Down Expand Up @@ -237,11 +215,23 @@ private XML xml() throws IOException {
String.format("XSL not found: %s", name)
);
}
return new XSLDocument(
new TextOf(res).asString(),
Sources.DUMMY,
this.params
).transform(this.skeleton);
return new XMLDocument(
new Xembler(
new Directives().xpath("metric").attr(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance"
).attr(
"xsi:noNamespaceSchemaLocation",
Report.SCHEMA_FILE
)
).applyQuietly(
new XSLDocument(
new TextOf(res).asString(),
Sources.DUMMY,
this.params
).transform(this.skeleton).node()
)
);
}

}
40 changes: 0 additions & 40 deletions src/main/resources/org/jpeek/xsl/metric-post-schemaloc.xsl

This file was deleted.

0 comments on commit 69637dc

Please sign in to comment.