|
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 /* |
|
7 |
|
8 A package of routines shared by the XUL content code. |
|
9 |
|
10 */ |
|
11 |
|
12 #ifndef nsXULContentUtils_h__ |
|
13 #define nsXULContentUtils_h__ |
|
14 |
|
15 #include "nsISupports.h" |
|
16 |
|
17 class nsIAtom; |
|
18 class nsIContent; |
|
19 class nsIDocument; |
|
20 class nsIDOMNodeList; |
|
21 class nsIRDFNode; |
|
22 class nsCString; |
|
23 class nsString; |
|
24 class nsIRDFResource; |
|
25 class nsIRDFLiteral; |
|
26 class nsIRDFService; |
|
27 class nsIDateTimeFormat; |
|
28 class nsICollation; |
|
29 |
|
30 // errors to pass to LogTemplateError |
|
31 #define ERROR_TEMPLATE_INVALID_QUERYPROCESSOR \ |
|
32 "querytype attribute doesn't specify a valid query processor" |
|
33 #define ERROR_TEMPLATE_INVALID_QUERYSET \ |
|
34 "unexpected <queryset> element" |
|
35 #define ERROR_TEMPLATE_NO_MEMBERVAR \ |
|
36 "no member variable found. Action body should have an element with uri attribute" |
|
37 #define ERROR_TEMPLATE_WHERE_NO_SUBJECT \ |
|
38 "<where> element is missing a subject attribute" |
|
39 #define ERROR_TEMPLATE_WHERE_NO_RELATION \ |
|
40 "<where> element is missing a rel attribute" |
|
41 #define ERROR_TEMPLATE_WHERE_NO_VALUE \ |
|
42 "<where> element is missing a value attribute" |
|
43 #define ERROR_TEMPLATE_WHERE_NO_VAR \ |
|
44 "<where> element must have at least one variable as a subject or value" |
|
45 #define ERROR_TEMPLATE_BINDING_BAD_SUBJECT \ |
|
46 "<binding> requires a variable for its subject attribute" |
|
47 #define ERROR_TEMPLATE_BINDING_BAD_PREDICATE \ |
|
48 "<binding> element is missing a predicate attribute" |
|
49 #define ERROR_TEMPLATE_BINDING_BAD_OBJECT \ |
|
50 "<binding> requires a variable for its object attribute" |
|
51 #define ERROR_TEMPLATE_CONTENT_NOT_FIRST \ |
|
52 "expected <content> to be first" |
|
53 #define ERROR_TEMPLATE_MEMBER_NOCONTAINERVAR \ |
|
54 "<member> requires a variable for its container attribute" |
|
55 #define ERROR_TEMPLATE_MEMBER_NOCHILDVAR \ |
|
56 "<member> requires a variable for its child attribute" |
|
57 #define ERROR_TEMPLATE_TRIPLE_NO_VAR \ |
|
58 "<triple> should have at least one variable as a subject or object" |
|
59 #define ERROR_TEMPLATE_TRIPLE_BAD_SUBJECT \ |
|
60 "<triple> requires a variable for its subject attribute" |
|
61 #define ERROR_TEMPLATE_TRIPLE_BAD_PREDICATE \ |
|
62 "<triple> should have a non-variable value as a predicate" |
|
63 #define ERROR_TEMPLATE_TRIPLE_BAD_OBJECT \ |
|
64 "<triple> requires a variable for its object attribute" |
|
65 #define ERROR_TEMPLATE_MEMBER_UNBOUND \ |
|
66 "neither container or child variables of <member> has a value" |
|
67 #define ERROR_TEMPLATE_TRIPLE_UNBOUND \ |
|
68 "neither subject or object variables of <triple> has a value" |
|
69 #define ERROR_TEMPLATE_BAD_XPATH \ |
|
70 "XPath expression in query could not be parsed" |
|
71 #define ERROR_TEMPLATE_BAD_ASSIGN_XPATH \ |
|
72 "XPath expression in <assign> could not be parsed" |
|
73 #define ERROR_TEMPLATE_BAD_BINDING_XPATH \ |
|
74 "XPath expression in <binding> could not be parsed" |
|
75 #define ERROR_TEMPLATE_STORAGE_BAD_URI \ |
|
76 "only profile: or file URI are allowed" |
|
77 #define ERROR_TEMPLATE_STORAGE_CANNOT_OPEN_DATABASE \ |
|
78 "cannot open given database" |
|
79 #define ERROR_TEMPLATE_STORAGE_BAD_QUERY \ |
|
80 "syntax error in the SQL query" |
|
81 #define ERROR_TEMPLATE_STORAGE_UNKNOWN_QUERY_PARAMETER \ |
|
82 "the given named parameter is unknown in the SQL query" |
|
83 #define ERROR_TEMPLATE_STORAGE_WRONG_TYPE_QUERY_PARAMETER \ |
|
84 "the type of a query parameter is wrong" |
|
85 #define ERROR_TEMPLATE_STORAGE_QUERY_PARAMETER_NOT_BOUND \ |
|
86 "a query parameter cannot be bound to the SQL query" |
|
87 |
|
88 class nsXULContentUtils |
|
89 { |
|
90 protected: |
|
91 static nsIRDFService* gRDF; |
|
92 static nsIDateTimeFormat* gFormat; |
|
93 static nsICollation *gCollation; |
|
94 |
|
95 static bool gDisableXULCache; |
|
96 |
|
97 static int |
|
98 DisableXULCacheChangedCallback(const char* aPrefName, void* aClosure); |
|
99 |
|
100 public: |
|
101 static nsresult |
|
102 Init(); |
|
103 |
|
104 static nsresult |
|
105 Finish(); |
|
106 |
|
107 static nsresult |
|
108 FindChildByTag(nsIContent *aElement, |
|
109 int32_t aNameSpaceID, |
|
110 nsIAtom* aTag, |
|
111 nsIContent **aResult); |
|
112 |
|
113 static nsresult |
|
114 FindChildByResource(nsIContent* aElement, |
|
115 nsIRDFResource* aResource, |
|
116 nsIContent** aResult); |
|
117 |
|
118 static nsresult |
|
119 GetElementResource(nsIContent* aElement, nsIRDFResource** aResult); |
|
120 |
|
121 static nsresult |
|
122 GetTextForNode(nsIRDFNode* aNode, nsAString& aResult); |
|
123 |
|
124 /** |
|
125 * Construct a URI from the element ID given. This uses aElement as the |
|
126 * ref and aDocument's document URI as the base. If aDocument's document |
|
127 * URI does not support refs, this will throw NS_ERROR_NOT_AVAILABLE. |
|
128 */ |
|
129 static nsresult |
|
130 MakeElementURI(nsIDocument* aDocument, const nsAString& aElementID, nsCString& aURI); |
|
131 |
|
132 static nsresult |
|
133 MakeElementResource(nsIDocument* aDocument, const nsAString& aElementID, nsIRDFResource** aResult); |
|
134 |
|
135 /** |
|
136 * Extract the element ID from aURI. Note that aURI must be an absolute |
|
137 * URI string in UTF8; the element ID is the ref from the URI. If the |
|
138 * scheme does not support refs, then the ID will be empty. |
|
139 */ |
|
140 static nsresult |
|
141 MakeElementID(nsIDocument* aDocument, const nsACString& aURI, nsAString& aElementID); |
|
142 |
|
143 static nsresult |
|
144 GetResource(int32_t aNameSpaceID, nsIAtom* aAttribute, nsIRDFResource** aResult); |
|
145 |
|
146 static nsresult |
|
147 GetResource(int32_t aNameSpaceID, const nsAString& aAttribute, nsIRDFResource** aResult); |
|
148 |
|
149 static nsresult |
|
150 SetCommandUpdater(nsIDocument* aDocument, nsIContent* aElement); |
|
151 |
|
152 /** |
|
153 * Log a message to the error console |
|
154 */ |
|
155 static void |
|
156 LogTemplateError(const char* aMsg); |
|
157 |
|
158 static nsIRDFService* |
|
159 RDFService() |
|
160 { |
|
161 return gRDF; |
|
162 } |
|
163 |
|
164 static nsICollation* |
|
165 GetCollation(); |
|
166 |
|
167 #define XUL_RESOURCE(ident, uri) static nsIRDFResource* ident |
|
168 #define XUL_LITERAL(ident, val) static nsIRDFLiteral* ident |
|
169 #include "nsXULResourceList.h" |
|
170 #undef XUL_RESOURCE |
|
171 #undef XUL_LITERAL |
|
172 }; |
|
173 |
|
174 #endif // nsXULContentUtils_h__ |