1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jeuclid.testsuite;
20
21 import javax.xml.transform.Result;
22 import javax.xml.transform.Source;
23 import javax.xml.transform.Transformer;
24 import javax.xml.transform.TransformerConfigurationException;
25 import javax.xml.transform.TransformerFactory;
26 import javax.xml.transform.dom.DOMResult;
27 import javax.xml.transform.dom.DOMSource;
28 import javax.xml.transform.stream.StreamSource;
29
30 import net.sourceforge.jeuclid.DOMBuilder;
31 import net.sourceforge.jeuclid.MutableLayoutContext;
32 import net.sourceforge.jeuclid.context.LayoutContextImpl;
33 import net.sourceforge.jeuclid.context.Parameter;
34 import net.sourceforge.jeuclid.converter.Processor;
35
36 import org.apache.commons.logging.Log;
37 import org.apache.commons.logging.LogFactory;
38 import org.w3c.dom.Node;
39
40
41
42
43
44
45 public final class TestSuiteProcessor {
46
47 private static final float DISPLAY_SIZE = 16.0f;
48
49 private static final Processor MML2SVGPROCESSOR = Processor.getInstance();
50
51
52
53 private static final Log LOGGER = LogFactory.getLog(Processor.class);
54
55 private final Transformer modificationTransformer;
56
57 private final MutableLayoutContext context;
58
59 private static final class SingletonHolder {
60 private static final TestSuiteProcessor INSTANCE = new TestSuiteProcessor();
61
62 private SingletonHolder() {
63 }
64 }
65
66 private TestSuiteProcessor() {
67 this.context = new LayoutContextImpl(LayoutContextImpl
68 .getDefaultLayoutContext());
69 this.context.setParameter(Parameter.MATHSIZE,
70 TestSuiteProcessor.DISPLAY_SIZE);
71 Transformer t;
72 try {
73 t = TransformerFactory.newInstance().newTemplates(
74 new StreamSource(DOMBuilder.class
75 .getResourceAsStream("/support/ModifySuite3.xsl")))
76 .newTransformer();
77 } catch (final TransformerConfigurationException e) {
78 t = null;
79 }
80 this.modificationTransformer = t;
81 }
82
83
84
85
86
87
88 public static TestSuiteProcessor getInstance() {
89 return TestSuiteProcessor.SingletonHolder.INSTANCE;
90 }
91
92
93
94
95
96
97
98
99
100
101
102
103 public boolean process(final Source inputSource, final Result result,
104 final boolean apply3Mod) {
105 boolean processed;
106 final DOMResult intermediate = new javax.xml.transform.dom.DOMResult();
107 try {
108 if (apply3Mod && (this.modificationTransformer != null)) {
109 TestSuiteProcessor.MML2SVGPROCESSOR.process(inputSource,
110 intermediate);
111 final Node head = intermediate.getNode();
112 this.modificationTransformer.transform(new DOMSource(head),
113 result);
114 } else {
115 TestSuiteProcessor.MML2SVGPROCESSOR
116 .process(inputSource, result);
117 }
118 processed = true;
119
120 } catch (final Exception e) {
121
122 TestSuiteProcessor.LOGGER.warn(e.getMessage(), e);
123 processed = false;
124 }
125 return processed;
126 }
127
128 }