Strabon

changeset 142:36df5f584371

merging with pico
author Manos Karpathiotakis <mk@di.uoa.gr>
date Wed May 09 16:07:36 2012 +0300 (2012-05-09)
parents 2392a5bf7b9c 59234a910710
children 9331be0ac3c3
files
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Wed May 09 16:06:35 2012 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Wed May 09 16:07:36 2012 +0300
     1.3 @@ -243,13 +243,14 @@
     1.4  		} else if ((hive.getFormat().equalsIgnoreCase("KMLMAP")) || (hive.getFormat().equalsIgnoreCase("KMZMAP"))) {
     1.5  
     1.6  			StringBuilder errorMessage = new StringBuilder ();
     1.7 -			String answer = evaluateQuery(strabonWrapper, hive.getFormat(), reqFuncionality, hive.getSPARQLQuery(), errorMessage);
     1.8 +			String answer = evaluateQuery(strabonWrapper, hive.getFormat().equalsIgnoreCase("KMLMAP") ? "KML" : "KMZ", reqFuncionality, hive.getSPARQLQuery(), errorMessage);
     1.9  			hive.setErrorMessage(errorMessage.toString());
    1.10  			SecureRandom random = new SecureRandom();
    1.11  			String temp = new BigInteger(130, random).toString(32);  			
    1.12 -			String basePath = context.getRealPath("/") + "/../ROOT/tmp/";
    1.13 +			String basePath = context.getRealPath("/") + "/../ROOT/tmp/"; 
    1.14  			String extension = (hive.format.equalsIgnoreCase("KMLMAP") ? "kml" : "kmz");
    1.15  
    1.16 +			
    1.17  			try{
    1.18  				Date date = new Date();
    1.19  
    1.20 @@ -280,11 +281,11 @@
    1.21  				e.printStackTrace();
    1.22  			}
    1.23  
    1.24 -			response.setDateHeader("Expires", 0);			
    1.25 -			response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
    1.26 +			//response.setDateHeader("Expires", 0);			
    1.27 +			//response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
    1.28  
    1.29  			String pathToKML = "";
    1.30 -			response.setHeader("Location", request.getScheme() + "://" +  request.getServerName() +":" + request.getServerPort() +"/tmp/" + temp + "."+extension);
    1.31 +			//response.setHeader("Location", request.getScheme() + "://" +  request.getServerName() +":" + request.getServerPort() +"/tmp/" + temp + "."+extension);
    1.32  			
    1.33  			if (answer!="")
    1.34  				pathToKML = request.getScheme() + "://" +  request.getServerName() +":" + request.getServerPort() +"/tmp/" + temp + "."+extension;
     2.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Wed May 09 16:06:35 2012 +0300
     2.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Wed May 09 16:07:36 2012 +0300
     2.3 @@ -19,9 +19,12 @@
     2.4  import java.util.Set;
     2.5  import java.util.zip.ZipEntry;
     2.6  import java.util.zip.ZipOutputStream;
     2.7 +import java.io.*;
     2.8 +import java.util.zip.*;
     2.9  
    2.10  import javax.xml.namespace.QName;
    2.11  
    2.12 +import org.apache.commons.io.FileUtils;
    2.13  import org.apache.commons.io.output.ByteArrayOutputStream;
    2.14  import org.geotools.data.simple.SimpleFeatureCollection;
    2.15  import org.geotools.feature.FeatureCollections;
    2.16 @@ -638,15 +641,53 @@
    2.17  				{
    2.18  					//compress
    2.19  //					FileOutputStream fos = new FileOutputStream(new File("deleteme.kmz"));
    2.20 -					ZipOutputStream kmzout = new ZipOutputStream(retStream);
    2.21 +					//ZipOutputStream kmzout = new ZipOutputStream(retStream);
    2.22  //					ZipOutputStream kmzout = new ZipOutputStream(fos);
    2.23 -					ZipEntry entry = new ZipEntry("doc.kml");
    2.24 +					//ZipEntry entry = new ZipEntry("doc.kml");
    2.25  
    2.26 -					kmzout.setLevel(9);
    2.27 -					kmzout.putNextEntry(entry);
    2.28 -					kmzout.write(newString.getBytes());
    2.29 -					kmzout.closeEntry();
    2.30 -					kmzout.close();
    2.31 +					//kmzout.setLevel(6);
    2.32 +					//kmzout.putNextEntry(entry);
    2.33 +					//kmzout.write(newString.getBytes());
    2.34 +					//kmzout.closeEntry();
    2.35 +					//kmzout.close();
    2.36 +					
    2.37 +					try {
    2.38 +						File file = new File("/tmp/tmp.kml");
    2.39 +						String filename = "/tmp/tmp.kml";
    2.40 +						FileUtils.writeStringToFile(file, newString);
    2.41 +						
    2.42 +						File zfile = new File("/tmp/tmp.kmz");
    2.43 +			            String zipfilename = "/tmp/tmp.kmz";
    2.44 +						
    2.45 +			            byte[] buf = new byte[1024];
    2.46 +			            FileInputStream fis = new FileInputStream(filename);
    2.47 +			            fis.read(buf,0,buf.length);
    2.48 +			            
    2.49 +			            CRC32 crc = new CRC32();
    2.50 +			            ZipOutputStream s = new ZipOutputStream(
    2.51 +			                    (OutputStream)new FileOutputStream(zipfilename));
    2.52 +			            
    2.53 +			            //s.setLevel(6);
    2.54 +			            
    2.55 +			            ZipEntry entry = new ZipEntry(filename);
    2.56 +			            entry.setSize((long)buf.length);
    2.57 +			            crc.reset();
    2.58 +			            crc.update(buf);
    2.59 +			            entry.setCrc( crc.getValue());
    2.60 +			            s.putNextEntry(entry);
    2.61 +			            s.write(buf, 0, buf.length);
    2.62 +			            s.finish();
    2.63 +			            s.close();
    2.64 +			            
    2.65 +			            String kmzString = FileUtils.readFileToString(zfile);
    2.66 +			            writeOut.write(kmzString);
    2.67 +			            
    2.68 +			            //FileUtils.forceDelete(file);
    2.69 +			            //FileUtils.forceDelete(zfile);
    2.70 +			            
    2.71 +			        } catch (Exception e) {
    2.72 +			            e.printStackTrace();
    2.73 +			        }
    2.74  										
    2.75  				}
    2.76