Server.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /*
  3. * GetCapabilities
  4. * DescribeProcess
  5. * Execute
  6. */
  7. Lib::loadClass('Api_WpsV1_ServerBase');
  8. Lib::loadClass('Api_WfsException');
  9. Lib::loadClass('Api_WfsGeomTypeConverter');
  10. Lib::loadClass('Api_WfsNs');
  11. Lib::loadClass('Core_XmlWriter');
  12. Lib::loadClass('DBG');
  13. Lib::loadClass('Api_WpsV1_GetCapabilities');
  14. Lib::loadClass('Api_WpsV1_DescribeProcess');
  15. Lib::loadClass('Core_AclBase');
  16. Lib::loadClass('Type_ApiRequest');
  17. Lib::loadClass('Type_WpsProcess');
  18. Lib::loadClass('Api_WpsHelper');
  19. class Api_WpsV1_Server extends Api_WpsV1_ServerBase {
  20. public function run(Type_ApiRequest $request) {
  21. $document = '';
  22. if ('WPS' != V::geti('service', '', $request->query)) {
  23. throw new Api_WfsException("Only WPS Service is allowed");
  24. }
  25. $req = V::geti('request', '', $request->query);
  26. if (!empty($req)) {
  27. $methodName = "{$req}Action";
  28. if (!method_exists($this, $methodName)) {
  29. throw new Api_WfsException("Not Implemented " . htmlspecialchars($req), 501);
  30. }
  31. $this->DBG("WpsServer->{$methodName}() ...", __LINE__);
  32. $document = $this->$methodName($urlQuery);
  33. }
  34. else {
  35. $this->DBG("WpsServer->parseXMLRequest() ...", __LINE__);
  36. $document = $this->parseXMLRequest();
  37. header('Content-type: application/xml');
  38. echo '<?xml version="1.0" encoding="UTF-8"?>';
  39. echo $document; exit;// TODO: return $document;
  40. }
  41. IF(V::get('DBG','',$_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$document (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($document);echo'</pre>';}
  42. if ('raw' == V::get('outputFormat', '', $request->query)) {
  43. header('Content-type: text/plain; charset=utf-8');
  44. echo $document;
  45. } else {
  46. header('Content-type: application/xml');
  47. echo $document;
  48. }
  49. }
  50. public function parseXMLRequest() {
  51. $data = array();
  52. $reqContent = Request::getRequestBody();
  53. if (empty($reqContent)) {
  54. throw new Exception("Empty request");
  55. }
  56. $parserXml = xml_parser_create();
  57. xml_parser_set_option($parserXml, XML_OPTION_CASE_FOLDING, 0);
  58. xml_parser_set_option($parserXml, XML_OPTION_SKIP_WHITE, 1);
  59. if (0 == xml_parse_into_struct($parserXml, $reqContent, $tags)) {
  60. throw new Exception("Error parsing xml");
  61. }
  62. xml_parser_free($parserXml);
  63. if (empty($tags)) {
  64. throw new Exception("Empty structure from request");
  65. }
  66. $rootTagName = V::get('tag', '', $tags[0]);
  67. if ('Transaction' == $rootTagName) return $this->_parseTransactionXmlStruct($reqContent, $tags);
  68. throw new Api_WfsException("Not implemented '{$rootTagName}' #L." . __LINE__, 501);
  69. }
  70. function describeProcessAction() {
  71. $identifier = V::geti('identifier', '', $_REQUEST);
  72. if (empty($identifier)) throw new HttpException("Missing identifier", 400);
  73. if ('JTS:Aarea' === $identifier) return self::exampleDescribeProcess_JTS_Area();
  74. if ('vec:Feature' === $identifier) return self::exampleDescribeProcess_vec_Feature();
  75. $wpsServerUrl = $this->getBaseUri();
  76. $wpsProcess = Api_WpsHelper::getUserWpsProcess($identifier);
  77. if (!$wpsProcess) throw new Api_WfsException("Forbidden", 403);
  78. Api_WpsV1_DescribeProcess::sendDescribeProcessXml($wpsServerUrl, $wpsProcess);
  79. }
  80. static function exampleDescribeProcess_JTS_Area() {
  81. header('Content-type: application/xml; charset=utf-8');
  82. echo '<?xml version="1.0" encoding="UTF-8"?><wps:ProcessDescriptions xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en" service="WPS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd"><ProcessDescription wps:processVersion="1.0.0" statusSupported="true" storeSupported="true"><ows:Identifier>JTS:area</ows:Identifier><ows:Title>Area</ows:Title><ows:Abstract>Returns the area of a geometry, in the units of the geometry. Assumes a Cartesian plane, so this process is only recommended for non-geographic CRSes.</ows:Abstract><DataInputs><Input maxOccurs="1" minOccurs="1"><ows:Identifier>geom</ows:Identifier><ows:Title>geom</ows:Title><ows:Abstract>Input geometry</ows:Abstract><ComplexData><Default><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format></Default><Supported><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format><Format><MimeType>text/xml; subtype=gml/2.1.2</MimeType></Format><Format><MimeType>application/wkt</MimeType></Format><Format><MimeType>application/json</MimeType></Format><Format><MimeType>application/gml-3.1.1</MimeType></Format><Format><MimeType>application/gml-2.1.2</MimeType></Format></Supported></ComplexData></Input></DataInputs><ProcessOutputs><Output><ows:Identifier>result</ows:Identifier><ows:Title>result</ows:Title><LiteralOutput><ows:DataType>double</ows:DataType></LiteralOutput></Output></ProcessOutputs></ProcessDescription></wps:ProcessDescriptions>';
  83. exit;
  84. }
  85. static function exampleDescribeProcess_vec_Feature() {
  86. header('Content-type: application/xml; charset=utf-8');
  87. echo '<?xml version="1.0" encoding="UTF-8"?><wps:ProcessDescriptions xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en" service="WPS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd"><ProcessDescription wps:processVersion="1.0.0" statusSupported="true" storeSupported="true"><ows:Identifier>vec:Feature</ows:Identifier><ows:Title>Feature from Geometry</ows:Title><ows:Abstract>Converts a geometry into a feature collection.</ows:Abstract><DataInputs><Input maxOccurs="1" minOccurs="1"><ows:Identifier>geometry</ows:Identifier><ows:Title>geometry</ows:Title><ows:Abstract>Input geometry</ows:Abstract><ComplexData><Default><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format></Default><Supported><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format><Format><MimeType>text/xml; subtype=gml/2.1.2</MimeType></Format><Format><MimeType>application/wkt</MimeType></Format><Format><MimeType>application/json</MimeType></Format><Format><MimeType>application/gml-3.1.1</MimeType></Format><Format><MimeType>application/gml-2.1.2</MimeType></Format></Supported></ComplexData></Input><Input maxOccurs="1" minOccurs="1"><ows:Identifier>crs</ows:Identifier><ows:Title>crs</ows:Title><ows:Abstract>Coordinate reference system of the input geometry (if not provided in the geometry)</ows:Abstract><LiteralData><ows:AnyValue/></LiteralData></Input><Input maxOccurs="1" minOccurs="1"><ows:Identifier>typeName</ows:Identifier><ows:Title>typeName</ows:Title><ows:Abstract>Feauturetype name for the feature collection</ows:Abstract><LiteralData><ows:AnyValue/></LiteralData></Input></DataInputs><ProcessOutputs><Output><ows:Identifier>result</ows:Identifier><ows:Title>result</ows:Title><ComplexOutput><Default><Format><MimeType>text/xml; subtype=wfs-collection/1.0</MimeType></Format></Default><Supported><Format><MimeType>text/xml; subtype=wfs-collection/1.0</MimeType></Format><Format><MimeType>text/xml; subtype=wfs-collection/1.1</MimeType></Format><Format><MimeType>application/json</MimeType></Format><Format><MimeType>application/wfs-collection-1.0</MimeType></Format><Format><MimeType>application/wfs-collection-1.1</MimeType></Format><Format><MimeType>application/zip</MimeType></Format></Supported></ComplexOutput></Output></ProcessOutputs></ProcessDescription></wps:ProcessDescriptions>';
  88. exit;
  89. }
  90. public function getCapabilitiesAction() {
  91. $wpsServerUrl = $this->getBaseUri();
  92. $serviceTitle = "Web Processing Service";
  93. $serviceDescription = "Web Processing Service";
  94. $idDefaultDB = DB::getPDO()->getZasobId();
  95. $wpsProcessList = Api_WpsHelper::getUserWpsProcessList();
  96. switch (V::get('outputFormat', 'xml', $_GET)) {
  97. case 'csv': {
  98. Api_WpsV1_GetCapabilities::sendGetCapabilitiesCsv($wpsServerUrl, $serviceTitle, $serviceDescription, $wpsProcessList);
  99. } break;
  100. case 'xml': {
  101. Api_WpsV1_GetCapabilities::sendGetCapabilitiesXml($wpsServerUrl, $serviceTitle, $serviceDescription, $wpsProcessList);
  102. } break;
  103. default: throw new Api_WfsException("Not Implemented outputFormat", 501); // , null, 'NotImplemented', 'request');
  104. }
  105. exit;
  106. }
  107. }