NIHVIVO-3510 fix to sparql query builder to work with empty Vitro

This commit is contained in:
brianjlowe 2011-12-14 21:31:46 +00:00
parent 7b422e883b
commit a30e1d5842
3 changed files with 33 additions and 6 deletions

View file

@ -13,6 +13,12 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.mindswap.pellet.jena.vocabulary.SWRL;
import org.openrdf.model.vocabulary.OWL;
import org.openrdf.model.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS;
import com.hp.hpl.jena.vocabulary.XSD;
import edu.cornell.mannlib.vedit.controller.BaseEditController; import edu.cornell.mannlib.vedit.controller.BaseEditController;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
@ -20,6 +26,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseMiscell
import edu.cornell.mannlib.vitro.webapp.beans.Ontology; import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao; import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
/** /**
* This servlet gets all the prefix for initizing the sparql query builder. * This servlet gets all the prefix for initizing the sparql query builder.
@ -69,19 +76,38 @@ public class GetAllPrefix extends BaseEditController {
while (ontItr.hasNext()) { while (ontItr.hasNext()) {
Ontology ont = (Ontology) ontItr.next(); Ontology ont = (Ontology) ontItr.next();
if (ont.getPrefix() != null) { if (ont.getPrefix() != null) {
respo += "<option>" + "<key>" + ont.getPrefix() + "</key>" respo += makeOption(ont.getPrefix(), ont.getURI());
+ "<value>" + ont.getURI() + "</value>"
+ "</option>";
} }
} }
} }
;
respo += makeOption("owl", OWL.NAMESPACE);
respo += makeOption("rdf", RDF.NAMESPACE);
respo += makeOption("rdfs", RDFS.getURI());
respo += makeOption("swrl", "http://www.w3.org/2003/11/swrl#");
respo += makeOption("swrlb", "http://www.w3.org/2003/11/swrlb#");
respo += makeOption("xsd", XSD.getURI());
respo += makeOption("vitro", VitroVocabulary.vitroURI);
respo += "</options>"; respo += "</options>";
out.println(respo); out.println(respo);
out.flush(); out.flush();
out.close(); out.close();
} }
/**
* Makes the markup for a prefix option
* @param prefix
* @param URI
* @return option string
*/
private String makeOption(String prefix, String URI) {
return "<option>" + "<key>" + prefix + "</key>"
+ "<value>" + URI + "</value>"
+ "</option>";
}
/** /**
* The doPost method of the servlet. <br> * The doPost method of the servlet. <br>
* *

View file

@ -1,4 +1,5 @@
<!-- $This file is distributed under the terms of the license in /doc/license.txt$ --> <!-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<%@page import="com.hp.hpl.jena.vocabulary.OWL"%>
<%@page import="com.hp.hpl.jena.rdf.model.ModelMaker"%> <%@page import="com.hp.hpl.jena.rdf.model.ModelMaker"%>
<%@page import="java.util.Iterator"%> <%@page import="java.util.Iterator"%>
<%@page import="java.util.ArrayList"%> <%@page import="java.util.ArrayList"%>
@ -40,7 +41,7 @@ td {
<tr id="clazz(0)"> <tr id="clazz(0)">
<td id="subject(0)" width="33%"> <td id="subject(0)" width="33%">
<select id="subject(0,0)"> <select id="subject(0,0)">
<option value=""> <option value="<%=OWL.Thing.getURI()%>">
Thing Thing
</option> </option>
</select> </select>

View file

@ -49,8 +49,8 @@
var myPrefixAjax = new Ajax.Request( preurl, {method: "get", parameters: "", onComplete: function(originalRequest){ var myPrefixAjax = new Ajax.Request( preurl, {method: "get", parameters: "", onComplete: function(originalRequest){
var response = originalRequest.responseXML; var response = originalRequest.responseXML;
var options = response.getElementsByTagName("option"); var options = response.getElementsByTagName("option");
if (options == null || options.length == 0){ if (options == null || options.length == 0) {
alert("Error: Cannot get all the prefix."); alert("Error: Cannot get all the prefixes.");
return; return;
} }
for(i=0; i<options.length; i++) for(i=0; i<options.length; i++)