Changeset 107
- Timestamp:
- 02/21/08 11:37:36 (9 months ago)
- Files:
-
- branches/routingservice/.classpath (modified) (1 diff)
- branches/routingservice/configuration.xml (deleted)
- branches/routingservice/lib/com.noelios.restlet.ext.simple_3.1.jar (modified) (previous)
- branches/routingservice/lib/com.noelios.restlet.jar (modified) (previous)
- branches/routingservice/lib/org.json.jar (modified) (previous)
- branches/routingservice/lib/org.restlet.ext.json_2.0.jar (modified) (previous)
- branches/routingservice/lib/org.restlet.jar (modified) (previous)
- branches/routingservice/pool.xml (added)
- branches/routingservice/src/jp/co/orkney/restlet/geo/ClosestEdge.java (modified) (4 diffs)
- branches/routingservice/src/jp/co/orkney/restlet/geo/DrivingDistance.java (modified) (1 diff)
- branches/routingservice/src/jp/co/orkney/restlet/geo/ShortestPath.java (modified) (1 diff)
- branches/routingservice/src/jp/co/orkney/restlet/geo/TravelingSalesPerson.java (modified) (4 diffs)
- branches/routingservice/src/jp/co/orkney/restlet/util/Configuration.java (modified) (16 diffs)
- branches/routingservice/src/jp/co/orkney/restlet/util/DatabaseConnection.java (modified) (8 diffs)
- branches/routingservice/src/jp/co/orkney/restlet/util/IOHelper.java (modified) (8 diffs)
- branches/routingservice/src/jp/co/orkney/restlet/WebRouting.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/routingservice/.classpath
r94 r107 12 12 <classpathentry kind="lib" path="/home/matthieu/workspace/pgRouting_Webservice/lib/org.simpleframework.jar"/> 13 13 <classpathentry kind="lib" path="/home/matthieu/workspace/pgRouting_Webservice/lib/postgresql-8.2-506.jdbc4.jar"/> 14 <classpathentry kind="lib" path="/home/matthieu/workspace/pgRouting_Webservice/lib/com.noelios.restlet.ext.jdbc_3.0.jar"/> 15 <classpathentry kind="lib" path="/home/matthieu/workspace/pgRouting_Webservice/lib/commons-pool-1.4.jar"/> 16 <classpathentry kind="lib" path="/home/matthieu/workspace/pgRouting_Webservice/lib/commons-dbcp-1.2.2.jar"/> 14 17 <classpathentry kind="output" path="bin"/> 15 18 </classpath> branches/routingservice/src/jp/co/orkney/restlet/geo/ClosestEdge.java
r102 r107 29 29 import org.antlr.stringtemplate.StringTemplate; 30 30 import org.json.JSONException; 31 32 import com.noelios.restlet.ext.jdbc.RowSetRepresentation; 31 33 32 34 /** … … 123 125 */ 124 126 public void start() throws SQLException, JSONException 125 { 127 { 126 128 databaseConnection = new DatabaseConnection(configuration); 129 130 StringTemplate query = ioHelper.getQuery(); 131 float bboxSize = Float.parseFloat(configuration.getService().getParameter("bbox").getValue()); 132 133 // Makes the SQL query 134 query.setAttribute("sonPx", point.getX()); 135 query.setAttribute("sonPy", point.getY()); 136 query.setAttribute("sonPxM", point.getX(-bboxSize)); 137 query.setAttribute("sonPxP", point.getX(bboxSize)); 138 query.setAttribute("sonPyM", point.getY(-bboxSize)); 139 query.setAttribute("sonPyP", point.getY(bboxSize)); 140 query.setAttribute("sridProvider", configuration.getService().getDataProjection()); 141 query.setAttribute("sridIn", configuration.getService().getParameter("sridInput").getValue()); 142 query.setAttribute("sridOut", configuration.getService().getParameter("sridOutput").getValue()); 143 144 ResultSet rs = ((RowSetRepresentation)databaseConnection.makeRequest(query.toString()).getEntity()).getJdbcResult().getResultSet(); 145 146 147 /*databaseConnection = new DatabaseConnection(configuration); 127 148 databaseConnection.start(); 128 149 … … 145 166 //System.out.println(query.toString()); 146 167 log.write(query.toString(),1); 147 ResultSet rs = databaseConnection.getResult(query.toString()); 148 168 ResultSet rs = databaseConnection.getResult(query.toString());*/ 169 149 170 // Converts the SQL Result in Geojson 150 171 if (configuration.getFormatOut().getName().equals("geojson")) … … 183 204 } 184 205 185 databaseConnection.close();186 } 206 /*databaseConnection.close(); 207 }*/ 187 208 } 188 209 } branches/routingservice/src/jp/co/orkney/restlet/geo/DrivingDistance.java
r102 r107 180 180 query.setAttribute("sridOut", configuration.getService().getParameter("sridOutput").getValue()); 181 181 182 System.out.println(query.toString());182 //System.out.println(query.toString()); 183 183 log.write(query.toString(),1); 184 184 ResultSet rs = databaseConnection.getResult(query.toString()); branches/routingservice/src/jp/co/orkney/restlet/geo/ShortestPath.java
r102 r107 148 148 query.setAttribute("sridOut", configuration.getService().getParameter("sridOutput").getValue()); 149 149 150 System.out.println(query.toString());150 //System.out.println(query.toString()); 151 151 log.write(query.toString(),1); 152 152 ResultSet rs = databaseConnection.getResult(query.toString()); branches/routingservice/src/jp/co/orkney/restlet/geo/TravelingSalesPerson.java
r102 r107 89 89 } 90 90 } 91 / *// extract method for Gml format91 // extract method for Gml format 92 92 else if (this.configuration.getFormatIn().getName().equals("gml")) 93 93 { 94 }94 } 95 95 // extract method for lonlat format 96 96 else if (this.configuration.getFormatIn().getName().equals("lonlat")) … … 104 104 else if (this.configuration.getFormatIn().getName().equals("kml")) 105 105 { 106 startPoint = ioHelper.extractKMLPxPy(this.configuration.getService().getParameter("point_start").getValue()); 107 endPoint = ioHelper.extractKMLPxPy(this.configuration.getService().getParameter("point_end").getValue()); 108 }*/ 106 } 109 107 } 110 108 … … 146 144 query.setAttribute("sridOut", configuration.getService().getParameter("sridOutput").getValue()); 147 145 148 System.out.println(query.toString());146 //System.out.println(query.toString()); 149 147 log.write(query.toString(),1); 150 148 ResultSet rs = databaseConnection.getResult(query.toString()); … … 155 153 result = ioHelper.travelingSalesPersonGEOJSONResult(rs); 156 154 } 157 / *// Converts the SQL Result in HTML155 // Converts the SQL Result in HTML 158 156 else if (configuration.getFormatOut().getName().equals("html")) 159 157 { 160 result = ioHelper. shortestPathHTMLResult(rs, startPoint, endPoint);158 result = ioHelper.travelingSalesPersonHTMLResult(rs, startPoint); 161 159 } 162 160 // Converts the SQL Result in XML 163 161 else if (configuration.getFormatOut().getName().equals("xml")) 164 162 { 165 result = ioHelper. shortestPathXMLResult(rs);163 result = ioHelper.travelingSalesPersonXMLResult(rs); 166 164 } 167 165 // Converts the SQL Result in GML 168 166 else if (configuration.getFormatOut().getName().equals("gml")) 169 167 { 170 result = ioHelper. shortestPathGMLResult(rs);168 result = ioHelper.travelingSalesPersonGMLResult(rs); 171 169 } 172 170 // Converts the SQL Result in WKT 173 171 else if (configuration.getFormatOut().getName().equals("wkt")) 174 172 { 175 result = ioHelper. shortestPathWKTResult(rs);173 result = ioHelper.travelingSalesPersonWKTResult(rs); 176 174 } 177 175 // Converts the SQL Result in KML 178 176 else if (configuration.getFormatOut().getName().equals("kml")) 179 177 { 180 result = ioHelper. shortestPathKMLResult(rs);181 } */178 result = ioHelper.travelingSalesPersonKMLResult(rs); 179 } 182 180 databaseConnection.close(); 183 181 } branches/routingservice/src/jp/co/orkney/restlet/util/Configuration.java
r96 r107 28 28 import org.jdom.JDOMException; 29 29 import org.jdom.input.SAXBuilder; 30 import org.jdom.output.XMLOutputter; 30 31 31 32 /** … … 58 59 { 59 60 private String urlConfigurationFile = "./configuration.xml"; 61 private String urlXMLTemplateQuery = "./pool.xml"; 62 private String commandCapabilities = "capabilities"; 60 63 61 64 private String port; … … 65 68 private String urlCss; 66 69 public Vector<Provider> providers; 70 private int askCapabilities; // -1 by default, 0 host capabilities, 1 71 // provider "x" capabilities 67 72 68 73 private Provider provider; … … 70 75 private Format formatIn; 71 76 private Format formatOut; 72 77 73 78 private int iProvider = 0; 74 79 private int iService = 0; … … 88 93 localhost = ""; 89 94 urlCss = ""; 95 askCapabilities = -1; 90 96 providers = new Vector<Provider>(); 91 97 provider = new Provider(); … … 122 128 localhost = root.getChild("localhost").getText(); 123 129 urlCss = root.getChild("css").getText(); 124 130 125 131 List<Element> listProviders = root.getChild("providers").getChildren("provider"); 126 Iterator<Element> i Provider = listProviders.iterator();127 128 while (i Provider.hasNext())132 Iterator<Element> itProvider = listProviders.iterator(); 133 134 while (itProvider.hasNext()) 129 135 { 130 136 Provider provider = new Provider(); 131 Element currentProvider = (Element) i Provider.next();137 Element currentProvider = (Element) itProvider.next(); 132 138 provider.setName(currentProvider.getAttributeValue("name")); 133 currentProvider.getChild("services").getChildren("service");134 139 List<Element> listServices = currentProvider.getChild("services").getChildren("service"); 135 Iterator<Element> i Service = listServices.iterator();140 Iterator<Element> itService = listServices.iterator(); 136 141 Vector<Service> services = new Vector<Service>(); 137 142 138 while (i Service.hasNext())143 while (itService.hasNext()) 139 144 { 140 145 Service service = new Service(); 141 Element currentService = i Service.next();146 Element currentService = itService.next(); 142 147 service.setName(currentService.getAttributeValue("name")); 143 148 service.setEnable(new Boolean(currentService.getAttributeValue("enable"))); 144 service.setConfigurationConnexion(new DatabaseConfiguration(currentService.getChild("connection") 145 .getAttributeValue("driver"), currentService.getChild("connection").getChildText("url"), currentService.getChild(146 "connection").getChildText("user"),currentService.getChild("connection").getChildText("password")));149 service.setConfigurationConnexion(new DatabaseConfiguration(currentService.getChild("connection").getAttributeValue("driver"), 150 currentService.getChild("connection").getChildText("url"), currentService.getChild("connection").getChildText("user"), 151 currentService.getChild("connection").getChildText("password"))); 147 152 service.setDataProjection(currentService.getChild("projection").getAttributeValue("srid")); 148 153 149 154 List<Element> listSQL = currentService.getChild("sql").getChildren("query"); 150 Iterator<Element> i Query = listSQL.iterator();151 while (i Query.hasNext())155 Iterator<Element> itQuery = listSQL.iterator(); 156 while (itQuery.hasNext()) 152 157 { 153 Element currentQuery = i Query.next();158 Element currentQuery = itQuery.next(); 154 159 if (currentQuery.getAttributeValue("transformProjectionIn").equals("false")) 155 160 { … … 187 192 188 193 List<Element> listParameters = currentService.getChild("parameters").getChildren("parameter"); 189 Iterator<Element> i Parametre = listParameters.iterator();194 Iterator<Element> itParametre = listParameters.iterator(); 190 195 Vector<Parameter> parameters = new Vector<Parameter>(); 191 196 192 while (i Parametre.hasNext())197 while (itParametre.hasNext()) 193 198 { 194 199 Parameter parameter = new Parameter(); 195 Element currentParameter = i Parametre.next();200 Element currentParameter = itParametre.next(); 196 201 parameter.setName(currentParameter.getAttributeValue("name")); 197 202 parameter.setType(currentParameter.getAttributeValue("type")); … … 205 210 206 211 List<Element> listFormat = currentService.getChild("formats").getChildren("format"); 207 Iterator<Element> i Format = listFormat.iterator();212 Iterator<Element> itFormat = listFormat.iterator(); 208 213 Vector<Format> formats = new Vector<Format>(); 209 214 210 while (i Format.hasNext())215 while (itFormat.hasNext()) 211 216 { 212 217 Format format = new Format(); 213 Element currentFormat = i Format.next();218 Element currentFormat = itFormat.next(); 214 219 format.setName(currentFormat.getAttributeValue("name")); 215 220 format.setSrid(currentFormat.getAttributeValue("srid")); … … 242 247 String urlSplit[] = url.split("/"); 243 248 249 if (urlSplit[0].equals(commandCapabilities)) 250 { 251 askCapabilities = 0; 252 return; 253 } 244 254 if ((iProvider = isProvider(urlSplit[0])) != -1) 245 255 { 246 256 provider.setName(providers.get(iProvider).getName()); 257 if (urlSplit[1].equals(commandCapabilities)) 258 { 259 askCapabilities = 1; 260 return; 261 } 247 262 } 248 263 else … … 252 267 { 253 268 Service tmpService = providers.get(iProvider).getServices().get(iService); 254 service = new Service(tmpService.getName(),tmpService.getDataProjection(),tmpService.getSQL(),tmpService.isEnable(),tmpService.getParameters(),null,tmpService.getDatabaseConfiguration()); 269 service = new Service(tmpService.getName(), tmpService.getDataProjection(), tmpService.getSQL(), tmpService.isEnable(), tmpService 270 .getParameters(), null, tmpService.getDatabaseConfiguration()); 255 271 } 256 272 else … … 260 276 { 261 277 Format tmpFormat = providers.get(iProvider).getServices().get(iService).getFormats().get(iFormat); 262 formatIn = new Format(tmpFormat.getName(), tmpFormat.getSrid(),tmpFormat.isEnableInput(),tmpFormat.isEnableOutput());278 formatIn = new Format(tmpFormat.getName(), tmpFormat.getSrid(), tmpFormat.isEnableInput(), tmpFormat.isEnableOutput()); 263 279 } 264 280 else … … 268 284 { 269 285 Format tmpFormat = providers.get(iProvider).getServices().get(iService).getFormats().get(iFormat); 270 formatOut = new Format(tmpFormat.getName(), tmpFormat.getSrid(),tmpFormat.isEnableInput(),tmpFormat.isEnableOutput());271 if (formatOut.getSrid() != null && !formatOut.getSrid().equals(""))286 formatOut = new Format(tmpFormat.getName(), tmpFormat.getSrid(), tmpFormat.isEnableInput(), tmpFormat.isEnableOutput()); 287 if (formatOut.getSrid() != null && !formatOut.getSrid().equals("")) 272 288 { 273 289 service.getParameter("sridOutput").setValue(formatOut.getSrid()); … … 285 301 public Log createLog() 286 302 { 287 return new Log(urlLog, modeLog);303 return new Log(urlLog, modeLog); 288 304 } 289 305 … … 388 404 /** 389 405 * Gets the requested provider 406 * 390 407 * @return the requested provider 391 408 */ … … 397 414 /** 398 415 * Gets the requested service 416 * 399 417 * @return the requested service 400 418 */ … … 403 421 return service; 404 422 } 423 424 /** 425 * Gets the url of CSS file (for HTML output) 426 * 427 * @return the CSS File 428 */ 429 public String getCss() 430 { 431 return urlCss; 432 } 433 434 /** 435 * Gets the database configuration of the requested service 436 * 437 * @return the database configuration 438 */ 439 public DatabaseConfiguration getConfigurationConnexion() 440 { 441 return service.getDatabaseConfiguration(); 442 } 443 444 /** 445 * Gets the parameters of the requested service 446 * 447 * @return a vector<Parameter> 448 */ 449 public Vector<Parameter> getParameters() 450 { 451 return service.getParameters(); 452 } 453 454 /** 455 * Gets the requested input data format 456 * 457 * @return a format 458 */ 459 public Format getFormatIn() 460 { 461 return formatIn; 462 } 463 464 /** 465 * Gets the requested output data format 466 * 467 * @return a format 468 */ 469 public Format getFormatOut() 470 { 471 return formatOut; 472 } 473 474 public int askCapabilities() 475 { 476 return askCapabilities; 477 } 478 479 public String getCapabilities() 480 { 481 String res = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n"; 482 SAXBuilder sxb = new SAXBuilder(); 483 Document document = null; 484 try 485 { 486 document = sxb.build(new File(urlConfigurationFile)); 487 } 488 catch (JDOMException e) 489 { 490 e.printStackTrace(); 491 } 492 catch (IOException e) 493 { 494 e.printStackTrace(); 495 } 496 Element root = document.getRootElement(); 497 List<Element> listProviders = root.getChild("providers").getChildren("provider"); 498 Iterator<Element> itProvider = listProviders.iterator(); 499 500 while (itProvider.hasNext()) 501 { 502 Element currentProvider = (Element) itProvider.next(); 503 List<Element> listServices = currentProvider.getChild("services").getChildren("service"); 504 Iterator<Element> itService = listServices.iterator(); 505 while (itService.hasNext()) 506 { 507 Element currentService = itService.next(); 508 currentService.removeChild("connection"); 509 currentService.removeChild("sql"); 510 } 511 } 512 513 switch (askCapabilities) { 514 case 0: 515 res += new XMLOutputter().outputString(root.getChild("providers")); 516 break; 517 case 1: 518 res += new XMLOutputter().outputString(listProviders.get(iProvider)); 519 break; 520 } 521 return res; 522 } 405 523 406 /** 407 * Gets the url of CSS file (for HTML output) 408 * @return the CSS File 409 */ 410 public String getCss() 411 { 412 return urlCss; 413 } 414 415 /** 416 * Gets the database configuration of the requested service 417 * @return the database configuration 418 */ 419 public DatabaseConfiguration getConfigurationConnexion() 420 { 421 return service.getDatabaseConfiguration(); 422 } 423 424 /** 425 * Gets the parameters of the requested service 426 * @return a vector<Parameter> 427 */ 428 public Vector<Parameter> getParameters() 429 { 430 return service.getParameters(); 431 } 432 433 /** 434 * Gets the requested input data format 435 * @return a format 436 */ 437 public Format getFormatIn() 438 { 439 return formatIn; 440 } 441 442 /** 443 * Gets the requested output data format 444 * @return a format 445 */ 446 public Format getFormatOut() 447 { 448 return formatOut; 524 public String getUrlXMLTemplateQuery () 525 { 526 return urlXMLTemplateQuery; 449 527 } 450 528 } branches/routingservice/src/jp/co/orkney/restlet/util/DatabaseConnection.java
r96 r107 18 18 package jp.co.orkney.restlet.util; 19 19 20 import java.io.File; 20 21 import java.sql.Connection; 21 22 import java.sql.DriverManager; … … 23 24 import java.sql.SQLException; 24 25 import java.sql.Statement; 26 27 import org.antlr.stringtemplate.StringTemplate; 28 import org.restlet.Client; 29 import org.restlet.data.MediaType; 30 import org.restlet.data.Protocol; 31 import org.restlet.data.Request; 32 import org.restlet.data.Response; 33 import org.restlet.resource.Representation; 34 import org.restlet.resource.StringRepresentation; 35 36 import com.noelios.restlet.ext.jdbc.JdbcClientHelper; 25 37 26 38 import jp.co.orkney.restlet.util.Log; … … 51 63 private Statement statement; 52 64 private boolean start; 65 private IOHelper ioHelper; 53 66 private Log log; 54 67 private DatabaseConfiguration databaseConfiguration; 68 private Configuration configuration; 55 69 56 70 /** … … 66 80 public DatabaseConnection(Configuration configuration) 67 81 { 82 this.configuration = configuration; 68 83 start = false; 69 84 log = configuration.createLog(); 70 85 databaseConfiguration = configuration.getService().getDatabaseConfiguration(); 86 ioHelper = new IOHelper(configuration); 71 87 } 72 88 … … 76 92 public void start() 77 93 { 78 log.write("Database connection started", 1);94 log.write("Database connection started", 1); 79 95 try 80 96 { … … 89 105 { 90 106 start = false; 91 log.write("--ERROR: unkown driver", 0);107 log.write("--ERROR: unkown driver", 0); 92 108 } 93 109 catch (SQLException e) 94 110 { 95 111 start = false; 96 log.write("--ERROR: Can not connect to the database", 0);112 log.write("--ERROR: Can not connect to the database", 0); 97 113 } 98 114 start = true; … … 116 132 * @return This query's result 117 133 */ 118 public ResultSet getResult(String sql)134 public ResultSet getResult(String query) 119 135 { 120 136 try 121 137 { 122 return statement.executeQuery( sql);138 return statement.executeQuery(query); 123 139 } 124 140 catch (SQLException e1) 125 141 { 126 log.write("--ERROR: query execution failed", 0);142 log.write("--ERROR: query execution failed", 0); 127 143 log.getStackTrace(e1); 128 144 } … … 140 156 statement.close(); 141 157 connection.close(); 142 log.write("Database connection finished", 1);158 log.write("Database connection finished", 1); 143 159 } 144 160 catch (SQLException e) 145 161 { 146 log.write("--ERROR: Can not close the connection", 0);162 log.write("--ERROR: Can not close the connection", 0); 147 163 } 148 164 } 165 166 public Response makeRequest(String query) 167 { 168 StringTemplate queryTemplate = new StringTemplate(ioHelper.loadFile(new File(configuration.getUrlXMLTemplateQuery()))); 149 169 170 // Makes the SQL query 171 queryTemplate.setAttribute("user",databaseConfiguration.getUser()); 172 queryTemplate.setAttribute("password", databaseConfiguration.getPassword()); 173 queryTemplate.setAttribute("query", query); 174 175 Client client = new Client(Protocol.JDBC); 176 JdbcClientHelper helper = new JdbcClientHelper(client); 177 try 178 { 179 Class.forName(databaseConfiguration.getDriver()); 180 } 181 catch (ClassNotFoundException e) 182 { 183 e.printStackTrace(); 184 } 185 System.out.println(queryTemplate.toString()); 186 Representation req = new StringRepresentation(queryTemplate.toString().replace("&", "&"),MediaType.TEXT_XML) ; 187 Request request = JdbcClientHelper.create("jdbc:postgresql://192.168.20.177:5432/geobase",req); 188 Response response = new Response(request); 189 helper.handle(request, response); 190 return response; 191 } 150 192 } branches/routingservice/src/jp/co/orkney/restlet/util/IOHelper.java
r102 r107 18 18 package jp.co.orkney.restlet.util; 19 19 20 import java.io.BufferedInputStream; 21 import java.io.File; 22 import java.io.FileInputStream; 23 import java.io.IOException; 24 import java.io.StringWriter; 20 25 import java.math.BigDecimal; 21 26 import java.sql.ResultSet; … … 569 574 int i = 0; 570 575 result = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n"; 571 result += "<ro ad>\n";576 result += "<route>\n"; 572 577 while (resultSet != null && resultSet.next()) 573 578 { … … 582 587 i++; 583 588 } 584 result += "</ro ad>\n";589 result += "</route>\n"; 585 590 return result; 586 591 } … … 825 830 String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<kml xmlns=\"http://earth.google.com/kml/2.1\">" 826 831 + "<Document><name>WebRouting Service</name><Style id=\"PolyStyle\"><PolyStyle><color>7f0000ff</color><width>4</width>" 827 + "<fill>1</fill><outline>1</outline></PolyStyle></Style><Placemark>" 828 + "< description>No+description+available</description>" + "<name>Isoline</name><styleUrl>#PolyStyle</styleUrl>"832 + "<fill>1</fill><outline>1</outline></PolyStyle></Style><Placemark>" + "<description>No+description+available</description>" 833 + "<name>Isoline</name><styleUrl>#PolyStyle</styleUrl>" 829 834 + "<Polygon><extrude>1</extrude><altitudeMode>clampToGround</altitudeMode><outerBoundaryIs>" + "<LinearRing><coordinates>"; 830 835 … … 901 906 } 902 907 908 909 public String travelingSalesPersonHTMLResult(ResultSet resultSet, Point point) throws SQLException 910 { 911 int i = 0; 912 String result = "<html><head>" + "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + configuration.getCss() + "\" />" 913 + "</head><body><table class=\"table\"><tr>"; 914 915 result += "<td colspan=\"3\">The travel sale person result is: </td></tr>"; 916 while (resultSet != null && resultSet.next()) 917 { 918 result += "<tr class=\"line\"><td rowspan=\"2\" class=\"case_id\">" + i + "</td><td>Gid:</td><td>" + +resultSet.getInt("gid") 919 + "</td></tr>"; 920 result += "<tr class=\"line\"><td>Geom:</td><td class=\"case_desc\">" + resultSet.getString("wkt") + "</td></tr>"; 921 i++; 922 } 923 if (resultSet == null) 924 { 925 result += "<tr class=\"line\"><td rowspan=\"2\" class=\"case_id\">" + i + "</td><td>Gid:</td><td>0</td></tr>"; 926 result += "<tr class=\"line\"><td>Geom:</td><td class=\"case_desc\">unkown_road</td></tr>"; 927 } 928 result += "</body></html>"; 929 return result; 930 } 931 932 public String travelingSalesPersonXMLResult(ResultSet resultSet) throws SQLException 933 { 934 String result = ""; 935 int i = 0; 936 result = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n"; 937 result += "<route>\n"; 938 while (resultSet != null && resultSet.next()) 939 { 940 result += "<edge id=\"" + i + "\">\n"; 941 result += "\t<gid>" + resultSet.getInt("gid") + "</gid>\n"; 942 result += "\t<name>" + null + "</name>\n"; 943 944 String wkt = resultSet.getString("wkt"); 945 wkt = wkt.split("MULTILINESTRING\\(\\(")[1].split("\\)\\)")[0]; 946 result += "\t<wkt>" + wkt + "</wkt>\n"; 947 result += "</edge>\n"; 948 i++; 949 } 950 result += "</route>\n"; 951 return result; 952 } 953 903 954 public String travelingSalesPersonGEOJSONResult(ResultSet resultSet) throws SQLException, JSONException 904 955 { … … 953 1004 954 1005 result = joRes.toString(); 1006 return result; 1007 } 1008 1009 public String travelingSalesPersonGMLResult(ResultSet resultSet) throws SQLException 1010 { 1011 String result = "<wfs:FeatureCollection xmlns:wfs=\"http://www.opengis.net/wfs\">"; 1012 int k = 0; 1013 1014 while (resultSet != null && resultSet.next()) 1015 { 1016 result += "<gml:featureMember xmlns:gml=\"http://www.opengis.net/gml\">" 1017 + "<feature:features xmlns:feature=\"http://mapserver.gis.umn.edu/mapserver\" " + "fid=\"id" + k + "\">" + "<feature:geometry>" 1018 + "<gml:MultiLineString>"; 1019 1020 String tmpSplit = resultSet.getString("wkt"); 1021 tmpSplit = tmpSplit.split("MULTILINESTRING\\(\\(")[1].split("\\)\\)")[0]; 1022 String wkt[] = tmpSplit.split("\\)\\("); 1023 for (int i = 0; i < wkt.length; i++) 1024 { 1025 result += "<gml:lineStringMember>" + "<gml:LineString>" + "<gml:coordinates decimal=\".\" cs=\",\" ts=\"+\">"; 1026 String wkt2[] = wkt[i].split(","); 1027 for (int j = 0; j < wkt2.length; j++) 1028 { 1029 result += new BigDecimal(wkt2[j].split(" ")[0]) + "," + new BigDecimal(wkt2[j].split(" ")[1]) + " "; 1030 } 1031 result += "</gml:coordinates>" + "</gml:LineString>" + "</gml:lineStringMember>"; 1032 } 1033 k++;
