| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292 |
- <?php
- Lib::loadClass('Api_WfsException');
- Lib::loadClass('Api_WfsGeomTypeConverter');
- class Api_WfsServerBase {
- public $_usrAcl;
- public $_typeConverter;
- public $_apiBaseUri;
- 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;
- }
- }
- 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 version="1.0.0"
- 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(); ?>
- xsi:schemaLocation="http://www.opengis.net/wfs <?php echo $this->_getSchemaLocationString(); ?>">
- <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 echo $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 _getSchemaLocationString() {
- $schemaLocations = array();
- // $schemaLocations[] = '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 implode(' ', $schemaLocations);
- }
- public function _getXmlNamespaceList() {
- $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);
- }
- 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->_usrAcl->getTablesAcl();
- 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->getRawLabel();
- $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;
- }
- /*
- <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) . ' />';
- }
- $featureTypesXml .= '</FeatureType>' . "\n";
- }
- return $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 Exception("Parse Request xml error #" . __LINE__);
- }
- // 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'];
- }
- }
- if (empty($usedSourceNsList)) {
- throw new Exception("Parse Request xml error #" . __LINE__ . ": not implemented");
- }
- $convertedTransaction = $this->_convertTransactionXml($requestXml, $usedSourceNsList);
- if($DBG){echo '$convertedTransaction:';print_r($convertedTransaction);echo "\n";}
- if (empty($convertedTransaction)) {
- throw new Exception("Parse Request xml error #" . __LINE__ . ": convert Transaction");
- }
- //echo "\ntags[0]:\n" . json_encode($requestXmlTags[0]) . "\n";
- //echo "\nconvertedTransaction:\n" . $convertedTransaction . "\n";
- //echo "\nsourceNsList:\n" . json_encode($sourceNsList) . "\n";
- if (!$this->_validateConvertedTransactionXml($convertedTransaction, $usedSourceNsList)) {
- 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 "\nTODO: tags 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']) {
- $actionTag = array();
- $actionTag['tag'] = substr($tag['tag'], 0, 6);
- $actionTag['typeName'] = $tag['attributes']['typeName'];
- if ('Insert' == substr($tag['tag'], 0, 6)) {
- $actionTag['typeName'] = "p5_default_db:{$actionTag['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!");
- }
- $actionTag['itemPatch'] = array();
- } else {
- $itemPatchs[] = $actionTag;
- $actionTag = null;
- }
- break;
- default: {// fields
- 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'];
- }
- }
- }
- }
- 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__ . ":\n"; print_r($this->_usrAcl->_user_id);echo "\n";}
- $changesList = array();
- if (!empty($itemPatchs)) {
- foreach ($itemPatchs as $itemPatchInfo) {
- if($DBG){echo "itemPatchInfo['itemPatch']:\n";print_r($itemPatchInfo['itemPatch']);}
- if (empty($itemPatchInfo['itemPatch'])) continue;
- $acl = $this->getAclFromTypeName($itemPatchInfo['typeName']);
- $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 "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 = '';
- 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 = <<<EOF
- <wfs:InsertResult>
- <ogc:FeatureId fid="{$createdFetureId}" xmlns:ogc="http://www.opengis.net/ogc"/>
- </wfs:InsertResult>
- 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 'sourceNsList:';print_r($sourceNsList);echo "\n";}
- $updateActionsXsd = array();
- $insertActionsXsd = 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]}";
- $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: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;
- }
- 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 = '';
- }
- $convertTransactionXslString = <<<EOF
- <?xml version="1.0"?>
- <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>
- <!-- TODO: Insert -->
- <xsl:for-each select="wfs:Insert/*">
- {$insertActionsXsd}
- </xsl:for-each>
- <!-- TODO: Delete -->
- <!-- TODO: Native -->
- </Transaction>
- </xsl:for-each>
- </xsl:template>
- </xsl:transform>
- EOF;
- if($DBG){echo '$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 '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"/> -->
- // <!-- <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]}";
- $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:sequence');
- $updateTypeNode->appendChild($seqNode);
- $pKeyField = $acl->getPrimaryKeyField();
- $fldList = $acl->getRealFieldList();
- 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';
- }
- else 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);
- }
- else {
- $fldType = 'xsd:string';
- }
- if ($fldType) $elNode->setAttribute('type', $fldType);
- $elNode->setAttribute('nillable', 'true');
- $elNode->setAttribute('minOccurs', '0');
- }
- 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 == '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]*');
- }
- }
- }
- $validateConvertedTransactionXsdString = $dom->saveXml();
- if($DBG){echo '$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 _generateXsdTypeNode($ns, $typeName, $dom, $parentNode) {
- //$fieldsXsd = '';
- //$fieldsXsd .= '<xsd:element name="PARENT_ID" minOccurs="0" maxOccurs="1" type="xsd:integer" />';
- $acl = $this->getAclFromTypeName($typeName);
- $cTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
- $rootNode = $cTypeNode;
- $cTypeNode->setAttribute('name', $typeName);
- $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');// or xsd:all ?
- $extNode->appendChild($seqNode);
- // <xsd:element maxOccurs="1" minOccurs="0" name="{$fldName}" nillable="true" type="xsd:integer"/>
- $pKeyField = $acl->getPrimaryKeyField();
- $fldList = $acl->getRealFieldList();
- foreach ($fldList as $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);
- 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';
- //$fldType = 'gml:Polygon';// nie działa musi być gml:GeometryPropertyType
- }
- else {
- $fldType = 'xsd:string';
- }
- $elNode->setAttribute('type', $fldType);
- $elNode->setAttribute('nillable', 'true');
- }
- /*
- <xsd:attribute name="typeName" type="xsd:token" use="required"/>
- <xsd:attribute name="featureId" use="required">
- <xsd:simpleType>
- <xsd:restriction base="xsd:string">
- <xsd:pattern value="[a-zA-Z_][a-zA-Z0-9_]*\.[0-9]*"/>
- </xsd:restriction>
- </xsd:simpleType>
- </xsd:attribute>
- */
- $cAttrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
- $rootNode->appendChild($cAttrNode);
- $cAttrNode->setAttribute('name', 'typeName');
- $cAttrNode->setAttribute('type', 'xsd:token');
- $cAttrNode->setAttribute('use', 'required');
- $cAttrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
- $rootNode->appendChild($cAttrNode);
- $cAttrNode->setAttribute('name', 'featureId');
- $cAttrNode->setAttribute('use', 'required');
- $sTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
- $cAttrNode->appendChild($sTypeNode);
- $restrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
- $cAttrNode->appendChild($restrNode);
- $restrNode->setAttribute('base', 'xsd:string');
- $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
- $restrNode->appendChild($patternNode);
- $patternNode->setAttribute('value', '[a-zA-Z_][a-zA-Z0-9_]*\.[0-9]*');
- return $dom->saveXml($cTypeNode);
- $typeXsd = <<<EOF
- <xsd:complexType name="{$typeName}">
- <xsd:all>
- {$fieldsXsd}
- </xsd:all>
- <xsd:attribute name="typeName" type="xsd:token" use="required"/>
- <xsd:attribute name="featureId" use="required">
- <xsd:simpleType>
- <xsd:restriction base="xsd:string">
- <xsd:pattern value="[a-zA-Z_][a-zA-Z0-9_]*\.[0-9]*"/>
- </xsd:restriction>
- </xsd:simpleType>
- </xsd:attribute>
- </xsd:complexType>
- EOF;
- return $typeXsd;
- }
- }
|