Search in sources :

Example 21 with RDFReader

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

the class SAX2RDFTest method runTest.

@Override
public void runTest() throws Exception {
    //System.err.println(base+" + "+this.file);
    Model m = ModelFactory.createDefaultModel();
    Model m2 = ModelFactory.createDefaultModel();
    RDFEHArray eh = new RDFEHArray();
    try (InputStream in = new FileInputStream(file)) {
        RDFReader w = m.getReader();
        w.setErrorHandler(eh);
        w.read(m, in, base);
    }
    RDFEHArray eh2 = new RDFEHArray();
    try (InputStream in = new FileInputStream(file)) {
        /*
             * w = m.getReader(); w.setErrorHandler(eh2); w.read(m2,in,base);
             * in.close();
             */
        loadXMLModel(m2, in, eh2);
    }
    /*
		 * System.out.println("Normal:"); m.write(System.out,"N-TRIPLE");
		 * 
		 * System.out.println("New:"); m2.write(System.out,"N-TRIPLE");
		 */
    if (eh.v.size() == 0)
        assertTrue("Not isomorphic", m.isIsomorphicWith(m2));
    if (eh.v.size() != eh2.v.size()) {
        for (int i = 0; i < eh.v.size(); i++) System.err.println(eh.v.get(i));
        System.err.println("---");
        for (int i = 0; i < eh2.v.size(); i++) System.err.println(eh2.v.get(i));
    }
    assertEquals("Different number of errors", eh.v.size(), eh2.v.size());
    Object[] a = eh.v.toArray();
    Object[] a2 = eh2.v.toArray();
    Arrays.sort(a);
    Arrays.sort(a2);
    for (int i = 0; i < eh.v.size(); i++) {
        assertEquals("Error " + i + " different.", a[i], a2[i]);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SAX2Model(org.apache.jena.rdfxml.xmlinput.SAX2Model) Model(org.apache.jena.rdf.model.Model) FileInputStream(java.io.FileInputStream) RDFReader(org.apache.jena.rdf.model.RDFReader)

Example 22 with RDFReader

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

the class MoreTests method testIcu.

public void testIcu() throws IOException {
    //	  "இந்தியா"
    //	    Normalizer.  isNormalized(
    //	            "்தியா"
    //	            ,Normalizer.NFC,0);
    Model m = createMemModel();
    RDFReader rdr = m.getReader();
    try (FileInputStream r = new FileInputStream("testing/arp/i18n/icubug.rdf")) {
        rdr.setErrorHandler(this);
        expected = new int[] { WARN_STRING_COMPOSING_CHAR };
        rdr.read(m, r, "http://example.org/");
    }
    checkExpected();
}
Also used : Model(org.apache.jena.rdf.model.Model) RDFReader(org.apache.jena.rdf.model.RDFReader)

Example 23 with RDFReader

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

the class MoreTests method subTestEncodingMismatch2.

private void subTestEncodingMismatch2(InputStreamReader r) {
    if (r.getEncoding().startsWith("UTF")) {
        // see above for warning message.
        return;
    }
    Model m = createMemModel();
    RDFReader rdr = m.getReader();
    rdr.setErrorHandler(this);
    expected = new int[] { WARN_ENCODING_MISMATCH, ERR_ENCODING_MISMATCH };
    rdr.read(m, r, "http://example.org/");
    checkExpected();
}
Also used : Model(org.apache.jena.rdf.model.Model) RDFReader(org.apache.jena.rdf.model.RDFReader)

Example 24 with RDFReader

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

the class MoreTests method testARPMacRoman.

public void testARPMacRoman() throws IOException {
    Model m = createMemModel();
    RDFReader rdr = m.getReader();
    InputStream r = new FileInputStream("testing/arp/i18n/macroman.rdf");
    rdr.setErrorHandler(this);
    expected = new int[] { WARN_UNSUPPORTED_ENCODING, WARN_NON_IANA_ENCODING };
    expected[Charset.isSupported("MacRoman") ? 0 : 1] = 0;
    //		 Only one of the warnings is expected, which depends on Java version
    rdr.read(m, r, "http://example.org/");
    checkExpected();
}
Also used : Model(org.apache.jena.rdf.model.Model) RDFReader(org.apache.jena.rdf.model.RDFReader)

Example 25 with RDFReader

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

the class ExceptionTests method testDefaultDemotedFatal.

public void testDefaultDemotedFatal() {
    RDFDefaultErrorHandler.silent = true;
    try {
        Model m = ModelFactory.createDefaultModel();
        RDFReader rdr = m.getReader();
        rdr.setProperty("ERR_SAX_FATAL_ERROR", "EM_ERROR");
        rdr.read(m, "file:testing/arp/error-msgs/test06.rdf");
    } catch (JenaException e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        fail("Demoted.error error threw an exception");
    } finally {
        RDFDefaultErrorHandler.silent = false;
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) Model(org.apache.jena.rdf.model.Model) RDFReader(org.apache.jena.rdf.model.RDFReader)

Aggregations

RDFReader (org.apache.jena.rdf.model.RDFReader)34 Model (org.apache.jena.rdf.model.Model)30 JenaException (org.apache.jena.shared.JenaException)8 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 SAX2Model (org.apache.jena.rdfxml.xmlinput.SAX2Model)2 StringReader (java.io.StringReader)1 IRIFactory (org.apache.jena.iri.IRIFactory)1 TurtleParseException (org.apache.jena.n3.turtle.TurtleParseException)1 TurtleReader (org.apache.jena.n3.turtle.TurtleReader)1 RDFWriter (org.apache.jena.rdf.model.RDFWriter)1 RecordingModelListener (org.apache.jena.rdf.model.test.helpers.RecordingModelListener)1 RDFEHArray (org.apache.jena.rdfxml.xmlinput.SAX2RDFTest.RDFEHArray)1 BadURIException (org.apache.jena.shared.BadURIException)1 ConfigException (org.apache.jena.shared.ConfigException)1 InvalidPropertyURIException (org.apache.jena.shared.InvalidPropertyURIException)1 NoReaderForLangException (org.apache.jena.shared.NoReaderForLangException)1 SAXParser (org.apache.xerces.parsers.SAXParser)1 InputSource (org.xml.sax.InputSource)1 SAXParseException (org.xml.sax.SAXParseException)1