Moved utility methods for parsing query results back to PageDaoJena from JenaBaseDao, because they are not all-purpose at this point.
This commit is contained in:
parent
cc9f132503
commit
38fef41a12
5 changed files with 64 additions and 70 deletions
|
@ -948,68 +948,5 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ****************************************************************************** */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a sparql query that returns a multiple rows to a list of maps.
|
|
||||||
* The maps will have column names as keys to the values.
|
|
||||||
*/
|
|
||||||
protected List<Map<String, Object>> executeQueryToCollection(
|
|
||||||
QueryExecution qexec) {
|
|
||||||
List<Map<String, Object>> rv = new ArrayList<Map<String, Object>>();
|
|
||||||
ResultSet results = qexec.execSelect();
|
|
||||||
while (results.hasNext()) {
|
|
||||||
QuerySolution soln = results.nextSolution();
|
|
||||||
rv.add(querySolutionToMap(soln));
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Map<String,Object> querySolutionToMap( QuerySolution soln ){
|
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
|
||||||
Iterator<String> varNames = soln.varNames();
|
|
||||||
while(varNames.hasNext()){
|
|
||||||
String varName = varNames.next();
|
|
||||||
map.put(varName, nodeToObject( soln.get(varName)));
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
static protected Object nodeToObject( RDFNode node ){
|
|
||||||
if( node == null ){
|
|
||||||
return "";
|
|
||||||
}else if( node.isLiteral() ){
|
|
||||||
Literal literal = node.asLiteral();
|
|
||||||
return literal.getValue();
|
|
||||||
}else if( node.isURIResource() ){
|
|
||||||
Resource resource = node.asResource();
|
|
||||||
return resource.getURI();
|
|
||||||
}else if( node.isAnon() ){
|
|
||||||
Resource resource = node.asResource();
|
|
||||||
return resource.getId().getLabelString(); //get b-node id
|
|
||||||
}else{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static protected String nodeToString( RDFNode node ){
|
|
||||||
if( node == null ){
|
|
||||||
return "";
|
|
||||||
}else if( node.isLiteral() ){
|
|
||||||
Literal literal = node.asLiteral();
|
|
||||||
return literal.getLexicalForm();
|
|
||||||
}else if( node.isURIResource() ){
|
|
||||||
Resource resource = node.asResource();
|
|
||||||
return resource.getURI();
|
|
||||||
}else if( node.isAnon() ){
|
|
||||||
Resource resource = node.asResource();
|
|
||||||
return resource.getId().getLabelString(); //get b-node id
|
|
||||||
}else{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected Map<String,Object> resultsToMap(){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,6 +160,69 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
|
||||||
return rv.get(0);
|
return rv.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ****************************************************************************** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a sparql query that returns a multiple rows to a list of maps.
|
||||||
|
* The maps will have column names as keys to the values.
|
||||||
|
*/
|
||||||
|
protected List<Map<String, Object>> executeQueryToCollection(
|
||||||
|
QueryExecution qexec) {
|
||||||
|
List<Map<String, Object>> rv = new ArrayList<Map<String, Object>>();
|
||||||
|
ResultSet results = qexec.execSelect();
|
||||||
|
while (results.hasNext()) {
|
||||||
|
QuerySolution soln = results.nextSolution();
|
||||||
|
rv.add(querySolutionToMap(soln));
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<String,Object> querySolutionToMap( QuerySolution soln ){
|
||||||
|
Map<String,Object> map = new HashMap<String,Object>();
|
||||||
|
Iterator<String> varNames = soln.varNames();
|
||||||
|
while(varNames.hasNext()){
|
||||||
|
String varName = varNames.next();
|
||||||
|
map.put(varName, nodeToObject( soln.get(varName)));
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
static protected Object nodeToObject( RDFNode node ){
|
||||||
|
if( node == null ){
|
||||||
|
return "";
|
||||||
|
}else if( node.isLiteral() ){
|
||||||
|
Literal literal = node.asLiteral();
|
||||||
|
return literal.getValue();
|
||||||
|
}else if( node.isURIResource() ){
|
||||||
|
Resource resource = node.asResource();
|
||||||
|
return resource.getURI();
|
||||||
|
}else if( node.isAnon() ){
|
||||||
|
Resource resource = node.asResource();
|
||||||
|
return resource.getId().getLabelString(); //get b-node id
|
||||||
|
}else{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static protected String nodeToString( RDFNode node ){
|
||||||
|
if( node == null ){
|
||||||
|
return "";
|
||||||
|
}else if( node.isLiteral() ){
|
||||||
|
Literal literal = node.asLiteral();
|
||||||
|
return literal.getLexicalForm();
|
||||||
|
}else if( node.isURIResource() ){
|
||||||
|
Resource resource = node.asResource();
|
||||||
|
return resource.getURI();
|
||||||
|
}else if( node.isAnon() ){
|
||||||
|
Resource resource = node.asResource();
|
||||||
|
return resource.getId().getLabelString(); //get b-node id
|
||||||
|
}else{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected Map<String,Object> resultsToMap(){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,7 @@ public class ViewFinder {
|
||||||
// NB this is not the value currently used for custom forms - we use the value on the object property.
|
// NB this is not the value currently used for custom forms - we use the value on the object property.
|
||||||
// This value is specifiable from the backend editor, however.
|
// This value is specifiable from the backend editor, however.
|
||||||
FORM("getCustomEntryForm", "form-default.ftl"),
|
FORM("getCustomEntryForm", "form-default.ftl"),
|
||||||
SEARCH("getCustomSearchView", "view-search-default.ftl"),
|
SEARCH("getCustomSearchView", "view-search-default.ftl");
|
||||||
SHORT("getCustomShortView", "view-short-default.ftl");
|
|
||||||
|
|
||||||
private Method method = null;
|
private Method method = null;
|
||||||
private String defaultTemplate = null;
|
private String defaultTemplate = null;
|
||||||
|
|
|
@ -109,10 +109,6 @@ public class IndividualTemplateModel extends BaseTemplateModel {
|
||||||
return getView(ClassView.SEARCH);
|
return getView(ClassView.SEARCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getShortView() {
|
|
||||||
return getView(ClassView.SHORT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDisplayView() {
|
public String getDisplayView() {
|
||||||
return getView(ClassView.DISPLAY);
|
return getView(ClassView.DISPLAY);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
<#list property.statements as statement>
|
<#list property.statements as statement>
|
||||||
<div class="obj-prop-stmt-obj">
|
<div class="obj-prop-stmt-obj">
|
||||||
<#-- ${statement.object.name} -->
|
|
||||||
statement ${statement_index +1}
|
statement ${statement_index +1}
|
||||||
</div> <!-- end obj-prop-stmt-obj -->
|
</div> <!-- end obj-prop-stmt-obj -->
|
||||||
</#list>
|
</#list>
|
Loading…
Add table
Reference in a new issue