use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.
the class JSONLDWriterBackgroundTest method testRoundTripNamespaces.
@Test
public void testRoundTripNamespaces() throws Exception {
String exNs = "http://example.org/";
IRI uri1 = vf.createIRI(exNs, "uri1");
IRI uri2 = vf.createIRI(exNs, "uri2");
Literal plainLit = vf.createLiteral("plain", XMLSchema.STRING);
Statement st1 = vf.createStatement(uri1, uri2, plainLit);
ByteArrayOutputStream out = new ByteArrayOutputStream();
RDFWriter rdfWriter = rdfWriterFactory.getWriter(out);
rdfWriter.getWriterConfig().set(JSONLDSettings.JSONLD_MODE, JSONLDMode.COMPACT);
rdfWriter.handleNamespace("ex", exNs);
rdfWriter.startRDF();
rdfWriter.handleStatement(st1);
rdfWriter.endRDF();
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
RDFParser rdfParser = rdfParserFactory.getParser();
ParserConfig config = new ParserConfig();
config.set(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES, true);
config.set(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES, true);
rdfParser.setParserConfig(config);
rdfParser.setValueFactory(vf);
Model model = new LinkedHashModel();
rdfParser.setRDFHandler(new StatementCollector(model));
rdfParser.parse(in, "foo:bar");
assertEquals("Unexpected number of statements, found " + model.size(), 1, model.size());
assertTrue("missing namespaced statement", model.contains(st1));
if (rdfParser.getRDFFormat().supportsNamespaces()) {
assertTrue("Expected at least one namespace, found " + model.getNamespaces().size(), model.getNamespaces().size() >= 1);
assertEquals(exNs, model.getNamespace("ex").get().getName());
}
}
use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.
the class ModelsTest method setUp.
@Before
public void setUp() {
model1 = new LinkedHashModel();
model2 = new LinkedHashModel();
foo = VF.createIRI("http://example.org/foo");
bar = VF.createIRI("http://example.org/bar");
baz = VF.createBNode();
}
use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.
the class RepositoryConfigUtil method updateRepositoryConfigs.
/**
* Update the specified RepositoryConnection with the specified set of RepositoryConfigs. This will
* overwrite all existing configurations in the Repository that have a Repository ID occurring in these
* RepositoryConfigs. Note: this method does NOT commit the updates on the connection.
*
* @param con
* the repository connection to perform the update on
* @param configs
* The RepositoryConfigs that should be added to or updated in the Repository. The
* RepositoryConfig's ID may already occur in the Repository, in which case all previous
* configuration data for that Repository will be cleared before the RepositoryConfig is added.
* @throws RepositoryException
* @throws RepositoryConfigException
*/
@Deprecated
public static void updateRepositoryConfigs(RepositoryConnection con, RepositoryConfig... configs) throws RepositoryException, RepositoryConfigException {
ValueFactory vf = con.getRepository().getValueFactory();
con.begin();
for (RepositoryConfig config : configs) {
Resource context = getContext(con, config.getID());
if (context != null) {
con.clear(context);
} else {
context = vf.createBNode();
}
con.add(context, RDF.TYPE, REPOSITORY_CONTEXT);
Model graph = new LinkedHashModel();
config.export(graph);
con.add(graph, context);
}
con.commit();
}
use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.
the class TriGParserCustomTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
vf = SimpleValueFactory.getInstance();
settingsNoVerifyLangTag = new ParserConfig();
settingsNoVerifyLangTag.set(BasicParserSettings.VERIFY_LANGUAGE_TAGS, false);
errors = new ParseErrorCollector();
parser = Rio.createParser(RDFFormat.TRIG);
statementCollector = new StatementCollector(new LinkedHashModel());
parser.setRDFHandler(statementCollector);
}
use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.
the class RDFXMLParserCustomTest method testEntityExpansionNoSecureProcessing.
/**
* Test with Secure processing setting off.
* <p>
* IMPORTANT: Only turn this on to verify it is still working, as there is no way to safely perform this
* test.
* <p>
* WARNING: This test will cause an OutOfMemoryException when it eventually fails, as it will eventually
* fail.
*
* @throws Exception
*/
@Ignore
@Test(timeout = 10000)
public void testEntityExpansionNoSecureProcessing() 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, false).setParseErrorListener(errorCollector);
try {
// IMPORTANT: This will not use the entity limit
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());
}
Aggregations