Search in sources :

Example 6 with RDFWriterI

use of org.apache.jena.rdf.model.RDFWriterI in project jena by apache.

the class TestXMLFeatures method testRelativeAPI.

/*
	 * public void testBadProperty2() throws IOException {
	 * checkPropURI("http:/a.b/", "brickley", "http://example.org/b#",
	 * ExtraTriples); }
	 * 
	 */
public void testRelativeAPI() {
    RDFWriterI w = createMemModel().getWriter(lang);
    String old = (String) w.setProperty("relativeURIs", "");
    assertEquals("default value check", old, "same-document, absolute, relative, parent");
    w.setProperty("relativeURIs", "network, grandparent,relative,  ");
    w.setProperty("relativeURIs", "  parent, same-document, network, parent, absolute ");
    // TestLogger tl = new TestLogger(URI.class);
    blockLogger();
    // will get warning
    w.setProperty("relativeURIs", "foo");
    assertTrue("A warning should have been generated.", unblockLogger());
}
Also used : RDFWriterI(org.apache.jena.rdf.model.RDFWriterI)

Example 7 with RDFWriterI

use of org.apache.jena.rdf.model.RDFWriterI in project jena by apache.

the class TestXMLFeatures method checkPropURI.

public void checkPropURI(String s, String p, Object val, int behaviour) throws IOException {
    // create triple and graph.
    // BaseXMLWriter.dbg = true;
    // SystemOutAndErr.block();
    // TestLogger tl = new TestLogger(BaseXMLWriter.class);
    blockLogger();
    Node blank = NodeFactory.createBlankNode();
    Node prop = NodeFactory.createURI(s);
    Graph g = Factory.createGraphMem();
    g.add(Triple.create(blank, prop, blank));
    // create Model
    Model m = ModelFactory.createModelForGraph(g);
    // serialize
    RDFWriterI rw = m.getWriter(lang);
    if (p != null)
        rw.setProperty(p, val);
    try (StringWriter w = new StringWriter()) {
        rw.write(m, w, "http://example.org/");
        String f = w.toString();
        switch(behaviour) {
            case BadPropURI:
                fail("Bad property URI <" + s + "> was not detected.");
                return;
            case BadURI:
                fail("Bad URI <" + s + "> was not detected.");
                return;
        }
        // read back in
        Model m2 = createMemModel();
        RDFReaderI rdr = m2.getReader("RDF/XML");
        rdr.setProperty("error-mode", "lax");
        try (StringReader sr = new StringReader(f)) {
            rdr.read(m2, sr, "http://example.org/");
        }
        // check
        switch(behaviour) {
            case ExtraTriples:
                assertTrue("Expecting Brickley behaviour.", m2.size() == 3);
                break;
            case NoError:
                assertTrue("Comparing Model written out and read in.", m.isIsomorphicWith(m2));
                break;
        }
    } catch (BadURIException e) {
        if (behaviour == BadURI)
            return;
        throw e;
    } catch (InvalidPropertyURIException je) {
        if (behaviour == BadPropURI)
            return;
        throw je;
    } catch (JenaException e) {
        throw e;
    } finally {
        // BaseXMLWriter.dbg = false;
        // tl.end();
        unblockLogger();
    // SystemOutAndErr.unblock();
    }
}
Also used : BadURIException(org.apache.jena.shared.BadURIException) JenaException(org.apache.jena.shared.JenaException) RDFReaderI(org.apache.jena.rdf.model.RDFReaderI) Model(org.apache.jena.rdf.model.Model) RDFWriterI(org.apache.jena.rdf.model.RDFWriterI) InvalidPropertyURIException(org.apache.jena.shared.InvalidPropertyURIException)

Example 8 with RDFWriterI

use of org.apache.jena.rdf.model.RDFWriterI in project jena by apache.

the class AdapterRDFWriter method write.

@Override
public void write(OutputStream out, Graph graph, PrefixMap prefixMap, String baseURI, Context context) {
    RDFWriterI w = create();
    setProperties(w, context);
    w.write(ModelFactory.createModelForGraph(graph), out, baseURI);
}
Also used : RDFWriterI(org.apache.jena.rdf.model.RDFWriterI)

Aggregations

RDFWriterI (org.apache.jena.rdf.model.RDFWriterI)8 Model (org.apache.jena.rdf.model.Model)4 StringWriter (java.io.StringWriter)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 Properties (java.util.Properties)1 RDFReaderI (org.apache.jena.rdf.model.RDFReaderI)1 BaseXMLWriter (org.apache.jena.rdfxml.xmloutput.impl.BaseXMLWriter)1 BadURIException (org.apache.jena.shared.BadURIException)1 InvalidPropertyURIException (org.apache.jena.shared.InvalidPropertyURIException)1 JenaException (org.apache.jena.shared.JenaException)1 Test (org.junit.Test)1