Back to index

lightning-sunbird  0.9+nobinonly
nsXFormsModule.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla XForms support.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * IBM Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2004
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *  Brian Ryner <bryner@brianryner.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsIGenericFactory.h"
00040 #include "nsXFormsElementFactory.h"
00041 #include "nsXFormsUtilityService.h"
00042 #include "nsXFormsAtoms.h"
00043 #include "nsXFormsModelElement.h"
00044 #include "nsXFormsUtils.h"
00045 #include "nsICategoryManager.h"
00046 #include "nsIServiceManager.h"
00047 
00048 // bb0d9c8b-3096-4b66-92a0-6c1ddf80e65f
00049 #define NS_XFORMSUTILITYSERVICE_CID \
00050 { 0xbb0d9c8b, 0x3096, 0x4b66, { 0x92, 0xa0, 0x6c, 0x1d, 0xdf, 0x80, 0xe6, 0x5f }}
00051 
00052 NS_GENERIC_FACTORY_CONSTRUCTOR(nsXFormsElementFactory)
00053 NS_GENERIC_FACTORY_CONSTRUCTOR(nsXFormsUtilityService)
00054 
00055 
00056 static NS_IMETHODIMP
00057 RegisterXFormsModule(nsIComponentManager *aCompMgr,
00058                      nsIFile *aPath,
00059                      const char *aRegistryLocation,
00060                      const char *aComponentType,
00061                      const nsModuleComponentInfo *aInfo)
00062 {
00063 #ifdef DEBUG
00064   printf("XFORMS Module: Registering\n");
00065 #endif
00066 
00067   nsCOMPtr<nsICategoryManager> catman =
00068     do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
00069 
00070   if (!catman)
00071     return NS_ERROR_FAILURE;
00072 
00073   nsXPIDLCString previous;
00074   nsresult rv =
00075     catman->AddCategoryEntry(NS_DOMNS_FEATURE_PREFIX "org.w3c.xforms.dom",
00076                              "1.0",
00077                              NS_XTF_ELEMENT_FACTORY_CONTRACTID_PREFIX NS_NAMESPACE_XFORMS,
00078                              PR_TRUE, PR_TRUE, getter_Copies(previous));
00079   NS_ENSURE_SUCCESS(rv, rv);
00080 
00081   rv =
00082     catman->AddCategoryEntry(NS_DOMNS_FEATURE_PREFIX NS_XFORMS_INSTANCE_OWNER,
00083                              "1.0",
00084                              NS_XTF_ELEMENT_FACTORY_CONTRACTID_PREFIX NS_NAMESPACE_XFORMS,
00085                              PR_TRUE, PR_TRUE, getter_Copies(previous));
00086   NS_ENSURE_SUCCESS(rv, rv);
00087 
00088   return catman->AddCategoryEntry("agent-style-sheets",
00089                                   "xforms stylesheet",
00090                                   "chrome://xforms/content/xforms.css",
00091                                   PR_TRUE, PR_TRUE, getter_Copies(previous));
00092 }
00093 
00094 static NS_IMETHODIMP
00095 UnregisterXFormsModule(nsIComponentManager *aCompMgr,
00096                        nsIFile *aPath,
00097                        const char *aRegistryLocation,
00098                        const nsModuleComponentInfo *aInfo)
00099 {
00100 #ifdef DEBUG
00101   printf("XFORMS Module: Unregistering\n");
00102 #endif
00103 
00104   nsCOMPtr<nsICategoryManager> catman =
00105     do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
00106 
00107   if (!catman)
00108     return NS_ERROR_FAILURE;
00109 
00110   catman->DeleteCategoryEntry(NS_DOMNS_FEATURE_PREFIX "org.w3c.xforms.dom",
00111                               "1.0", PR_TRUE);
00112 
00113   catman->DeleteCategoryEntry(NS_DOMNS_FEATURE_PREFIX NS_XFORMS_INSTANCE_OWNER,
00114                               "1.0", PR_TRUE);
00115 
00116   return catman->DeleteCategoryEntry("agent-style-sheets",
00117                                      "xforms stylesheet", PR_TRUE);
00118 }
00119 
00120 static const nsModuleComponentInfo components[] = {
00121   { "XForms element factory",
00122     NS_XFORMSELEMENTFACTORY_CID,
00123     NS_XTF_ELEMENT_FACTORY_CONTRACTID_PREFIX NS_NAMESPACE_XFORMS,
00124     nsXFormsElementFactoryConstructor,
00125     RegisterXFormsModule,
00126     UnregisterXFormsModule
00127   },
00128   { "XForms Utility Service",
00129     NS_XFORMSUTILITYSERVICE_CID,
00130     NS_XFORMS_UTILITY_CONTRACTID,
00131     nsXFormsUtilityServiceConstructor }
00132 };
00133 
00134 PR_STATIC_CALLBACK(nsresult)
00135 XFormsModuleCtor(nsIModule* aSelf)
00136 {
00137   nsXFormsAtoms::InitAtoms();
00138   nsXFormsUtils::Init();
00139   nsXFormsModelElement::Startup();
00140   return NS_OK;
00141 }
00142 
00143 NS_IMPL_NSGETMODULE_WITH_CTOR(xforms, components, XFormsModuleCtor)