Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#227) Refactor setting schema reference attribute #325

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 24 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,26 @@ 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.