nsXULContentUtils.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /*
  6. A package of routines shared by the XUL content code.
  7. */
  8. #ifndef nsXULContentUtils_h__
  9. #define nsXULContentUtils_h__
  10. #include "nsISupports.h"
  11. class nsIAtom;
  12. class nsIContent;
  13. class nsIDocument;
  14. class nsIRDFNode;
  15. class nsIRDFResource;
  16. class nsIRDFLiteral;
  17. class nsIRDFService;
  18. class nsIDateTimeFormat;
  19. class nsICollation;
  20. // errors to pass to LogTemplateError
  21. #define ERROR_TEMPLATE_INVALID_QUERYPROCESSOR \
  22. "querytype attribute doesn't specify a valid query processor"
  23. #define ERROR_TEMPLATE_INVALID_QUERYSET \
  24. "unexpected <queryset> element"
  25. #define ERROR_TEMPLATE_NO_MEMBERVAR \
  26. "no member variable found. Action body should have an element with uri attribute"
  27. #define ERROR_TEMPLATE_WHERE_NO_SUBJECT \
  28. "<where> element is missing a subject attribute"
  29. #define ERROR_TEMPLATE_WHERE_NO_RELATION \
  30. "<where> element is missing a rel attribute"
  31. #define ERROR_TEMPLATE_WHERE_NO_VALUE \
  32. "<where> element is missing a value attribute"
  33. #define ERROR_TEMPLATE_WHERE_NO_VAR \
  34. "<where> element must have at least one variable as a subject or value"
  35. #define ERROR_TEMPLATE_BINDING_BAD_SUBJECT \
  36. "<binding> requires a variable for its subject attribute"
  37. #define ERROR_TEMPLATE_BINDING_BAD_PREDICATE \
  38. "<binding> element is missing a predicate attribute"
  39. #define ERROR_TEMPLATE_BINDING_BAD_OBJECT \
  40. "<binding> requires a variable for its object attribute"
  41. #define ERROR_TEMPLATE_CONTENT_NOT_FIRST \
  42. "expected <content> to be first"
  43. #define ERROR_TEMPLATE_MEMBER_NOCONTAINERVAR \
  44. "<member> requires a variable for its container attribute"
  45. #define ERROR_TEMPLATE_MEMBER_NOCHILDVAR \
  46. "<member> requires a variable for its child attribute"
  47. #define ERROR_TEMPLATE_TRIPLE_NO_VAR \
  48. "<triple> should have at least one variable as a subject or object"
  49. #define ERROR_TEMPLATE_TRIPLE_BAD_SUBJECT \
  50. "<triple> requires a variable for its subject attribute"
  51. #define ERROR_TEMPLATE_TRIPLE_BAD_PREDICATE \
  52. "<triple> should have a non-variable value as a predicate"
  53. #define ERROR_TEMPLATE_TRIPLE_BAD_OBJECT \
  54. "<triple> requires a variable for its object attribute"
  55. #define ERROR_TEMPLATE_MEMBER_UNBOUND \
  56. "neither container or child variables of <member> has a value"
  57. #define ERROR_TEMPLATE_TRIPLE_UNBOUND \
  58. "neither subject or object variables of <triple> has a value"
  59. #define ERROR_TEMPLATE_BAD_XPATH \
  60. "XPath expression in query could not be parsed"
  61. #define ERROR_TEMPLATE_BAD_ASSIGN_XPATH \
  62. "XPath expression in <assign> could not be parsed"
  63. #define ERROR_TEMPLATE_BAD_BINDING_XPATH \
  64. "XPath expression in <binding> could not be parsed"
  65. #define ERROR_TEMPLATE_STORAGE_BAD_URI \
  66. "only profile: or file URI are allowed"
  67. #define ERROR_TEMPLATE_STORAGE_CANNOT_OPEN_DATABASE \
  68. "cannot open given database"
  69. #define ERROR_TEMPLATE_STORAGE_BAD_QUERY \
  70. "syntax error in the SQL query"
  71. #define ERROR_TEMPLATE_STORAGE_UNKNOWN_QUERY_PARAMETER \
  72. "the given named parameter is unknown in the SQL query"
  73. #define ERROR_TEMPLATE_STORAGE_WRONG_TYPE_QUERY_PARAMETER \
  74. "the type of a query parameter is wrong"
  75. #define ERROR_TEMPLATE_STORAGE_QUERY_PARAMETER_NOT_BOUND \
  76. "a query parameter cannot be bound to the SQL query"
  77. class nsXULContentUtils
  78. {
  79. protected:
  80. static nsIRDFService* gRDF;
  81. static nsIDateTimeFormat* gFormat;
  82. static nsICollation *gCollation;
  83. static bool gDisableXULCache;
  84. static int
  85. DisableXULCacheChangedCallback(const char* aPrefName, void* aClosure);
  86. public:
  87. static nsresult
  88. Init();
  89. static nsresult
  90. Finish();
  91. static nsresult
  92. FindChildByTag(nsIContent *aElement,
  93. int32_t aNameSpaceID,
  94. nsIAtom* aTag,
  95. nsIContent **aResult);
  96. static nsresult
  97. FindChildByResource(nsIContent* aElement,
  98. nsIRDFResource* aResource,
  99. nsIContent** aResult);
  100. static nsresult
  101. GetTextForNode(nsIRDFNode* aNode, nsAString& aResult);
  102. static nsresult
  103. GetResource(int32_t aNameSpaceID, nsIAtom* aAttribute, nsIRDFResource** aResult);
  104. static nsresult
  105. GetResource(int32_t aNameSpaceID, const nsAString& aAttribute, nsIRDFResource** aResult);
  106. static nsresult
  107. SetCommandUpdater(nsIDocument* aDocument, nsIContent* aElement);
  108. /**
  109. * Log a message to the error console
  110. */
  111. static void
  112. LogTemplateError(const char* aMsg);
  113. static nsIRDFService*
  114. RDFService()
  115. {
  116. return gRDF;
  117. }
  118. static nsICollation*
  119. GetCollation();
  120. #define XUL_RESOURCE(ident, uri) static nsIRDFResource* ident
  121. #define XUL_LITERAL(ident, val) static nsIRDFLiteral* ident
  122. #include "nsXULResourceList.h"
  123. #undef XUL_RESOURCE
  124. #undef XUL_LITERAL
  125. };
  126. #endif // nsXULContentUtils_h__