WfsServerBase.php 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615
  1. <?php
  2. Lib::loadClass('Api_WfsException');
  3. Lib::loadClass('Api_WfsGeomTypeConverter');
  4. Lib::loadClass('Api_WfsNs');
  5. Lib::loadClass('Request');
  6. class Api_WfsServerBase {
  7. public $_usrAcl;
  8. public $_typeConverter;
  9. public $_apiBaseUri;
  10. protected $_logFile;
  11. public function __construct($usrAcl) {
  12. $this->_usrAcl = $usrAcl;
  13. $this->_typeConverter = new Api_WfsGeomTypeConverter();
  14. $this->_apiBaseUri = '';
  15. }
  16. public function setBaseUri($uri) {
  17. $this->_apiBaseUri = $uri;
  18. }
  19. public function getBaseUri() {// TODO: RMME
  20. return $this->_apiBaseUri;
  21. }
  22. public function isAllowedFeatureType($nsPrefix, $type) {
  23. if ('p5_' != substr($nsPrefix, 0, 3)) return false;
  24. if ('p5_default_db' == $nsPrefix) {
  25. $typeName = "p5_default_db:{$type}";
  26. try {
  27. $acl = $this->getAclFromTypeName($typeName);
  28. } catch (Exception $e) {
  29. return false;
  30. }
  31. if ($acl) {
  32. return true;
  33. }
  34. } else if ('p5_objects' == $nsPrefix) {
  35. // TODO: generate class name like in: UserAcl->getObjectAcl($sourceName = $nsPrefix, $objName = $type)
  36. $objClassName = "Schema_{$type}StorageAcl";
  37. if (Lib::tryLoadClass($objClassName)) return true;
  38. }
  39. return false;
  40. }
  41. /**
  42. * @param string $typeName - 'p5_default_db:TEST_PERMS'
  43. */
  44. public function getAclFromTypeName($typeName) {
  45. $typeEx = explode(':', $typeName);
  46. if (2 != count($typeEx)) throw new Api_WfsException("Could not get acl for '{$typeName}' - syntax error");
  47. if ('p5_' != substr($typeEx[0], 0, 3)) throw new Api_WfsException("Could not get acl for '{$typeName}' - prefix error");
  48. $sourceName = substr($typeEx[0], 3);
  49. $objName = $typeEx[1];
  50. $acl = $this->_usrAcl->getObjectAcl($sourceName, $objName);
  51. if (!$acl) throw new Api_WfsException("Could not get acl for '{$typeName}'");
  52. $forceTblAclInit = 0;//('1' == V::get('_force', '', $_GET));
  53. $acl->init($forceTblAclInit);
  54. return $acl;
  55. }
  56. /**
  57. * @param $_GET [ , POST Body - XML file ]
  58. * @return array $args
  59. * TODO: get $acl and check more restrictions
  60. */
  61. public function parseGetFeatureArgsFromRequest() {
  62. $rawArgs = $_GET;// $_REQUEST; ($_POST values not allowed, only xml in post body)
  63. $args = array();
  64. $args['xsd:type'] = null;// @from: TYPENAME, typeName (typename)
  65. $args['typePrefix'] = null;// @from: TYPENAME, typeName (typename)
  66. $args['typeName'] = null;// @from: TYPENAME, typeName (typename)
  67. $args['srsname'] = null;// @from: SRSNAME (srsname)
  68. $args['limit'] = 0;// @from: MAXFEATURES, maxFeatures, COUNT (maxfeatures, count)
  69. $args['offset'] = 0;// @from: startIndex (startindex, count)
  70. $args['ogc:filter'] = null;// @from: FILTER, Filter (filter)
  71. $args['sortBy'] = null;// @from: sortBy (sortby)
  72. $args['wfs:propertyName'] = null;// @from: propertyName (propertyname)
  73. $args['filterFields'] = array();// array of field names to show - @from: propertyName
  74. $args['resultType'] = null;// @from: resultType (resulttype)
  75. $args['bbox'] = null;// @from: BBOX (bbox)
  76. $args['wfs:featureID'] = null;// @from: featureID, featureId (featureid)
  77. $args['primaryKey'] = null;// primaryKey type - @from: featureID
  78. $lowerArgs = array(); foreach ($rawArgs as $name => $value) $lowerArgs[ strtolower($name) ] = trim($value);
  79. $args['xsd:type'] = V::get('typename', '', $lowerArgs);
  80. $exType = explode(':', $args['xsd:type']);
  81. if (count($exType) != 2) throw new HttpException("Wrong param TYPENAME", 400);
  82. $args['typePrefix'] = $exType[0];
  83. $args['typeName'] = $exType[1];
  84. $args['srsname'] = V::get('SRSNAME', '', $lowerArgs);// eg. EPSG:4326
  85. $args['limit'] = V::get('maxfeatures', $args['limit'], $lowerArgs, 'int');
  86. $args['limit'] = V::get('count', $args['limit'], $lowerArgs, 'int');
  87. if ($args['limit'] <= 0) $args['limit'] = 10000;// default limit
  88. $args['offset'] = V::get('startindex', 0, $lowerArgs, 'int');
  89. $args['ogc:filter'] = urldecode(V::get('filter', '', $lowerArgs));
  90. if (empty($args['ogc:filter'])) {// read ogc:Filter from POST body if not defined in GET
  91. $reqBody = Request::getRequestBody();
  92. if (!empty($reqBody)) {
  93. $args['ogc:filter'] = $this->convertOgcFilterFromRequestBody($reqBody);
  94. if (empty($args['ogc:filter'])) throw new Api_WfsException("Error Processing ogc:Filter", 501);
  95. }
  96. }
  97. $args['sortBy'] = V::get('sortby', '', $lowerArgs);// TODO: split to array of array(fieldName, (asc | desc))
  98. $args['wfs:propertyName'] = trim(V::get('propertyname', '', $lowerArgs));// TODO: fields to show - split by ','
  99. if (strlen($args['wfs:propertyName']) > 0) {
  100. $args['filterFields'] = array();
  101. $exFields = explode(',', $args['wfs:propertyName']);
  102. foreach ($exFields as $fieldName) {
  103. $fieldName = trim($fieldName);
  104. if (!empty($fieldName)) $args['filterFields'][] = $fieldName;
  105. }
  106. }
  107. $args['resultType'] = V::get('resulttype', '', $lowerArgs);
  108. $args['bbox'] = V::get('bbox', '', $lowerArgs);
  109. if (!empty($args['bbox'])) {
  110. // BBOX may have EPSG at then end - example: ",EPSG:4326"
  111. if (!preg_match("/^\d+(.\d+)?,\d+(.\d+)?,\d+(.\d+)?,\d+(.\d+)?(\,EPSG:\d+)?$/", $args['bbox'], $matches)) throw new Exception("Wrong param BBOX");
  112. if (preg_match("/\,EPSG:\d+$/", $args['bbox'], $matches)) {
  113. $args['bbox'] = substr($args['bbox'], 0, strlen($args['bbox']) - strlen($matches[0]));
  114. }
  115. if (!preg_match("/^\d+(.\d+)?,\d+(.\d+)?,\d+(.\d+)?,\d+(.\d+)?$/", $args['bbox'], $matches)) throw new Exception("Illegal BBOX format");
  116. $searchParams['f_the_geom'] = "BBOX:{$args['bbox']}";
  117. }
  118. $args['wfs:featureID'] = V::get('featureid', null, $lowerArgs);// TODO: allow multiply feature id (csv)
  119. if ($args['wfs:featureID']) {
  120. $dotPos = strpos($args['wfs:featureID'], '.');
  121. if (!$dotPos) throw new Exception("Wrong param fetureID");
  122. if ($args['typeName'] != substr($args['wfs:featureID'], 0, $dotPos)) throw new Exception("Wrong typeName in param fetureID");
  123. $args['primaryKey'] = substr($args['wfs:featureID'], $dotPos + 1);
  124. }
  125. if(DBG::isActive() && V::get('DBG', 0, $_GET)){ echo "\$lowerArgs:";print_r($lowerArgs); }
  126. if(DBG::isActive() && V::get('DBG', 0, $_GET)){ echo "\$args:";print_r($args); }
  127. return $args;
  128. }
  129. public function _getCapabilities($wfsServerUrl, $serviceTitle, $serviceDescription) {
  130. echo '<?xml version="1.0" encoding="UTF-8"?>';
  131. ?>
  132. <WFS_Capabilities
  133. xmlns="http://www.opengis.net/wfs"
  134. xmlns:ogc="http://www.opengis.net/ogc"
  135. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  136. <?= $this->_printXmlNamespaceList(); ?>
  137. <?= $this->_getXmlSchemaLocation(); ?>
  138. version="1.0.0">
  139. <Service>
  140. <Name>WFS</Name>
  141. <Title><?= $serviceTitle; ?></Title>
  142. <Abstract><?= $serviceDescription; ?></Abstract>
  143. <Keywords>WFS, WMS</Keywords>
  144. <OnlineResource><?= $wfsServerUrl; ?></OnlineResource>
  145. <Fees>NONE</Fees>
  146. <AccessConstraints>NONE</AccessConstraints>
  147. </Service>
  148. <Capability>
  149. <Request>
  150. <?php $this->_printGetCapabilitiesXml($wfsServerUrl); ?>
  151. <?php $this->_printDescribeFeatureTypeXml($wfsServerUrl); ?>
  152. <?php $this->_printGetFeatureXml($wfsServerUrl); ?>
  153. <?php $this->_printTransactionXml($wfsServerUrl); ?>
  154. <?php $this->_printLockFeatureXml($wfsServerUrl); ?>
  155. <?php $this->_printGetFeatureWithLockXml($wfsServerUrl); ?>
  156. </Request>
  157. </Capability>
  158. <FeatureTypeList>
  159. <Operations>
  160. <Query />
  161. <Insert />
  162. <Update />
  163. <Delete />
  164. <Lock />
  165. </Operations>
  166. <?php $this->_printFeatureTypeListXml(); ?>
  167. </FeatureTypeList>
  168. <ogc:Filter_Capabilities>
  169. <ogc:Spatial_Capabilities>
  170. <ogc:Spatial_Operators>
  171. <ogc:Disjoint />
  172. <ogc:Equals />
  173. <ogc:DWithin />
  174. <ogc:Beyond />
  175. <ogc:Intersect />
  176. <ogc:Touches />
  177. <ogc:Crosses />
  178. <ogc:Within />
  179. <ogc:Contains />
  180. <ogc:Overlaps />
  181. <ogc:BBOX />
  182. </ogc:Spatial_Operators>
  183. </ogc:Spatial_Capabilities>
  184. <ogc:Scalar_Capabilities>
  185. <ogc:Logical_Operators />
  186. <ogc:Comparison_Operators>
  187. <ogc:Simple_Comparisons />
  188. <ogc:Between />
  189. <ogc:Like />
  190. <ogc:NullCheck />
  191. </ogc:Comparison_Operators>
  192. <ogc:Arithmetic_Operators>
  193. <ogc:Simple_Arithmetic />
  194. <ogc:Functions>
  195. <ogc:Function_Names>
  196. <ogc:Function_Name nArgs="1">abs</ogc:Function_Name>
  197. <ogc:Function_Name nArgs="1">abs_2</ogc:Function_Name>
  198. <ogc:Function_Name nArgs="1">abs_3</ogc:Function_Name>
  199. <ogc:Function_Name nArgs="1">abs_4</ogc:Function_Name>
  200. <ogc:Function_Name nArgs="1">acos</ogc:Function_Name>
  201. <ogc:Function_Name nArgs="2">AddCoverages</ogc:Function_Name>
  202. <ogc:Function_Name nArgs="4">Aggregate</ogc:Function_Name>
  203. <ogc:Function_Name nArgs="1">Area</ogc:Function_Name>
  204. <ogc:Function_Name nArgs="1">area2</ogc:Function_Name>
  205. <ogc:Function_Name nArgs="3">AreaGrid</ogc:Function_Name>
  206. <ogc:Function_Name nArgs="1">asin</ogc:Function_Name>
  207. <ogc:Function_Name nArgs="1">atan</ogc:Function_Name>
  208. <ogc:Function_Name nArgs="2">atan2</ogc:Function_Name>
  209. <ogc:Function_Name nArgs="14">BarnesSurface</ogc:Function_Name>
  210. <ogc:Function_Name nArgs="3">between</ogc:Function_Name>
  211. <ogc:Function_Name nArgs="1">boundary</ogc:Function_Name>
  212. <ogc:Function_Name nArgs="1">boundaryDimension</ogc:Function_Name>
  213. <ogc:Function_Name nArgs="1">Bounds</ogc:Function_Name>
  214. <ogc:Function_Name nArgs="2">buffer</ogc:Function_Name>
  215. <ogc:Function_Name nArgs="3">BufferFeatureCollection</ogc:Function_Name>
  216. <ogc:Function_Name nArgs="3">bufferWithSegments</ogc:Function_Name>
  217. <ogc:Function_Name nArgs="7">Categorize</ogc:Function_Name>
  218. <ogc:Function_Name nArgs="1">ceil</ogc:Function_Name>
  219. <ogc:Function_Name nArgs="1">Centroid</ogc:Function_Name>
  220. <ogc:Function_Name nArgs="2">classify</ogc:Function_Name>
  221. <ogc:Function_Name nArgs="2">Clip</ogc:Function_Name>
  222. <ogc:Function_Name nArgs="1">CollectGeometries</ogc:Function_Name>
  223. <ogc:Function_Name nArgs="1">Collection_Average</ogc:Function_Name>
  224. <ogc:Function_Name nArgs="1">Collection_Bounds</ogc:Function_Name>
  225. <ogc:Function_Name nArgs="0">Collection_Count</ogc:Function_Name>
  226. <ogc:Function_Name nArgs="1">Collection_Max</ogc:Function_Name>
  227. <ogc:Function_Name nArgs="1">Collection_Median</ogc:Function_Name>
  228. <ogc:Function_Name nArgs="1">Collection_Min</ogc:Function_Name>
  229. <ogc:Function_Name nArgs="1">Collection_Sum</ogc:Function_Name>
  230. <ogc:Function_Name nArgs="1">Collection_Unique</ogc:Function_Name>
  231. <ogc:Function_Name nArgs="1">Concatenate</ogc:Function_Name>
  232. <ogc:Function_Name nArgs="2">contains</ogc:Function_Name>
  233. <ogc:Function_Name nArgs="7">Contour</ogc:Function_Name>
  234. <ogc:Function_Name nArgs="2">convert</ogc:Function_Name>
  235. <ogc:Function_Name nArgs="1">convexHull</ogc:Function_Name>
  236. <ogc:Function_Name nArgs="1">cos</ogc:Function_Name>
  237. <ogc:Function_Name nArgs="1">Count</ogc:Function_Name>
  238. <ogc:Function_Name nArgs="2">CropCoverage</ogc:Function_Name>
  239. <ogc:Function_Name nArgs="2">crosses</ogc:Function_Name>
  240. <ogc:Function_Name nArgs="2">dateFormat</ogc:Function_Name>
  241. <ogc:Function_Name nArgs="2">dateParse</ogc:Function_Name>
  242. <ogc:Function_Name nArgs="2">difference</ogc:Function_Name>
  243. <ogc:Function_Name nArgs="1">dimension</ogc:Function_Name>
  244. <ogc:Function_Name nArgs="2">disjoint</ogc:Function_Name>
  245. <ogc:Function_Name nArgs="2">disjoint3D</ogc:Function_Name>
  246. <ogc:Function_Name nArgs="2">distance</ogc:Function_Name>
  247. <ogc:Function_Name nArgs="2">distance3D</ogc:Function_Name>
  248. <ogc:Function_Name nArgs="1">double2bool</ogc:Function_Name>
  249. <ogc:Function_Name nArgs="1">endAngle</ogc:Function_Name>
  250. <ogc:Function_Name nArgs="1">endPoint</ogc:Function_Name>
  251. <ogc:Function_Name nArgs="1">env</ogc:Function_Name>
  252. <ogc:Function_Name nArgs="1">envelope</ogc:Function_Name>
  253. <ogc:Function_Name nArgs="2">EqualInterval</ogc:Function_Name>
  254. <ogc:Function_Name nArgs="2">equalsExact</ogc:Function_Name>
  255. <ogc:Function_Name nArgs="3">equalsExactTolerance</ogc:Function_Name>
  256. <ogc:Function_Name nArgs="2">equalTo</ogc:Function_Name>
  257. <ogc:Function_Name nArgs="1">exp</ogc:Function_Name>
  258. <ogc:Function_Name nArgs="1">exteriorRing</ogc:Function_Name>
  259. <ogc:Function_Name nArgs="3">Feature</ogc:Function_Name>
  260. <ogc:Function_Name nArgs="1">floor</ogc:Function_Name>
  261. <ogc:Function_Name nArgs="1">geometryType</ogc:Function_Name>
  262. <ogc:Function_Name nArgs="1">geomFromWKT</ogc:Function_Name>
  263. <ogc:Function_Name nArgs="1">geomLength</ogc:Function_Name>
  264. <ogc:Function_Name nArgs="2">getGeometryN</ogc:Function_Name>
  265. <ogc:Function_Name nArgs="1">getX</ogc:Function_Name>
  266. <ogc:Function_Name nArgs="1">getY</ogc:Function_Name>
  267. <ogc:Function_Name nArgs="1">getz</ogc:Function_Name>
  268. <ogc:Function_Name nArgs="2">greaterEqualThan</ogc:Function_Name>
  269. <ogc:Function_Name nArgs="2">greaterThan</ogc:Function_Name>
  270. <ogc:Function_Name nArgs="5">Grid</ogc:Function_Name>
  271. <ogc:Function_Name nArgs="7">Heatmap</ogc:Function_Name>
  272. <ogc:Function_Name nArgs="0">id</ogc:Function_Name>
  273. <ogc:Function_Name nArgs="2">IEEEremainder</ogc:Function_Name>
  274. <ogc:Function_Name nArgs="3">if_then_else</ogc:Function_Name>
  275. <ogc:Function_Name nArgs="11">in10</ogc:Function_Name>
  276. <ogc:Function_Name nArgs="3">in2</ogc:Function_Name>
  277. <ogc:Function_Name nArgs="4">in3</ogc:Function_Name>
  278. <ogc:Function_Name nArgs="5">in4</ogc:Function_Name>
  279. <ogc:Function_Name nArgs="6">in5</ogc:Function_Name>
  280. <ogc:Function_Name nArgs="7">in6</ogc:Function_Name>
  281. <ogc:Function_Name nArgs="8">in7</ogc:Function_Name>
  282. <ogc:Function_Name nArgs="9">in8</ogc:Function_Name>
  283. <ogc:Function_Name nArgs="10">in9</ogc:Function_Name>
  284. <ogc:Function_Name nArgs="2">InclusionFeatureCollection</ogc:Function_Name>
  285. <ogc:Function_Name nArgs="1">int2bbool</ogc:Function_Name>
  286. <ogc:Function_Name nArgs="1">int2ddouble</ogc:Function_Name>
  287. <ogc:Function_Name nArgs="1">interiorPoint</ogc:Function_Name>
  288. <ogc:Function_Name nArgs="2">interiorRingN</ogc:Function_Name>
  289. <ogc:Function_Name nArgs="3">Interpolate</ogc:Function_Name>
  290. <ogc:Function_Name nArgs="2">intersection</ogc:Function_Name>
  291. <ogc:Function_Name nArgs="7">IntersectionFeatureCollection</ogc:Function_Name>
  292. <ogc:Function_Name nArgs="2">intersects</ogc:Function_Name>
  293. <ogc:Function_Name nArgs="2">intersects3D</ogc:Function_Name>
  294. <ogc:Function_Name nArgs="1">isClosed</ogc:Function_Name>
  295. <ogc:Function_Name nArgs="0">isCoverage</ogc:Function_Name>
  296. <ogc:Function_Name nArgs="1">isEmpty</ogc:Function_Name>
  297. <ogc:Function_Name nArgs="2">isLike</ogc:Function_Name>
  298. <ogc:Function_Name nArgs="1">isNull</ogc:Function_Name>
  299. <ogc:Function_Name nArgs="2">isometric</ogc:Function_Name>
  300. <ogc:Function_Name nArgs="1">isRing</ogc:Function_Name>
  301. <ogc:Function_Name nArgs="1">isSimple</ogc:Function_Name>
  302. <ogc:Function_Name nArgs="1">isValid</ogc:Function_Name>
  303. <ogc:Function_Name nArgs="3">isWithinDistance</ogc:Function_Name>
  304. <ogc:Function_Name nArgs="3">isWithinDistance3D</ogc:Function_Name>
  305. <ogc:Function_Name nArgs="2">Jenks</ogc:Function_Name>
  306. <ogc:Function_Name nArgs="1">length</ogc:Function_Name>
  307. <ogc:Function_Name nArgs="2">lessEqualThan</ogc:Function_Name>
  308. <ogc:Function_Name nArgs="2">lessThan</ogc:Function_Name>
  309. <ogc:Function_Name nArgs="1">list</ogc:Function_Name>
  310. <ogc:Function_Name nArgs="1">log</ogc:Function_Name>
  311. <ogc:Function_Name nArgs="4">LRSGeocode</ogc:Function_Name>
  312. <ogc:Function_Name nArgs="5">LRSMeasure</ogc:Function_Name>
  313. <ogc:Function_Name nArgs="5">LRSSegment</ogc:Function_Name>
  314. <ogc:Function_Name nArgs="2">max</ogc:Function_Name>
  315. <ogc:Function_Name nArgs="2">max_2</ogc:Function_Name>
  316. <ogc:Function_Name nArgs="2">max_3</ogc:Function_Name>
  317. <ogc:Function_Name nArgs="2">max_4</ogc:Function_Name>
  318. <ogc:Function_Name nArgs="2">min</ogc:Function_Name>
  319. <ogc:Function_Name nArgs="2">min_2</ogc:Function_Name>
  320. <ogc:Function_Name nArgs="2">min_3</ogc:Function_Name>
  321. <ogc:Function_Name nArgs="2">min_4</ogc:Function_Name>
  322. <ogc:Function_Name nArgs="1">mincircle</ogc:Function_Name>
  323. <ogc:Function_Name nArgs="1">minimumdiameter</ogc:Function_Name>
  324. <ogc:Function_Name nArgs="1">minrectangle</ogc:Function_Name>
  325. <ogc:Function_Name nArgs="2">modulo</ogc:Function_Name>
  326. <ogc:Function_Name nArgs="2">MultiplyCoverages</ogc:Function_Name>
  327. <ogc:Function_Name nArgs="3">Nearest</ogc:Function_Name>
  328. <ogc:Function_Name nArgs="1">not</ogc:Function_Name>
  329. <ogc:Function_Name nArgs="2">notEqualTo</ogc:Function_Name>
  330. <ogc:Function_Name nArgs="2">numberFormat</ogc:Function_Name>
  331. <ogc:Function_Name nArgs="5">numberFormat2</ogc:Function_Name>
  332. <ogc:Function_Name nArgs="1">numGeometries</ogc:Function_Name>
  333. <ogc:Function_Name nArgs="1">numInteriorRing</ogc:Function_Name>
  334. <ogc:Function_Name nArgs="1">numPoints</ogc:Function_Name>
  335. <ogc:Function_Name nArgs="1">octagonalenvelope</ogc:Function_Name>
  336. <ogc:Function_Name nArgs="3">offset</ogc:Function_Name>
  337. <ogc:Function_Name nArgs="2">overlaps</ogc:Function_Name>
  338. <ogc:Function_Name nArgs="1">parameter</ogc:Function_Name>
  339. <ogc:Function_Name nArgs="1">parseBoolean</ogc:Function_Name>
  340. <ogc:Function_Name nArgs="1">parseDouble</ogc:Function_Name>
  341. <ogc:Function_Name nArgs="1">parseInt</ogc:Function_Name>
  342. <ogc:Function_Name nArgs="1">parseLong</ogc:Function_Name>
  343. <ogc:Function_Name nArgs="0">pi</ogc:Function_Name>
  344. <ogc:Function_Name nArgs="4">PointBuffers</ogc:Function_Name>
  345. <ogc:Function_Name nArgs="2">pointN</ogc:Function_Name>
  346. <ogc:Function_Name nArgs="7">PointStacker</ogc:Function_Name>
  347. <ogc:Function_Name nArgs="6">PolygonExtraction</ogc:Function_Name>
  348. <ogc:Function_Name nArgs="2">pow</ogc:Function_Name>
  349. <ogc:Function_Name nArgs="1">property</ogc:Function_Name>
  350. <ogc:Function_Name nArgs="1">PropertyExists</ogc:Function_Name>
  351. <ogc:Function_Name nArgs="2">Quantile</ogc:Function_Name>
  352. <ogc:Function_Name nArgs="3">Query</ogc:Function_Name>
  353. <ogc:Function_Name nArgs="0">random</ogc:Function_Name>
  354. <ogc:Function_Name nArgs="5">RangeLookup</ogc:Function_Name>
  355. <ogc:Function_Name nArgs="1">RasterAsPointCollection</ogc:Function_Name>
  356. <ogc:Function_Name nArgs="4">RasterZonalStatistics</ogc:Function_Name>
  357. <ogc:Function_Name nArgs="5">Recode</ogc:Function_Name>
  358. <ogc:Function_Name nArgs="2">RectangularClip</ogc:Function_Name>
  359. <ogc:Function_Name nArgs="2">relate</ogc:Function_Name>
  360. <ogc:Function_Name nArgs="3">relatePattern</ogc:Function_Name>
  361. <ogc:Function_Name nArgs="3">Reproject</ogc:Function_Name>
  362. <ogc:Function_Name nArgs="1">rint</ogc:Function_Name>
  363. <ogc:Function_Name nArgs="1">round</ogc:Function_Name>
  364. <ogc:Function_Name nArgs="1">round_2</ogc:Function_Name>
  365. <ogc:Function_Name nArgs="1">roundDouble</ogc:Function_Name>
  366. <ogc:Function_Name nArgs="6">ScaleCoverage</ogc:Function_Name>
  367. <ogc:Function_Name nArgs="4">sdo_nn</ogc:Function_Name>
  368. <ogc:Function_Name nArgs="2">setCRS</ogc:Function_Name>
  369. <ogc:Function_Name nArgs="3">Simplify</ogc:Function_Name>
  370. <ogc:Function_Name nArgs="1">sin</ogc:Function_Name>
  371. <ogc:Function_Name nArgs="3">Snap</ogc:Function_Name>
  372. <ogc:Function_Name nArgs="1">sqrt</ogc:Function_Name>
  373. <ogc:Function_Name nArgs="2">StandardDeviation</ogc:Function_Name>
  374. <ogc:Function_Name nArgs="1">startAngle</ogc:Function_Name>
  375. <ogc:Function_Name nArgs="1">startPoint</ogc:Function_Name>
  376. <ogc:Function_Name nArgs="1">strCapitalize</ogc:Function_Name>
  377. <ogc:Function_Name nArgs="2">strConcat</ogc:Function_Name>
  378. <ogc:Function_Name nArgs="2">strEndsWith</ogc:Function_Name>
  379. <ogc:Function_Name nArgs="2">strEqualsIgnoreCase</ogc:Function_Name>
  380. <ogc:Function_Name nArgs="2">strIndexOf</ogc:Function_Name>
  381. <ogc:Function_Name nArgs="2">strLastIndexOf</ogc:Function_Name>
  382. <ogc:Function_Name nArgs="1">strLength</ogc:Function_Name>
  383. <ogc:Function_Name nArgs="2">strMatches</ogc:Function_Name>
  384. <ogc:Function_Name nArgs="3">strPosition</ogc:Function_Name>
  385. <ogc:Function_Name nArgs="4">strReplace</ogc:Function_Name>
  386. <ogc:Function_Name nArgs="2">strStartsWith</ogc:Function_Name>
  387. <ogc:Function_Name nArgs="3">strSubstring</ogc:Function_Name>
  388. <ogc:Function_Name nArgs="2">strSubstringStart</ogc:Function_Name>
  389. <ogc:Function_Name nArgs="1">strToLowerCase</ogc:Function_Name>
  390. <ogc:Function_Name nArgs="1">strToUpperCase</ogc:Function_Name>
  391. <ogc:Function_Name nArgs="1">strTrim</ogc:Function_Name>
  392. <ogc:Function_Name nArgs="3">strTrim2</ogc:Function_Name>
  393. <ogc:Function_Name nArgs="2">StyleCoverage</ogc:Function_Name>
  394. <ogc:Function_Name nArgs="2">symDifference</ogc:Function_Name>
  395. <ogc:Function_Name nArgs="1">tan</ogc:Function_Name>
  396. <ogc:Function_Name nArgs="1">toDegrees</ogc:Function_Name>
  397. <ogc:Function_Name nArgs="1">toRadians</ogc:Function_Name>
  398. <ogc:Function_Name nArgs="2">touches</ogc:Function_Name>
  399. <ogc:Function_Name nArgs="1">toWKT</ogc:Function_Name>
  400. <ogc:Function_Name nArgs="2">Transform</ogc:Function_Name>
  401. <ogc:Function_Name nArgs="2">union</ogc:Function_Name>
  402. <ogc:Function_Name nArgs="2">UnionFeatureCollection</ogc:Function_Name>
  403. <ogc:Function_Name nArgs="2">Unique</ogc:Function_Name>
  404. <ogc:Function_Name nArgs="2">UniqueInterval</ogc:Function_Name>
  405. <ogc:Function_Name nArgs="6">VectorToRaster</ogc:Function_Name>
  406. <ogc:Function_Name nArgs="3">VectorZonalStatistics</ogc:Function_Name>
  407. <ogc:Function_Name nArgs="1">vertices</ogc:Function_Name>
  408. <ogc:Function_Name nArgs="2">within</ogc:Function_Name>
  409. </ogc:Function_Names>
  410. </ogc:Functions>
  411. </ogc:Arithmetic_Operators>
  412. </ogc:Scalar_Capabilities>
  413. </ogc:Filter_Capabilities>
  414. </WFS_Capabilities>
  415. <?php
  416. exit;
  417. }
  418. public function _getXmlSchemaLocation() {
  419. $schemaLocations = array();
  420. //$schemaLocations[] = 'http://www.opengis.net/wfs http://webgis.regione.sardegna.it:80/geoserver/schemas/wfs/1.0.0/WFS-capabilities.xsd';// @from http://webgis.regione.sardegna.it/geoserver/ows?service=WFS&request=GetCapabilities
  421. return (!empty($schemaLocations))? 'xsi:schemaLocation="' . implode(' ', $schemaLocations) . '"' : '';
  422. }
  423. public function _printXmlNamespaceList() {
  424. $listNs = array();
  425. foreach (Api_WfsNs::getNsList() as $uri => $prefix) {
  426. $listNs[] = 'xmlns:' . $prefix . '="' . $uri . '"';
  427. }
  428. return implode("\n", $listNs);
  429. }
  430. public function _getSourceNsList() {
  431. $usrObjList = array();
  432. $tblsAcl = $this->_usrAcl->getTablesAcl();
  433. foreach ($tblsAcl as $tblAcl) {
  434. $dataSourceName = 'default_db';// TODO: getSourceName
  435. $tblName = $tblAcl->getName();
  436. $usrObjList[] = array($dataSourceName, $tblName);
  437. }
  438. $usrObjList[] = array('objects', 'File');
  439. $usrObjList[] = array('objects', 'TestPerms');
  440. $usrObjList[] = array('objects', 'Korespondencja');
  441. return $usrObjList;
  442. }
  443. public function _printGetCapabilitiesXml($wfsServerUrl) {
  444. ?>
  445. <GetCapabilities>
  446. <DCPType>
  447. <HTTP>
  448. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetCapabilities" />
  449. </HTTP>
  450. </DCPType>
  451. <DCPType>
  452. <HTTP>
  453. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  454. </HTTP>
  455. </DCPType>
  456. </GetCapabilities>
  457. <?php
  458. }
  459. public function _printDescribeFeatureTypeXml($wfsServerUrl) {
  460. ?>
  461. <DescribeFeatureType>
  462. <SchemaDescriptionLanguage>
  463. <XMLSCHEMA />
  464. </SchemaDescriptionLanguage>
  465. <DCPType>
  466. <HTTP>
  467. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=DescribeFeatureType" />
  468. </HTTP>
  469. </DCPType>
  470. <DCPType>
  471. <HTTP>
  472. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  473. </HTTP>
  474. </DCPType>
  475. </DescribeFeatureType>
  476. <?php
  477. }
  478. public function _printGetFeatureXml($wfsServerUrl) {
  479. ?>
  480. <GetFeature>
  481. <ResultFormat>
  482. <WFSKMLOutputFormat />
  483. <GML2 />
  484. <GML3 />
  485. <SHAPE-ZIP />
  486. <CSV />
  487. <JSON />
  488. </ResultFormat>
  489. <DCPType>
  490. <HTTP>
  491. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetFeature" />
  492. </HTTP>
  493. </DCPType>
  494. <DCPType>
  495. <HTTP>
  496. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  497. </HTTP>
  498. </DCPType>
  499. </GetFeature>
  500. <?php
  501. }
  502. public function _printTransactionXml($wfsServerUrl) {
  503. ?>
  504. <Transaction>
  505. <DCPType>
  506. <HTTP>
  507. <Get onlineResource="<?php echo $wfsServerUrl; ?>?request=Transaction" />
  508. </HTTP>
  509. </DCPType>
  510. <DCPType>
  511. <HTTP>
  512. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  513. </HTTP>
  514. </DCPType>
  515. </Transaction>
  516. <?php
  517. }
  518. public function _printLockFeatureXml($wfsServerUrl) {
  519. ?>
  520. <LockFeature>
  521. <DCPType>
  522. <HTTP>
  523. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=LockFeature" />
  524. </HTTP>
  525. </DCPType>
  526. <DCPType>
  527. <HTTP>
  528. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  529. </HTTP>
  530. </DCPType>
  531. </LockFeature>
  532. <?php
  533. }
  534. public function _printGetFeatureWithLockXml($wfsServerUrl) {
  535. ?>
  536. <GetFeatureWithLock>
  537. <ResultFormat>
  538. <GML2 />
  539. </ResultFormat>
  540. <DCPType>
  541. <HTTP>
  542. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetFeatureWithLock" />
  543. </HTTP>
  544. </DCPType>
  545. <DCPType>
  546. <HTTP>
  547. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  548. </HTTP>
  549. </DCPType>
  550. </GetFeatureWithLock>
  551. <?php
  552. }
  553. public function _printFeatureTypeListXml() {
  554. $featureTypes = array();
  555. $tblsAcl = $this->_getTableAclList();
  556. foreach ($tblsAcl as $tblAcl) {
  557. $dataSourceName = 'default_db';// TODO: getSourceName
  558. $tblName = $tblAcl->getName();
  559. $usrObjList[] = array($dataSourceName, $tblName);
  560. $featureType = array();
  561. $featureType['ns'] = "p5_{$dataSourceName}";
  562. $featureType['Title'] = $tblAcl->getRawLabel();
  563. $featureType['Abstract'] = $tblAcl->getRawOpis();
  564. $featureType['Keywords'] = array();
  565. $featureType['Keywords'][] = $tblAcl->getID();
  566. $featureType['Keywords'][] = $tblName;
  567. $featureType['Keywords'][] = $tblAcl->getRawLabel();
  568. $featureType['Keywords'] = implode(", ", $featureType['Keywords']);
  569. $featureType['SRS'] = "EPSG:4326";
  570. $featureType['LatLongBoundingBox'] = array();// TODO: feature LatLongBoundingBox
  571. $featureType['LatLongBoundingBox']['minx'] = "8.12328509871721";
  572. $featureType['LatLongBoundingBox']['miny'] = "38.8575126897477";
  573. $featureType['LatLongBoundingBox']['maxx'] = "9.838674658246807";
  574. $featureType['LatLongBoundingBox']['maxy'] = "41.31378404137082";
  575. $featureTypes[$tblName] = $featureType;
  576. }
  577. function __generateObjectFeatureType($name) {
  578. $featureType = array();
  579. $featureType['ns'] = "p5_objects";
  580. $featureType['Title'] = $name;
  581. $featureType['Abstract'] = $name;
  582. $featureType['Keywords'] = $name;
  583. $featureType['SRS'] = "EPSG:4326";
  584. return $featureType;
  585. }
  586. $featureTypes['AccessOwner'] = __generateObjectFeatureType("AccessOwner");
  587. $featureTypes['AccessGroup'] = __generateObjectFeatureType("AccessGroup");
  588. $featureTypes['File'] = __generateObjectFeatureType("Pliki");
  589. $featureTypes['Korespondencja'] = __generateObjectFeatureType("Korespondencja");
  590. $featureTypes['TestPerms'] = __generateObjectFeatureType("TestPerms");
  591. /*
  592. <FeatureType>
  593. <Name>ppr06:AMBITIPAESAGGIO</Name>
  594. <Title>AMBITIPAESAGGIO</Title>
  595. <Abstract />
  596. <Keywords>features, AMBITIPAESAGGIO</Keywords>
  597. <SRS>EPSG:4326</SRS>
  598. <LatLongBoundingBox minx="8.12328509871721" miny="38.8575126897477" maxx="9.838674658246807" maxy="41.31378404137082" />
  599. </FeatureType>
  600. */
  601. $featureTypesXml = '';
  602. foreach ($featureTypes as $tblName => $feature) {
  603. $featureTypesXml .= " " . '<FeatureType>' . "\n";
  604. $featureTypesXml .= " " . '<Name>' . "{$feature['ns']}:{$tblName}" . '</Name>' . "\n";
  605. $featureTypesXml .= " " . '<Title>' . "{$feature['Title']}" . '</Title>' . "\n";
  606. if (!empty($feature['Abstract'])) {
  607. $featureTypesXml .= " " . '<Abstract>' . "{$feature['Abstract']}" . '</Abstract>' . "\n";
  608. } else {
  609. $featureTypesXml .= " " . '<Abstract/>' . "\n";
  610. }
  611. if (!empty($feature['Keywords'])) {
  612. $featureTypesXml .= " " . '<Keywords>' . "{$feature['Keywords']}" . '</Keywords>' . "\n";
  613. } else {
  614. $featureTypesXml .= " " . '<Keywords/>' . "\n";
  615. }
  616. $featureTypesXml .= " " . '<SRS>' . "{$feature['SRS']}" . '</SRS>' . "\n";
  617. if (!empty($feature['LatLongBoundingBox'])) {
  618. $latLongBoundingBoxOut = array();
  619. $latLongBoundingBoxOut[] = 'minx="' . $feature['LatLongBoundingBox']['minx'] . '"';
  620. $latLongBoundingBoxOut[] = 'miny="' . $feature['LatLongBoundingBox']['miny'] . '"';
  621. $latLongBoundingBoxOut[] = 'maxx="' . $feature['LatLongBoundingBox']['maxx'] . '"';
  622. $latLongBoundingBoxOut[] = 'maxy="' . $feature['LatLongBoundingBox']['maxy'] . '"';
  623. $featureTypesXml .= " " . '<LatLongBoundingBox ' . implode(' ', $latLongBoundingBoxOut) . ' />' . "\n";
  624. }
  625. $featureTypesXml .= " " . '</FeatureType>' . "\n";
  626. }
  627. echo $featureTypesXml;
  628. }
  629. public function _parseTransactionXmlStruct($requestXml, $requestXmlTags) {
  630. $DBG = V::get('DBG_XML', 0, $_GET, 'int');// TODO: Profiler
  631. $rootTagName = V::get('tag', '', $requestXmlTags[0]);
  632. if ('Transaction' != $rootTagName) throw new Api_WfsException("Parse Request XML Error - Missing Transaction as root xml tag", __LINE__, null, 'TransactionParseError', 'request');
  633. // TODO: special actions if action on nested objects
  634. // 1. convert request: wfs.transaction.convert-wfs-request.xsl
  635. // 2. validate converted request: wfs.transaction-converted-request.xsd
  636. // 3. execute request in data source
  637. // if($DBG){echo 'L.' . __LINE__ . ' $requestXmlTags:';print_r($requestXmlTags);echo "\n";}
  638. /*
  639. <Transaction
  640. xmlns="http://www.opengis.net/wfs"
  641. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  642. version="1.0.0"
  643. service="WFS"
  644. xmlns:p5_objects="https://biuro.biall-net.pl/wfs/objects"
  645. xmlns:gml="http://www.opengis.net/gml">
  646. <Insert xmlns="http://www.opengis.net/wfs">
  647. <TestPerms xmlns="https://biuro.biall-net.pl/wfs/objects">
  648. <plik xmlns="https://biuro.biall-net.pl/wfs/objects">
  649. <p5_objects:File>
  650. <p5_objects:name>blank-wfs.gif</p5_objects:name>
  651. <p5_objects:content>R0lGODlhAQABAIAAAP///////yH+EUNyZWF0ZWQgd2l0aCBHSU1QACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==</p5_objects:content>
  652. </p5_objects:File>
  653. </plik>
  654. </TestPerms>
  655. </Insert>
  656. </Transaction>
  657. */
  658. $actionXmlTags = array();// // [ 0 => [ 'action'=>Insert, 'typeName'=>str, 'tags'=>[] ]
  659. {// split xml for action tags (Insert, Update, Delete)
  660. $tagsCount = count($requestXmlTags);
  661. for ($i = 1, $actionTagName = null, $actionIdx = -1, $tagLvl = 0; $i < $tagsCount - 1; $i++) {// skip Transaction open/close tag
  662. $tag = $requestXmlTags[$i];
  663. if (null == $actionTagName) {
  664. $actionTagName = $tag['tag'];
  665. $tagLvl = $tag['level'];
  666. $actionIdx += 1;
  667. $actionXmlTags[$actionIdx] = array();
  668. $actionXmlTags[$actionIdx]['action'] = $actionTagName;
  669. $actionXmlTags[$actionIdx]['typeName'] = V::get('typeName', '', $tag['attributes']);
  670. $actionXmlTags[$actionIdx]['isDeepObject'] = null;// null - unknown, false - not seed, true - deep
  671. $actionXmlTags[$actionIdx]['tags'] = array();
  672. } else if ($tag['tag'] == $actionTagName && 'close' == $tag['type'] && $tagLvl == $tag['level']) {
  673. $actionTagName = null;
  674. } else {
  675. $actionXmlTags[$actionIdx]['tags'][] = $tag;
  676. }
  677. }
  678. }
  679. {// Validate Request: WFS allow multiple tags inside Insert tag
  680. // TODO: implement multiple tags in Insert tag if reauired. Use array_splice($actionXmlTags, $actionIdx, 0, $insertTags);
  681. {// throw (Not Implemented, 501) if found multiple tags in Insert tag
  682. foreach ($actionXmlTags as $actionIdx => $action) {
  683. if ('Insert' !== $action['action']) continue;
  684. $lvl = $action['tags'][0]['level'];
  685. for ($i = 1, $cnt = count($action['tags']); $i < $cnt - 1; $i++) {
  686. $tag = $action['tags'][$i];
  687. // if($DBG){echo 'L.' . __LINE__ . " actionXmlTags loop({$i}) \$tag:";print_r($tag);echo "\n";}
  688. if ($tag['level'] == $lvl) throw new Exception("Error Processing Request - multiple tags inside Insert tag is not implemented", 501);
  689. }
  690. }
  691. }
  692. }
  693. {// Insert tag - fix typeName from first tag, remove first and last tag - leave only fields
  694. foreach ($actionXmlTags as $actionIdx => $action) {
  695. if ('Insert' !== $action['action']) continue;
  696. array_pop($action['tags']);// remove last tag (close tag)
  697. $tag = array_shift($action['tags']);// remove last tag (close tag)
  698. $typeName = $tag['tag'];// eg. with prefix 'p5_objects:File' or without prefix but with @xmlns
  699. if (false === strpos($typeName, ':')) {
  700. $nsType = V::get('xmlns', '', $tag['attributes']);
  701. if (!$nsType) throw new Exception("Error Processing Request - Missing object namespace '{$tag['tag']}'");
  702. $prefix = Api_WfsNs::getNsPrefix($nsType);
  703. if (!$prefix) {
  704. if ($typeName == substr(rtrim($nsType, '/'), -1 * strlen($typeName))) {// typeName may be added to ns uri
  705. $nsBaseForType = substr(rtrim($nsType, '/'), 0, -1 * strlen($typeName) - 1);
  706. $prefix = Api_WfsNs::getNsPrefix($nsBaseForType);
  707. }
  708. }
  709. if (!$prefix) throw new Exception("Error Processing Request - Unrecognized namespace uri '{$nsType}' for object '{$tag['tag']}'");
  710. $typeName = "{$prefix}:{$typeName}";
  711. }
  712. $action['typeName'] = $typeName;
  713. $actionXmlTags[$actionIdx] = $action;
  714. }
  715. }
  716. {// validate
  717. // if($DBG){echo 'L.' . __LINE__ . ' before validate $actionXmlTags:';print_r($actionXmlTags);echo "\n";}
  718. foreach ($actionXmlTags as $actionIdx => $action) {
  719. if ('Insert' == $action['action']) {
  720. if (empty($action['typeName'])) throw new Exception("Error Processing Request - unknown object typeName to Insert");
  721. $acl = $this->getAclFromTypeName($action['typeName']);
  722. $actionXmlTags[$actionIdx] = $acl->validateInsertXml($action);
  723. } else if ('Update' == $action['action']) {
  724. $acl = $this->getAclFromTypeName($action['typeName']);
  725. $actionXmlTags[$actionIdx] = $acl->validateUpdateXml($action);
  726. } else if ('Delete' == $action['action']) {
  727. if($DBG>1){echo'<pre>$action: ';print_r($action);echo'</pre>';}
  728. $acl = $this->getAclFromTypeName($action['typeName']);
  729. $actionXmlTags[$actionIdx] = $acl->validateDeleteXml($action);
  730. } else {
  731. if($DBG>1){echo'<pre>$action: ';print_r($action);echo'</pre>';}
  732. throw new Exception("{$action['action']} action not implemented", 501);
  733. }
  734. // continue;// TODO: validate all by type
  735. }
  736. }
  737. {// execute
  738. $returnIds = array();
  739. $changesList = array();
  740. foreach ($actionXmlTags as $actionIdx => $action) {
  741. if ('Insert' == $action['action']) {
  742. if (empty($action['typeName'])) throw new Exception("Error Processing Request - unknown object typeName to Insert");
  743. $acl = $this->getAclFromTypeName($action['typeName']);
  744. $newId = $acl->insertXml($action);
  745. $returnIds[$actionIdx] = $newId;
  746. $changesList[$actionIdx] = array('Status'=>(($newId > 0)? 'SUCCESS' : 'FAILED'), 'Message'=>"created {$newId}.", 'Action' => $action['action']);
  747. if ($newId > 0) $changesList[$actionIdx]['fid'] = $acl->getName() . '.' . $newId;
  748. } else if ('Update' == $action['action']) {
  749. if($DBG>1){echo'<pre>$action: ';print_r($action);echo'</pre>';}
  750. $acl = $this->getAclFromTypeName($action['typeName']);
  751. $affected = $acl->updateXml($action);
  752. $changesList[$actionIdx] = array('Status'=>(($affected >= 0)? 'SUCCESS' : 'FAILED'), 'Message'=>"affected {$affected}.", 'Action' => $action['action']);
  753. } else if ('Delete' == $action['action']) {
  754. $acl = $this->getAclFromTypeName($action['typeName']);
  755. $affected = $acl->deleteXml($action);
  756. $changesList[$actionIdx] = array('Status'=>(($affected >= 0)? 'SUCCESS' : 'FAILED'), 'Message'=>"deleted {$affected}.", 'Action' => $action['action']);
  757. } else throw new Exception("TODO: {$action['action']} action not implemented", 501);
  758. }
  759. if($DBG){echo 'L.' . __LINE__ . ' $changesList:';print_r($changesList);echo "\n";}
  760. }
  761. return $this->_transactionResponse($changesList);
  762. }
  763. public function _transactionResponse($changesList) {
  764. // <WFS_TransactionResponse>
  765. // <TransactionResult>
  766. // <Status> : SUCCESS / FAILED / PARTIAL
  767. // [<Locator]
  768. // [<Message]
  769. $messageTag = '';
  770. $statusTag = '';
  771. $statusIsFailed = false;
  772. $statusAll = null;
  773. $createdFetureId = array();
  774. foreach ($changesList as $featureId => $change) {
  775. if ('FAILED' == $change['Status']) {
  776. $statusIsFailed = true;
  777. }
  778. if ('SUCCESS' == $change['Status'] && !empty($change['fid'])) {
  779. $createdFetureId[] = $change['fid'];
  780. }
  781. // if (!empty($change['Message'])) $messageTag .= "Feature '{$featureId}' {$change['Status']}: {$change['Message']}\n";
  782. }
  783. $statusTag = ($statusIsFailed)? 'FAILED' : 'SUCCESS';
  784. $statusTag = "<wfs:{$statusTag}/>";
  785. $messageTag = '';//"<wfs:Message>{$messageTag}</wfs:Message>";
  786. /* Example:
  787. <?xml version="1.0" encoding="UTF-8"?>
  788. <wfs:WFS_TransactionResponse version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs"
  789. xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  790. xsi:schemaLocation="http://www.opengis.net/wfs http://localhost:8080/geoserver/schemas/wfs/1.0.0/WFS-transaction.xsd">
  791. <wfs:InsertResult>
  792. <ogc:FeatureId fid="archsites.26" />
  793. </wfs:InsertResult>
  794. <wfs:TransactionResult handle="Updating Signature rock label">
  795. <wfs:Status>
  796. <wfs:SUCCESS />
  797. </wfs:Status>
  798. </wfs:TransactionResult>
  799. </wfs:WFS_TransactionResponse>*/
  800. // TODO: build xml by DOMDocument
  801. // TODO: xsi:schemaLocation="http://www.opengis.net/wfs http://localhost:8080/geoserver/schemas/wfs/1.0.0/WFS-transaction.xsd"
  802. $wfsInsertResult = '';
  803. if (!empty($createdFetureId)) {
  804. $wfsInsertResult = "\n<wfs:InsertResult>\n";
  805. foreach ($createdFetureId as $fid) {
  806. $wfsInsertResult .= '<ogc:FeatureId fid="' . $fid . '" xmlns:ogc="http://www.opengis.net/ogc"/>' . "\n";
  807. }
  808. $wfsInsertResult .= "\n</wfs:InsertResult>\n";
  809. EOF;
  810. }
  811. $tranRes = <<<EOF
  812. <wfs:WFS_TransactionResponse version="1.0.0"
  813. xmlns:wfs="http://www.opengis.net/wfs"
  814. xmlns:ogc="http://www.opengis.net/ogc"
  815. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  816. {$wfsInsertResult}
  817. <wfs:TransactionResult>
  818. <wfs:Status>{$statusTag}</wfs:Status>
  819. {$messageTag}
  820. </wfs:TransactionResult>
  821. </wfs:WFS_TransactionResponse>
  822. EOF;
  823. return $tranRes;
  824. }
  825. public function _convertTransactionXml($requestXmlString, $sourceNsList) {
  826. $DBG = (V::get('DBG_XSL', '', $_GET) > 0);// TODO: Profiler
  827. if($DBG){echo 'L.' . __LINE__ . ' sourceNsList:';print_r($sourceNsList);echo "\n";}
  828. $updateActionsXsd = array();
  829. $insertActionsXsd = array();
  830. $deleteActionsXsd = array();
  831. //<!-- TODO: create tag Update{X} where X is namespace index -->
  832. foreach ($sourceNsList as $nsInd => $sourceNs) {
  833. // <Update>
  834. $theGeomField = 'the_geom';// TODO: get from fields list
  835. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  836. if($DBG){echo 'L.' . __LINE__ . ' typeName:';print_r($typeName);echo "\n";}
  837. $updateElementName = "UpdateNs{$nsInd}";
  838. $geomCoordsUpdateXpath = "//wfs:Value/*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
  839. $geomCoordsInsertXpath = "//*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
  840. $acl = $this->getAclFromTypeName($typeName);
  841. $geomType = $acl->getGeomFieldType($theGeomField);
  842. if ('polygon' == $geomType) {
  843. $geomCoordsUpdateXpath = ".//wfs:Value/*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
  844. $geomCoordsUpdateXpath = "((<xsl:value-of select=\"{$geomCoordsUpdateXpath}\"/>))";
  845. $geomCoordsInsertXpath = ".//*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
  846. $geomCoordsInsertXpath = "((<xsl:value-of select=\"{$geomCoordsInsertXpath}\"/>))";
  847. } else if ('linestring' == $geomType) {
  848. $geomCoordsUpdateXpath = ".//wfs:Value/*/gml:coordinates";
  849. $geomCoordsUpdateXpath = "(<xsl:value-of select=\"{$geomCoordsUpdateXpath}\"/>)";
  850. $geomCoordsInsertXpath = ".//*/gml:coordinates";
  851. $geomCoordsInsertXpath = "(<xsl:value-of select=\"{$geomCoordsInsertXpath}\"/>)";
  852. } else if ('point' == $geomType) {
  853. $geomCoordsUpdateXpath = ".//wfs:Value/*/gml:coordinates";
  854. $geomCoordsUpdateXpath = "(<xsl:value-of select=\"{$geomCoordsUpdateXpath}\"/>)";
  855. $geomCoordsInsertXpath = ".//*/gml:coordinates";
  856. $geomCoordsInsertXpath = "(<xsl:value-of select=\"{$geomCoordsInsertXpath}\"/>)";
  857. }
  858. $actionXsd = <<<EOF
  859. <xsl:when test="@typeName = '{$typeName}'">
  860. <xsl:element name="{$updateElementName}">
  861. <xsl:attribute name="typeName"><xsl:value-of select="@typeName" /></xsl:attribute>
  862. <xsl:attribute name="featureId"><xsl:value-of select="ogc:Filter/ogc:FeatureId/@fid" /></xsl:attribute>
  863. <xsl:for-each select="wfs:Property">
  864. <xsl:element name="{wfs:Name}">
  865. <xsl:choose>
  866. <xsl:when test="wfs:Name = '{$theGeomField}'"><xsl:value-of select="local-name(//wfs:Value/*[1])"/>{$geomCoordsUpdateXpath}</xsl:when>
  867. <xsl:otherwise><xsl:value-of select="wfs:Value"/></xsl:otherwise>
  868. </xsl:choose>
  869. </xsl:element>
  870. </xsl:for-each>
  871. </xsl:element>
  872. </xsl:when>
  873. EOF;
  874. $updateActionsXsd[] = $actionXsd;
  875. $typeName = "{$sourceNs[1]}";//"p5_{$sourceNs[0]}:{$sourceNs[1]}";
  876. $insertElementName = "InsertNs{$nsInd}";
  877. $actionXsd = <<<EOF
  878. <xsl:when test="local-name() = '{$typeName}'">
  879. <xsl:element name="{$insertElementName}">
  880. <xsl:attribute name="typeName"><xsl:value-of select="local-name()" /></xsl:attribute>
  881. <xsl:attribute name="typeNsUri"><xsl:value-of select="namespace-uri()" /></xsl:attribute>
  882. <xsl:for-each select="*">
  883. <xsl:element name="{local-name()}">
  884. <xsl:choose>
  885. <xsl:when test="local-name() = '{$theGeomField}'"><xsl:value-of select="local-name(*[1])"/>{$geomCoordsInsertXpath}</xsl:when>
  886. <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
  887. </xsl:choose>
  888. </xsl:element>
  889. </xsl:for-each>
  890. </xsl:element>
  891. </xsl:when>
  892. EOF;
  893. $insertActionsXsd[] = $actionXsd;
  894. $deleteElementName = "DeleteNs{$nsInd}";
  895. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  896. $actionXsd = <<<EOF
  897. <xsl:when test="@typeName = '{$typeName}'">
  898. <xsl:variable name="typeName" select="@typeName" />
  899. <xsl:for-each select="ogc:Filter/ogc:FeatureId">
  900. <xsl:element name="{$deleteElementName}">
  901. <xsl:attribute name="typeName"><xsl:value-of select="\$typeName" /></xsl:attribute>
  902. <xsl:attribute name="featureId"><xsl:value-of select="@fid" /></xsl:attribute>
  903. </xsl:element>
  904. </xsl:for-each>
  905. </xsl:when>
  906. EOF;
  907. $deleteActionsXsd[] = $actionXsd;
  908. }
  909. if (!empty($updateActionsXsd)) {
  910. $updateActionsXsd = implode("\n", $updateActionsXsd);
  911. $updateActionsXsd = <<<EOF
  912. <xsl:choose>
  913. {$updateActionsXsd}
  914. </xsl:choose>
  915. EOF;
  916. } else {
  917. $updateActionsXsd = '';
  918. }
  919. if (!empty($insertActionsXsd)) {
  920. $insertActionsXsd = implode("\n", $insertActionsXsd);
  921. $insertActionsXsd = <<<EOF
  922. <xsl:choose>
  923. {$insertActionsXsd}
  924. </xsl:choose>
  925. EOF;
  926. } else {
  927. $insertActionsXsd = '';
  928. }
  929. if (!empty($deleteActionsXsd)) {
  930. $deleteActionsXsd = implode("\n", $deleteActionsXsd);
  931. $deleteActionsXsd = <<<EOF
  932. <xsl:choose>
  933. {$deleteActionsXsd}
  934. </xsl:choose>
  935. EOF;
  936. } else {
  937. $deleteActionsXsd = '';
  938. }
  939. $convertTransactionXslString = '<?xml version="1.0"?>';
  940. $convertTransactionXslString .= <<<EOF
  941. <xsl:transform version="1.0"
  942. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  943. xmlns:wfs="http://www.opengis.net/wfs"
  944. xmlns:ogc="http://www.opengis.net/ogc"
  945. xmlns:gml="http://www.opengis.net/gml">
  946. <xsl:template match="/">
  947. <xsl:for-each select="wfs:Transaction">
  948. <Transaction>
  949. <xsl:attribute name="version"><xsl:value-of select="@version" /></xsl:attribute>
  950. <xsl:attribute name="service"><xsl:value-of select="@service" /></xsl:attribute>
  951. <xsl:for-each select="wfs:Update">
  952. {$updateActionsXsd}
  953. </xsl:for-each>
  954. <xsl:for-each select="wfs:Insert/*">
  955. {$insertActionsXsd}
  956. </xsl:for-each>
  957. <xsl:for-each select="wfs:Delete">
  958. {$deleteActionsXsd}
  959. </xsl:for-each>
  960. <!-- TODO: Native -->
  961. </Transaction>
  962. </xsl:for-each>
  963. </xsl:template>
  964. </xsl:transform>
  965. EOF;
  966. if($DBG){echo 'L.' . __LINE__ . ' $convertTransactionXslString:' . $convertTransactionXslString . "\n";}
  967. $requestXml = new DOMDocument();
  968. $requestXml->loadXml($requestXmlString);
  969. $convertTransactionXsl = new DOMDocument();
  970. $convertTransactionXsl->loadXml($convertTransactionXslString);
  971. $proc = new XSLTProcessor();
  972. $proc->importStylesheet($convertTransactionXsl);
  973. return $proc->transformToXML($requestXml);
  974. }
  975. public function _validateConvertedTransactionXml($convertedTransaction, $sourceNsList) {
  976. $DBG = (V::get('DBG_XSD', '', $_GET) > 0);// TODO: Profiler
  977. if($DBG){echo 'L.' . __LINE__ . ' sourceNsList:';print_r($sourceNsList);echo "\n";}
  978. $dom = new DOMDocument('1.0', 'utf-8');
  979. $dom->formatOutput = true;
  980. $dom->preserveWhiteSpace = false;
  981. $rootNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:schema');
  982. $dom->appendChild($rootNode);
  983. $rootNode->setAttribute('elementFormDefault', 'qualified');
  984. $rootNode->setAttribute('version', '1.0');
  985. {// <xsd:element name="Transaction" type="TransactionType">
  986. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  987. $rootNode->appendChild($elNode);
  988. $elNode->setAttribute('name', 'Transaction');
  989. $elNode->setAttribute('type', 'TransactionType');
  990. $cTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  991. $rootNode->appendChild($cTypeNode);
  992. $cTypeNode->setAttribute('name', 'TransactionType');
  993. $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
  994. $cTypeNode->appendChild($seqNode);
  995. $choiceNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:choice');
  996. $seqNode->appendChild($choiceNode);
  997. $choiceNode->setAttribute('minOccurs', '0');
  998. $choiceNode->setAttribute('maxOccurs', 'unbounded');
  999. // <!-- <xsd:element ref="Update"/> -->
  1000. foreach ($sourceNsList as $nsInd => $sourceNs) {
  1001. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  1002. $updateElementName = "UpdateNs{$nsInd}";
  1003. $updateElementType = "UpdateNs{$nsInd}ElementType";
  1004. $updateElemNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1005. $choiceNode->appendChild($updateElemNode);
  1006. $updateElemNode->setAttribute('name', $updateElementName);
  1007. $updateElemNode->setAttribute('type', $updateElementType);
  1008. }
  1009. // <!-- <xsd:element ref="Insert"/> -->
  1010. foreach ($sourceNsList as $nsInd => $sourceNs) {
  1011. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  1012. $insertElementName = "InsertNs{$nsInd}";
  1013. $insertElementType = "InsertNs{$nsInd}ElementType";
  1014. $insertElemNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1015. $choiceNode->appendChild($insertElemNode);
  1016. $insertElemNode->setAttribute('name', $insertElementName);
  1017. $insertElemNode->setAttribute('type', $insertElementType);
  1018. }
  1019. // <!-- <xsd:element ref="Delete"/> -->
  1020. foreach ($sourceNsList as $nsInd => $sourceNs) {
  1021. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  1022. $deleteElementName = "DeleteNs{$nsInd}";
  1023. $deleteElementType = "DeleteNs{$nsInd}ElementType";
  1024. $deleteElemNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1025. $choiceNode->appendChild($deleteElemNode);
  1026. $deleteElemNode->setAttribute('name', $deleteElementName);
  1027. $deleteElemNode->setAttribute('type', $deleteElementType);
  1028. }
  1029. // <!-- <xsd:element ref="Native"/> -->
  1030. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1031. $cTypeNode->appendChild($attrNode);
  1032. $attrNode->setAttribute('name', 'version');
  1033. $attrNode->setAttribute('type', 'xsd:string');
  1034. $attrNode->setAttribute('use', 'required');
  1035. $attrNode->setAttribute('fixed', '1.0.0');
  1036. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1037. $cTypeNode->appendChild($attrNode);
  1038. $attrNode->setAttribute('name', 'service');
  1039. $attrNode->setAttribute('type', 'xsd:string');
  1040. $attrNode->setAttribute('use', 'required');
  1041. $attrNode->setAttribute('fixed', 'WFS');
  1042. }
  1043. foreach ($sourceNsList as $nsInd => $sourceNs) {
  1044. $transactionTypesList = array();
  1045. $transactionTypesList[] = 'Update';
  1046. $transactionTypesList[] = 'Insert';
  1047. foreach ($transactionTypesList as $transactionType) {
  1048. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  1049. if($DBG){echo 'L.' . __LINE__ . ' TODO: get acl typeName:';print_r($typeName);echo "\n";}
  1050. $acl = $this->getAclFromTypeName($typeName);
  1051. $updateElementName = "{$transactionType}Ns{$nsInd}";
  1052. $updateElementType = "{$transactionType}Ns{$nsInd}ElementType";
  1053. /*
  1054. <xsd:complexType name="{$updateElementType}">
  1055. <xsd:sequence>
  1056. <xsd:element name="PARENT_ID" minOccurs="0" maxOccurs="1" type="xsd:integer" />
  1057. </xsd:sequence>
  1058. */
  1059. $updateTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  1060. $rootNode->appendChild($updateTypeNode);
  1061. $updateTypeNode->setAttribute('name', $updateElementType);
  1062. {
  1063. $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:all');
  1064. $updateTypeNode->appendChild($seqNode);
  1065. {
  1066. $pKeyField = $acl->getPrimaryKeyField();
  1067. $fldList = $this->_getFieldListFromAcl($acl);
  1068. // fields without geometry fields
  1069. foreach ($fldList as $fldName) {
  1070. if ($acl->isGeomField($fldName)) continue;
  1071. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1072. $seqNode->appendChild($elNode);
  1073. $elNode->setAttribute('name', $fldName);
  1074. $minOccurs = 0;
  1075. if ($pKeyField == $fldName) {
  1076. $minOccurs = '1';
  1077. } else {
  1078. $minOccurs = '0';
  1079. }
  1080. $elNode->setAttribute('minOccurs', $minOccurs);
  1081. $fldType = null;
  1082. if ($acl->isIntegerField($fldName)) {
  1083. $fldType = 'xsd:integer';
  1084. }
  1085. else if ($acl->isDecimalField($fldName)) {
  1086. $fldType = 'xsd:decimal';
  1087. }
  1088. else if ($acl->isDateField($fldName)) {
  1089. $fldType = 'xsd:date';
  1090. }
  1091. else if ($acl->isDateTimeField($fldName)) {
  1092. // $fldType = 'xsd:dateTime';
  1093. $fldType = null;// 'xsd:string';
  1094. $patternDataTime = "(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})(:(\d{2}))?";
  1095. // <xsd:element name="..." minOccurs="0" nillable="true">
  1096. // <xsd:simpleType>
  1097. // <xsd:restriction base="xsd:string">
  1098. // <xsd:pattern value="[a-zA-Z]+\(\((\-?\d+\.?\d*,\-?\d+\.?\d*)( \-?\d+\.?\d*,\-?\d+\.?\d*)+\)\)"/>
  1099. // </xsd:restriction>
  1100. // </xsd:simpleType>
  1101. // </xsd:element>
  1102. $simpleTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  1103. $restrictionNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  1104. $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
  1105. $restrictionNode->setAttribute('base', 'xsd:string');
  1106. $patternNode->setAttribute('value', $patternDataTime);
  1107. $restrictionNode->appendChild($patternNode);
  1108. $simpleTypeNode->appendChild($restrictionNode);
  1109. $elNode->appendChild($simpleTypeNode);
  1110. // continue;// TODO: ? below added nillable = true, minOccurs = 0, type = $fldType
  1111. }
  1112. else if ($acl->isBinaryField($fldName)) {
  1113. $fldType = 'xsd:base64Binary';
  1114. }
  1115. else {
  1116. $fldType = 'xsd:string';
  1117. }
  1118. if ($fldType) $elNode->setAttribute('type', $fldType);
  1119. $elNode->setAttribute('nillable', 'true');
  1120. $elNode->setAttribute('minOccurs', '0');
  1121. }
  1122. // only geometry fields
  1123. foreach ($fldList as $fldName) {
  1124. if (!$acl->isGeomField($fldName)) continue;
  1125. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1126. $seqNode->appendChild($elNode);
  1127. $elNode->setAttribute('name', $fldName);
  1128. $minOccurs = 0;
  1129. if ($pKeyField == $fldName) {
  1130. $minOccurs = '1';
  1131. } else {
  1132. $minOccurs = '0';
  1133. }
  1134. $elNode->setAttribute('minOccurs', $minOccurs);
  1135. if ($acl->isGeomField($fldName)) {
  1136. //$fldType = 'gml:GeometryPropertyType';
  1137. // TODO: use geom types from gml to wkt
  1138. // TODO: pattern wg atrybutów gml:coordinates decimal="." cs="," ts=" "
  1139. $patternWkt = '';// TODO: error if empty - unsupported geom type
  1140. $patternNum = '\-?\d+\.?\d*';
  1141. $patternPoint = $patternNum . ',' . $patternNum;
  1142. $patternPoints = '(' . $patternPoint . ')( ' . $patternPoint . ')+';
  1143. $geomType = $acl->getGeomFieldType($fldName);
  1144. if ('polygon' == $geomType) {
  1145. // [a-zA-Z]+\(\((\-?\d+\.?\d*,\-?\d+\.?\d*)( (\-?\d+\.?\d*,\-?\d+\.?\d*))+\)\)
  1146. $patternWkt = '[a-zA-Z]+\(\(' . $patternPoints . '\)\)';
  1147. } else if ('linestring' == $geomType) {
  1148. // [a-zA-Z]+\((\-?\d+\.?\d*,\-?\d+\.?\d*)( (\-?\d+\.?\d*,\-?\d+\.?\d*))+\)
  1149. $patternWkt = '[a-zA-Z]+\(' . $patternPoints . '\)';
  1150. } else if ('point' == $geomType) {
  1151. // [a-zA-Z]+\(\-?\d\.?\d*,\-?\d\.?\d*\)
  1152. $patternWkt = '[a-zA-Z]+\(' . $patternPoint . '\)';
  1153. }
  1154. $simpleTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  1155. $restrictionNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  1156. $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
  1157. $restrictionNode->setAttribute('base', 'xsd:string');
  1158. $patternNode->setAttribute('value', $patternWkt);
  1159. $restrictionNode->appendChild($patternNode);
  1160. $simpleTypeNode->appendChild($restrictionNode);
  1161. $elNode->appendChild($simpleTypeNode);
  1162. }
  1163. $elNode->setAttribute('nillable', 'true');
  1164. $elNode->setAttribute('minOccurs', '0');
  1165. }
  1166. }
  1167. }
  1168. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1169. $updateTypeNode->appendChild($attrNode);
  1170. $attrNode->setAttribute('name', 'typeName');
  1171. $attrNode->setAttribute('type', 'xsd:token');
  1172. $attrNode->setAttribute('use', 'required');
  1173. if ($transactionType == 'Insert') {
  1174. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1175. $updateTypeNode->appendChild($attrNode);
  1176. $attrNode->setAttribute('name', 'typeNsUri');
  1177. $attrNode->setAttribute('type', 'xsd:anyURI');
  1178. $attrNode->setAttribute('use', 'required');
  1179. }
  1180. if ($transactionType == 'Update') {
  1181. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1182. $updateTypeNode->appendChild($attrNode);
  1183. $attrNode->setAttribute('name', 'featureId');
  1184. $attrNode->setAttribute('use', 'required');
  1185. $sTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  1186. $attrNode->appendChild($sTypeNode);
  1187. $resNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  1188. $sTypeNode->appendChild($resNode);
  1189. $resNode->setAttribute('base', 'xsd:string');
  1190. $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
  1191. $resNode->appendChild($patternNode);
  1192. $patternNode->setAttribute('value', '[a-zA-Z_][a-zA-Z0-9_]*\.[0-9]*');
  1193. }
  1194. }
  1195. {// 'Delete'
  1196. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  1197. $acl = $this->getAclFromTypeName($typeName);
  1198. $deleteElementType = "DeleteNs{$nsInd}ElementType";
  1199. $deleteTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  1200. $rootNode->appendChild($deleteTypeNode);
  1201. $deleteTypeNode->setAttribute('name', $deleteElementType);
  1202. /* <xsd:attribute name="typeName" type="xsd:token" use="required"/> */
  1203. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1204. $deleteTypeNode->appendChild($attrNode);
  1205. $attrNode->setAttribute('name', 'typeName');
  1206. $attrNode->setAttribute('type', 'xsd:token');
  1207. $attrNode->setAttribute('use', 'required');
  1208. /* <xsd:attribute name="featureId" use="required"> */
  1209. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1210. $deleteTypeNode->appendChild($attrNode);
  1211. $attrNode->setAttribute('name', 'featureId');
  1212. $attrNode->setAttribute('use', 'required');
  1213. $sTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  1214. $attrNode->appendChild($sTypeNode);
  1215. $resNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  1216. $sTypeNode->appendChild($resNode);
  1217. $resNode->setAttribute('base', 'xsd:string');
  1218. $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
  1219. $resNode->appendChild($patternNode);
  1220. $patternNode->setAttribute('value', '[a-zA-Z_][a-zA-Z0-9_]*\.[0-9]*');
  1221. }
  1222. }
  1223. $validateConvertedTransactionXsdString = $dom->saveXml();
  1224. if($DBG){echo 'L.' . __LINE__ . ' $validateConvertedTransactionXsdString:';print_r($validateConvertedTransactionXsdString);echo "\n";}
  1225. $reqXml = new DOMDocument();
  1226. $reqXml->loadXml($convertedTransaction);
  1227. // TODO: fetch PHP Warning: DOMDocument::schemaValidateSource(): Element 'PARENT_ID': 'abc' is not a valid value of the atomic type 'xs:integer'.
  1228. return $reqXml->schemaValidateSource($validateConvertedTransactionXsdString);
  1229. }
  1230. public function _getDescribeFeatureType($nsPrefix, $type, $simple = true) {
  1231. return $this->_getDescribeFeatureTypes(array(array($nsPrefix, $type)), $simple);
  1232. }
  1233. public function _parseDescribeFeatureTypeRequest($reqContent, $simple = true) {
  1234. $parserXml = xml_parser_create();
  1235. xml_parser_set_option($parserXml, XML_OPTION_CASE_FOLDING, 0);
  1236. xml_parser_set_option($parserXml, XML_OPTION_SKIP_WHITE, 1);
  1237. if (0 == xml_parse_into_struct($parserXml, $reqContent, $tags)) {
  1238. throw new Exception("Error parsing xml");
  1239. }
  1240. xml_parser_free($parserXml);
  1241. if (empty($tags)) {
  1242. throw new Exception("Empty structure from request");
  1243. }
  1244. $rootTagName = V::get('tag', '', $tags[0]);
  1245. if ('DescribeFeatureType' != $rootTagName) {
  1246. throw new Api_WfsException("Wrong xml root tag '{$rootTagName}' #" . __LINE__, 501);
  1247. }
  1248. $requestXmlTags = $tags;
  1249. $DBG = (V::get('DBG_XML', '', $_GET) > 0);// TODO: Profiler
  1250. $rootTagName = V::get('tag', '', $requestXmlTags[0]);
  1251. if ('DescribeFeatureType' != $rootTagName) {
  1252. throw new Exception("Parse Request xml error #" . __LINE__);
  1253. }
  1254. /*[1] => Array(
  1255. [tag] => TypeName
  1256. [type] => complete
  1257. [level] => 2
  1258. [value] => p5_default_db:Rozdzielcza_rurociag_wsg84)
  1259. */
  1260. $typeNames = array();
  1261. $totalTypes = count($requestXmlTags) - 1;
  1262. for ($i = 1; $i < $totalTypes; $i++) {
  1263. if($DBG){echo "TAG[{$i}]:" . json_encode($requestXmlTags[$i]) . "\n";}
  1264. $typeNames[] = explode(':', $requestXmlTags[$i]['value'], 2);
  1265. }
  1266. //echo "typeNames: " . json_encode($typeNames) . "\n";
  1267. return $this->_getDescribeFeatureTypes($typeNames, $simple);
  1268. }
  1269. public function _getDescribeFeatureAllTypes($simple = true) {
  1270. $db = DB::getDB();
  1271. $idDefaultDB = $db->_zasob_id;
  1272. $tblsAcl = $this->_getTableAclList();
  1273. foreach ($tblsAcl as $tblAcl) {
  1274. $dataSourceName = 'default_db';// TODO: getSourceName
  1275. $tblName = $tblAcl->getName();
  1276. $typeNames[] = array("p5_{$dataSourceName}", $tblName);
  1277. }
  1278. $typeNames[] = array("p5_objects", 'File');
  1279. return $this->_getDescribeFeatureTypes($typeNames, $simple);
  1280. }
  1281. // @param $typeNames = array( array( $nsPrefix, $type ) )
  1282. public function _getDescribeFeatureTypes($typeNames, $simple = true) {
  1283. if (empty($typeNames)) throw new HttpException("Feature Type Names not defined", 400);
  1284. $this->DBG("types:" . json_encode($typeNames), __LINE__, __FUNCTION__, __CLASS__);
  1285. $baseNsUri = Api_WfsNs::getBaseWfsUri();
  1286. $rootWfsNs = 'p5';
  1287. $rootWfsNsUri = "{$baseNsUri}";
  1288. $featureTypeUri = Api_WfsNs::getBaseWfsUri() . "?SERVICE=WFS&VERSION=1.0.0&REQUEST=DescribeFeatureType";
  1289. header('Content-type: application/xml');
  1290. // <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://webgis.regione.sardegna.it:80/geoserver/schemas/gml/2.1.2/feature.xsd"/>
  1291. // <xsd:element name="{type}" substitutionGroup="gml:_Feature" type="dbu:{typeName}"/>
  1292. $dom = new DOMDocument('1.0', 'utf-8');
  1293. $dom->formatOutput = true;
  1294. $dom->preserveWhiteSpace = false;
  1295. $rootNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:schema');
  1296. $dom->appendChild($rootNode);
  1297. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gml', 'http://www.opengis.net/gml');
  1298. foreach (Api_WfsNs::getNsList() as $uri => $prefix) {
  1299. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', "xmlns:{$prefix}", $uri);
  1300. }
  1301. $rootNode->setAttribute('elementFormDefault', 'qualified');
  1302. $rootNode->setAttribute('targetNamespace', Api_WfsNs::getNsUri('p5_default_db'));// TODO:? what targetNamespace if showing types from p5_objects and p5_default_db
  1303. {// <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="...../gml/2.1.2/feature.xsd"/>
  1304. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:import');
  1305. $rootNode->appendChild($elNode);
  1306. $elNode->setAttribute('namespace', "http://www.opengis.net/gml");
  1307. $elNode->setAttribute('schemaLocation', Request::getPathUri() . "schema/gml/2.1.2/feature.xsd");
  1308. }
  1309. foreach ($typeNames as $typeNameEx) {
  1310. $nsPrefix = $typeNameEx[0];
  1311. $type = $typeNameEx[1];
  1312. $typeName = "{$nsPrefix}:{$type}";
  1313. $acl = $this->getAclFromTypeName($typeName);
  1314. if (!$this->isAllowedFeatureType($nsPrefix, $type)) {
  1315. throw new Api_WfsException("Could not find type: " . htmlspecialchars($type));
  1316. }
  1317. $typeName = $type . 'Type';
  1318. $fldList = $this->_getFieldListFromAcl($acl);
  1319. $cTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  1320. $rootNode->appendChild($cTypeNode);
  1321. $cTypeNode->setAttribute('name', $typeName);
  1322. if (!$simple) $cTypeNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:web_link", Request::getPathUri() . "index.php?_route=ViewTableAjax&namespace=" . $acl->getNamespace());
  1323. $cConNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexContent');
  1324. $cTypeNode->appendChild($cConNode);
  1325. $extNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:extension');
  1326. $cConNode->appendChild($extNode);
  1327. $extNode->setAttribute('base', 'gml:AbstractFeatureType');
  1328. $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
  1329. $extNode->appendChild($seqNode);
  1330. // <xsd:element maxOccurs="1" minOccurs="0" name="{$fldName}" nillable="true" type="xsd:integer"/>
  1331. $pKeyField = $acl->getPrimaryKeyField();
  1332. $p5Attributes = ($simple)? array() : $acl->getAttributesFromZasoby();
  1333. foreach ($fldList as $fldName) {
  1334. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1335. $seqNode->appendChild($elNode);
  1336. $minOccurs = 0;
  1337. if ($pKeyField == $fldName) {
  1338. $minOccurs = '1';
  1339. } else {
  1340. $minOccurs = '0';
  1341. }
  1342. $elNode->setAttribute('minOccurs', $minOccurs);
  1343. $elNode->setAttribute('maxOccurs', '1');
  1344. $elNode->setAttribute('nillable', 'true');
  1345. $fldType = $acl->getXsdFieldType($fldName);
  1346. if (!$simple && $acl->isEnumerationField($fldName)) {
  1347. $fldType = "{$nsPrefix}:{$fldName}Type";
  1348. }
  1349. if ('ref:' == substr($fldType, 0, 4)) {
  1350. $elNode->setAttribute('ref', substr($fldType, 4));
  1351. $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:name", $fldName);
  1352. } else if ('local_ref:' == substr($fldType, 0, 10)) {
  1353. $elNode->setAttribute('type', "{$fldName}Type");
  1354. $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:name", $fldName);
  1355. } else if ('alias_ref:' == substr($fldType, 0, 10)) {
  1356. $elNode->setAttribute('ref', "p5_" . $acl->getSourceName() . ":{$fldName}");
  1357. $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:name", $fldName);
  1358. } else {
  1359. $elNode->setAttribute('name', $fldName);
  1360. $elNode->setAttribute('type', $fldType);
  1361. }
  1362. if (!$simple) {
  1363. if (!empty($p5Attributes[$fldName])) {
  1364. $p5attrs = $p5Attributes[$fldName];
  1365. if (!empty($p5attrs['id_zasob'])) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:id_zasob", $p5attrs['id_zasob']);
  1366. if (!empty($p5attrs['label'])) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:label", $p5attrs['label']);
  1367. if (!empty($p5attrs['description'])) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:description", $p5attrs['description']);
  1368. }
  1369. if ($acl->canWriteField($fldName)) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_write", "true");
  1370. if ($acl->canCreateField($fldName)) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_create", "true");
  1371. if (!$acl->canReadField($fldName)) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_read", "false");
  1372. }
  1373. }
  1374. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1375. $rootNode->appendChild($elNode);
  1376. $elNode->setAttribute('name', $type);
  1377. $elNode->setAttribute('type', $nsPrefix . ':' . $typeName);// TODO: $acl->getSourceName() != $nsPrefix
  1378. if ($simple) {
  1379. $elNode->setAttribute('substitutionGroup', 'gml:_Feature');
  1380. } else {
  1381. $elNode->setAttribute('substitutionGroup', 'gml:AbstractFeature');
  1382. }
  1383. foreach ($fldList as $fldName) {
  1384. $fldType = $acl->getXsdFieldType($fldName);
  1385. if ('alias_ref:' == substr($fldType, 0, 10)) {
  1386. $localRefType = substr($fldType, 10);
  1387. // <xsd:element name="{$fldName}" ref="{$localRefType}">
  1388. $ctNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1389. $rootNode->appendChild($ctNode);
  1390. $ctNode->setAttribute('name', $fldName);
  1391. $ctNode->setAttribute('type', $localRefType);
  1392. } else if ('local_ref:' == substr($fldType, 0, 10)) {
  1393. $localRefType = substr($fldType, 10);
  1394. // <xsd:complexType name="produkt_Type">
  1395. // <xsd:sequence>
  1396. // <xsd:element name="idProd" type="xsd:integer" />
  1397. // <xsd:element name="nazwa" type="xsd:string" />
  1398. // <xsd:element name="cena" type="xsd:decimal" />
  1399. // </xsd:sequence>
  1400. // </xsd:complexType>
  1401. $ctNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  1402. $rootNode->appendChild($ctNode);
  1403. $ctNode->setAttribute('name', "{$fldName}Type");
  1404. $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
  1405. $ctNode->appendChild($seqNode);
  1406. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1407. $seqNode->appendChild($elNode);
  1408. $elNode->setAttribute('name', "test_id");
  1409. $elNode->setAttribute('type', "xsd:integer");
  1410. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1411. $seqNode->appendChild($elNode);
  1412. $elNode->setAttribute('name', "test_opis");
  1413. $elNode->setAttribute('type', "xsd:string");
  1414. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1415. $seqNode->appendChild($elNode);
  1416. $elNode->setAttribute('name', "test_decimal");
  1417. $elNode->setAttribute('type', "xsd:decimal");
  1418. }
  1419. }
  1420. if (!$simple) {
  1421. foreach ($fldList as $fldName) {
  1422. if ($acl->isEnumerationField($fldName)) {
  1423. $enum = $acl->getEnumerations($fldName);
  1424. $stNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  1425. $stNode->setAttribute('name', "{$fldName}Type");//"{$nsPrefix}:{$fldName}Type");
  1426. $rootNode->appendChild($stNode);
  1427. $resNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  1428. $stNode->appendChild($resNode);
  1429. $resNode->setAttribute('base', 'xsd:string');
  1430. // TODO: if (!empty($p5Attributes[$fldName]['valuesMap'])) -> show only this values
  1431. foreach ($enum as $val => $label) {
  1432. $enumNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:enumeration');
  1433. $resNode->appendChild($enumNode);
  1434. $enumNode->setAttribute('value', "{$val}");
  1435. if (!empty($p5Attributes[$fldName]['valuesMap'][$val])) {
  1436. $enumNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:label", $p5Attributes[$fldName]['valuesMap'][$val]);
  1437. }
  1438. }
  1439. }
  1440. }
  1441. }
  1442. }
  1443. return $dom->saveXML();
  1444. }
  1445. public function _getTableAclList() {// Use only Tables from default_db
  1446. $tblAclList = array();
  1447. $db = DB::getDB();
  1448. $idDefaultDB = $db->_zasob_id;
  1449. $fullTblAclList = $this->_usrAcl->getTablesAcl();
  1450. foreach ($fullTblAclList as $tblAcl) {
  1451. $dataSourceName = 'default_db';// TODO: getSourceName
  1452. $tblName = $tblAcl->getName();
  1453. if ($idDefaultDB != $tblAcl->getDB()) {// hide non default_db tables
  1454. continue;
  1455. }
  1456. try {
  1457. $acl = $this->getAclFromTypeName($typeName = "p5_{$dataSourceName}:{$tblName}");
  1458. } catch (Exception $e) {
  1459. // TODO: error log $e->getMessage();
  1460. }
  1461. if (!$acl) {
  1462. // TODO: error log msg
  1463. continue;
  1464. }
  1465. $tblAclList[] = $tblAcl;
  1466. }
  1467. return $tblAclList;
  1468. }
  1469. public function _getFieldListFromAcl($acl) {
  1470. $fldList = $acl->getRealFieldListByIdZasob();
  1471. return $fldList;
  1472. }
  1473. public function setLogger($logger) {
  1474. $this->_logger = $logger;
  1475. }
  1476. public function DBG($reqLog, $lineNr = null, $funName = null, $className = null) {
  1477. if (!$this->_logger) return;
  1478. $this->_logger->DBG($reqLog, $lineNr, $funName, $className);
  1479. }
  1480. public function convertOgcFilterFromRequestBody($requestOgcFilter) {
  1481. $ogcFilter = '';
  1482. if (empty($requestOgcFilter)) return '';
  1483. {
  1484. $convertOgcFilterXslString .= <<<EOF
  1485. <xsl:transform version="1.0"
  1486. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  1487. xmlns:wfs="http://www.opengis.net/wfs"
  1488. xmlns:ogc="http://www.opengis.net/ogc"
  1489. xmlns:gml="http://www.opengis.net/gml">
  1490. <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
  1491. <xsl:template match="/">
  1492. <xsl:for-each select="//*[local-name() = 'GetFeature']">
  1493. <xsl:copy-of select="ogc:Filter"/>
  1494. </xsl:for-each>
  1495. </xsl:template>
  1496. </xsl:transform>
  1497. EOF;
  1498. DBG::_('DBG_XML', '>2', "convertOgcFilterXslString", $convertOgcFilterXslString, __CLASS__, __FUNCTION__, __LINE__);
  1499. $convertTransactionXsl = new DOMDocument();
  1500. $convertTransactionXsl->loadXml($convertOgcFilterXslString);
  1501. $requestXml = new DOMDocument();
  1502. $requestXml->loadXml($requestOgcFilter);
  1503. $proc = new XSLTProcessor();
  1504. $proc->importStylesheet($convertTransactionXsl);
  1505. $ogcFilter = $proc->transformToXML($requestXml);
  1506. DBG::_('DBG_XML', '>2', "ogcFilter", $ogcFilter, __CLASS__, __FUNCTION__, __LINE__);
  1507. }
  1508. return $ogcFilter;
  1509. }
  1510. }