1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/xul/templates/src/nsXULContentUtils.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,174 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + 1.11 + A package of routines shared by the XUL content code. 1.12 + 1.13 + */ 1.14 + 1.15 +#ifndef nsXULContentUtils_h__ 1.16 +#define nsXULContentUtils_h__ 1.17 + 1.18 +#include "nsISupports.h" 1.19 + 1.20 +class nsIAtom; 1.21 +class nsIContent; 1.22 +class nsIDocument; 1.23 +class nsIDOMNodeList; 1.24 +class nsIRDFNode; 1.25 +class nsCString; 1.26 +class nsString; 1.27 +class nsIRDFResource; 1.28 +class nsIRDFLiteral; 1.29 +class nsIRDFService; 1.30 +class nsIDateTimeFormat; 1.31 +class nsICollation; 1.32 + 1.33 +// errors to pass to LogTemplateError 1.34 +#define ERROR_TEMPLATE_INVALID_QUERYPROCESSOR \ 1.35 + "querytype attribute doesn't specify a valid query processor" 1.36 +#define ERROR_TEMPLATE_INVALID_QUERYSET \ 1.37 + "unexpected <queryset> element" 1.38 +#define ERROR_TEMPLATE_NO_MEMBERVAR \ 1.39 + "no member variable found. Action body should have an element with uri attribute" 1.40 +#define ERROR_TEMPLATE_WHERE_NO_SUBJECT \ 1.41 + "<where> element is missing a subject attribute" 1.42 +#define ERROR_TEMPLATE_WHERE_NO_RELATION \ 1.43 + "<where> element is missing a rel attribute" 1.44 +#define ERROR_TEMPLATE_WHERE_NO_VALUE \ 1.45 + "<where> element is missing a value attribute" 1.46 +#define ERROR_TEMPLATE_WHERE_NO_VAR \ 1.47 + "<where> element must have at least one variable as a subject or value" 1.48 +#define ERROR_TEMPLATE_BINDING_BAD_SUBJECT \ 1.49 + "<binding> requires a variable for its subject attribute" 1.50 +#define ERROR_TEMPLATE_BINDING_BAD_PREDICATE \ 1.51 + "<binding> element is missing a predicate attribute" 1.52 +#define ERROR_TEMPLATE_BINDING_BAD_OBJECT \ 1.53 + "<binding> requires a variable for its object attribute" 1.54 +#define ERROR_TEMPLATE_CONTENT_NOT_FIRST \ 1.55 + "expected <content> to be first" 1.56 +#define ERROR_TEMPLATE_MEMBER_NOCONTAINERVAR \ 1.57 + "<member> requires a variable for its container attribute" 1.58 +#define ERROR_TEMPLATE_MEMBER_NOCHILDVAR \ 1.59 + "<member> requires a variable for its child attribute" 1.60 +#define ERROR_TEMPLATE_TRIPLE_NO_VAR \ 1.61 + "<triple> should have at least one variable as a subject or object" 1.62 +#define ERROR_TEMPLATE_TRIPLE_BAD_SUBJECT \ 1.63 + "<triple> requires a variable for its subject attribute" 1.64 +#define ERROR_TEMPLATE_TRIPLE_BAD_PREDICATE \ 1.65 + "<triple> should have a non-variable value as a predicate" 1.66 +#define ERROR_TEMPLATE_TRIPLE_BAD_OBJECT \ 1.67 + "<triple> requires a variable for its object attribute" 1.68 +#define ERROR_TEMPLATE_MEMBER_UNBOUND \ 1.69 + "neither container or child variables of <member> has a value" 1.70 +#define ERROR_TEMPLATE_TRIPLE_UNBOUND \ 1.71 + "neither subject or object variables of <triple> has a value" 1.72 +#define ERROR_TEMPLATE_BAD_XPATH \ 1.73 + "XPath expression in query could not be parsed" 1.74 +#define ERROR_TEMPLATE_BAD_ASSIGN_XPATH \ 1.75 + "XPath expression in <assign> could not be parsed" 1.76 +#define ERROR_TEMPLATE_BAD_BINDING_XPATH \ 1.77 + "XPath expression in <binding> could not be parsed" 1.78 +#define ERROR_TEMPLATE_STORAGE_BAD_URI \ 1.79 + "only profile: or file URI are allowed" 1.80 +#define ERROR_TEMPLATE_STORAGE_CANNOT_OPEN_DATABASE \ 1.81 + "cannot open given database" 1.82 +#define ERROR_TEMPLATE_STORAGE_BAD_QUERY \ 1.83 + "syntax error in the SQL query" 1.84 +#define ERROR_TEMPLATE_STORAGE_UNKNOWN_QUERY_PARAMETER \ 1.85 + "the given named parameter is unknown in the SQL query" 1.86 +#define ERROR_TEMPLATE_STORAGE_WRONG_TYPE_QUERY_PARAMETER \ 1.87 + "the type of a query parameter is wrong" 1.88 +#define ERROR_TEMPLATE_STORAGE_QUERY_PARAMETER_NOT_BOUND \ 1.89 + "a query parameter cannot be bound to the SQL query" 1.90 + 1.91 +class nsXULContentUtils 1.92 +{ 1.93 +protected: 1.94 + static nsIRDFService* gRDF; 1.95 + static nsIDateTimeFormat* gFormat; 1.96 + static nsICollation *gCollation; 1.97 + 1.98 + static bool gDisableXULCache; 1.99 + 1.100 + static int 1.101 + DisableXULCacheChangedCallback(const char* aPrefName, void* aClosure); 1.102 + 1.103 +public: 1.104 + static nsresult 1.105 + Init(); 1.106 + 1.107 + static nsresult 1.108 + Finish(); 1.109 + 1.110 + static nsresult 1.111 + FindChildByTag(nsIContent *aElement, 1.112 + int32_t aNameSpaceID, 1.113 + nsIAtom* aTag, 1.114 + nsIContent **aResult); 1.115 + 1.116 + static nsresult 1.117 + FindChildByResource(nsIContent* aElement, 1.118 + nsIRDFResource* aResource, 1.119 + nsIContent** aResult); 1.120 + 1.121 + static nsresult 1.122 + GetElementResource(nsIContent* aElement, nsIRDFResource** aResult); 1.123 + 1.124 + static nsresult 1.125 + GetTextForNode(nsIRDFNode* aNode, nsAString& aResult); 1.126 + 1.127 + /** 1.128 + * Construct a URI from the element ID given. This uses aElement as the 1.129 + * ref and aDocument's document URI as the base. If aDocument's document 1.130 + * URI does not support refs, this will throw NS_ERROR_NOT_AVAILABLE. 1.131 + */ 1.132 + static nsresult 1.133 + MakeElementURI(nsIDocument* aDocument, const nsAString& aElementID, nsCString& aURI); 1.134 + 1.135 + static nsresult 1.136 + MakeElementResource(nsIDocument* aDocument, const nsAString& aElementID, nsIRDFResource** aResult); 1.137 + 1.138 + /** 1.139 + * Extract the element ID from aURI. Note that aURI must be an absolute 1.140 + * URI string in UTF8; the element ID is the ref from the URI. If the 1.141 + * scheme does not support refs, then the ID will be empty. 1.142 + */ 1.143 + static nsresult 1.144 + MakeElementID(nsIDocument* aDocument, const nsACString& aURI, nsAString& aElementID); 1.145 + 1.146 + static nsresult 1.147 + GetResource(int32_t aNameSpaceID, nsIAtom* aAttribute, nsIRDFResource** aResult); 1.148 + 1.149 + static nsresult 1.150 + GetResource(int32_t aNameSpaceID, const nsAString& aAttribute, nsIRDFResource** aResult); 1.151 + 1.152 + static nsresult 1.153 + SetCommandUpdater(nsIDocument* aDocument, nsIContent* aElement); 1.154 + 1.155 + /** 1.156 + * Log a message to the error console 1.157 + */ 1.158 + static void 1.159 + LogTemplateError(const char* aMsg); 1.160 + 1.161 + static nsIRDFService* 1.162 + RDFService() 1.163 + { 1.164 + return gRDF; 1.165 + } 1.166 + 1.167 + static nsICollation* 1.168 + GetCollation(); 1.169 + 1.170 +#define XUL_RESOURCE(ident, uri) static nsIRDFResource* ident 1.171 +#define XUL_LITERAL(ident, val) static nsIRDFLiteral* ident 1.172 +#include "nsXULResourceList.h" 1.173 +#undef XUL_RESOURCE 1.174 +#undef XUL_LITERAL 1.175 +}; 1.176 + 1.177 +#endif // nsXULContentUtils_h__