OGCExceptionReport.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
  2. * full list of contributors). Published under the 2-clause BSD license.
  3. * See license.txt in the OpenLayers distribution or repository for the
  4. * full text of the license. */
  5. /**
  6. * @requires OpenLayers/Format/XML.js
  7. */
  8. /**
  9. * Class: OpenLayers.Format.OGCExceptionReport
  10. * Class to read exception reports for various OGC services and versions.
  11. *
  12. * Inherits from:
  13. * - <OpenLayers.Format.XML>
  14. */
  15. OpenLayers.Format.OGCExceptionReport = OpenLayers.Class(OpenLayers.Format.XML, {
  16. /**
  17. * Property: namespaces
  18. * {Object} Mapping of namespace aliases to namespace URIs.
  19. */
  20. namespaces: {
  21. ogc: "http://www.opengis.net/ogc"
  22. },
  23. /**
  24. * Property: regExes
  25. * Compiled regular expressions for manipulating strings.
  26. */
  27. regExes: {
  28. trimSpace: (/^\s*|\s*$/g),
  29. removeSpace: (/\s*/g),
  30. splitSpace: (/\s+/),
  31. trimComma: (/\s*,\s*/g)
  32. },
  33. /**
  34. * Property: defaultPrefix
  35. */
  36. defaultPrefix: "ogc",
  37. /**
  38. * Constructor: OpenLayers.Format.OGCExceptionReport
  39. * Create a new parser for OGC exception reports.
  40. *
  41. * Parameters:
  42. * options - {Object} An optional object whose properties will be set on
  43. * this instance.
  44. */
  45. /**
  46. * APIMethod: read
  47. * Read OGC exception report data from a string, and return an object with
  48. * information about the exceptions.
  49. *
  50. * Parameters:
  51. * data - {String} or {DOMElement} data to read/parse.
  52. *
  53. * Returns:
  54. * {Object} Information about the exceptions that occurred.
  55. */
  56. read: function(data) {
  57. var result;
  58. if(typeof data == "string") {
  59. data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
  60. }
  61. var root = data.documentElement;
  62. var exceptionInfo = {exceptionReport: null};
  63. if (root) {
  64. this.readChildNodes(data, exceptionInfo);
  65. if (exceptionInfo.exceptionReport === null) {
  66. // fall-back to OWSCommon since this is a common output format for exceptions
  67. // we cannot easily use the ows readers directly since they differ for 1.0 and 1.1
  68. exceptionInfo = new OpenLayers.Format.OWSCommon().read(data);
  69. }
  70. }
  71. return exceptionInfo;
  72. },
  73. /**
  74. * Property: readers
  75. * Contains public functions, grouped by namespace prefix, that will
  76. * be applied when a namespaced node is found matching the function
  77. * name. The function will be applied in the scope of this parser
  78. * with two arguments: the node being read and a context object passed
  79. * from the parent.
  80. */
  81. readers: {
  82. "ogc": {
  83. "ServiceExceptionReport": function(node, obj) {
  84. obj.exceptionReport = {exceptions: []};
  85. this.readChildNodes(node, obj.exceptionReport);
  86. },
  87. "ServiceException": function(node, exceptionReport) {
  88. var exception = {
  89. code: node.getAttribute("code"),
  90. locator: node.getAttribute("locator"),
  91. text: this.getChildValue(node)
  92. };
  93. exceptionReport.exceptions.push(exception);
  94. }
  95. }
  96. },
  97. CLASS_NAME: "OpenLayers.Format.OGCExceptionReport"
  98. });