improvement and bugfix to getUrl() in IndividualSDB

This commit is contained in:
bjl23 2010-12-14 17:31:31 +00:00
parent 80d5602dea
commit d76b4bd3bd

View file

@ -24,6 +24,7 @@ import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntResource; import com.hp.hpl.jena.ontology.OntResource;
import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.QuerySolution;
@ -668,42 +669,37 @@ public class IndividualSDB extends IndividualImpl implements Individual {
private void doUrlAndAnchor() { private void doUrlAndAnchor() {
Model tempModel = ModelFactory.createDefaultModel(); Model tempModel = ModelFactory.createDefaultModel();
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); OntModel ontModel = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM);
DatasetWrapper w = getDatasetWrapper(); DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try { try {
if (webappDaoFactory.getJenaBaseDao().PRIMARY_LINK != null) { StringBuffer selectPrimaryLinkQueryBuff = new StringBuffer().append(
String listPropertyValues = "SELECT ?url ?anchor \n" ).append(
"SELECT ?values" + "WHERE{ GRAPH ?g { \n " ).append(
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + webappDaoFactory.getJenaBaseDao().PRIMARY_LINK + "> ?values} }"; " <" + this.individualURI + "> ").append(
ResultSet links = QueryExecutionFactory.create(QueryFactory.create(listPropertyValues), dataset).execSelect(); "<" + VitroVocabulary.PRIMARY_LINK + "> " ).append(
QuerySolution result = null; "?link . \n").append(
if (links.hasNext()) { " ?link <" + VitroVocabulary.LINK_URL + "> ?url . \n"
result = links.next(); ).append(
try { " ?link <" + VitroVocabulary.LINK_ANCHOR + "> ?anchor . \n"
com.hp.hpl.jena.ontology.Individual linkInd = ((com.hp.hpl.jena.ontology.Individual)((Resource)result.get("values")).as(com.hp.hpl.jena.ontology.Individual.class)); ).append(
if (webappDaoFactory.getJenaBaseDao().LINK_ANCHOR != null) { "} }");
try { QueryExecution qexec = QueryExecutionFactory.create(
Literal l = (Literal) linkInd.getPropertyValue(webappDaoFactory.getJenaBaseDao().LINK_ANCHOR); QueryFactory.create(selectPrimaryLinkQueryBuff.toString())
if (l != null) { , dataset);
anchor = l.getString(); try {
} ResultSet linkResults = qexec.execSelect();
} catch (ClassCastException e) {} if (linkResults.hasNext()) {
} QuerySolution solution = linkResults.next();
if (webappDaoFactory.getJenaBaseDao().LINK_URL != null) { this.setUrl(solution.getLiteral("url").getLexicalForm());
try { this.setAnchor(solution.getLiteral("anchor")
Literal l = (Literal) linkInd.getPropertyValue(webappDaoFactory.getJenaBaseDao().LINK_URL); .getLexicalForm());
if (l != null) { }
try { } finally {
url = URLDecoder.decode(l.getString(), "UTF-8"); qexec.close();
} catch (UnsupportedEncodingException use) {} }
}
} catch (ClassCastException e) {}
}
} catch (ClassCastException cce) {}
}
}
} finally { } finally {
tempModel.close(); tempModel.close();
ontModel.close(); ontModel.close();