improvement and bugfix to getUrl() in IndividualSDB
This commit is contained in:
parent
80d5602dea
commit
d76b4bd3bd
1 changed files with 28 additions and 32 deletions
|
@ -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,41 +669,36 @@ 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(
|
||||||
|
" ?link <" + VitroVocabulary.LINK_ANCHOR + "> ?anchor . \n"
|
||||||
|
).append(
|
||||||
|
"} }");
|
||||||
|
QueryExecution qexec = QueryExecutionFactory.create(
|
||||||
|
QueryFactory.create(selectPrimaryLinkQueryBuff.toString())
|
||||||
|
, dataset);
|
||||||
try {
|
try {
|
||||||
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));
|
ResultSet linkResults = qexec.execSelect();
|
||||||
if (webappDaoFactory.getJenaBaseDao().LINK_ANCHOR != null) {
|
if (linkResults.hasNext()) {
|
||||||
try {
|
QuerySolution solution = linkResults.next();
|
||||||
Literal l = (Literal) linkInd.getPropertyValue(webappDaoFactory.getJenaBaseDao().LINK_ANCHOR);
|
this.setUrl(solution.getLiteral("url").getLexicalForm());
|
||||||
if (l != null) {
|
this.setAnchor(solution.getLiteral("anchor")
|
||||||
anchor = l.getString();
|
.getLexicalForm());
|
||||||
}
|
|
||||||
} catch (ClassCastException e) {}
|
|
||||||
}
|
|
||||||
if (webappDaoFactory.getJenaBaseDao().LINK_URL != null) {
|
|
||||||
try {
|
|
||||||
Literal l = (Literal) linkInd.getPropertyValue(webappDaoFactory.getJenaBaseDao().LINK_URL);
|
|
||||||
if (l != null) {
|
|
||||||
try {
|
|
||||||
url = URLDecoder.decode(l.getString(), "UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException use) {}
|
|
||||||
}
|
|
||||||
} catch (ClassCastException e) {}
|
|
||||||
}
|
|
||||||
} catch (ClassCastException cce) {}
|
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
qexec.close();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
tempModel.close();
|
tempModel.close();
|
||||||
|
|
Loading…
Add table
Reference in a new issue