WfsServerBase.php 71 KB

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