Search in sources :

Example 1 with RDFEHArray

use of org.apache.jena.rdfxml.xmlinput.SAX2RDFTest.RDFEHArray in project jena by apache.

the class SAX2RDFMoreTests method testLang.

public void testLang() throws Exception {
    Model m = ModelFactory.createDefaultModel();
    Model m2 = ModelFactory.createDefaultModel();
    RDFEHArray eh = new RDFEHArray();
    try (InputStream in = new FileInputStream("testing/wg/rdfms-xmllang/test004.rdf")) {
        RDFReader w = m.getReader();
        w.setErrorHandler(eh);
        w.read(m, in, "http://example.org/");
    }
    RDFEHArray eh2 = new RDFEHArray();
    try (InputStream in = new FileInputStream("testing/wg/rdfms-xmllang/test003.rdf")) {
        XMLReader saxParser = new SAXParser();
        SAX2Model handler = SAX2Model.create("http://example.org/", m2, "fr");
        SAX2RDF.installHandlers(saxParser, handler);
        handler.setErrorHandler(eh2);
        InputSource ins = new InputSource(in);
        ins.setSystemId("http://example.org/");
        try {
            try {
                saxParser.parse(ins);
            } finally {
                handler.close();
            }
        } catch (SAXParseException e) {
        // already reported, leave it be.
        }
    }
    /*
		 * 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 <a.length;i++)
		 * System.err.println(eh.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 : InputSource(org.xml.sax.InputSource) SAX2Model(org.apache.jena.rdfxml.xmlinput.SAX2Model) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) RDFReader(org.apache.jena.rdf.model.RDFReader) SAXParseException(org.xml.sax.SAXParseException) SAX2Model(org.apache.jena.rdfxml.xmlinput.SAX2Model) Model(org.apache.jena.rdf.model.Model) RDFEHArray(org.apache.jena.rdfxml.xmlinput.SAX2RDFTest.RDFEHArray) SAXParser(org.apache.xerces.parsers.SAXParser) XMLReader(org.xml.sax.XMLReader)

Aggregations

FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Model (org.apache.jena.rdf.model.Model)1 RDFReader (org.apache.jena.rdf.model.RDFReader)1 SAX2Model (org.apache.jena.rdfxml.xmlinput.SAX2Model)1 RDFEHArray (org.apache.jena.rdfxml.xmlinput.SAX2RDFTest.RDFEHArray)1 SAXParser (org.apache.xerces.parsers.SAXParser)1 InputSource (org.xml.sax.InputSource)1 SAXParseException (org.xml.sax.SAXParseException)1 XMLReader (org.xml.sax.XMLReader)1