info.aduna.xml.XMLWriter Java Examples

The following examples show how to use info.aduna.xml.XMLWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SparqlEvaluator.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public void toWriter(Writer writer) throws OpenRDFException,
		TransformerException, IOException {
	if (query.isGraphQuery()) {
		QueryResultUtil.report(asGraphQueryResult(), new RDFXMLWriter(
				writer));
	} else if (query.isTupleQuery()) {
		QueryResultUtil.report(asTupleQueryResult(),
				new SPARQLResultsXMLWriter(new XMLWriter(writer)));
	} else if (query.isBooleanQuery()) {
		new SPARQLBooleanXMLWriter(new XMLWriter(writer))
				.write(asBoolean());
	} else {
		throw new AssertionError("Unknown query type");
	}
}
 
Example #2
Source File: TestUnions.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
     * Tests mapping of UNIONS in SPARQL onto unions in bigdata rules.
     * 
     * @throws Exception 
     */
    public void testSesameFilters() throws Exception {

        final BigdataSail sail = getSail();
        sail.initialize();
        final BigdataSailRepository repo = new BigdataSailRepository(sail);
        final BigdataSailRepositoryConnection cxn = 
            (BigdataSailRepositoryConnection) repo.getConnection();
        cxn.setAutoCommit(false);
        
        try {
    
            final URI jack = new URIImpl("_:Jack");
            final URI jill = new URIImpl("_:Jill");
            final URI person = new URIImpl("_:Person");
            final URI age = new URIImpl("_:age");
            final URI integer = new URIImpl("http://www.w3.org/2001/XMLSchema#integer");
/**/            
            cxn.add(
                    jack,
                    RDF.TYPE,
                    person
                    );
            cxn.add(
                    jill,
                    RDF.TYPE,
                    person
                    );
            cxn.add(
                    jack,
                    age,
                    new LiteralImpl("40", integer)
                    );
            cxn.add(
                    jill,
                    age,
                    new LiteralImpl("30", integer)
                    );
/**/

            /*
             * Note: The either flush() or commit() is required to flush the
             * statement buffers to the database before executing any operations
             * that go around the sail.
             */
            cxn.flush();//commit();
            
/**/            
            log.info("hello");
            if (log.isInfoEnabled()) {
                log.info(cxn.getTripleStore().dumpStore());
            }

            {
                
                String query = 
                    "SELECT * " +
                    "WHERE { " +
                    "  { " +
                    "    ?x <"+RDF.TYPE+"> <"+person+"> . " +
                    "    ?x <"+age+"> ?age1 . " +
                    "    FILTER( ?age1 > 35 ) . " +
                    "  } " +
                    "  UNION " +
                    "  { " +
                    "    ?x <"+RDF.TYPE+"> <"+person+"> . " +
                    "    ?x <"+age+"> ?age2 . " +
                    "    FILTER( ?age2 > 25 ) . " +
                    "  } " +
                    "}";
                
                final StringWriter sw = new StringWriter();
                
                final TupleQuery tupleQuery = 
                    cxn.prepareTupleQuery(QueryLanguage.SPARQL, query);
                tupleQuery.setIncludeInferred(true /* includeInferred */);
                tupleQuery.evaluate(new SPARQLResultsXMLWriter(new XMLWriter(sw)));
    
                if(log.isInfoEnabled())log.info(sw.toString());
            }
            
        } finally {
            cxn.close();
            sail.__tearDownUnitTest();
        }

    }