Strabon

changeset 136:2e6a4b6d6450

Added two output formats: KMZMAP and KMLMAP
author Kostis Kyzirakos <kkyzir@di.uoa.gr>
date Tue May 08 22:20:44 2012 +0300 (2012-05-08)
parents de305c240be4
children 1de6a3e4670f
files endpoint/WebContent/WEB-INF/beans.xml endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java
line diff
     1.1 --- a/endpoint/WebContent/WEB-INF/beans.xml	Tue May 08 20:29:23 2012 +0300
     1.2 +++ b/endpoint/WebContent/WEB-INF/beans.xml	Tue May 08 22:20:44 2012 +0300
     1.3 @@ -92,7 +92,7 @@
     1.4  		</constructor-arg>
     1.5                  <constructor-arg type="java.lang.String">
     1.6                          <!-- Default format -->
     1.7 -                        <value><![CDATA[format=HTML]]></value>
     1.8 +                        <value><![CDATA[format=KMZMAP]]></value>
     1.9                  </constructor-arg>
    1.10  	</bean>
    1.11  
     2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Tue May 08 20:29:23 2012 +0300
     2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Tue May 08 22:20:44 2012 +0300
     2.3 @@ -240,12 +240,12 @@
     2.4  		} else if ((hive.getFormat().equalsIgnoreCase("KMLMAP")) || (hive.getFormat().equalsIgnoreCase("KMZMAP"))) {
     2.5  
     2.6  			StringBuilder errorMessage = new StringBuilder ();
     2.7 -			String answer = evaluateQuery(strabonWrapper, "KML", reqFuncionality, hive.getSPARQLQuery(), errorMessage);
     2.8 +			String answer = evaluateQuery(strabonWrapper, hive.getFormat(), reqFuncionality, hive.getSPARQLQuery(), errorMessage);
     2.9  			hive.setErrorMessage(errorMessage.toString());
    2.10  			SecureRandom random = new SecureRandom();
    2.11 -			String temp = new BigInteger(130, random).toString(32);   
    2.12 -			
    2.13 +			String temp = new BigInteger(130, random).toString(32);  			
    2.14  			String basePath = context.getRealPath("/") + "/../ROOT/tmp/";
    2.15 +			String extension = (hive.format.equalsIgnoreCase("KMLMAP") ? "kml" : "kmz");
    2.16  
    2.17  			try{
    2.18  				Date date = new Date();
    2.19 @@ -260,46 +260,19 @@
    2.20  					}
    2.21  				}
    2.22  
    2.23 -				File file =new File(basePath + temp + ".kml");
    2.24 +				File file = new File(basePath + temp + ".kml");
    2.25  
    2.26  				//if file doesnt exists, then create it
    2.27  				if(!file.exists()){
    2.28  					file.createNewFile();
    2.29  				}
    2.30  
    2.31 -				FileWriter fw = new FileWriter(basePath + temp + ".kml");
    2.32 +				FileWriter fw = new FileWriter(basePath + temp + "." + extension);
    2.33  				BufferedWriter bw = new BufferedWriter(fw);
    2.34  				bw.write(answer);
    2.35  				bw.close();
    2.36  				//FileUtils.forceDeleteOnExit(new File((String) context.getRealPath("/") + "/../ROOT/tmp/" + temp + ".kml"));
    2.37  
    2.38 -				//System.out.println("Done");
    2.39 -
    2.40 -				if (hive.getFormat().equalsIgnoreCase("KMZMAP")) {
    2.41 -					//compress
    2.42 -					byte[] buf = new byte[1024];
    2.43 -					String outFilename = basePath + temp + ".kmz";
    2.44 -					ZipOutputStream kmzout = new ZipOutputStream(new FileOutputStream(outFilename));
    2.45 -
    2.46 -					// Compress the files
    2.47 -					FileInputStream in = new FileInputStream(basePath + temp + ".kml");
    2.48 -
    2.49 -					// Add ZIP entry to output stream.
    2.50 -					kmzout.putNextEntry(new ZipEntry("doc.kml"));
    2.51 -
    2.52 -					// Transfer bytes from the file to the ZIP file
    2.53 -					int len;
    2.54 -					while ((len = in.read(buf)) > 0) {
    2.55 -						kmzout.write(buf, 0, len);
    2.56 -					}
    2.57 -
    2.58 -					// Complete the entry
    2.59 -					kmzout.closeEntry();
    2.60 -					in.close();
    2.61 -
    2.62 -					// Complete the ZIP file
    2.63 -					kmzout.close();
    2.64 -				}
    2.65  			} catch(IOException e) {
    2.66  				e.printStackTrace();
    2.67  			}
    2.68 @@ -308,17 +281,10 @@
    2.69  			response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
    2.70  
    2.71  			String pathToKML = "";
    2.72 -			if (hive.getFormat().equalsIgnoreCase("KMLMAP")) {
    2.73 -				//response.setContentType("application/vnd.google-earth.kml+xml; charset=UTF-8");
    2.74 -				response.setHeader("Location", request.getScheme() + "://" +  request.getServerName() +":" + request.getServerPort() +"/tmp/" + temp + ".kml");
    2.75 -				if (answer!="")
    2.76 -					pathToKML = request.getScheme() + "://" +  request.getServerName() +":" + request.getServerPort() +"/tmp/" + temp + ".kml";
    2.77 -			} else {
    2.78 -				//response.setContentType("application/vnd.google-earth.kmz; charset=UTF-8");
    2.79 -				response.setHeader("Location", request.getScheme() + "://" +  request.getServerName() +":" + request.getServerPort() +"/tmp/" + temp + ".kmz");
    2.80 -				if (answer!="")
    2.81 -					pathToKML = request.getScheme() + "://" +  request.getServerName() +":" + request.getServerPort() +"/tmp/" + temp + ".kmz";
    2.82 -			}
    2.83 +			response.setHeader("Location", request.getScheme() + "://" +  request.getServerName() +":" + request.getServerPort() +"/tmp/" + temp + "."+extension);
    2.84 +			
    2.85 +			if (answer!="")
    2.86 +				pathToKML = request.getScheme() + "://" +  request.getServerName() +":" + request.getServerPort() +"/tmp/" + temp + "."+extension;
    2.87  			
    2.88  			appendHTML1a(out,pathToKML);
    2.89  
    2.90 @@ -474,10 +440,10 @@
    2.91  		out.println("<script type=\"text/javascript\" src=\"http://maps.googleapis.com/maps/api/js?sensor=false\"></script>");
    2.92  		out.println("<script type=\"text/javascript\">");
    2.93  		out.println("function initialize() {");
    2.94 -		out.println("  var chicago = new google.maps.LatLng(41.875696,-87.624207);");
    2.95 +		out.println("  var brahames = new google.maps.LatLng(37.92253, 23.72275);");
    2.96  		out.println("  var myOptions = {");
    2.97  		out.println("    zoom: 11,");
    2.98 -		out.println("    center: chicago,");
    2.99 +		out.println("    center: brahames,");
   2.100  		out.println("   mapTypeId: google.maps.MapTypeId.ROADMAP");
   2.101  		out.println("  }");
   2.102  		out.println("");
   2.103 @@ -553,6 +519,8 @@
   2.104  		//		out.println("<td style=\"border: 1px dashed #bbbbbb;\"><input type=\"radio\" name=\"format\" value=\"KML\">KML<br/>");
   2.105  		//		out.println("<input type=\"radio\" name=\"format\" value=\"HTML\">HTML</td>");
   2.106  		out.println("<td style=\"border: 1px dashed #bbbbbb;\"><center>Output Format:<br/><select name=\"format\">");
   2.107 +		out.println("	<option value=\"KMZMAP\">HTML with google maps (kmz)</option>");
   2.108 +		out.println("	<option value=\"KMLMAP\">HTML with google maps (kml)</option>");
   2.109  		out.println("	<option value=\"HTML\">HTML</option>");
   2.110  		out.println("	<option value=\"KML\">KML</option>");
   2.111  		out.println("	<option value=\"XML\">XML</option>");