Strabon

changeset 144:450e41a1a7ce

Moved KML zipping to endpoint, temp fix, beware
author Michael Sioutis
date Wed May 09 18:24:26 2012 +0300 (2012-05-09)
parents 9331be0ac3c3
children 17ed5c26cf7a 3b8c73978d32
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 May 09 17:28:13 2012 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Wed May 09 18:24:26 2012 +0300
     1.3 @@ -160,6 +160,7 @@
     1.4  			String answer = evaluateQuery(strabonWrapper, hive.getFormat(), reqFuncionality, hive.getSPARQLQuery(), errorMessage);
     1.5  			hive.setErrorMessage(errorMessage.toString());
     1.6  			SecureRandom random = new SecureRandom();
     1.7 +			String extension = (hive.format.equalsIgnoreCase("KMLMAP") ? "kml" : "kmz");
     1.8  			String temp = new BigInteger(130, random).toString(32);   
     1.9  			
    1.10  			String basePath = context.getRealPath("/") + "/../ROOT/tmp/";
    1.11 @@ -177,7 +178,7 @@
    1.12  					}
    1.13  				}
    1.14  
    1.15 -				File file =new File(basePath + temp + ".kml");
    1.16 +				File file =new File(basePath + temp + "." + extension);
    1.17  
    1.18  				//if file doesnt exists, then create it
    1.19  				if(!file.exists()){
    1.20 @@ -243,7 +244,7 @@
    1.21  		} else if ((hive.getFormat().equalsIgnoreCase("KMLMAP")) || (hive.getFormat().equalsIgnoreCase("KMZMAP"))) {
    1.22  
    1.23  			StringBuilder errorMessage = new StringBuilder ();
    1.24 -			String answer = evaluateQuery(strabonWrapper, hive.getFormat().equalsIgnoreCase("KMLMAP") ? "KML" : "KMZ", reqFuncionality, hive.getSPARQLQuery(), errorMessage);
    1.25 +			String answer = evaluateQuery(strabonWrapper, hive.getFormat().equalsIgnoreCase("KMLMAP") ? "KML" : "KML", reqFuncionality, hive.getSPARQLQuery(), errorMessage);
    1.26  			hive.setErrorMessage(errorMessage.toString());
    1.27  			SecureRandom random = new SecureRandom();
    1.28  			String temp = new BigInteger(130, random).toString(32);  			
    1.29 @@ -264,7 +265,7 @@
    1.30  					}
    1.31  				}
    1.32  
    1.33 -				File file = new File(basePath + temp + ".kml");
    1.34 +				File file = new File(basePath + temp + "." + extension);
    1.35  
    1.36  				//if file doesnt exists, then create it
    1.37  				if(!file.exists()){
    1.38 @@ -273,7 +274,20 @@
    1.39  
    1.40  				FileWriter fw = new FileWriter(basePath + temp + "." + extension);
    1.41  				BufferedWriter bw = new BufferedWriter(fw);
    1.42 -				bw.write(answer);
    1.43 +				if (hive.getFormat().equalsIgnoreCase("KMLMAP")) {
    1.44 +				   bw.write(answer);
    1.45 +				}
    1.46 +				else {
    1.47 +				   FileOutputStream fos = new FileOutputStream(file);
    1.48 +				   ZipOutputStream kmzout = new ZipOutputStream(fos);
    1.49 +				   ZipEntry entry = new ZipEntry("doc.kml");
    1.50 +
    1.51 +				//kmzout.setLevel(6);
    1.52 +				   kmzout.putNextEntry(entry);
    1.53 +				   kmzout.write(answer.getBytes());
    1.54 +			       kmzout.closeEntry();
    1.55 +				   kmzout.close();
    1.56 +				   }
    1.57  				bw.close();
    1.58  				//FileUtils.forceDeleteOnExit(new File((String) context.getRealPath("/") + "/../ROOT/tmp/" + temp + ".kml"));
    1.59