*@param DOM document element to which all elements are appended
*@param set of URI's of lenses to be rendered
* @throws RepositoryException
*/
void render(FresnelDocument fd, Repository dataRepo, Document doc, Element parent, Lens[] lens, int offset, int limit) throws ParserConfigurationException, RepositoryException {
Lens renderLens = SesameLens.selectRenderLens(lens);
MResutls mres = new MResutls();
if (renderLens == null)
return;
if (renderLens.getSPARQLInstanceDomains() != null) {
System.out.println("Rendering getSPARQLInstanceDomains()...");
SPARQLQuery[] sid = renderLens.getSPARQLInstanceDomains();
SesameLens sl = (SesameLens)renderLens;
//call extended version of SPARQLSesameEvaluator (to get metadata)
SPARQLSesameEvaluator msse = new SPARQLSesameEvaluator();
msse.setDataRepository(dataRepo);
for (int i = 0; i < sid.length; i++)
{
String query = sid[i].toString() + "LIMIT "+limit+" OFFSET "+offset;
//return values with metadata
Map<Value, ComplexProvenance> mqueryResults = msse.metaEvaluateQuery(query);
if(!mqueryResults.isEmpty()){
for (Value value: mqueryResults.keySet()) {
Object end = value;
//resources++;
if (end instanceof Resource)
{
Resource r = (Resource)end;
Element eR;
//serialize meta knowledge or not
eR = createResourceElement(fd, dataRepo, doc, sl, null, r, mqueryResults.get(value), Constants.DEFAULT_MAX_DEPTH, mres);
parent.appendChild(eR);
}
else if (end instanceof Literal)
{
Literal l = (Literal)end;
ValueFactory f = dataRepo.getValueFactory();
URI r = f.createURI(l.getLabel());
if (r == null)
continue;
Element eR;
//serialize meta knowledge or not
eR = createResourceElement(fd, dataRepo, doc, sl, null, r, mqueryResults.get(value), Constants.DEFAULT_MAX_DEPTH, mres);
parent.appendChild(eR);
}
else if (end instanceof Statement)
{
String error = "Render Error: SPARQL query must end on node";
throw new ParserConfigurationException(error);
}
}
}else{
//return values without metadata
fr.inria.jfresnel.sparql.sesame.SPARQLSesameEvaluator fsse = new fr.inria.jfresnel.sparql.sesame.SPARQLSesameEvaluator();
fsse.setDataRepository(dataRepo);
Vector queryResults = fsse.evaluateQuery(new SPARQLQuery(query));
for (int k=0; k<queryResults.size(); k++) {
Object end = queryResults.get(k);
//resources++;
if (end instanceof Resource)
{
Resource r = (Resource)end;
Element eR = createResourceElement(fd, dataRepo, doc, sl, null, r, Constants.DEFAULT_MAX_DEPTH);
parent.appendChild(eR);
}
else if (end instanceof Literal)
{
Literal l = (Literal)end;
ValueFactory f = dataRepo.getValueFactory();
URI r = f.createURI(l.getLabel());
if (r == null)
continue;
Element eR = createResourceElement(fd, dataRepo, doc, sl, null, r, Constants.DEFAULT_MAX_DEPTH);
parent.appendChild(eR);
}
else if (end instanceof Statement)
{
String error = "Render Error: SPARQL query must end on node";
throw new ParserConfigurationException(error);
}
}
}
}
}
//still not extended to return results with metadata!
else if (renderLens.getFSLInstanceDomains() != null)
{
System.out.println("Rendering getFSLInstanceDomains()...");
FSLPath[] fid = renderLens.getFSLInstanceDomains();
SesameLens sl = (SesameLens)renderLens;
FSLSesameEvaluator fse = new FSLSesameEvaluator();
fse.setDataRepository(dataRepo);
for (int i = 0; i < fid.length; i++)
{
//resources ++;
Vector pathInstances = fse.evaluatePath(fid[i]);
for (int k=0; k<pathInstances.size(); k++) {
Object end = ((Vector)pathInstances.get(k)).get(0);
if (end instanceof Resource)
{
Resource r = (Resource)end;
Element eR = createResourceElement(fd, dataRepo, doc, sl, null, r, Constants.DEFAULT_MAX_DEPTH);
parent.appendChild(eR);
}
else if (end instanceof Literal)
{
Literal l = (Literal)end;
ValueFactory f = dataRepo.getValueFactory();
URI r = f.createURI(l.getLabel());
if (r == null)
continue;
Element eR = createResourceElement(fd, dataRepo, doc, sl, null, r, Constants.DEFAULT_MAX_DEPTH);
parent.appendChild(eR);
}
else if (end instanceof Statement)
{
String error = "Render Error: FSL path must end on node";
throw new ParserConfigurationException(error);
}
}
}
}
// I don't know if here it should be return metadata here !!!
else if (renderLens.getBasicInstanceDomains() != null)
{
System.out.println("Rendering getBasicInstanceDomains()...");
java.lang.String[] bid = renderLens.getBasicInstanceDomains();
SesameLens sl = (SesameLens)renderLens;
HashMap resSet = new HashMap();
for (int j = 0; j < bid.length; j++)
{
ValueFactory f = dataRepo.getValueFactory();
URI r = f.createURI(bid[j]);
if (r == null)
continue;
// Don't render resource twice (???)
if (resSet.containsKey(r))
continue;
resSet.put(r, null);
SPARQLSesameEvaluator sse = new SPARQLSesameEvaluator();
sse.setDataRepository(dataRepo);
try {
String query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+
"SELECT DISTINCT *" +
"WHERE {{ <"+r+"> rdf:type ?t}}"+
"LIMIT "+limit+" OFFSET "+offset;
//return values with metadata
Map<Value, ComplexProvenance> queryResults = sse.metaEvaluateQuery(query);
//with metadata
if(!queryResults.isEmpty()){
for (Value value: queryResults.keySet()) {
Element eR;
//serialize meta knowledge or not
//resources ++;
eR = createResourceElement(fd, dataRepo, doc, sl, null, r, queryResults.get(value), Constants.DEFAULT_MAX_DEPTH, mres);
parent.appendChild(eR);
}
//without metadata
}else{
//resources ++;
Element eR = createResourceElement(fd, dataRepo, doc, sl, null, r, Constants.DEFAULT_MAX_DEPTH);
parent.appendChild(eR);
}
}catch (Exception ex){
System.out.println("Error while getting statements from repository:");
}
}
}
else if (renderLens.getBasicClassDomains() != null)
{
System.out.println("Rendering getBasicClassDomains() ...");
java.lang.String[] cd = renderLens.getBasicClassDomains();
SesameLens sl = (SesameLens)renderLens;
HashMap resSet = new HashMap();
SPARQLSesameEvaluator sse = new SPARQLSesameEvaluator();
sse.setDataRepository(dataRepo);
for (int j = 0; j < cd.length; j++) {