Import 3.0 beta 3 tarball
[mozilla-extra.git] / extensions / xforms / nsXFormsModule.cpp
blob83c20ac3ac6aa17fdf44eb71a0b8ca8bc1123690
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla XForms support.
17 * The Initial Developer of the Original Code is
18 * IBM Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2004
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Brian Ryner <bryner@brianryner.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsIGenericFactory.h"
40 #include "nsXFormsElementFactory.h"
41 #include "nsXFormsUtilityService.h"
42 #include "nsXFormsAtoms.h"
43 #include "nsXFormsModelElement.h"
44 #include "nsXFormsUtils.h"
45 #include "nsICategoryManager.h"
46 #include "nsIServiceManager.h"
47 #include "nsIClassInfoImpl.h"
48 #include "nsXFormsXPathFunctions.h"
49 #include "nsServiceManagerUtils.h"
51 // bb0d9c8b-3096-4b66-92a0-6c1ddf80e65f
52 #define NS_XFORMSUTILITYSERVICE_CID \
53 { 0xbb0d9c8b, 0x3096, 0x4b66, { 0x92, 0xa0, 0x6c, 0x1d, 0xdf, 0x80, 0xe6, 0x5f }}
55 #define NS_XFORMSUTILITYSERVICE_CONTRACTID \
56 "@mozilla.org/xforms-utility-service;1"
58 #define XFORMSXPATHFUNCTIONS_CID \
59 { 0x8edc8cf1, 0x69a3, 0x11d9, { 0x97, 0x91, 0x00, 0x0a, 0x95, 0xdc, 0x23, 0x4c } }
60 #define XFORMSXPATHFUNCTIONS_CONTRACTID \
61 "@mozilla.org/xforms-xpath-functions;1"
63 NS_GENERIC_FACTORY_CONSTRUCTOR(nsXFormsElementFactory)
64 NS_GENERIC_FACTORY_CONSTRUCTOR(nsXFormsUtilityService)
65 NS_GENERIC_FACTORY_CONSTRUCTOR(nsXFormsXPathFunctions)
66 NS_DECL_CLASSINFO(nsXFormsXPathFunctions)
68 static NS_IMETHODIMP
69 RegisterXFormsModule(nsIComponentManager *aCompMgr,
70 nsIFile *aPath,
71 const char *aRegistryLocation,
72 const char *aComponentType,
73 const nsModuleComponentInfo *aInfo)
75 #ifdef DEBUG
76 printf("XFORMS Module: Registering\n");
77 #endif
79 nsCOMPtr<nsICategoryManager> catman =
80 do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
82 if (!catman)
83 return NS_ERROR_FAILURE;
85 nsCString previous;
86 nsresult rv =
87 catman->AddCategoryEntry(NS_DOMNS_FEATURE_PREFIX "org.w3c.xforms.dom",
88 "1.0",
89 NS_XTF_ELEMENT_FACTORY_CONTRACTID_PREFIX NS_NAMESPACE_XFORMS,
90 PR_TRUE, PR_TRUE, getter_Copies(previous));
91 NS_ENSURE_SUCCESS(rv, rv);
93 rv =
94 catman->AddCategoryEntry(NS_DOMNS_FEATURE_PREFIX NS_XFORMS_INSTANCE_OWNER,
95 "1.0",
96 NS_XTF_ELEMENT_FACTORY_CONTRACTID_PREFIX NS_NAMESPACE_XFORMS,
97 PR_TRUE, PR_TRUE, getter_Copies(previous));
98 NS_ENSURE_SUCCESS(rv, rv);
100 return catman->AddCategoryEntry("agent-style-sheets",
101 "xforms stylesheet",
102 "chrome://xforms/content/xforms.css",
103 PR_TRUE, PR_TRUE, getter_Copies(previous));
106 static NS_IMETHODIMP
107 UnregisterXFormsModule(nsIComponentManager *aCompMgr,
108 nsIFile *aPath,
109 const char *aRegistryLocation,
110 const nsModuleComponentInfo *aInfo)
112 #ifdef DEBUG
113 printf("XFORMS Module: Unregistering\n");
114 #endif
116 nsXFormsUtils::Shutdown();
118 nsCOMPtr<nsICategoryManager> catman =
119 do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
121 if (!catman)
122 return NS_ERROR_FAILURE;
124 catman->DeleteCategoryEntry(NS_DOMNS_FEATURE_PREFIX "org.w3c.xforms.dom",
125 "1.0", PR_TRUE);
127 catman->DeleteCategoryEntry(NS_DOMNS_FEATURE_PREFIX NS_XFORMS_INSTANCE_OWNER,
128 "1.0", PR_TRUE);
130 return catman->DeleteCategoryEntry("agent-style-sheets",
131 "xforms stylesheet", PR_TRUE);
134 static const nsModuleComponentInfo components[] = {
135 { "XForms element factory",
136 NS_XFORMSELEMENTFACTORY_CID,
137 NS_XTF_ELEMENT_FACTORY_CONTRACTID_PREFIX NS_NAMESPACE_XFORMS,
138 nsXFormsElementFactoryConstructor,
139 RegisterXFormsModule,
140 UnregisterXFormsModule
142 { "XForms Utility Service",
143 NS_XFORMSUTILITYSERVICE_CID,
144 NS_XFORMSUTILITYSERVICE_CONTRACTID,
145 nsXFormsUtilityServiceConstructor
147 { "XForms XPath extension functions",
148 XFORMSXPATHFUNCTIONS_CID,
149 XFORMSXPATHFUNCTIONS_CONTRACTID,
150 nsXFormsXPathFunctionsConstructor,
151 nsnull, nsnull, nsnull,
152 NS_CI_INTERFACE_GETTER_NAME(nsXFormsXPathFunctions),
153 nsnull,
154 &NS_CLASSINFO_NAME(nsXFormsXPathFunctions)
158 PR_STATIC_CALLBACK(nsresult)
159 XFormsModuleCtor(nsIModule* aSelf)
161 nsXFormsAtoms::InitAtoms();
162 nsXFormsUtils::Init();
163 nsXFormsModelElement::Startup();
164 return NS_OK;
167 NS_IMPL_NSGETMODULE_WITH_CTOR(xforms, components, XFormsModuleCtor)