WfsServerBase.php 72 KB

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