|
4 | 4 | import com.formulasearchengine.mathmltools.io.XmlDocumentReader; |
5 | 5 | import com.formulasearchengine.mathmltools.utils.mml.CSymbol; |
6 | 6 | import com.formulasearchengine.mathmltools.xml.PartialLocalEntityResolver; |
| 7 | +import com.sun.org.apache.xerces.internal.dom.DOMInputImpl; |
7 | 8 | import org.apache.commons.lang3.NotImplementedException; |
8 | 9 | import org.apache.logging.log4j.LogManager; |
9 | 10 | import org.apache.logging.log4j.Logger; |
@@ -103,14 +104,22 @@ public static String tryFixHeader(String inputXMLString, String prefix) { |
103 | 104 | return inputXMLString; |
104 | 105 | } |
105 | 106 |
|
106 | | - private static Validator getXsdValidator() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { |
| 107 | + public static DOMInputImpl getMathMLSchema() { |
| 108 | + SchemaInput schemaInput = new SchemaInput().invoke(); |
| 109 | + InputSource inputSource = schemaInput.getInputSource(); |
| 110 | + final DOMInputImpl input = new DOMInputImpl(); |
| 111 | + input.setByteStream(inputSource.getByteStream()); |
| 112 | + input.setPublicId(inputSource.getPublicId()); |
| 113 | + input.setSystemId(inputSource.getSystemId()); |
| 114 | + return input; |
| 115 | + } |
| 116 | + |
| 117 | + private static Validator getXsdValidator() { |
107 | 118 | if (v == null) { |
108 | | - SchemaFactory schemaFactory = SchemaFactory.newInstance(Languages.W3C_XML_SCHEMA_NS_URI); |
109 | | - final PartialLocalEntityResolver resolver = new PartialLocalEntityResolver(); |
110 | | - schemaFactory.setResourceResolver(resolver); |
| 119 | + SchemaInput schemaInput = new SchemaInput().invoke(); |
| 120 | + SchemaFactory schemaFactory = schemaInput.getSchemaFactory(); |
| 121 | + InputSource inputSource = schemaInput.getInputSource(); |
111 | 122 | v = new JAXPValidator(Languages.W3C_XML_SCHEMA_NS_URI, schemaFactory); |
112 | | - final InputSource inputSource = resolver.resolveEntity("math", MATHML3_XSD); |
113 | | - assert inputSource != null; |
114 | 123 | final StreamSource streamSource = new StreamSource(inputSource.getByteStream()); |
115 | 124 | streamSource.setPublicId(inputSource.getPublicId()); |
116 | 125 | streamSource.setSystemId(inputSource.getSystemId()); |
@@ -197,4 +206,26 @@ List<CSymbol> getCSymbols() { |
197 | 206 | public Document getDom() { |
198 | 207 | return dom; |
199 | 208 | } |
| 209 | + |
| 210 | + private static class SchemaInput { |
| 211 | + private SchemaFactory schemaFactory; |
| 212 | + private InputSource inputSource; |
| 213 | + |
| 214 | + SchemaFactory getSchemaFactory() { |
| 215 | + return schemaFactory; |
| 216 | + } |
| 217 | + |
| 218 | + InputSource getInputSource() { |
| 219 | + return inputSource; |
| 220 | + } |
| 221 | + |
| 222 | + SchemaInput invoke() { |
| 223 | + schemaFactory = SchemaFactory.newInstance(Languages.W3C_XML_SCHEMA_NS_URI); |
| 224 | + final PartialLocalEntityResolver resolver = new PartialLocalEntityResolver(); |
| 225 | + schemaFactory.setResourceResolver(resolver); |
| 226 | + inputSource = resolver.resolveEntity("math", MATHML3_XSD); |
| 227 | + assert inputSource != null; |
| 228 | + return this; |
| 229 | + } |
| 230 | + } |
200 | 231 | } |
0 commit comments