1: <?php
2:
3: namespace Mapbender\WmsBundle\Component;
4:
5: use Mapbender\CoreBundle\Component\BoundingBox;
6: use Mapbender\CoreBundle\Entity\Contact;
7: use Mapbender\CoreBundle\Entity\Keyword;
8: use Mapbender\WmsBundle\Entity\WmsSource;
9: use Mapbender\WmsBundle\Entity\WmsLayerSource;
10: use Mapbender\WmsBundle\Component\RequestInformation;
11:
12: 13: 14: 15: 16:
17: class WmsCapabilitiesParser130
18: extends WmsCapabilitiesParser
19: {
20:
21: 22: 23: 24:
25: public function __construct(\DOMDocument $doc)
26: {
27: parent::__construct($doc);
28:
29: foreach($this->xpath->query('namespace::*', $this->doc->documentElement) as $node)
30: {
31: $nsPrefix = $node->prefix;
32: $nsUri = $node->nodeValue;
33: if($nsPrefix == "" && $nsUri == "http://www.opengis.net/wms")
34: {
35: $nsPrefix = "wms";
36: }
37: $this->xpath->registerNamespace($nsPrefix, $nsUri);
38: }
39: }
40:
41: 42: 43: 44: 45:
46: public function parse()
47: {
48: $wms = new WmsSource();
49: $root = $this->doc->documentElement;
50:
51: $wms->setVersion($this->getValue("./@version", $root));
52: $this->parseService($wms, $this->getValue("./wms:Service", $root));
53: $capabilities = $this->xpath->query("./wms:Capability/*", $root);
54: foreach($capabilities as $capabilityEl)
55: {
56: if($capabilityEl->localName === "Request")
57: {
58: $this->parseCapabilityRequest($wms, $capabilityEl);
59: } else if($capabilityEl->localName === "Exception")
60: {
61: $this->parseCapabilityException($wms, $capabilityEl);
62: } else if($capabilityEl->localName === "Layer")
63: {
64: $rootlayer = new WmsLayerSource();
65: $wms->addLayer($rootlayer);
66: $layer = $this->parseLayer($wms, $rootlayer, $capabilityEl);
67: }
68: else if($capabilityEl->localName === "UserDefinedSymbolization")
69: {
70: $this->parseUserDefinedSymbolization($wms, $capabilityEl);
71: }
72:
73: }
74: return $wms;
75: }
76:
77: 78: 79: 80: 81: 82: 83:
84: private function parseService(WmsSource $wms, \DOMElement $contextElm)
85: {
86: $wms->setName($this->getValue("./wms:Name/text()", $contextElm));
87: $wms->setTitle($this->getValue("./wms:Title/text()", $contextElm));
88: $wms->setDescription($this->getValue("./wms:Abstract/text()", $contextElm));
89:
90: $keywordElList = $this->xpath->query("./wms:KeywordList/wms:Keyword", $contextElm);
91: foreach($keywordElList as $keywordEl)
92: {
93: $keyword = new Keyword();
94: $keyword->setValue(trim($this->getValue("./text()", $keywordEl)));
95: $keyword->setSourceclass($wms->getClassname());
96: $keyword->setSourceid($wms);
97:
98:
99:
100: }
101:
102: $wms->setOnlineResource($this->getValue("./wms:OnlineResource/@xlink:href", $contextElm));
103:
104: $wms->setFees($this->getValue("./wms:Fees/text()", $contextElm));
105: $wms->setAccessConstraints($this->getValue("./wms:AccessConstraints/text()", $contextElm));
106:
107: $layerLimit = intval($this->getValue("./wms:LayerLimit/text()", $contextElm));
108: if($layerLimit > 0)
109: {
110: $wms->setLayerLimit(intval($layerLimit));
111: }
112:
113: $maxWidth = intval($this->getValue("./wms:MaxWidth/text()", $contextElm));
114: if($maxWidth > 0)
115: {
116: $wms->setMaxWidth(intval($maxWidth));
117: }
118: $maxHeight = intval($this->getValue("./wms:MaxHeight/text()", $contextElm));
119: if($maxHeight > 0)
120: {
121: $wms->setMaxHeight(intval($maxHeight));
122: }
123:
124: $contact = new Contact();
125: $contact->setPerson($this->getValue("./wms:ContactInformation/wms:ContactPersonPrimary/wms:ContactPerson/text()", $contextElm));
126: $contact->setOrganization($this->getValue("./wms:ContactInformation/wms:ContactPersonPrimary/wms:ContactOrganization/text()", $contextElm));
127: $contact->setPosition($this->getValue("./wms:ContactInformation/wms:ContactPosition/text()", $contextElm));
128:
129: $contact->setAddressType($this->getValue("./wms:ContactInformation/wms:ContactAddress/wms:AddressType/text()", $contextElm));
130: $contact->setAddress($this->getValue("./wms:ContactInformation/wms:ContactAddress/wms:Address/text()", $contextElm));
131: $contact->setAddressCity($this->getValue("./wms:ContactInformation/wms:ContactAddress/wms:City/text()", $contextElm));
132: $contact->setAddressStateOrProvince($this->getValue("./wms:ContactInformation/wms:ContactAddress/wms:StateOrProvince/text()", $contextElm));
133: $contact->setAddressPostCode($this->getValue("./wms:ContactInformation/wms:ContactAddress/wms:PostCode/text()", $contextElm));
134: $contact->setAddressCountry($this->getValue("./wms:ContactInformation/wms:ContactAddress/wms:Country/text()", $contextElm));
135:
136: $contact->setVoiceTelephone($this->getValue("./wms:ContactInformation/wms:ContactVoiceTelephone/text()", $contextElm));
137: $contact->setFacsimileTelephone($this->getValue("./wms:ContactInformation/wms:ContactFacsimileTelephone/text()", $contextElm));
138: $contact->setElectronicMailAddress($this->getValue("./wms:ContactInformation/wms:ContactElectronicMailAddress/text()", $contextElm));
139:
140: $wms->setContact($contact);
141: }
142:
143: 144: 145: 146: 147: 148: 149:
150: private function parseCapabilityRequest(WmsSource $wms, \DOMElement $contextElm)
151: {
152: $operations = $this->xpath->query("./*", $contextElm);
153: foreach($operations as $operation)
154: {
155: if($operation->localName === "GetCapabilities")
156: {
157: $getCapabilities = $this->parseOperationRequestInformation($operation);
158: $wms->setGetCapabilities($getCapabilities);
159: } else if($operation->localName === "GetMap")
160: {
161: $getMap = $this->parseOperationRequestInformation($operation);
162: $wms->setGetMap($getMap);
163: } else if($operation->localName === "GetFeatureInfo")
164: {
165: $getFeatureInfo = $this->parseOperationRequestInformation($operation);
166: $wms->setGetFeatureInfo($getFeatureInfo);
167: }
168: else if($operation->localName === "GetLegendGraphic")
169: {
170: $getLegendGraphic = $this->parseOperationRequestInformation($operation);
171: $wms->setGetLegendGraphic($getLegendGraphic);
172: } else if($operation->localName === "DescribeLayer")
173: {
174: $describeLayer = $this->parseOperationRequestInformation($operation);
175: $wms->setDescribeLayer($describeLayer);
176: } else if($operation->localName === "GetStyles")
177: {
178: $getStyles = $this->parseOperationRequestInformation($operation);
179: $wms->setGetStyles($getStyles);
180: } else if($operation->localName === "PutStyles")
181: {
182: $putStyles = $this->parseOperationRequestInformation($operation);
183: $wms->setPutStyles($putStyles);
184: }
185: }
186: }
187:
188: 189: 190: 191: 192: 193: 194:
195: private function parseOperationRequestInformation(\DOMElement $contextElm)
196: {
197: $requestImformation = new RequestInformation();
198: $tempList = $this->xpath->query("./wms:Format", $contextElm);
199: if($tempList !== null)
200: {
201: foreach($tempList as $item)
202: {
203: $requestImformation->addFormat($this->getValue("./text()", $item));
204: }
205: }
206: $requestImformation->setHttpGet($this->getValue(
207: "./wms:DCPType/wms:HTTP/wms:Get/wms:OnlineResource/@xlink:href", $contextElm));
208: $requestImformation->setHttpPost($this->getValue(
209: "./wms:DCPType/wms:HTTP/wms:Post/wms:OnlineResource/@xlink:href", $contextElm));
210:
211: return $requestImformation;
212: }
213:
214: 215: 216: 217: 218: 219: 220: 221:
222: private function parseCapabilityException(WmsSource $wms, \DOMElement $contextElm)
223: {
224: $tempList = $this->xpath->query("./wms:Format", $contextElm);
225: if($tempList !== null)
226: {
227: foreach($tempList as $item)
228: {
229: $wms->addExceptionFormat($this->getValue("./text()", $item));
230: }
231: }
232: }
233:
234: 235: 236: 237: 238: 239: 240: 241:
242: private function parseUserDefinedSymbolization(WmsSource $wms, \DOMElement $contextElm)
243: {
244: if($contextElm !== null)
245: {
246: $wms->setSupportSld($this->getValue("./@SupportSLD", $contextElm));
247: $wms->setUserLayer($this->getValue("./@UserLayer", $contextElm));
248: $wms->setUserStyle($this->getValue("./@UserStyle", $contextElm));
249: $wms->setRemoteWfs($this->getValue("./@RemoteWFS", $contextElm));
250: $wms->setInlineFeature($this->getValue("./@InlineFeature", $contextElm));
251: $wms->setRemoteWcs($this->getValue("./@RemoteWCS", $contextElm));
252: }
253: }
254:
255: 256: 257: 258: 259: 260: 261: 262: 263:
264: private function parseLayer(WmsSource $wms, WmsLayerSource $wmslayer, \DOMElement $contextElm)
265: {
266: $wmslayer->setQueryable($this->getValue("./@queryable", $contextElm));
267: $wmslayer->setCascaded($this->getValue("./@cascaded", $contextElm));
268: $wmslayer->setOpaque($this->getValue("./@opaque", $contextElm));
269: $wmslayer->setNoSubset($this->getValue("./@noSubsets", $contextElm));
270: $wmslayer->setFixedWidth($this->getValue("./@fixedWidth", $contextElm));
271: $wmslayer->setFixedHeight($this->getValue("./@fixedHeight", $contextElm));
272:
273: $wmslayer->setName($this->getValue("./wms:Name/text()", $contextElm));
274: $wmslayer->setTitle($this->getValue("./wms:Title/text()", $contextElm));
275: $wmslayer->setAbstract($this->getValue("./wms:Abstract/text()", $contextElm));
276:
277: $keywordElList = $this->xpath->query("./wms:KeywordList/wms:Keyword", $contextElm);
278: foreach($keywordElList as $keywordEl)
279: {
280: $keyword = new Keyword();
281: $keyword->setValue(trim($this->getValue("./text()", $keywordEl)));
282: $keyword->setSourceclass($wmslayer->getClassname());
283: $keyword->setSourceid($wmslayer);
284:
285:
286:
287: }
288:
289: $tempList = $this->xpath->query("./wms:CRS", $contextElm);
290: if($tempList !== null)
291: {
292: foreach($tempList as $item)
293: {
294: $wmslayer->addSrs($this->getValue("./text()", $item));
295: }
296: }
297: $latlonbboxEl = $this->getValue("./wms:EX_GeographicBoundingBox", $contextElm);
298: if($latlonbboxEl !== null)
299: {
300: $latlonBounds = new BoundingBox();
301: $latlonBounds->setSrs("EPSG:4326");
302: $latlonBounds->setMinx($this->getValue("./wms:westBoundLongitude/text()", $latlonbboxEl));
303: $latlonBounds->setMiny($this->getValue("./wms:southBoundLatitude/text()", $latlonbboxEl));
304: $latlonBounds->setMaxx($this->getValue("./wms:eastBoundLongitude/text()", $latlonbboxEl));
305: $latlonBounds->setMaxy($this->getValue("./wms:northBoundLatitude/text()", $latlonbboxEl));
306: $wmslayer->setLatlonBounds($latlonBounds);
307: }
308:
309: $tempList = $this->xpath->query("./wms:BoundingBox", $contextElm);
310: if($tempList !== null)
311: {
312: foreach($tempList as $item)
313: {
314: $bbox = new BoundingBox();
315: $bbox->setSrs($this->getValue("./@CRS", $item));
316: $bbox->setMinx($this->getValue("./@minx", $item));
317: $bbox->setMiny($this->getValue("./@miny", $item));
318: $bbox->setMaxx($this->getValue("./@maxx", $item));
319: $bbox->setMaxy($this->getValue("./@maxy", $item));
320: $wmslayer->addBoundingBox($bbox);
321: }
322: }
323:
324: $attributionEl = $this->getValue("./wms:Attribution", $contextElm);
325: if($attributionEl !== null)
326: {
327: $attribution = new Attribution();
328: $attribution->setTitle($this->getValue("./wms:Title/text()", $attributionEl));
329: $attribution->setOnlineResource($this->getValue("./wms:OnlineResource/text()", $attributionEl));
330:
331: $logoUrl = new LegendUrl();
332: $logoUrl->setHeight($this->getValue("./wms:LogoURL/@height", $attributionEl));
333: $logoUrl->setWidth($this->getValue("./wms:LogoURL/@width", $attributionEl));
334: $onlineResource = new OnlineResource();
335: $onlineResource->setHref($this->getValue("./wms:LogoURL/wms:OnlineResource/text()", $attributionEl));
336: $onlineResource->setFormat($this->getValue("./wms:LogoURL/wms:Format/text()", $attributionEl));
337: $logoUrl->setOnlineResource($onlineResource);
338: $attribution->setLogoUrl($logoUrl);
339: $wmslayer->setAttribution($attribution);
340: }
341:
342: $authorityList = $this->xpath->query("./wms:AuthorityURL", $contextElm);
343: $identifierList = $this->xpath->query("./wms:Identifier", $contextElm);
344:
345: if($authorityList !== null)
346: {
347: foreach($authorityList as $authorityEl)
348: {
349: $authority = new Authority();
350: $authority->setName($this->getValue("./@name", $authorityEl));
351: $authority->setUrl($this->getValue("./wms:OnlineResource/text()", $authorityEl));
352: $wmslayer->addAuthority($authority);
353: }
354: }
355: if($identifierList !== null)
356: {
357: foreach($identifierList as $identifierEl)
358: {
359: $identifier = new Identifier();
360: $identifier->setAuthority($this->getValue("./@authority", $identifierEl));
361: $identifier->setValue($this->getValue("./text()", $identifierEl));
362: $wmslayer->setIdentifier($identifier);
363: }
364: }
365:
366: $metadataUrlList = $this->xpath->query("./wms:MetadataURL", $contextElm);
367: if($metadataUrlList !== null)
368: {
369: foreach($metadataUrlList as $metadataUrlEl)
370: {
371: $metadataUrl = new MetadataUrl();
372: $onlineResource = new OnlineResource();
373: $onlineResource->setFormat($this->getValue("./wms:Format/text()", $metadataUrlEl));
374: $onlineResource->setHref($this->getValue("./wms:OnlineResource/text()", $metadataUrlEl));
375: $metadataUrl->setOnlineResource($onlineResource);
376: $metadataUrl->setType($this->getValue("./@type", $metadataUrlEl));
377: $wmslayer->addMetadataUrl($metadataUrl);
378: }
379: }
380:
381: $dimentionList = $this->xpath->query("./wms:Dimension", $contextElm);
382: if($dimentionList !== null)
383: {
384: foreach($dimentionList as $dimensionEl)
385: {
386: $dimension = new Dimension();
387: $dimension->setName($this->getValue("./@name", $dimensionEl));
388: $dimension->setUnits($this->getValue("./@units", $dimensionEl));
389: $dimension->setUnitSymbol($this->getValue("./@unitSymbol", $dimensionEl));
390: $dimension->setDefault($this->getValue("./@default", $dimensionEl));
391: $dimension->setMultipleValues($this->getValue("./@multipleValues", $dimensionEl) !== null ? (bool) $this->getValue("./@name", $dimensionEl) : null);
392: $dimension->setNearestValue($this->getValue("./@nearestValue", $dimensionEl) !== null ? (bool) $this->getValue("./@name", $dimensionEl) : null);
393: $dimension->setCurrent($this->getValue("./@current", $dimensionEl) !== null ? (bool) $this->getValue("./@name", $dimensionEl) : null);
394: $dimension->setExtentValue($this->getValue("./text()", $dimensionEl));
395: $wmslayer->addDimensionl($dimension);
396: }
397: }
398:
399: $dataUrlList = $this->xpath->query("./wms:DataURL", $contextElm);
400: if($dataUrlList !== null)
401: {
402: foreach($dataUrlList as $dataUrlEl)
403: {
404: $onlineResource = new OnlineResource();
405: $onlineResource->setFormat($this->getValue("./wms:Format/text()", $dataUrlEl));
406: $onlineResource->setHref($this->getValue("./wms:OnlineResource/text()", $dataUrlEl));
407:
408: $wmslayer->addDataUrl($onlineResource);
409: }
410: }
411:
412: $featureListUrlList = $this->xpath->query("./wms:FeatureListURL", $contextElm);
413: if($featureListUrlList !== null)
414: {
415: foreach($featureListUrlList as $featureListUrlEl)
416: {
417: $onlineResource = new OnlineResource();
418: $onlineResource->setFormat($this->getValue("./wms:Format/text()", $featureListUrlEl));
419: $onlineResource->setHref($this->getValue("./wms:OnlineResource/text()", $featureListUrlEl));
420:
421: $wmslayer->addFeatureListUrl($onlineResource);
422: }
423: }
424:
425: $tempList = $this->xpath->query("./wms:Style", $contextElm);
426: if($tempList !== null)
427: {
428: foreach($tempList as $item)
429: {
430: $style = new Style();
431: $style->setName($this->getValue("./wms:Name/text()", $item));
432: $style->setTitle($this->getValue("./wms:Title/text()", $item));
433: $style->setAbstract($this->getValue("./wms:Abstract/text()", $item));
434:
435: $legendUrlEl = $this->getValue("./wms:LegendURL", $item);
436: if($legendUrlEl !== null)
437: {
438: $legendUrl = new LegendUrl();
439: $legendUrl->setWidth($this->getValue("./@width", $legendUrlEl));
440: $legendUrl->setHeight($this->getValue("./@height", $legendUrlEl));
441: $onlineResource = new OnlineResource();
442: $onlineResource->setFormat($this->getValue("./wms:Format/text()", $legendUrlEl));
443: $onlineResource->setHref($this->getValue("./wms:OnlineResource/@xlink:href", $legendUrlEl));
444: $legendUrl->setOnlineResource($onlineResource);
445: $style->setLegendUrl($legendUrl);
446: }
447:
448: $styleUrlEl = $this->getValue("./wms:StyleSheetURL", $item);
449: if($styleUrlEl !== null)
450: {
451: $onlineResource = new OnlineResource();
452: $onlineResource->setFormat($this->getValue("./wms:Format/text()", $styleUrlEl));
453: $onlineResource->setHref($this->getValue("./wms:OnlineResource/@xlink:href", $styleUrlEl));
454: $style->setStyleUlr($onlineResource);
455: }
456: $stylesheetUrlEl = $this->getValue("./wms:StyleSheetURL", $item);
457: if($stylesheetUrlEl !== null)
458: {
459: $onlineResource = new OnlineResource();
460: $onlineResource->setFormat($this->getValue("./wms:Format/text()", $stylesheetUrlEl));
461: $onlineResource->setHref($this->getValue("./wms:OnlineResource/@xlink:href", $stylesheetUrlEl));
462: $style->setStyleSheetUrl($onlineResource);
463: }
464:
465: $wmslayer->addStyle($style);
466: }
467: }
468:
469: $minScaleEl = $this->getValue("./wms:MinScaleDenominator", $contextElm);
470: $maxScaleEl = $this->getValue("./wms:MaxScaleDenominator", $contextElm);
471: if($minScaleEl !== null || $minScaleEl !== null)
472: {
473: $scale = new MinMax();
474: $min = $this->getValue("./wms:MinScaleDenominator/text()", $contextElm);
475: $scale->setMin($min !== null ? floatval($min) : null);
476: $max = $this->getValue("./wms:MaxScaleDenominator/text()", $contextElm);
477: $scale->setMax($max !== null ? floatval($max) : null);
478: $wmslayer->setScale($scale);
479:
480: $scaleHint = new MinMax();
481: $minScaleHint = sqrt(2.0)*$scale->getMin()/($this->resolution/2.54*100);
482: $maxScaleHint = sqrt(2.0)*$scale->getMax()/($this->resolution/2.54*100);
483:
484: $scaleHint->setMax($maxScaleHint);
485: $scaleHint->setMin($minScaleHint);
486: $wmslayer->setScaleHint($scaleHint);
487: }
488:
489: $tempList = $this->xpath->query("./wms:Layer", $contextElm);
490: if($tempList !== null)
491: {
492: foreach($tempList as $item)
493: {
494: $subwmslayer = $this->parseLayer($wms, new WmsLayerSource(), $item);
495: $subwmslayer->setParent($wmslayer);
496: $subwmslayer->setSource($wms);
497: $wmslayer->addSublayer($subwmslayer);
498: $wms->addLayer($subwmslayer);
499: }
500: }
501: $wmslayer->setSource($wms);
502: return $wmslayer;
503: }
504:
505: }
506:
507: