TriXParser extends XMLReaderBasedParser implements ErrorHandler { @Override public void parse(InputStream in, String baseURI) throws IOException, RDFParseException, RDFHandlerException { if (in == null) { throw new IllegalArgumentException("Input stream cannot be 'null'"); } if (baseURI == null) { throw new IllegalArgumentException("Base URI cannot be 'null'"); } InputSource inputSource = new InputSource(new BOMInputStream(in, false)); inputSource.setSystemId(baseURI); parse(inputSource); } TriXParser();  TriXParser(ValueFactory valueFactory); @Override final RDFFormat getRDFFormat(); @Override Collection<RioSetting<?>> getSupportedSettings(); @Override void parse(InputStream in, String baseURI); @Override void parse(Reader reader, String baseURI); @Override void warning(SAXParseException exception); @Override void error(SAXParseException exception); @Override void fatalError(SAXParseException exception);  }
@Test public void testFatalErrorDoctypeDecl() throws Exception { parser.getParserConfig().set(XMLParserSettings.DISALLOW_DOCTYPE_DECL, true); try (final InputStream in = this.getClass() .getResourceAsStream("/org/eclipse/rdf4j/rio/trix/trix-xxe-external-entity.trix");) { parser.parse(in, ""); } catch (RDFParseException e) { assertEquals( "DOCTYPE is disallowed when the feature \"http: e.getMessage()); } assertEquals(0, el.getWarnings().size()); assertEquals(0, el.getErrors().size()); assertEquals(1, el.getFatalErrors().size()); assertEquals( "[Rio fatal] DOCTYPE is disallowed when the feature \"http: el.getFatalErrors().get(0)); }
@Test public void testIgnoreExternalGeneralEntity() throws Exception { try (final InputStream in = this.getClass() .getResourceAsStream("/org/eclipse/rdf4j/rio/trix/trix-xxe-external-entity.trix");) { parser.parse(in, ""); } catch (FileNotFoundException e) { fail("parser tried to read external file from external general entity"); } assertEquals(0, el.getWarnings().size()); assertEquals(0, el.getErrors().size()); assertEquals(0, el.getFatalErrors().size()); assertThat(sc.getStatements().size()).isEqualTo(1); Statement st = sc.getStatements().iterator().next(); assertThat(st.getObject().stringValue()).isEqualTo(""); }
@Test public void testIgnoreExternalParameterEntity() throws Exception { parser.getParserConfig().set(XMLParserSettings.DISALLOW_DOCTYPE_DECL, false); try (final InputStream in = this.getClass() .getResourceAsStream("/org/eclipse/rdf4j/rio/trix/trix-xxe-external-param-entity.trix");) { parser.parse(in, ""); } catch (FileNotFoundException e) { fail("parser tried to read external file from external parameter entity"); } assertEquals(0, el.getWarnings().size()); assertEquals(0, el.getErrors().size()); assertEquals(0, el.getFatalErrors().size()); }
@Test public void testFatalErrorPrologContent() throws Exception { try (final InputStream in = this.getClass() .getResourceAsStream("/org/eclipse/rdf4j/rio/trix/not-a-trix-file.trix");) { parser.parse(in, ""); } catch (RDFParseException e) { assertEquals("Content is not allowed in prolog. [line 1, column 1]", e.getMessage()); } assertEquals(0, el.getWarnings().size()); assertEquals(0, el.getErrors().size()); assertEquals(1, el.getFatalErrors().size()); assertEquals("[Rio fatal] Content is not allowed in prolog. (1, 1)", el.getFatalErrors().get(0)); }