error.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. /**
  3. * Copyright (C) 2019 Michael Kourlas
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. var __importDefault = (this && this.__importDefault) || function (mod) {
  18. return (mod && mod.__esModule) ? mod : { "default": mod };
  19. };
  20. Object.defineProperty(exports, "__esModule", { value: true });
  21. exports.getContext = void 0;
  22. var XmlAttribute_1 = __importDefault(require("./nodes/XmlAttribute"));
  23. var XmlDocument_1 = __importDefault(require("./nodes/XmlDocument"));
  24. var XmlDtd_1 = __importDefault(require("./nodes/XmlDtd"));
  25. var XmlElement_1 = __importDefault(require("./nodes/XmlElement"));
  26. /**
  27. * Returns a context string for the specified node, for use in error messages.
  28. */
  29. function getContext(obj) {
  30. if (obj instanceof XmlAttribute_1.default) {
  31. return getContext(obj.up()) + (" > attribute \"" + obj.name + "\"");
  32. }
  33. else if (obj instanceof XmlDocument_1.default) {
  34. return "in XML document";
  35. }
  36. else if (obj instanceof XmlDtd_1.default) {
  37. return getContext(obj.up()) + " > DTD";
  38. }
  39. else if (obj instanceof XmlElement_1.default) {
  40. return getContext(obj.up()) + (" > element \"" + obj.name + "\"");
  41. }
  42. else {
  43. throw new Error("Unrecognized object of type "
  44. + Object.prototype.toString.call(obj));
  45. }
  46. }
  47. exports.getContext = getContext;