Strabon

changeset 87:e1a54ea341b2

removed useless commented code, replaced hardcoded HTTP codes with HtppServletResponse.SC_<code-name> static fields, added comments
author Babis Nikolaou <charnik@di.uoa.gr>
date Wed Apr 04 16:12:08 2012 +0300 (2012-04-04)
parents 64d3889773a9
children fe79e508b1a4 a932ab72a29f
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Wed Apr 04 16:02:04 2012 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Wed Apr 04 16:12:08 2012 +0300
     1.3 @@ -76,44 +76,10 @@
     1.4  				this.errorMessage = error;
     1.5  			}
     1.6  		}
     1.7 -		
     1.8 -//		System.out.println("\n\n\n\n\n\n\nrequest: ");
     1.9 -//		System.out.println("HEADERS");
    1.10 -//	    Enumeration headerNames = request.getHeaderNames();
    1.11 -//	    while(headerNames.hasMoreElements()) {
    1.12 -//	      String headerName = (String)headerNames.nextElement();
    1.13 -//	      System.out.println(headerName + ":" +request.getHeader(headerName));
    1.14 -//	    }
    1.15 -//	    System.out.println("ATTRIBUTES");
    1.16 -//	    Enumeration attributeNames = request.getAttributeNames();
    1.17 -//	    while(attributeNames.hasMoreElements()) {
    1.18 -//	      String attributeName = (String)attributeNames.nextElement();
    1.19 -//	      System.out.println(attributeName + ":" +request.getAttribute(attributeName).toString());
    1.20 -//	    }
    1.21 -//	    Enumeration paramNames = request.getParameterNames();
    1.22 -//	    while(paramNames.hasMoreElements()) {
    1.23 -//	      String paramName = (String)paramNames.nextElement();
    1.24 -//	      System.out.print(paramName + ":");
    1.25 -//	      String[] paramValues = request.getParameterValues(paramName);
    1.26 -//	      if (paramValues.length == 1) {
    1.27 -//	        String paramValue = paramValues[0];
    1.28 -//	        if (paramValue.length() == 0)
    1.29 -//	          System.out.print("No Value");
    1.30 -//	        else
    1.31 -//	          System.out.print(paramValue + " ");
    1.32 -//	      } else {
    1.33 -//	        for(int i=0; i<paramValues.length; i++) {
    1.34 -//	          System.out.println(":" + paramValues[i]);
    1.35 -//	        }
    1.36 -//	      }	    
    1.37 -//	    }
    1.38 -//		
    1.39 -//		System.out.println("\n\n\n\n\nREQUEST.CONTENTTYPE='"+request.getContentType()+"'\n\n\n\n\n");
    1.40 -		
    1.41 +				
    1.42  		DataHive hive = new DataHive(); 
    1.43  		
    1.44  		hive.setSPARQLQuery(request.getParameter("SPARQLQuery"));
    1.45 -		//System.out.println("SPARQLQuery = " + this.SPARQLQuery);
    1.46  		
    1.47  		String reqFormat = (request.getParameter("format") == null) ? "" : request.getParameter("format");
    1.48  		String reqAccept = (request.getHeader("accept") == null) ? "" : request.getHeader("accept");
    1.49 @@ -153,6 +119,7 @@
    1.50  		WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(context);
    1.51  		StrabonBeanWrapper strabonWrapper = (StrabonBeanWrapper)applicationContext.getBean("strabonBean");
    1.52  		
    1.53 +		/* Execution of UPDATE query */  
    1.54  		if (isUpdate) {
    1.55  			String answer = "";
    1.56  			try {
    1.57 @@ -166,23 +133,16 @@
    1.58  			}
    1.59  			
    1.60  			// write response to client
    1.61 -			response.getWriter().append(getHeaderResponse());
    1.62 +			response.getWriter().append(getUPDATEHeaderResponse());
    1.63  			response.getWriter().append(answer);
    1.64 -			response.getWriter().append(getFooterResponse());
    1.65 +			response.getWriter().append(getUPDATEFooterResponse());
    1.66  			return;
    1.67  		}
    1.68 +		/* Execution of UPDATE query */
    1.69  
    1.70  		PrintWriter out = response.getWriter();
    1.71  		
    1.72  		if ((hive.getFormat().equalsIgnoreCase("KML"))) {
    1.73 -			//try {
    1.74 -		    //     String url = "http://www.google.com";
    1.75 -		    //     java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
    1.76 -		    //     }
    1.77 -		    //  catch (java.io.IOException e) {
    1.78 -		    //     System.out.println(e.getMessage());
    1.79 -		    //     }
    1.80 -			
    1.81  			StringBuilder errorMessage = new StringBuilder ();
    1.82  			String answer = evaluateQuery(strabonWrapper, hive.getFormat(), reqFuncionality, hive.getSPARQLQuery(), errorMessage);
    1.83  			hive.setErrorMessage(errorMessage.toString());
    1.84 @@ -223,27 +183,13 @@
    1.85      	     
    1.86   			 response.setContentType("application/vnd.google-earth.kml+xml; charset=UTF-8");
    1.87   			 response.setDateHeader("Expires", 0);
    1.88 - 			 //InetAddress thisIp =InetAddress.getLocalHost();
    1.89   			 response.setHeader("Location", request.getScheme() + "://" +  request.getServerName() +":" + request.getServerPort() +"/tmp/" + temp + ".kml");
    1.90 - 			 response.setStatus(301);
    1.91 -             
    1.92 - 			 //out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
    1.93 -             //out.println("<html>");
    1.94 -             //out.println("<head>");
    1.95 -             //out.println("<title>:)</title>");
    1.96 -             //out.println("<meta http-equiv=\"REFRESH\" content=\"0;url=http://maps.google.com/maps?q=http://localhost:8080/tmp/temp.kml\"></HEAD>");
    1.97 -             //out.println("<BODY>");
    1.98 -             //out.println("Redirection WILL occur!");
    1.99 -             //out.println("</BODY>");
   1.100 -             //out.println("</HTML>");
   1.101 -			//out.println(answer);
   1.102 -			 
   1.103 + 			 response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
   1.104  			 
   1.105      	    String pathToKML = "";
   1.106 -    	    //InetAddress thisIp = InetAddress.getLocalHost();
   1.107      	    
   1.108      	    if (answer!="")
   1.109 -			   pathToKML = request.getScheme() + "://" +  request.getServerName() +":" + request.getServerPort() +"/tmp/" + temp + ".kml";//"http://dl.dropbox.com/u/19752551/dlr.kml";
   1.110 +			   pathToKML = request.getScheme() + "://" +  request.getServerName() +":" + request.getServerPort() +"/tmp/" + temp + ".kml";
   1.111  			
   1.112              appendHTML1a(out,pathToKML);
   1.113  			
   1.114 @@ -312,13 +258,21 @@
   1.115  		out.flush();
   1.116  	}
   1.117  
   1.118 -	private String getHeaderResponse() {
   1.119 +	/**
   1.120 +	 * Used as the template answer for UPDATE queries.
   1.121 +	 * @return
   1.122 +	 */
   1.123 +	private String getUPDATEHeaderResponse() {
   1.124  		return "<?xml version='1.0' encoding='UTF-8'?>\n" +
   1.125  			   "<response>\n" +
   1.126  			   "\t";
   1.127  	}
   1.128  	
   1.129 -	private String getFooterResponse() {
   1.130 +	/**
   1.131 +	 * Used as the template answer for UPDATE queries.
   1.132 +	 * @return
   1.133 +	 */
   1.134 +	private String getUPDATEFooterResponse() {
   1.135  		return "\n</response>\n";
   1.136  	}
   1.137