use of org.eclipse.rdf4j.rio.helpers.ParseErrorCollector in project rdf4j by eclipse.
the class RDFXMLParserCustomTest method testEntityExpansionSecureProcessing.
/**
* Test with Secure processing setting on.
*
* @throws Exception
*/
@Test
public void testEntityExpansionSecureProcessing() throws Exception {
final Model aGraph = new LinkedHashModel();
ParseErrorCollector errorCollector = new ParseErrorCollector();
RDFParser aParser = Rio.createParser(RDFFormat.RDFXML).setRDFHandler(new StatementCollector(aGraph)).set(XMLParserSettings.SECURE_PROCESSING, true).setParseErrorListener(errorCollector);
try {
// this should trigger a SAX parse exception that will blow up at the
// 64k entity limit rather than OOMing
aParser.parse(this.getClass().getResourceAsStream("/testcases/rdfxml/openrdf/bad-entity-expansion-limit.rdf"), "http://example.org");
fail("Parser did not throw an exception");
} catch (RDFParseException e) {
// assertTrue(e.getMessage().contains(
// "The parser has encountered more than \"64,000\" entity expansions in this document; this is the limit imposed by the "));
}
assertEquals(0, errorCollector.getWarnings().size());
assertEquals(0, errorCollector.getErrors().size());
assertEquals(1, errorCollector.getFatalErrors().size());
}
use of org.eclipse.rdf4j.rio.helpers.ParseErrorCollector in project rdf4j by eclipse.
the class RDFParserHelperTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
parserConfig = new ParserConfig();
// By default we wipe out the SPI loaded datatype and language handlers
parserConfig.set(BasicParserSettings.DATATYPE_HANDLERS, Collections.<DatatypeHandler>emptyList());
parserConfig.set(BasicParserSettings.LANGUAGE_HANDLERS, Collections.<LanguageHandler>emptyList());
// Ensure that the set of non-fatal errors is empty by default
parserConfig.setNonFatalErrors(new HashSet<RioSetting<?>>());
errListener = new ParseErrorCollector();
valueFactory = SimpleValueFactory.getInstance();
}
use of org.eclipse.rdf4j.rio.helpers.ParseErrorCollector in project rdf4j by eclipse.
the class RDFXMLParserTest method setUp.
@Before
public void setUp() throws Exception {
platformLocale = Locale.getDefault();
Locale.setDefault(Locale.ENGLISH);
vf = SimpleValueFactory.getInstance();
parser = new RDFXMLParser();
sc = new StatementCollector();
parser.setRDFHandler(sc);
el = new ParseErrorCollector();
parser.setParseErrorListener(el);
}
use of org.eclipse.rdf4j.rio.helpers.ParseErrorCollector in project rdf4j by eclipse.
the class JSONLDInternalTripleCallbackTest method triplesTest.
@Test
public void triplesTest() throws JsonLdError, IOException {
// String inputstring =
// "{\"@id\":{\"@id\":\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/machine/DVC-1_8\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceElement\":\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceelement/DET-1_8\",\"http://igreen-projekt.de/ontologies/isoxml#deviceID\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"DVC-1\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceLocalizationLabel\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"FF000000406564\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceProcessData\":[\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/13_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/6_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/14_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/11_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/8_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/4_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/5_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/10_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/2_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/21_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/15_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/16_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/19_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/17_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/3_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/12_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/7_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/18_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/9_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/22_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/20_8\"],\"http://igreen-projekt.de/ontologies/isoxml#deviceSerialNumber\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"12345\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceSoftwareVersion\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"01.009\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceStructureLabel\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"31303030303030\"},\"http://igreen-projekt.de/ontologies/isoxml#workingSetMasterNAME\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"A000860020800001\"},\"http://www.w3.org/1999/02/22-rdf-syntax-ns#type\":{\"@iri\":\"http://www.agroxml.de/rdfs#Machine\"},\"http://www.w3.org/2000/01/rdf-schema#label\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"Krone Device\"}}";
final String inputstring = "{ \"@id\":\"http://nonexistent.com/abox#Document1823812\", \"@type\":\"http://nonexistent.com/tbox#Document\" }";
final String expectedString = "(http://nonexistent.com/abox#Document1823812, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://nonexistent.com/tbox#Document) [null]";
final Object input = JsonUtils.fromString(inputstring);
final Model graph = new LinkedHashModel();
final ParseErrorCollector parseErrorListener = new ParseErrorCollector();
final ParserConfig parserConfig = new ParserConfig();
final JSONLDInternalTripleCallback callback = new JSONLDInternalTripleCallback(new StatementCollector(graph), SimpleValueFactory.getInstance(), parserConfig, parseErrorListener, nodeID -> SimpleValueFactory.getInstance().createBNode(nodeID), () -> SimpleValueFactory.getInstance().createBNode());
JsonLdProcessor.toRDF(input, callback);
final Iterator<Statement> statements = graph.iterator();
// contains only one statement (type)
while (statements.hasNext()) {
final Statement stmt = statements.next();
System.out.println(stmt.toString());
assertEquals("Output was not as expected", stmt.toString(), expectedString);
}
assertEquals(0, parseErrorListener.getFatalErrors().size());
assertEquals(0, parseErrorListener.getErrors().size());
assertEquals(0, parseErrorListener.getWarnings().size());
}
Aggregations