-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRunTestsAndProcessFiles.java
More file actions
59 lines (52 loc) · 1.97 KB
/
Copy pathRunTestsAndProcessFiles.java
File metadata and controls
59 lines (52 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.io.File;
import java.net.URI;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.Serializer;
import net.sf.saxon.s9api.XdmAtomicValue;
import net.sf.saxon.s9api.XdmDestination;
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltTransformer;
import org.junit.Before;
import org.junit.Test;
/**
* This class also used to convert the examples to XProcSpec tests and
* include the test results in the specification. If you want to
* restore this functionality have a look at the Git history. */
public class RunTestsAndProcessFiles {
private File baseDir;
private XsltCompiler compiler;
@Test
public void run() throws Exception {
if ("".equals("${source}") || "".equals("${target}"))
throw new RuntimeException("source or target not specified");
baseDir = new File(new File(this.getClass().getResource("/").toURI()), "../..");
Processor processor = new Processor(false);
compiler = processor.newXsltCompiler();
Source source = new StreamSource(new File(baseDir, "${source}"));
File target = new File(baseDir, "${target}");
XdmNode tmp;
tmp = combineSources(source);
new Serializer(target).serializeNode(tmp);
}
// TODO: use XProc's p:xinclude
private XdmNode combineSources(Source source) throws SaxonApiException {
XsltTransformer transformer = compiler.compile(new StreamSource(new File(baseDir, "combine-sources.xsl"))).load();
XdmDestination dest = new XdmDestination();
transformer.setSource(source);
transformer.setDestination(dest);
transformer.transform();
// FIXME: index.getXdmNode() should have the same base URI as index!
return dest.getXdmNode();
}
}