michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: michael@0: A package of routines shared by the XUL content code. michael@0: michael@0: */ michael@0: michael@0: #ifndef nsXULContentUtils_h__ michael@0: #define nsXULContentUtils_h__ michael@0: michael@0: #include "nsISupports.h" michael@0: michael@0: class nsIAtom; michael@0: class nsIContent; michael@0: class nsIDocument; michael@0: class nsIDOMNodeList; michael@0: class nsIRDFNode; michael@0: class nsCString; michael@0: class nsString; michael@0: class nsIRDFResource; michael@0: class nsIRDFLiteral; michael@0: class nsIRDFService; michael@0: class nsIDateTimeFormat; michael@0: class nsICollation; michael@0: michael@0: // errors to pass to LogTemplateError michael@0: #define ERROR_TEMPLATE_INVALID_QUERYPROCESSOR \ michael@0: "querytype attribute doesn't specify a valid query processor" michael@0: #define ERROR_TEMPLATE_INVALID_QUERYSET \ michael@0: "unexpected element" michael@0: #define ERROR_TEMPLATE_NO_MEMBERVAR \ michael@0: "no member variable found. Action body should have an element with uri attribute" michael@0: #define ERROR_TEMPLATE_WHERE_NO_SUBJECT \ michael@0: " element is missing a subject attribute" michael@0: #define ERROR_TEMPLATE_WHERE_NO_RELATION \ michael@0: " element is missing a rel attribute" michael@0: #define ERROR_TEMPLATE_WHERE_NO_VALUE \ michael@0: " element is missing a value attribute" michael@0: #define ERROR_TEMPLATE_WHERE_NO_VAR \ michael@0: " element must have at least one variable as a subject or value" michael@0: #define ERROR_TEMPLATE_BINDING_BAD_SUBJECT \ michael@0: " requires a variable for its subject attribute" michael@0: #define ERROR_TEMPLATE_BINDING_BAD_PREDICATE \ michael@0: " element is missing a predicate attribute" michael@0: #define ERROR_TEMPLATE_BINDING_BAD_OBJECT \ michael@0: " requires a variable for its object attribute" michael@0: #define ERROR_TEMPLATE_CONTENT_NOT_FIRST \ michael@0: "expected to be first" michael@0: #define ERROR_TEMPLATE_MEMBER_NOCONTAINERVAR \ michael@0: " requires a variable for its container attribute" michael@0: #define ERROR_TEMPLATE_MEMBER_NOCHILDVAR \ michael@0: " requires a variable for its child attribute" michael@0: #define ERROR_TEMPLATE_TRIPLE_NO_VAR \ michael@0: " should have at least one variable as a subject or object" michael@0: #define ERROR_TEMPLATE_TRIPLE_BAD_SUBJECT \ michael@0: " requires a variable for its subject attribute" michael@0: #define ERROR_TEMPLATE_TRIPLE_BAD_PREDICATE \ michael@0: " should have a non-variable value as a predicate" michael@0: #define ERROR_TEMPLATE_TRIPLE_BAD_OBJECT \ michael@0: " requires a variable for its object attribute" michael@0: #define ERROR_TEMPLATE_MEMBER_UNBOUND \ michael@0: "neither container or child variables of has a value" michael@0: #define ERROR_TEMPLATE_TRIPLE_UNBOUND \ michael@0: "neither subject or object variables of has a value" michael@0: #define ERROR_TEMPLATE_BAD_XPATH \ michael@0: "XPath expression in query could not be parsed" michael@0: #define ERROR_TEMPLATE_BAD_ASSIGN_XPATH \ michael@0: "XPath expression in could not be parsed" michael@0: #define ERROR_TEMPLATE_BAD_BINDING_XPATH \ michael@0: "XPath expression in could not be parsed" michael@0: #define ERROR_TEMPLATE_STORAGE_BAD_URI \ michael@0: "only profile: or file URI are allowed" michael@0: #define ERROR_TEMPLATE_STORAGE_CANNOT_OPEN_DATABASE \ michael@0: "cannot open given database" michael@0: #define ERROR_TEMPLATE_STORAGE_BAD_QUERY \ michael@0: "syntax error in the SQL query" michael@0: #define ERROR_TEMPLATE_STORAGE_UNKNOWN_QUERY_PARAMETER \ michael@0: "the given named parameter is unknown in the SQL query" michael@0: #define ERROR_TEMPLATE_STORAGE_WRONG_TYPE_QUERY_PARAMETER \ michael@0: "the type of a query parameter is wrong" michael@0: #define ERROR_TEMPLATE_STORAGE_QUERY_PARAMETER_NOT_BOUND \ michael@0: "a query parameter cannot be bound to the SQL query" michael@0: michael@0: class nsXULContentUtils michael@0: { michael@0: protected: michael@0: static nsIRDFService* gRDF; michael@0: static nsIDateTimeFormat* gFormat; michael@0: static nsICollation *gCollation; michael@0: michael@0: static bool gDisableXULCache; michael@0: michael@0: static int michael@0: DisableXULCacheChangedCallback(const char* aPrefName, void* aClosure); michael@0: michael@0: public: michael@0: static nsresult michael@0: Init(); michael@0: michael@0: static nsresult michael@0: Finish(); michael@0: michael@0: static nsresult michael@0: FindChildByTag(nsIContent *aElement, michael@0: int32_t aNameSpaceID, michael@0: nsIAtom* aTag, michael@0: nsIContent **aResult); michael@0: michael@0: static nsresult michael@0: FindChildByResource(nsIContent* aElement, michael@0: nsIRDFResource* aResource, michael@0: nsIContent** aResult); michael@0: michael@0: static nsresult michael@0: GetElementResource(nsIContent* aElement, nsIRDFResource** aResult); michael@0: michael@0: static nsresult michael@0: GetTextForNode(nsIRDFNode* aNode, nsAString& aResult); michael@0: michael@0: /** michael@0: * Construct a URI from the element ID given. This uses aElement as the michael@0: * ref and aDocument's document URI as the base. If aDocument's document michael@0: * URI does not support refs, this will throw NS_ERROR_NOT_AVAILABLE. michael@0: */ michael@0: static nsresult michael@0: MakeElementURI(nsIDocument* aDocument, const nsAString& aElementID, nsCString& aURI); michael@0: michael@0: static nsresult michael@0: MakeElementResource(nsIDocument* aDocument, const nsAString& aElementID, nsIRDFResource** aResult); michael@0: michael@0: /** michael@0: * Extract the element ID from aURI. Note that aURI must be an absolute michael@0: * URI string in UTF8; the element ID is the ref from the URI. If the michael@0: * scheme does not support refs, then the ID will be empty. michael@0: */ michael@0: static nsresult michael@0: MakeElementID(nsIDocument* aDocument, const nsACString& aURI, nsAString& aElementID); michael@0: michael@0: static nsresult michael@0: GetResource(int32_t aNameSpaceID, nsIAtom* aAttribute, nsIRDFResource** aResult); michael@0: michael@0: static nsresult michael@0: GetResource(int32_t aNameSpaceID, const nsAString& aAttribute, nsIRDFResource** aResult); michael@0: michael@0: static nsresult michael@0: SetCommandUpdater(nsIDocument* aDocument, nsIContent* aElement); michael@0: michael@0: /** michael@0: * Log a message to the error console michael@0: */ michael@0: static void michael@0: LogTemplateError(const char* aMsg); michael@0: michael@0: static nsIRDFService* michael@0: RDFService() michael@0: { michael@0: return gRDF; michael@0: } michael@0: michael@0: static nsICollation* michael@0: GetCollation(); michael@0: michael@0: #define XUL_RESOURCE(ident, uri) static nsIRDFResource* ident michael@0: #define XUL_LITERAL(ident, val) static nsIRDFLiteral* ident michael@0: #include "nsXULResourceList.h" michael@0: #undef XUL_RESOURCE michael@0: #undef XUL_LITERAL michael@0: }; michael@0: michael@0: #endif // nsXULContentUtils_h__