| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665 |
- <?php
- Lib::loadClass('Api_WfsException');
- Lib::loadClass('Api_WfsGeomTypeConverter');
- class Api_WfsServerBase {
- public $_usrAcl;
- public $_typeConverter;
- public $_apiBaseUri;
- protected $_logFile;
- public function __construct($usrAcl) {
- $this->_usrAcl = $usrAcl;
- $this->_typeConverter = new Api_WfsGeomTypeConverter();
- $this->_apiBaseUri = '';
- }
- public function setBaseUri($uri) {
- $this->_apiBaseUri = $uri;
- }
- public function getBaseUri() {
- return $this->_apiBaseUri;
- }
- public function getBaseNamespaceUri() {
- $baseNsUri = $this->_apiBaseUri;
- $protocolType = '';
- if (!empty($baseNsUri)) {
- if ('https://' == substr($baseNsUri, 0, 8)) {
- $protocolType = 'https';
- $baseNsUri = substr($baseNsUri, 8);
- } else if ('http://' == substr($baseNsUri, 0, 7)) {
- $protocolType = 'http';
- $baseNsUri = substr($baseNsUri, 6);
- }
- }
- if (!empty($baseNsUri)) {
- if (false !== ($pos = strpos($baseNsUri, '/'))) {
- $baseNsUri = substr($baseNsUri, 0, $pos);
- }
- }
- return "{$protocolType}://{$baseNsUri}/wfs";
- }
- public function isAllowedFeatureType($nsPrefix, $type) {
- if ('p5_' != substr($nsPrefix, 0, 3)) return false;
- if ('p5_default_db' == $nsPrefix) {
- $typeName = "p5_default_db:{$type}";
- try {
- $acl = $this->getAclFromTypeName($typeName);
- } catch (Exception $e) {
- return false;
- }
- if ($acl) {
- return true;
- }
- } else if ('p5_objects' == $nsPrefix && 'File' == $type) {
- return true;
- }
- return false;
- }
- /**
- * @param string $typeName - 'p5_default_db:TEST_PERMS'
- */
- public function getAclFromTypeName($typeName) {
- $typeEx = explode(':', $typeName);
- if (2 != count($typeEx)) throw new Api_WfsException("Could not get acl for '{$typeName}' - syntax error");
- if ('p5_' != substr($typeEx[0], 0, 3)) throw new Api_WfsException("Could not get acl for '{$typeName}' - prefix error");
- $sourceName = substr($typeEx[0], 3);
- $objName = $typeEx[1];
- $acl = $this->_usrAcl->getObjectAcl($sourceName, $objName);
- if (!$acl) throw new Api_WfsException("Could not get acl for '{$typeName}'");
- $forceTblAclInit = 0;//('1' == V::get('_force', '', $_GET));
- $acl->init($forceTblAclInit);
- return $acl;
- }
- public function _getCapabilities($wfsServerUrl, $serviceTitle, $serviceDescription) {
- echo '<?xml version="1.0" encoding="UTF-8"?>';
- ?>
- <WFS_Capabilities
- xmlns="http://www.opengis.net/wfs"
- xmlns:ogc="http://www.opengis.net/ogc"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- <?php echo $this->_getXmlNamespaceList(); ?>
- <?php echo $this->_getXmlSchemaLocation(); ?>
- version="1.0.0">
- <Service>
- <Name>WFS</Name>
- <Title><?php echo $serviceTitle; ?></Title>
- <Abstract><?php echo $serviceDescription; ?></Abstract>
- <Keywords>WFS, WMS</Keywords>
- <OnlineResource><?php echo $wfsServerUrl; ?></OnlineResource>
- <Fees>NONE</Fees>
- <AccessConstraints>NONE</AccessConstraints>
- </Service>
- <Capability>
- <Request>
- <?php $this->_printGetCapabilitiesXml($wfsServerUrl); ?>
- <?php $this->_printDescribeFeatureTypeXml($wfsServerUrl); ?>
- <?php $this->_printGetFeatureXml($wfsServerUrl); ?>
- <?php $this->_printTransactionXml($wfsServerUrl); ?>
- <?php $this->_printLockFeatureXml($wfsServerUrl); ?>
- <?php $this->_printGetFeatureWithLockXml($wfsServerUrl); ?>
- </Request>
- </Capability>
- <FeatureTypeList>
- <Operations>
- <Query />
- <Insert />
- <Update />
- <Delete />
- <Lock />
- </Operations>
- <?php $this->_printFeatureTypeListXml(); ?>
- </FeatureTypeList>
- <ogc:Filter_Capabilities>
- <ogc:Spatial_Capabilities>
- <ogc:Spatial_Operators>
- <ogc:Disjoint />
- <ogc:Equals />
- <ogc:DWithin />
- <ogc:Beyond />
- <ogc:Intersect />
- <ogc:Touches />
- <ogc:Crosses />
- <ogc:Within />
- <ogc:Contains />
- <ogc:Overlaps />
- <ogc:BBOX />
- </ogc:Spatial_Operators>
- </ogc:Spatial_Capabilities>
- <ogc:Scalar_Capabilities>
- <ogc:Logical_Operators />
- <ogc:Comparison_Operators>
- <ogc:Simple_Comparisons />
- <ogc:Between />
- <ogc:Like />
- <ogc:NullCheck />
- </ogc:Comparison_Operators>
- <ogc:Arithmetic_Operators>
- <ogc:Simple_Arithmetic />
- <ogc:Functions>
- <ogc:Function_Names>
- <ogc:Function_Name nArgs="1">abs</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">abs_2</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">abs_3</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">abs_4</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">acos</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">AddCoverages</ogc:Function_Name>
- <ogc:Function_Name nArgs="4">Aggregate</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">Area</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">area2</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">AreaGrid</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">asin</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">atan</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">atan2</ogc:Function_Name>
- <ogc:Function_Name nArgs="14">BarnesSurface</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">between</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">boundary</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">boundaryDimension</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">Bounds</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">buffer</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">BufferFeatureCollection</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">bufferWithSegments</ogc:Function_Name>
- <ogc:Function_Name nArgs="7">Categorize</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">ceil</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">Centroid</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">classify</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">Clip</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">CollectGeometries</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">Collection_Average</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">Collection_Bounds</ogc:Function_Name>
- <ogc:Function_Name nArgs="0">Collection_Count</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">Collection_Max</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">Collection_Median</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">Collection_Min</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">Collection_Sum</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">Collection_Unique</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">Concatenate</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">contains</ogc:Function_Name>
- <ogc:Function_Name nArgs="7">Contour</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">convert</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">convexHull</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">cos</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">Count</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">CropCoverage</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">crosses</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">dateFormat</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">dateParse</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">difference</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">dimension</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">disjoint</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">disjoint3D</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">distance</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">distance3D</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">double2bool</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">endAngle</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">endPoint</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">env</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">envelope</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">EqualInterval</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">equalsExact</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">equalsExactTolerance</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">equalTo</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">exp</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">exteriorRing</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">Feature</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">floor</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">geometryType</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">geomFromWKT</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">geomLength</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">getGeometryN</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">getX</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">getY</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">getz</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">greaterEqualThan</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">greaterThan</ogc:Function_Name>
- <ogc:Function_Name nArgs="5">Grid</ogc:Function_Name>
- <ogc:Function_Name nArgs="7">Heatmap</ogc:Function_Name>
- <ogc:Function_Name nArgs="0">id</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">IEEEremainder</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">if_then_else</ogc:Function_Name>
- <ogc:Function_Name nArgs="11">in10</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">in2</ogc:Function_Name>
- <ogc:Function_Name nArgs="4">in3</ogc:Function_Name>
- <ogc:Function_Name nArgs="5">in4</ogc:Function_Name>
- <ogc:Function_Name nArgs="6">in5</ogc:Function_Name>
- <ogc:Function_Name nArgs="7">in6</ogc:Function_Name>
- <ogc:Function_Name nArgs="8">in7</ogc:Function_Name>
- <ogc:Function_Name nArgs="9">in8</ogc:Function_Name>
- <ogc:Function_Name nArgs="10">in9</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">InclusionFeatureCollection</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">int2bbool</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">int2ddouble</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">interiorPoint</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">interiorRingN</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">Interpolate</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">intersection</ogc:Function_Name>
- <ogc:Function_Name nArgs="7">IntersectionFeatureCollection</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">intersects</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">intersects3D</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">isClosed</ogc:Function_Name>
- <ogc:Function_Name nArgs="0">isCoverage</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">isEmpty</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">isLike</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">isNull</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">isometric</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">isRing</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">isSimple</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">isValid</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">isWithinDistance</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">isWithinDistance3D</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">Jenks</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">length</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">lessEqualThan</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">lessThan</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">list</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">log</ogc:Function_Name>
- <ogc:Function_Name nArgs="4">LRSGeocode</ogc:Function_Name>
- <ogc:Function_Name nArgs="5">LRSMeasure</ogc:Function_Name>
- <ogc:Function_Name nArgs="5">LRSSegment</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">max</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">max_2</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">max_3</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">max_4</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">min</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">min_2</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">min_3</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">min_4</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">mincircle</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">minimumdiameter</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">minrectangle</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">modulo</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">MultiplyCoverages</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">Nearest</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">not</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">notEqualTo</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">numberFormat</ogc:Function_Name>
- <ogc:Function_Name nArgs="5">numberFormat2</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">numGeometries</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">numInteriorRing</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">numPoints</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">octagonalenvelope</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">offset</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">overlaps</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">parameter</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">parseBoolean</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">parseDouble</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">parseInt</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">parseLong</ogc:Function_Name>
- <ogc:Function_Name nArgs="0">pi</ogc:Function_Name>
- <ogc:Function_Name nArgs="4">PointBuffers</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">pointN</ogc:Function_Name>
- <ogc:Function_Name nArgs="7">PointStacker</ogc:Function_Name>
- <ogc:Function_Name nArgs="6">PolygonExtraction</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">pow</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">property</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">PropertyExists</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">Quantile</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">Query</ogc:Function_Name>
- <ogc:Function_Name nArgs="0">random</ogc:Function_Name>
- <ogc:Function_Name nArgs="5">RangeLookup</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">RasterAsPointCollection</ogc:Function_Name>
- <ogc:Function_Name nArgs="4">RasterZonalStatistics</ogc:Function_Name>
- <ogc:Function_Name nArgs="5">Recode</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">RectangularClip</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">relate</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">relatePattern</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">Reproject</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">rint</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">round</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">round_2</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">roundDouble</ogc:Function_Name>
- <ogc:Function_Name nArgs="6">ScaleCoverage</ogc:Function_Name>
- <ogc:Function_Name nArgs="4">sdo_nn</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">setCRS</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">Simplify</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">sin</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">Snap</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">sqrt</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">StandardDeviation</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">startAngle</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">startPoint</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">strCapitalize</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">strConcat</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">strEndsWith</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">strEqualsIgnoreCase</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">strIndexOf</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">strLastIndexOf</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">strLength</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">strMatches</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">strPosition</ogc:Function_Name>
- <ogc:Function_Name nArgs="4">strReplace</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">strStartsWith</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">strSubstring</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">strSubstringStart</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">strToLowerCase</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">strToUpperCase</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">strTrim</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">strTrim2</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">StyleCoverage</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">symDifference</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">tan</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">toDegrees</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">toRadians</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">touches</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">toWKT</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">Transform</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">union</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">UnionFeatureCollection</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">Unique</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">UniqueInterval</ogc:Function_Name>
- <ogc:Function_Name nArgs="6">VectorToRaster</ogc:Function_Name>
- <ogc:Function_Name nArgs="3">VectorZonalStatistics</ogc:Function_Name>
- <ogc:Function_Name nArgs="1">vertices</ogc:Function_Name>
- <ogc:Function_Name nArgs="2">within</ogc:Function_Name>
- </ogc:Function_Names>
- </ogc:Functions>
- </ogc:Arithmetic_Operators>
- </ogc:Scalar_Capabilities>
- </ogc:Filter_Capabilities>
- </WFS_Capabilities>
- <?php
- }
- public function _getXmlSchemaLocation() {
- $schemaLocations = array();
- //$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
- return (!empty($schemaLocations))? 'xsi:schemaLocation="' . implode(' ', $schemaLocations) . '"' : '';
- }
- public function _getXmlNamespaceList() {
- $baseNsUri = $this->getBaseNamespaceUri();
- $listNs = array();
- $listNs[] = 'xmlns:p5_default_db="' . $baseNsUri . '/default_db"';
- $listNs[] = 'xmlns:p5_objects="' . $baseNsUri . '/objects"';
- return implode("\n", $listNs);
- }
- public function _getXmlNamespaceList__OLD() {
- $baseNsUri = $this->getBaseNamespaceUri();
- $namespaceList = $this->_getSourceNsList();
- $namespaceListOut = array();
- foreach ($namespaceList as $nsObj) {
- $ns = "p5_{$nsObj[0]}_{$nsObj[1]}";
- $uri = "{$baseNsUri}/{$nsObj[0]}/{$nsObj[1]}";
- $namespaceListOut[] = 'xmlns:' . $ns . '="' . $uri . '"';
- }
- return implode(' ', $namespaceListOut);
- }
- public function _getSourceNsList() {
- $usrObjList = array();
- $tblsAcl = $this->_usrAcl->getTablesAcl();
- foreach ($tblsAcl as $tblAcl) {
- $dataSourceName = 'default_db';// TODO: getSourceName
- $tblName = $tblAcl->getName();
- $usrObjList[] = array($dataSourceName, $tblName);
- }
- $usrObjList[] = array('objects', 'File');
- return $usrObjList;
- }
- public function _printGetCapabilitiesXml($wfsServerUrl) {
- ?>
- <GetCapabilities>
- <DCPType>
- <HTTP>
- <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetCapabilities" />
- </HTTP>
- </DCPType>
- <DCPType>
- <HTTP>
- <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
- </HTTP>
- </DCPType>
- </GetCapabilities>
- <?php
- }
- public function _printDescribeFeatureTypeXml($wfsServerUrl) {
- ?>
- <DescribeFeatureType>
- <SchemaDescriptionLanguage>
- <XMLSCHEMA />
- </SchemaDescriptionLanguage>
- <DCPType>
- <HTTP>
- <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=DescribeFeatureType" />
- </HTTP>
- </DCPType>
- <DCPType>
- <HTTP>
- <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
- </HTTP>
- </DCPType>
- </DescribeFeatureType>
- <?php
- }
- public function _printGetFeatureXml($wfsServerUrl) {
- ?>
- <GetFeature>
- <ResultFormat>
- <WFSKMLOutputFormat />
- <GML2 />
- <GML3 />
- <SHAPE-ZIP />
- <CSV />
- <JSON />
- </ResultFormat>
- <DCPType>
- <HTTP>
- <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetFeature" />
- </HTTP>
- </DCPType>
- <DCPType>
- <HTTP>
- <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
- </HTTP>
- </DCPType>
- </GetFeature>
- <?php
- }
- public function _printTransactionXml($wfsServerUrl) {
- ?>
- <Transaction>
- <DCPType>
- <HTTP>
- <Get onlineResource="<?php echo $wfsServerUrl; ?>?request=Transaction" />
- </HTTP>
- </DCPType>
- <DCPType>
- <HTTP>
- <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
- </HTTP>
- </DCPType>
- </Transaction>
- <?php
- }
- public function _printLockFeatureXml($wfsServerUrl) {
- ?>
- <LockFeature>
- <DCPType>
- <HTTP>
- <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=LockFeature" />
- </HTTP>
- </DCPType>
- <DCPType>
- <HTTP>
- <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
- </HTTP>
- </DCPType>
- </LockFeature>
- <?php
- }
- public function _printGetFeatureWithLockXml($wfsServerUrl) {
- ?>
- <GetFeatureWithLock>
- <ResultFormat>
- <GML2 />
- </ResultFormat>
- <DCPType>
- <HTTP>
- <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetFeatureWithLock" />
- </HTTP>
- </DCPType>
- <DCPType>
- <HTTP>
- <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
- </HTTP>
- </DCPType>
- </GetFeatureWithLock>
- <?php
- }
- public function _printFeatureTypeListXml() {
- $featureTypes = array();
- $tblsAcl = $this->_getTableAclList();
- foreach ($tblsAcl as $tblAcl) {
- $dataSourceName = 'default_db';// TODO: getSourceName
- $tblName = $tblAcl->getName();
- $usrObjList[] = array($dataSourceName, $tblName);
- $featureType = array();
- $featureType['ns'] = "p5_{$dataSourceName}";
- $featureType['Title'] = $tblAcl->getRawLabel();
- $featureType['Abstract'] = $tblAcl->getRawOpis();
- $featureType['Keywords'] = array();
- $featureType['Keywords'][] = $tblAcl->getID();
- $featureType['Keywords'][] = $tblName;
- $featureType['Keywords'][] = $tblAcl->getRawLabel();
- $featureType['Keywords'] = implode(", ", $featureType['Keywords']);
- $featureType['SRS'] = "EPSG:4326";
- $featureType['LatLongBoundingBox'] = array();// TODO: feature LatLongBoundingBox
- $featureType['LatLongBoundingBox']['minx'] = "8.12328509871721";
- $featureType['LatLongBoundingBox']['miny'] = "38.8575126897477";
- $featureType['LatLongBoundingBox']['maxx'] = "9.838674658246807";
- $featureType['LatLongBoundingBox']['maxy'] = "41.31378404137082";
- $featureTypes[$tblName] = $featureType;
- }
- {// add p5_objects:File
- Lib::loadClass('FileStorage');
- $featureType = array();
- $featureType['ns'] = "p5_objects";
- $featureType['Title'] = "Pliki";
- $featureType['Abstract'] = "Pliki";
- $featureType['Keywords'] = "Pliki";
- $featureType['SRS'] = "EPSG:4326";
- // $featureType['LatLongBoundingBox'] = array();// TODO: feature LatLongBoundingBox
- // $featureType['LatLongBoundingBox']['minx'] = "8.12328509871721";
- // $featureType['LatLongBoundingBox']['miny'] = "38.8575126897477";
- // $featureType['LatLongBoundingBox']['maxx'] = "9.838674658246807";
- // $featureType['LatLongBoundingBox']['maxy'] = "41.31378404137082";
- $featureTypes['File'] = $featureType;
- }
- /*
- <FeatureType>
- <Name>ppr06:AMBITIPAESAGGIO</Name>
- <Title>AMBITIPAESAGGIO</Title>
- <Abstract />
- <Keywords>features, AMBITIPAESAGGIO</Keywords>
- <SRS>EPSG:4326</SRS>
- <LatLongBoundingBox minx="8.12328509871721" miny="38.8575126897477" maxx="9.838674658246807" maxy="41.31378404137082" />
- </FeatureType>
- */
- $featureTypesXml = '';
- foreach ($featureTypes as $tblName => $feature) {
- $featureTypesXml .= " " . '<FeatureType>' . "\n";
- $featureTypesXml .= " " . '<Name>' . "{$feature['ns']}:{$tblName}" . '</Name>' . "\n";
- $featureTypesXml .= " " . '<Title>' . "{$feature['Title']}" . '</Title>' . "\n";
- if (!empty($feature['Abstract'])) {
- $featureTypesXml .= " " . '<Abstract>' . "{$feature['Abstract']}" . '</Abstract>' . "\n";
- } else {
- $featureTypesXml .= " " . '<Abstract/>' . "\n";
- }
- if (!empty($feature['Keywords'])) {
- $featureTypesXml .= " " . '<Keywords>' . "{$feature['Keywords']}" . '</Keywords>' . "\n";
- } else {
- $featureTypesXml .= " " . '<Keywords/>' . "\n";
- }
- $featureTypesXml .= " " . '<SRS>' . "{$feature['SRS']}" . '</SRS>' . "\n";
- if (!empty($feature['LatLongBoundingBox'])) {
- $latLongBoundingBoxOut = array();
- $latLongBoundingBoxOut[] = 'minx="' . $feature['LatLongBoundingBox']['minx'] . '"';
- $latLongBoundingBoxOut[] = 'miny="' . $feature['LatLongBoundingBox']['miny'] . '"';
- $latLongBoundingBoxOut[] = 'maxx="' . $feature['LatLongBoundingBox']['maxx'] . '"';
- $latLongBoundingBoxOut[] = 'maxy="' . $feature['LatLongBoundingBox']['maxy'] . '"';
- $featureTypesXml .= " " . '<LatLongBoundingBox ' . implode(' ', $latLongBoundingBoxOut) . ' />' . "\n";
- }
- $featureTypesXml .= " " . '</FeatureType>' . "\n";
- }
- echo $featureTypesXml;
- }
- public function _parseTransactionXmlStruct($requestXml, $requestXmlTags) {
- $DBG = (V::get('DBG_XML', '', $_GET) > 0);// TODO: Profiler
- $rootTagName = V::get('tag', '', $requestXmlTags[0]);
- if ('Transaction' != $rootTagName) {
- throw new Api_WfsException("Parse Request XML Error - Missing Transaction as root xml tag", __LINE__, null, 'TransactionParseError', 'request');
- }
- // 1. convert request: wfs.transaction.convert-wfs-request.xsl
- // 2. validate converted request: wfs.transaction-converted-request.xsd
- // 3. execute request in data source
- // ? acl check?
- $usedSourceNsList = array();
- $sourceNsList = $this->_getSourceNsList();
- //$sourceNsList = array();
- //foreach ($requestXmlTags[0]['attributes'] as $attrName => $attrValue) {
- // if ('xmlns:p5_' == substr($attrName, 0, 9)) {
- // $sourceNsList[substr($attrName, 6)] = $attrValue;
- // }
- //}
- {// get used typeNames
- $usedTypeNames = array();
- // <Update xmlns="http://www.opengis.net/wfs" typeName="p5_default_db:TEST_PERMS">
- foreach ($requestXmlTags as $tag) {
- if ('Update' == $tag['tag'] && 'open' == $tag['type']) {
- $typeName = $tag['attributes']['typeName'];
- foreach ($sourceNsList as $nsInd => $ns) {
- if ("p5_{$ns[0]}:{$ns[1]}" == $typeName) {
- $usedSourceNsList[$nsInd] = $ns;
- }
- }
- }
- }
- // TODO: check: <Transaction xmlns:p5_default_db="https://biuro.biall-net.pl/wfs/default_db/TEST_PERMS"
- // <Insert xmlns="http://www.opengis.net/wfs">
- // <TEST_PERMS xmlns="https://biuro.biall-net.pl/wfs/default_db/TEST_PERMS">
- $lastTagName = '';
- foreach ($requestXmlTags as $tag) {
- if ('Insert' == $lastTagName) {
- $typeName = $tag['tag'];
- foreach ($sourceNsList as $nsInd => $ns) {
- if ("{$ns[1]}" == $typeName) {
- $usedSourceNsList[$nsInd] = $ns;
- }
- }
- }
- $lastTagName = $tag['tag'];
- }
- // <Delete xmlns="http://www.opengis.net/wfs" typeName="p5_default_db:TEST_GEOM_POINT">
- foreach ($requestXmlTags as $tag) {
- if ('Delete' == $tag['tag'] && 'open' == $tag['type']) {
- $typeName = $tag['attributes']['typeName'];
- foreach ($sourceNsList as $nsInd => $ns) {
- if ("p5_{$ns[0]}:{$ns[1]}" == $typeName) {
- $usedSourceNsList[$nsInd] = $ns;
- }
- }
- }
- }
- }
- if (empty($usedSourceNsList)) {
- throw new Api_WfsException("Parse Request XML Error - Empty source NS list", __LINE__, null, 'TransactionParseError', 'request');
- }
- $convertedTransaction = $this->_convertTransactionXml($requestXml, $usedSourceNsList);
- if($DBG){echo 'L.' . __LINE__ . ' $convertedTransaction:';print_r($convertedTransaction);echo "\n";}
- if (empty($convertedTransaction)) {
- throw new Api_WfsException("Parse Request XML Error - Empty transaction", __LINE__, null, 'TransactionParseError', 'request');
- }
- if (!$this->_validateConvertedTransactionXml($convertedTransaction, $usedSourceNsList)) {
- // <Transaction version="1.0.0" service="WFS">
- // <InsertNs0 typeName="TEST_PERMS">
- // <ID>41</ID>
- // <ADM_ADMIN_LEVEL>3</ADM_ADMIN_LEVEL>
- // </InsertNs0>
- // </Transaction>
- $transXml = @simplexml_load_string($convertedTransaction);
- foreach ($transXml->children() as $funcXml) {
- $funcName = substr($funcXml->getName(), 0, 6);// Insert... , Update... , Delete...
- if (empty($funcXml['typeName'][0])) throw new Api_WfsException("Missing typeName for function '{$funcName}'", __LINE__, null, 'MissingTypeName', 'request');
- $typeName = $funcXml['typeName'][0];
- $acl = $this->getAclFromTypeName("p5_default_db:{$typeName}");
- $primaryKey = $acl->getPrimaryKeyField();
- $pkObject = null;
- foreach ($funcXml->children() as $fieldXml) {
- if ($primaryKey == $fieldXml->getName()) $pkObject = $fieldXml[0];
- }
- if ('Insert' == $funcName && $pkObject) $funcName = 'Update';
- if ('Update' == $funcName) {// check perm W - skip $primaryKey
- if (!$pkObject) throw new Api_WfsException("Missing primary key ({$primaryKey}) for action Update", __LINE__, null, 'MissingPrimaryKey', 'request');
- $toUpdateFields = array();
- foreach ($funcXml->children() as $fieldXml) {
- if ($primaryKey == $fieldXml->getName()) continue;// skip primary key
- $toUpdateFields[] = $fieldXml->getName();
- }
- if (empty($toUpdateFields)) throw new Api_WfsException("Missing fields to update", __LINE__, null, 'MissingFieldToUpdate', 'request');
- $oldObject = $acl->getItem($pkObject);
- if (!$oldObject) throw new Api_WfsException("Object '{$typeName}.{$pkObject}' not exists", __LINE__, null, 'ObjectNotExists', 'request');
- if (!$acl->canWriteRecord($oldObject) && !$acl->hasPermSuperWrite()) {
- throw new Api_WfsException("Access Denied to Update object '{$typeName}.{$pkObject}'", __LINE__, null, 'MissingObjectPermUpdate', 'request');
- }
- foreach ($toUpdateFields as $fieldName) {
- $aclIdFld = $acl->getFieldIdByName($fieldName);
- if (!$acl->isAllowed($aclIdFld, 'W', $oldObject)) {
- throw new Api_WfsException("Access Denied to Update field '{$fieldName}' in object '{$typeName}.{$pkObject}'", __LINE__, null, 'MissingFieldPermWrite', 'request');
- }
- }
- } else if ('Insert' == $funcName) {// check perm C
- foreach ($funcXml->children() as $fieldXml) {
- $fieldName = $fieldXml->getName();
- $aclIdFld = $acl->getFieldIdByName($fieldXml->getName());
- if (!$acl->isAllowed($aclIdFld, 'C')) {
- throw new Api_WfsException("Access Denied to Create field '{$fieldName}' in object '{$typeName}.{$pkObject}'", __LINE__, null, 'MissingFieldPermCreate', 'request');
- }
- }
- } else {
- // TODO: Delete, ... ?
- }
- }
- throw new Exception("Parse Request xml error #" . __LINE__ . ": schema validation failed");
- }
- $parserXml = xml_parser_create();
- xml_parser_set_option($parserXml, XML_OPTION_CASE_FOLDING, 0);
- xml_parser_set_option($parserXml, XML_OPTION_SKIP_WHITE, 1);
- if (0 == xml_parse_into_struct($parserXml, $convertedTransaction, $tags)) {
- throw new Exception("Parse Request xml error #" . __LINE__ . ": parse converted transaction failed");
- }
- xml_parser_free($parserXml);
- if (empty($tags)) {
- throw new Exception("Parse Request xml error #" . __LINE__ . ": parse converted transaction returns empty structure");
- }
- // [{"tag":"Transaction","type":"open","level":1,"attributes":{"version":"1.0.0","service":"WFS"}},
- // {"tag":"Update","type":"open","level":2,"attributes":
- // {"typeName":"p5_default_db_13051:TEST_PERMS","featureId":"TEST_PERMS.25"}},
- // {"tag":"PARENT_ID","type":"complete","level":3,"value":"0"},
- // {"tag":"Update","type":"close","level":2},
- // {"tag":"Transaction","type":"close","level":1}]
- if($DBG){echo "\ntags L." . __LINE__ . ":\n"; print_r($tags);echo "\n";}
- $actionTag = null;
- $prevTagName = '';
- $theGeomField = 'the_geom';// TODO: get the geom field name from acl
- $itemPatchs = array();
- foreach ($tags as $tag) {
- switch (substr($tag['tag'], 0, 6)) {
- case 'Transa': continue; break;// Transaction
- case 'Update':
- case 'Insert':
- case 'Delete':
- case 'Native':
- if ('open' == $tag['type'] // Insert, Update
- || 'complete' == $tag['type'] // Delete
- ) {
- if($DBG){echo "\ntags loop 1 - tag: L." . __LINE__ . ":\n"; print_r($tag);echo "\n";}
- $actionTag = array();
- $actionTag['tag'] = substr($tag['tag'], 0, 6);
- $actionTag['typeName'] = $tag['attributes']['typeName'];
- if ('Insert' == substr($tag['tag'], 0, 6)) {
- $typeNsPrefix = 'p5_default_db';
- if (!empty($tag['attributes']['typeNsUri'])) {
- $baseNsUri = $this->getBaseNamespaceUri();
- if ("{$baseNsUri}/objects" == $tag['attributes']['typeNsUri']) {
- $typeNsPrefix = 'p5_objects';
- }
- }
- $actionTag['typeName'] = "{$typeNsPrefix}:{$tag['attributes']['typeName']}";
- }
- $featureEx = explode('.', $tag['attributes']['featureId'], 2);
- $actionTag['featureId'] = $featureEx[1];
- if ('Update' == substr($tag['tag'], 0, 6) && empty($actionTag['featureId'])) {
- throw new Api_WfsException("Syntax error - could not read feature id!");
- }
- if ('Delete' == substr($tag['tag'], 0, 6) && empty($actionTag['featureId'])) {
- throw new Api_WfsException("Syntax error - could not read feature id!");
- }
- if ('complete' == $tag['type']) {
- $itemPatchs[] = $actionTag;
- $actionTag = null;
- } else {
- $actionTag['itemPatch'] = array();
- }
- } else {
- $itemPatchs[] = $actionTag;
- $actionTag = null;
- }
- break;
- default: {// fields
- if($DBG){echo "\ntags loop 2 - tag: L." . __LINE__ . ":\n"; print_r($tag);echo "\n";}
- if (3 != $tag['level'] && 'close' == $tag['type']) {
- $actionTag = null;
- }
- if (3 != $tag['level']) continue;
- if (empty($actionTag)) continue;
- if ('Update' == $actionTag['tag']) {
- if ($theGeomField == $tag['tag']) {
- $actionTag['itemPatch'][$tag['tag']] = $this->_typeConverter->convertGmlCoordinatesToWkt($tag['value']);
- } else {
- $actionTag['itemPatch'][$tag['tag']] = $tag['value'];
- }
- }
- else if ('Insert' == $actionTag['tag']) {
- if ($theGeomField == $tag['tag']) {
- $actionTag['itemPatch'][$tag['tag']] = $this->_typeConverter->convertGmlCoordinatesToWkt($tag['value']);
- } else {
- $actionTag['itemPatch'][$tag['tag']] = $tag['value'];
- }
- }
- else if ('Delete' == $actionTag['tag']) {
- }
- }
- }
- if (empty($prevTagName)) $prevTagName = $tag['tag'];
- }
- if($DBG){echo "\nTODO: itemPatchs L." . __LINE__ . ":\n"; print_r($itemPatchs);echo "\n";}
- if($DBG){echo "\nTODO: _user_id L." . __LINE__ . " '{$this->_usrAcl->_user_id}'" . "\n";}
- $changesList = array();
- if (!empty($itemPatchs)) {
- foreach ($itemPatchs as $itemPatchInfo) {
- if($DBG){echo "L." . __LINE__ . " itemPatchInfo: {typeName:'{$itemPatchInfo['typeName']}'}:\n";print_r($itemPatchInfo);}
- $acl = $this->getAclFromTypeName($itemPatchInfo['typeName']);
- if ('Delete' == $itemPatchInfo['tag']) {
- $itemPatch = array();
- $itemPatch[$acl->getPrimaryKeyField()] = $itemPatchInfo['featureId'];
- $itemPatch['the_geom'] = 'NULL';
- } else {
- if (empty($itemPatchInfo['itemPatch'])) continue;
- $itemPatch = $itemPatchInfo['itemPatch'];
- if ('Update' == $itemPatchInfo['tag']) {
- $itemPatch[$acl->getPrimaryKeyField()] = $itemPatchInfo['featureId'];
- }
- else if ('Insert' == $itemPatchInfo['tag']) {
- if (!empty($itemPatch[$acl->getPrimaryKeyField()])) {
- $itemPatchInfo['featureId'] = $itemPatch[$acl->getPrimaryKeyField()];
- }
- else {
- //throw new Exception("TODO: Insert #" . __LINE__ . ": Create new record");
- }
- }
- }
- if($DBG){echo "L." . __LINE__ . " TODO '" . ($itemPatchInfo['tag'])? 'Insert' : 'Update' . "' itemPatch:\n";print_r($itemPatch);}
- if ('Insert' == $itemPatchInfo['tag'] && empty($itemPatch[$acl->getPrimaryKeyField()])) {
- $newId = $acl->addItem($itemPatch);
- $changesList[$newId] = array('Status'=>(($newId > 0)? 'SUCCESS' : 'FAILED'), 'Message'=>"created {$newId}.");
- if ($newId > 0) {
- $changesList[$newId]['fid'] = $acl->getName() . '.' . $newId;
- }
- if($DBG){echo "created {$newId}.\n";}
- } else {
- $affected = $acl->updateItem($itemPatch);
- $changesList[$itemPatchInfo['featureId']] = array('Status'=>(($affected >= 0)? 'SUCCESS' : 'FAILED'), 'Message'=>"affected {$affected}.");
- if($DBG){echo "affected {$affected}.\n";}
- }
- }
- //throw new Exception("TODO: run query #" . __LINE__ . " \nitemPatchs:\n" . json_encode($itemPatchs) . " \ntags:\n" . json_encode($tags) . "\n");
- }
- else {
- throw new Exception("Parse Request xml error #" . __LINE__ . ": Nothing to change");
- }
- return $this->_transactionResponse($changesList);
- }
- public function _transactionResponse($changesList) {
- // <WFS_TransactionResponse>
- // <TransactionResult>
- // <Status> : SUCCESS / FAILED / PARTIAL
- // [<Locator]
- // [<Message]
- $messageTag = '';
- $statusTag = '';
- $statusIsFailed = false;
- $statusAll = null;
- $createdFetureId = array();
- foreach ($changesList as $featureId => $change) {
- if ('FAILED' == $change['Status']) {
- $statusIsFailed = true;
- }
- if ('SUCCESS' == $change['Status'] && !empty($change['fid'])) {
- $createdFetureId[] = $change['fid'];
- }
- if (!empty($change['Message'])) $messageTag .= "Feature '{$featureId}' {$change['Status']}: {$change['Message']}\n";
- }
- $statusTag = ($statusIsFailed)? 'FAILED' : 'SUCCESS';
- $statusTag = "<wfs:{$statusTag}/>";
- $messageTag = '';//"<wfs:Message>{$messageTag}</wfs:Message>";
- /* Example:
- <?xml version="1.0" encoding="UTF-8"?>
- <wfs:WFS_TransactionResponse version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs"
- xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.opengis.net/wfs http://localhost:8080/geoserver/schemas/wfs/1.0.0/WFS-transaction.xsd">
- <wfs:InsertResult>
- <ogc:FeatureId fid="archsites.26" />
- </wfs:InsertResult>
- <wfs:TransactionResult handle="Updating Signature rock label">
- <wfs:Status>
- <wfs:SUCCESS />
- </wfs:Status>
- </wfs:TransactionResult>
- </wfs:WFS_TransactionResponse>*/
- // TODO: build xml by DOMDocument
- // TODO: xsi:schemaLocation="http://www.opengis.net/wfs http://localhost:8080/geoserver/schemas/wfs/1.0.0/WFS-transaction.xsd"
- $wfsInsertResult = '';
- if (!empty($createdFetureId)) {
- $wfsInsertResult = "\n<wfs:InsertResult>\n";
- foreach ($createdFetureId as $fid) {
- $wfsInsertResult .= '<ogc:FeatureId fid="' . $fid . '" xmlns:ogc="http://www.opengis.net/ogc"/>' . "\n";
- }
- $wfsInsertResult .= "\n</wfs:InsertResult>\n";
- EOF;
- }
- $tranRes = <<<EOF
- <wfs:WFS_TransactionResponse version="1.0.0"
- xmlns:wfs="http://www.opengis.net/wfs"
- xmlns:ogc="http://www.opengis.net/ogc"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- {$wfsInsertResult}
- <wfs:TransactionResult>
- <wfs:Status>{$statusTag}</wfs:Status>
- {$messageTag}
- </wfs:TransactionResult>
- </wfs:WFS_TransactionResponse>
- EOF;
- return $tranRes;
- }
- public function _convertTransactionXml($requestXmlString, $sourceNsList) {
- $DBG = (V::get('DBG_XSL', '', $_GET) > 0);// TODO: Profiler
- if($DBG){echo 'L.' . __LINE__ . ' sourceNsList:';print_r($sourceNsList);echo "\n";}
- $updateActionsXsd = array();
- $insertActionsXsd = array();
- $deleteActionsXsd = array();
- //<!-- TODO: create tag Update{X} where X is namespace index -->
- foreach ($sourceNsList as $nsInd => $sourceNs) {
- // <Update>
- $theGeomField = 'the_geom';// TODO: get from fields list
- $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
- if($DBG){echo 'L.' . __LINE__ . ' typeName:';print_r($typeName);echo "\n";}
- $updateElementName = "UpdateNs{$nsInd}";
- $geomCoordsUpdateXpath = "//wfs:Value/*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
- $geomCoordsInsertXpath = "//*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
- $acl = $this->getAclFromTypeName($typeName);
- $geomType = $acl->getGeomFieldType($theGeomField);
- if ('polygon' == $geomType) {
- $geomCoordsUpdateXpath = ".//wfs:Value/*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
- $geomCoordsUpdateXpath = "((<xsl:value-of select=\"{$geomCoordsUpdateXpath}\"/>))";
- $geomCoordsInsertXpath = ".//*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
- $geomCoordsInsertXpath = "((<xsl:value-of select=\"{$geomCoordsInsertXpath}\"/>))";
- } else if ('linestring' == $geomType) {
- $geomCoordsUpdateXpath = ".//wfs:Value/*/gml:coordinates";
- $geomCoordsUpdateXpath = "(<xsl:value-of select=\"{$geomCoordsUpdateXpath}\"/>)";
- $geomCoordsInsertXpath = ".//*/gml:coordinates";
- $geomCoordsInsertXpath = "(<xsl:value-of select=\"{$geomCoordsInsertXpath}\"/>)";
- } else if ('point' == $geomType) {
- $geomCoordsUpdateXpath = ".//wfs:Value/*/gml:coordinates";
- $geomCoordsUpdateXpath = "(<xsl:value-of select=\"{$geomCoordsUpdateXpath}\"/>)";
- $geomCoordsInsertXpath = ".//*/gml:coordinates";
- $geomCoordsInsertXpath = "(<xsl:value-of select=\"{$geomCoordsInsertXpath}\"/>)";
- }
- $actionXsd = <<<EOF
- <xsl:when test="@typeName = '{$typeName}'">
- <xsl:element name="{$updateElementName}">
- <xsl:attribute name="typeName"><xsl:value-of select="@typeName" /></xsl:attribute>
- <xsl:attribute name="featureId"><xsl:value-of select="ogc:Filter/ogc:FeatureId/@fid" /></xsl:attribute>
- <xsl:for-each select="wfs:Property">
- <xsl:element name="{wfs:Name}">
- <xsl:choose>
- <xsl:when test="wfs:Name = '{$theGeomField}'"><xsl:value-of select="local-name(//wfs:Value/*[1])"/>{$geomCoordsUpdateXpath}</xsl:when>
- <xsl:otherwise><xsl:value-of select="wfs:Value"/></xsl:otherwise>
- </xsl:choose>
- </xsl:element>
- </xsl:for-each>
- </xsl:element>
- </xsl:when>
- EOF;
- $updateActionsXsd[] = $actionXsd;
- $typeName = "{$sourceNs[1]}";//"p5_{$sourceNs[0]}:{$sourceNs[1]}";
- $insertElementName = "InsertNs{$nsInd}";
- $actionXsd = <<<EOF
- <xsl:when test="local-name() = '{$typeName}'">
- <xsl:element name="{$insertElementName}">
- <xsl:attribute name="typeName"><xsl:value-of select="local-name()" /></xsl:attribute>
- <xsl:attribute name="typeNsUri"><xsl:value-of select="namespace-uri()" /></xsl:attribute>
- <xsl:for-each select="*">
- <xsl:element name="{local-name()}">
- <xsl:choose>
- <xsl:when test="local-name() = '{$theGeomField}'"><xsl:value-of select="local-name(*[1])"/>{$geomCoordsInsertXpath}</xsl:when>
- <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
- </xsl:choose>
- </xsl:element>
- </xsl:for-each>
- </xsl:element>
- </xsl:when>
- EOF;
- $insertActionsXsd[] = $actionXsd;
- $deleteElementName = "DeleteNs{$nsInd}";
- $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
- $actionXsd = <<<EOF
- <xsl:when test="@typeName = '{$typeName}'">
- <xsl:variable name="typeName" select="@typeName" />
- <xsl:for-each select="ogc:Filter/ogc:FeatureId">
- <xsl:element name="{$deleteElementName}">
- <xsl:attribute name="typeName"><xsl:value-of select="\$typeName" /></xsl:attribute>
- <xsl:attribute name="featureId"><xsl:value-of select="@fid" /></xsl:attribute>
- </xsl:element>
- </xsl:for-each>
- </xsl:when>
- EOF;
- $deleteActionsXsd[] = $actionXsd;
- }
- if (!empty($updateActionsXsd)) {
- $updateActionsXsd = implode("\n", $updateActionsXsd);
- $updateActionsXsd = <<<EOF
- <xsl:choose>
- {$updateActionsXsd}
- </xsl:choose>
- EOF;
- } else {
- $updateActionsXsd = '';
- }
- if (!empty($insertActionsXsd)) {
- $insertActionsXsd = implode("\n", $insertActionsXsd);
- $insertActionsXsd = <<<EOF
- <xsl:choose>
- {$insertActionsXsd}
- </xsl:choose>
- EOF;
- } else {
- $insertActionsXsd = '';
- }
- if (!empty($deleteActionsXsd)) {
- $deleteActionsXsd = implode("\n", $deleteActionsXsd);
- $deleteActionsXsd = <<<EOF
- <xsl:choose>
- {$deleteActionsXsd}
- </xsl:choose>
- EOF;
- } else {
- $deleteActionsXsd = '';
- }
- $convertTransactionXslString = '<?xml version="1.0"?>';
- $convertTransactionXslString .= <<<EOF
- <xsl:transform version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:wfs="http://www.opengis.net/wfs"
- xmlns:ogc="http://www.opengis.net/ogc"
- xmlns:gml="http://www.opengis.net/gml">
- <xsl:template match="/">
- <xsl:for-each select="wfs:Transaction">
- <Transaction>
- <xsl:attribute name="version"><xsl:value-of select="@version" /></xsl:attribute>
- <xsl:attribute name="service"><xsl:value-of select="@service" /></xsl:attribute>
- <xsl:for-each select="wfs:Update">
- {$updateActionsXsd}
- </xsl:for-each>
- <xsl:for-each select="wfs:Insert/*">
- {$insertActionsXsd}
- </xsl:for-each>
- <xsl:for-each select="wfs:Delete">
- {$deleteActionsXsd}
- </xsl:for-each>
- <!-- TODO: Native -->
- </Transaction>
- </xsl:for-each>
- </xsl:template>
- </xsl:transform>
- EOF;
- if($DBG){echo 'L.' . __LINE__ . ' $convertTransactionXslString:' . $convertTransactionXslString . "\n";}
- $requestXml = new DOMDocument();
- $requestXml->loadXml($requestXmlString);
- $convertTransactionXsl = new DOMDocument();
- $convertTransactionXsl->loadXml($convertTransactionXslString);
- $proc = new XSLTProcessor();
- $proc->importStylesheet($convertTransactionXsl);
- return $proc->transformToXML($requestXml);
- }
- public function _validateConvertedTransactionXml($convertedTransaction, $sourceNsList) {
- $DBG = (V::get('DBG_XSD', '', $_GET) > 0);// TODO: Profiler
- if($DBG){echo 'L.' . __LINE__ . ' sourceNsList:';print_r($sourceNsList);echo "\n";}
- $dom = new DOMDocument('1.0', 'utf-8');
- $dom->formatOutput = true;
- $dom->preserveWhiteSpace = false;
- $rootNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:schema');
- $dom->appendChild($rootNode);
- // $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gml', 'http://www.opengis.net/gml');
- // $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . $wfsNs, $wfsNsUri);
- $rootNode->setAttribute('elementFormDefault', 'qualified');
- // $rootNode->setAttribute('targetNamespace', $wfsNsUri);
- $rootNode->setAttribute('version', '1.0');
- {// <xsd:element name="Transaction" type="TransactionType">
- $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
- $rootNode->appendChild($elNode);
- $elNode->setAttribute('name', 'Transaction');
- $elNode->setAttribute('type', 'TransactionType');
- $cTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
- $rootNode->appendChild($cTypeNode);
- $cTypeNode->setAttribute('name', 'TransactionType');
- $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
- $cTypeNode->appendChild($seqNode);
- $choiceNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:choice');
- $seqNode->appendChild($choiceNode);
- $choiceNode->setAttribute('minOccurs', '0');
- $choiceNode->setAttribute('maxOccurs', 'unbounded');
- // <!-- <xsd:element ref="Update"/> -->
- foreach ($sourceNsList as $nsInd => $sourceNs) {
- $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
- $updateElementName = "UpdateNs{$nsInd}";
- $updateElementType = "UpdateNs{$nsInd}ElementType";
- $updateElemNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
- $choiceNode->appendChild($updateElemNode);
- $updateElemNode->setAttribute('name', $updateElementName);
- $updateElemNode->setAttribute('type', $updateElementType);
- }
- // <!-- <xsd:element ref="Insert"/> -->
- foreach ($sourceNsList as $nsInd => $sourceNs) {
- $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
- $insertElementName = "InsertNs{$nsInd}";
- $insertElementType = "InsertNs{$nsInd}ElementType";
- $insertElemNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
- $choiceNode->appendChild($insertElemNode);
- $insertElemNode->setAttribute('name', $insertElementName);
- $insertElemNode->setAttribute('type', $insertElementType);
- }
- // <!-- <xsd:element ref="Delete"/> -->
- foreach ($sourceNsList as $nsInd => $sourceNs) {
- $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
- $deleteElementName = "DeleteNs{$nsInd}";
- $deleteElementType = "DeleteNs{$nsInd}ElementType";
- $deleteElemNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
- $choiceNode->appendChild($deleteElemNode);
- $deleteElemNode->setAttribute('name', $deleteElementName);
- $deleteElemNode->setAttribute('type', $deleteElementType);
- }
- // <!-- <xsd:element ref="Native"/> -->
- $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
- $cTypeNode->appendChild($attrNode);
- $attrNode->setAttribute('name', 'version');
- $attrNode->setAttribute('type', 'xsd:string');
- $attrNode->setAttribute('use', 'required');
- $attrNode->setAttribute('fixed', '1.0.0');
- $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
- $cTypeNode->appendChild($attrNode);
- $attrNode->setAttribute('name', 'service');
- $attrNode->setAttribute('type', 'xsd:string');
- $attrNode->setAttribute('use', 'required');
- $attrNode->setAttribute('fixed', 'WFS');
- }
- foreach ($sourceNsList as $nsInd => $sourceNs) {
- $transactionTypesList = array();
- $transactionTypesList[] = 'Update';
- $transactionTypesList[] = 'Insert';
- foreach ($transactionTypesList as $transactionType) {
- $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
- if($DBG){echo 'L.' . __LINE__ . ' TODO: get acl typeName:';print_r($typeName);echo "\n";}
- $acl = $this->getAclFromTypeName($typeName);
- $updateElementName = "{$transactionType}Ns{$nsInd}";
- $updateElementType = "{$transactionType}Ns{$nsInd}ElementType";
- /*
- <xsd:complexType name="{$updateElementType}">
- <xsd:sequence>
- <xsd:element name="PARENT_ID" minOccurs="0" maxOccurs="1" type="xsd:integer" />
- </xsd:sequence>
- */
- $updateTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
- $rootNode->appendChild($updateTypeNode);
- $updateTypeNode->setAttribute('name', $updateElementType);
- {
- $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:all');
- $updateTypeNode->appendChild($seqNode);
- {
- $pKeyField = $acl->getPrimaryKeyField();
- $fldList = $this->_getFieldListFromAcl($acl);
- // fields without geometry fields
- foreach ($fldList as $fldName) {
- if ($acl->isGeomField($fldName)) continue;
- $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
- $seqNode->appendChild($elNode);
- $elNode->setAttribute('name', $fldName);
- $minOccurs = 0;
- if ($pKeyField == $fldName) {
- $minOccurs = '1';
- } else {
- $minOccurs = '0';
- }
- $elNode->setAttribute('minOccurs', $minOccurs);
- $fldType = null;
- if ($acl->isIntegerField($fldName)) {
- $fldType = 'xsd:integer';
- }
- else if ($acl->isDecimalField($fldName)) {
- $fldType = 'xsd:decimal';
- }
- else if ($acl->isDateField($fldName)) {
- $fldType = 'xsd:date';
- }
- else if ($acl->isDateTimeField($fldName)) {
- // $fldType = 'xsd:dateTime';
- $fldType = null;// 'xsd:string';
- $patternDataTime = "(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})(:(\d{2}))?";
- // <xsd:element name="..." minOccurs="0" nillable="true">
- // <xsd:simpleType>
- // <xsd:restriction base="xsd:string">
- // <xsd:pattern value="[a-zA-Z]+\(\((\-?\d+\.?\d*,\-?\d+\.?\d*)( \-?\d+\.?\d*,\-?\d+\.?\d*)+\)\)"/>
- // </xsd:restriction>
- // </xsd:simpleType>
- // </xsd:element>
- $simpleTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
- $restrictionNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
- $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
- $restrictionNode->setAttribute('base', 'xsd:string');
- $patternNode->setAttribute('value', $patternDataTime);
- $restrictionNode->appendChild($patternNode);
- $simpleTypeNode->appendChild($restrictionNode);
- $elNode->appendChild($simpleTypeNode);
- // continue;// TODO: ? below added nillable = true, minOccurs = 0, type = $fldType
- }
- else if ($acl->isBinaryField($fldName)) {
- $fldType = 'xsd:base64Binary';
- }
- else {
- $fldType = 'xsd:string';
- }
- if ($fldType) $elNode->setAttribute('type', $fldType);
- $elNode->setAttribute('nillable', 'true');
- $elNode->setAttribute('minOccurs', '0');
- }
- // only geometry fields
- foreach ($fldList as $fldName) {
- if (!$acl->isGeomField($fldName)) continue;
- $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
- $seqNode->appendChild($elNode);
- $elNode->setAttribute('name', $fldName);
- $minOccurs = 0;
- if ($pKeyField == $fldName) {
- $minOccurs = '1';
- } else {
- $minOccurs = '0';
- }
- $elNode->setAttribute('minOccurs', $minOccurs);
- if ($acl->isGeomField($fldName)) {
- //$fldType = 'gml:GeometryPropertyType';
- // TODO: use geom types from gml to wkt
- // TODO: pattern wg atrybutów gml:coordinates decimal="." cs="," ts=" "
- $patternWkt = '';// TODO: error if empty - unsupported geom type
- $patternNum = '\-?\d+\.?\d*';
- $patternPoint = $patternNum . ',' . $patternNum;
- $patternPoints = '(' . $patternPoint . ')( ' . $patternPoint . ')+';
- $geomType = $acl->getGeomFieldType($fldName);
- if ('polygon' == $geomType) {
- // [a-zA-Z]+\(\((\-?\d+\.?\d*,\-?\d+\.?\d*)( (\-?\d+\.?\d*,\-?\d+\.?\d*))+\)\)
- $patternWkt = '[a-zA-Z]+\(\(' . $patternPoints . '\)\)';
- } else if ('linestring' == $geomType) {
- // [a-zA-Z]+\((\-?\d+\.?\d*,\-?\d+\.?\d*)( (\-?\d+\.?\d*,\-?\d+\.?\d*))+\)
- $patternWkt = '[a-zA-Z]+\(' . $patternPoints . '\)';
- } else if ('point' == $geomType) {
- // [a-zA-Z]+\(\-?\d\.?\d*,\-?\d\.?\d*\)
- $patternWkt = '[a-zA-Z]+\(' . $patternPoint . '\)';
- }
- $simpleTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
- $restrictionNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
- $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
- $restrictionNode->setAttribute('base', 'xsd:string');
- $patternNode->setAttribute('value', $patternWkt);
- $restrictionNode->appendChild($patternNode);
- $simpleTypeNode->appendChild($restrictionNode);
- $elNode->appendChild($simpleTypeNode);
- }
- $elNode->setAttribute('nillable', 'true');
- $elNode->setAttribute('minOccurs', '0');
- }
- }
- }
- $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
- $updateTypeNode->appendChild($attrNode);
- $attrNode->setAttribute('name', 'typeName');
- $attrNode->setAttribute('type', 'xsd:token');
- $attrNode->setAttribute('use', 'required');
- if ($transactionType == 'Insert') {
- $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
- $updateTypeNode->appendChild($attrNode);
- $attrNode->setAttribute('name', 'typeNsUri');
- $attrNode->setAttribute('type', 'xsd:anyURI');
- $attrNode->setAttribute('use', 'required');
- }
- if ($transactionType == 'Update') {
- $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
- $updateTypeNode->appendChild($attrNode);
- $attrNode->setAttribute('name', 'featureId');
- $attrNode->setAttribute('use', 'required');
- $sTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
- $attrNode->appendChild($sTypeNode);
- $resNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
- $sTypeNode->appendChild($resNode);
- $resNode->setAttribute('base', 'xsd:string');
- $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
- $resNode->appendChild($patternNode);
- $patternNode->setAttribute('value', '[a-zA-Z_][a-zA-Z0-9_]*\.[0-9]*');
- }
- }
- {// 'Delete'
- $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
- $acl = $this->getAclFromTypeName($typeName);
- $deleteElementType = "DeleteNs{$nsInd}ElementType";
- $deleteTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
- $rootNode->appendChild($deleteTypeNode);
- $deleteTypeNode->setAttribute('name', $deleteElementType);
- /* <xsd:attribute name="typeName" type="xsd:token" use="required"/> */
- $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
- $deleteTypeNode->appendChild($attrNode);
- $attrNode->setAttribute('name', 'typeName');
- $attrNode->setAttribute('type', 'xsd:token');
- $attrNode->setAttribute('use', 'required');
- /* <xsd:attribute name="featureId" use="required"> */
- $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
- $deleteTypeNode->appendChild($attrNode);
- $attrNode->setAttribute('name', 'featureId');
- $attrNode->setAttribute('use', 'required');
- $sTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
- $attrNode->appendChild($sTypeNode);
- $resNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
- $sTypeNode->appendChild($resNode);
- $resNode->setAttribute('base', 'xsd:string');
- $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
- $resNode->appendChild($patternNode);
- $patternNode->setAttribute('value', '[a-zA-Z_][a-zA-Z0-9_]*\.[0-9]*');
- }
- }
- $validateConvertedTransactionXsdString = $dom->saveXml();
- if($DBG){echo 'L.' . __LINE__ . ' $validateConvertedTransactionXsdString:';print_r($validateConvertedTransactionXsdString);echo "\n";}
- $reqXml = new DOMDocument();
- $reqXml->loadXml($convertedTransaction);
- // TODO: fetch PHP Warning: DOMDocument::schemaValidateSource(): Element 'PARENT_ID': 'abc' is not a valid value of the atomic type 'xs:integer'.
- return $reqXml->schemaValidateSource($validateConvertedTransactionXsdString);
- }
- public function _getDescribeFeatureType($nsPrefix, $type, $simple = true) {
- return $this->_getDescribeFeatureTypes(array(array($nsPrefix, $type)), $simple);
- }
- public function _parseDescribeFeatureTypeRequest($reqContent, $simple = true) {
- $parserXml = xml_parser_create();
- xml_parser_set_option($parserXml, XML_OPTION_CASE_FOLDING, 0);
- xml_parser_set_option($parserXml, XML_OPTION_SKIP_WHITE, 1);
- if (0 == xml_parse_into_struct($parserXml, $reqContent, $tags)) {
- throw new Exception("Error parsing xml");
- }
- xml_parser_free($parserXml);
- if (empty($tags)) {
- throw new Exception("Empty structure from request");
- }
- $rootTagName = V::get('tag', '', $tags[0]);
- if ('DescribeFeatureType' != $rootTagName) {
- throw new Api_WfsException("Wrong xml root tag '{$rootTagName}' #" . __LINE__, 501);
- }
- $requestXmlTags = $tags;
- $DBG = (V::get('DBG_XML', '', $_GET) > 0);// TODO: Profiler
- $rootTagName = V::get('tag', '', $requestXmlTags[0]);
- if ('DescribeFeatureType' != $rootTagName) {
- throw new Exception("Parse Request xml error #" . __LINE__);
- }
- /*[1] => Array(
- [tag] => TypeName
- [type] => complete
- [level] => 2
- [value] => p5_default_db:Rozdzielcza_rurociag_wsg84)
- */
- $typeNames = array();
- $totalTypes = count($requestXmlTags) - 1;
- for ($i = 1; $i < $totalTypes; $i++) {
- if($DBG){echo "TAG[{$i}]:" . json_encode($requestXmlTags[$i]) . "\n";}
- $typeNames[] = explode(':', $requestXmlTags[$i]['value'], 2);
- }
- //echo "typeNames: " . json_encode($typeNames) . "\n";
- return $this->_getDescribeFeatureTypes($typeNames, $simple);
- }
- public function _getDescribeFeatureAllTypes($simple = true) {
- $db = DB::getDB();
- $idDefaultDB = $db->_zasob_id;
- $tblsAcl = $this->_getTableAclList();
- foreach ($tblsAcl as $tblAcl) {
- $dataSourceName = 'default_db';// TODO: getSourceName
- $tblName = $tblAcl->getName();
- $typeNames[] = array("p5_{$dataSourceName}", $tblName);
- }
- $typeNames[] = array("p5_objects", 'File');
- return $this->_getDescribeFeatureTypes($typeNames, $simple);
- }
- // @param $typeNames = array( array( $nsPrefix, $type ) )
- public function _getDescribeFeatureTypes($typeNames, $simple = true) {
- if (empty($typeNames)) throw new HttpException("Feature Type Names not defined", 400);
- $this->DBG("types:" . json_encode($typeNames), __LINE__, __FUNCTION__, __CLASS__);
- $baseNsUri = $this->getBaseNamespaceUri();
- $rootWfsNs = 'p5';
- $rootWfsNsUri = "{$baseNsUri}";
- $wfsNs = 'p5_default_db';
- $wfsNsUri = "{$baseNsUri}/default_db";
- $featureTypeUri = $this->getBaseUri() . "?SERVICE=WFS&VERSION=1.0.0&REQUEST=DescribeFeatureType";
- header('Content-type: application/xml');
- // <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://webgis.regione.sardegna.it:80/geoserver/schemas/gml/2.1.2/feature.xsd"/>
- // <xsd:element name="{type}" substitutionGroup="gml:_Feature" type="dbu:{typeName}"/>
- $dom = new DOMDocument('1.0', 'utf-8');
- $dom->formatOutput = true;
- $dom->preserveWhiteSpace = false;
- $rootNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:schema');
- $dom->appendChild($rootNode);
- $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gml', 'http://www.opengis.net/gml');
- $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . $wfsNs, $wfsNsUri);
- $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', "xmlns:{$rootWfsNs}", $rootWfsNsUri);
- $rootNode->setAttribute('elementFormDefault', 'qualified');
- $rootNode->setAttribute('targetNamespace', $wfsNsUri);
- {// <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="...../gml/2.1.2/feature.xsd"/>
- $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:import');
- $rootNode->appendChild($elNode);
- $elNode->setAttribute('namespace', "http://www.opengis.net/gml");
- $elNode->setAttribute('schemaLocation', $this->getBaseUri() . "/../../../schema/gml/2.1.2/feature.xsd");
- }
- foreach ($typeNames as $typeNameEx) {
- $nsPrefix = $typeNameEx[0];
- $type = $typeNameEx[1];
- $typeName = "{$nsPrefix}:{$type}";
- $acl = $this->getAclFromTypeName($typeName);
- if (!$this->isAllowedFeatureType($nsPrefix, $type)) {
- throw new Api_WfsException("Could not find type: " . htmlspecialchars($type));
- }
- $typeName = $type . 'Type';
- $fldList = $this->_getFieldListFromAcl($acl);
- $cTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
- $rootNode->appendChild($cTypeNode);
- $cTypeNode->setAttribute('name', $typeName);
- if (!$simple) {
- $idZasob = $acl->getID();
- $cTypeNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:web_link", Request::getPathUri() . "index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID={$idZasob}");
- }
- $cConNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexContent');
- $cTypeNode->appendChild($cConNode);
- $extNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:extension');
- $cConNode->appendChild($extNode);
- $extNode->setAttribute('base', 'gml:AbstractFeatureType');
- $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
- $extNode->appendChild($seqNode);
- // <xsd:element maxOccurs="1" minOccurs="0" name="{$fldName}" nillable="true" type="xsd:integer"/>
- $pKeyField = $acl->getPrimaryKeyField();
- $p5Attributes = ($simple)? array() : $acl->getAttributesFromZasoby();
- foreach ($fldList as $idZasob => $fldName) {
- $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
- $seqNode->appendChild($elNode);
- $elNode->setAttribute('name', $fldName);
- $minOccurs = 0;
- if ($pKeyField == $fldName) {
- $minOccurs = '1';
- } else {
- $minOccurs = '0';
- }
- $elNode->setAttribute('minOccurs', $minOccurs);
- $elNode->setAttribute('maxOccurs', '1');
- $elNode->setAttribute('nillable', 'true');
- $fldType = 'xsd:string';
- if ($acl->isIntegerField($fldName)) {
- $fldType = 'xsd:integer';
- }
- else if ($acl->isDecimalField($fldName)) {
- $fldType = 'xsd:decimal';
- }
- else if ($acl->isDateField($fldName)) {
- $fldType = 'xsd:date';
- }
- else if ($acl->isDateTimeField($fldName)) {
- $fldType = 'xsd:dateTime';
- }
- else if ($acl->isGeomField($fldName)) {
- //$fldType = 'gml:GeometryPropertyType';
- $geomType = $acl->getGeomFieldType($fldName);
- if ('polygon' == $geomType) {
- $fldType = 'gml:PolygonPropertyType';
- } else if ('point' == $geomType) {
- $fldType = 'gml:PointPropertyType';
- } else if ('linestring' == $geomType) {
- $fldType = 'gml:LineStringPropertyType';
- } else {
- $fldType = 'gml:GeometryPropertyType';
- }
- }
- else if ($acl->isEnumerationField($fldName)) {
- $fldType = ($simple)? 'xsd:string' : "{$nsPrefix}:{$fldName}Type";
- }
- else if ($acl->isBinaryField($fldName)) {
- $fldType = 'xsd:base64Binary';
- }
- $elNode->setAttribute('type', $fldType);
- if (!$simple) {
- if (!empty($p5Attributes[$fldName])) {
- $p5attrs = $p5Attributes[$fldName];
- if (!empty($p5attrs['id_zasob'])) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:id_zasob", $p5attrs['id_zasob']);
- if (!empty($p5attrs['label'])) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:label", $p5attrs['label']);
- if (!empty($p5attrs['description'])) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:description", $p5attrs['description']);
- }
- if ($acl->hasFieldPerm($idZasob, 'W')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_write", "true");
- if ($acl->hasFieldPerm($idZasob, 'C')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_create", "true");
- if (!$acl->hasFieldPerm($idZasob, 'R')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_read", "false");
- }
- }
- $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
- $rootNode->appendChild($elNode);
- $elNode->setAttribute('name', $type);
- $elNode->setAttribute('type', $wfsNs . ':' . $typeName);
- if ($simple) {
- $elNode->setAttribute('substitutionGroup', 'gml:_Feature');
- } else {
- $elNode->setAttribute('substitutionGroup', 'gml:AbstractFeature');
- }
- if (!$simple) {
- foreach ($fldList as $fldName) {
- if ($acl->isEnumerationField($fldName)) {
- $enum = $acl->getEnumerations($fldName);
- $stNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
- $stNode->setAttribute('name', "{$fldName}Type");//"{$nsPrefix}:{$fldName}Type");
- $rootNode->appendChild($stNode);
- $resNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
- $stNode->appendChild($resNode);
- $resNode->setAttribute('base', 'xsd:string');
- // TODO: if (!empty($p5Attributes[$fldName]['valuesMap'])) -> show only this values
- foreach ($enum as $val => $label) {
- $enumNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:enumeration');
- $resNode->appendChild($enumNode);
- $enumNode->setAttribute('value', "{$val}");
- if (!empty($p5Attributes[$fldName]['valuesMap'][$val])) {
- $enumNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:label", $p5Attributes[$fldName]['valuesMap'][$val]);
- }
- }
- }
- }
- }
- }
- return $dom->saveXML();
- }
- public function _getTableAclList() {// Use only Tables from default_db
- $tblAclList = array();
- $db = DB::getDB();
- $idDefaultDB = $db->_zasob_id;
- $fullTblAclList = $this->_usrAcl->getTablesAcl();
- foreach ($fullTblAclList as $tblAcl) {
- $dataSourceName = 'default_db';// TODO: getSourceName
- $tblName = $tblAcl->getName();
- if ($idDefaultDB != $tblAcl->getDB()) {// hide non default_db tables
- continue;
- }
- try {
- $acl = $this->getAclFromTypeName($typeName = "p5_{$dataSourceName}:{$tblName}");
- } catch (Exception $e) {
- // TODO: error log $e->getMessage();
- }
- if (!$acl) {
- // TODO: error log msg
- continue;
- }
- $tblAclList[] = $tblAcl;
- }
- return $tblAclList;
- }
- public function _getFieldListFromAcl($acl) {
- $fldList = $acl->getRealFieldListByIdZasob();
- return $fldList;
- }
- public function setLogger($logger) {
- $this->_logger = $logger;
- }
- public function DBG($reqLog, $lineNr = null, $funName = null, $className = null) {
- if (!$this->_logger) return;
- $this->_logger->DBG($reqLog, $lineNr, $funName, $className);
- }
- public function convertOgcFilterFromRequestBody($requestOgcFilter) {
- $ogcFilter = '';
- if (empty($requestOgcFilter)) return '';
- {
- $convertOgcFilterXslString .= <<<EOF
- <xsl:transform version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:wfs="http://www.opengis.net/wfs"
- xmlns:ogc="http://www.opengis.net/ogc"
- xmlns:gml="http://www.opengis.net/gml">
- <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
- <xsl:template match="/">
- <xsl:for-each select="//*[local-name() = 'GetFeature']">
- <xsl:copy-of select="ogc:Filter"/>
- </xsl:for-each>
- </xsl:template>
- </xsl:transform>
- EOF;
- DBG::_('DBG_XML', '>2', "convertOgcFilterXslString", $convertOgcFilterXslString, __CLASS__, __FUNCTION__, __LINE__);
- $convertTransactionXsl = new DOMDocument();
- $convertTransactionXsl->loadXml($convertOgcFilterXslString);
- $requestXml = new DOMDocument();
- $requestXml->loadXml($requestOgcFilter);
- $proc = new XSLTProcessor();
- $proc->importStylesheet($convertTransactionXsl);
- $ogcFilter = $proc->transformToXML($requestXml);
- DBG::_('DBG_XML', '>2', "ogcFilter", $ogcFilter, __CLASS__, __FUNCTION__, __LINE__);
- }
- return $ogcFilter;
- }
- }
|