NIHVIVO-1363 Clean up code: remove unused variables and parameters, remove commented code, add generic types to collections.

This commit is contained in:
jeb228 2010-12-13 20:49:46 +00:00
parent d6906af33b
commit ae5de265d8

View file

@ -56,13 +56,10 @@ import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
* *
*/ */
public class SparqlQueryServlet extends BaseEditController { public class SparqlQueryServlet extends BaseEditController {
private static final Log log = LogFactory.getLog(SparqlQueryServlet.class.getName()); private static final Log log = LogFactory.getLog(SparqlQueryServlet.class.getName());
private static final String kb2 = "http://vitro.mannlib.cornell.edu/default/vitro-kb-2";
protected static final Syntax SYNTAX = Syntax.syntaxARQ; protected static final Syntax SYNTAX = Syntax.syntaxARQ;
protected static HashMap<String,ResultSetFormat>formatSymbols = new HashMap<String,ResultSetFormat>(); protected static HashMap<String,ResultSetFormat>formatSymbols = new HashMap<String,ResultSetFormat>();
static{ static{
formatSymbols.put( ResultSetFormat.syntaxXML.getSymbol(), ResultSetFormat.syntaxXML); formatSymbols.put( ResultSetFormat.syntaxXML.getSymbol(), ResultSetFormat.syntaxXML);
@ -107,18 +104,15 @@ public class SparqlQueryServlet extends BaseEditController {
// rjy7 Allows any editor (including self-editors) access to this servlet. // rjy7 Allows any editor (including self-editors) access to this servlet.
// This servlet is now requested via Ajax from some custom forms, so anyone // This servlet is now requested via Ajax from some custom forms, so anyone
// using the custom form needs access rights. // using the custom form needs access rights.
// TODO Actually, this only allows someone who is logged in to use this servlet.
// If a self-editor is not logged in, they will not have access. -- jb
if( !checkLoginStatus(request, response) ) { if( !checkLoginStatus(request, response) ) {
return; return;
} }
VitroRequest vreq = new VitroRequest(request); VitroRequest vreq = new VitroRequest(request);
Model model = vreq.getJenaOntModel(); // getModel() Model model = vreq.getJenaOntModel();
if( model == null ){ if( model == null ){
doNoModelInContext(request,response); doNoModelInContext(response);
return; return;
} }
@ -175,12 +169,11 @@ public class SparqlQueryServlet extends BaseEditController {
dataSource.setDefaultModel(model) ; dataSource.setDefaultModel(model) ;
} }
} }
executeQuery(request, response, resultFormatParam, rdfResultFormatParam, queryParam, (dataset != null) ? dataset : dataSource); executeQuery(response, resultFormatParam, rdfResultFormatParam, queryParam, (dataset != null) ? dataset : dataSource);
return; return;
} }
private void executeQuery(HttpServletRequest req, private void executeQuery(HttpServletResponse response, String resultFormatParam, String rdfResultFormatParam, String queryParam, Dataset dataset ) throws IOException {
HttpServletResponse response, String resultFormatParam, String rdfResultFormatParam, String queryParam, Dataset dataset ) throws IOException {
ResultSetFormat rsf = null; ResultSetFormat rsf = null;
/* BJL23 2008-11-06 /* BJL23 2008-11-06
@ -227,19 +220,7 @@ public class SparqlQueryServlet extends BaseEditController {
} }
} }
/* private void doNoModelInContext(HttpServletResponse res){
private Model getModel(){
Model model = null;
try{
model = (Model)getServletContext().getAttribute("jenaOntModel");
}catch(Throwable thr){
log.error("could not cast getServletContext().getAttribute(\"jenaOntModel\") to Model");
}
return model;
}
*/
private void doNoModelInContext(HttpServletRequest request, HttpServletResponse res){
try { try {
res.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); res.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
ServletOutputStream sos = res.getOutputStream(); ServletOutputStream sos = res.getOutputStream();
@ -261,9 +242,9 @@ public class SparqlQueryServlet extends BaseEditController {
while (results.hasNext()) { while (results.hasNext()) {
QuerySolution solution = (QuerySolution) results.next(); QuerySolution solution = (QuerySolution) results.next();
List<String> valueList = new LinkedList<String>(); List<String> valueList = new LinkedList<String>();
Iterator varNameIt = solution.varNames(); Iterator<String> varNameIt = solution.varNames();
while (varNameIt.hasNext()) { while (varNameIt.hasNext()) {
String varName = (String) varNameIt.next(); String varName = varNameIt.next();
String value = ""; String value = "";
try { try {
Literal lit = solution.getLiteral(varName); Literal lit = solution.getLiteral(varName);
@ -328,18 +309,14 @@ public class SparqlQueryServlet extends BaseEditController {
OntologyDao daoObj = vreq.getFullWebappDaoFactory().getOntologyDao(); OntologyDao daoObj = vreq.getFullWebappDaoFactory().getOntologyDao();
List ontologiesObj = daoObj.getAllOntologies(); List<Ontology> ontologiesObj = daoObj.getAllOntologies();
ArrayList prefixList = new ArrayList(); ArrayList<String> prefixList = new ArrayList<String>();
if(ontologiesObj !=null && ontologiesObj.size()>0){ if(ontologiesObj !=null && ontologiesObj.size()>0){
for(Ontology ont: ontologiesObj) {
Iterator ontItr = ontologiesObj.iterator();
while(ontItr.hasNext()){
Ontology ont = (Ontology) ontItr.next();
prefixList.add(ont.getPrefix() == null ? "(not yet specified)" : ont.getPrefix()); prefixList.add(ont.getPrefix() == null ? "(not yet specified)" : ont.getPrefix());
prefixList.add(ont.getURI() == null ? "" : ont.getURI()); prefixList.add(ont.getURI() == null ? "" : ont.getURI());
} }
} }
else{ else{
prefixList.add("<strong>" + "No Ontologies added" + "</strong>"); prefixList.add("<strong>" + "No Ontologies added" + "</strong>");
@ -414,7 +391,8 @@ public class SparqlQueryServlet extends BaseEditController {
"ORDER BY ASC( ?pred )\n"; "ORDER BY ASC( ?pred )\n";
*/ */
private String example = @SuppressWarnings("unused")
private String example =
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"+
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"+
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n"+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n"+