!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
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/
9 *
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.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Peter Van der Beken.
19 * Portions created by the Initial Developer are Copyright (C) 2006
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * Peter Van der Beken <peterv@propagandism.org>
24 *
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40 const EXSLT_REGEXP_CONTRACTID = "@mozilla.org/exslt/regexp;1";
41 const EXSLT_REGEXP_CID = Components.ID("{18a03189-067b-4978-b4f1-bafe35292ed6}");
42 const EXSLT_REGEXP_NS = "http://exslt.org/regular-expressions";
43 const EXSLT_REGEXP_DESC = "EXSLT RegExp extension functions"
44
45 const XSLT_EXTENSIONS_CAT = "XSLT extension functions";
46
47 const CATMAN_CONTRACTID = "@mozilla.org/categorymanager;1";
48 const NODESET_CONTRACTID = "@mozilla.org/transformiix-nodeset;1";
49
50 const Ci = Components.interfaces;
51
txEXSLTRegExFunctions
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
52 function txEXSLTRegExFunctions()
53 {
54 }
55
56 txEXSLTRegExFunctions.prototype = {
QueryInterface
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
57 QueryInterface: function(iid) {
58 if (iid.equals(Ci.nsISupports) ||
59 iid.equals(Ci.txIEXSLTRegExFunctions))
60 return this;
61
62 if (iid.equals(Ci.nsIClassInfo))
63 return txEXSLTRegExModule.factory
64
65 throw Components.results.NS_ERROR_NO_INTERFACE;
66 },
67
match
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
68 match: function(context, str, regex, flags) {
69 var nodeset = Components.classes[NODESET_CONTRACTID]
70 .createInstance(Ci.txINodeSet);
71
72 var re = new RegExp(regex, flags);
73 var matches = str.match(re);
74 if (matches != null && matches.length > 0) {
75 var contextNode = context.contextNode;
76 var doc = contextNode.nodeType == Ci.nsIDOMNode.DOCUMENT_NODE ?
77 contextNode : contextNode.ownerDocument;
78 var docFrag = doc.createDocumentFragment();
79
80 for (var i = 0; i < matches.length; ++i) {
81 var match = matches[i];
82 var elem = doc.createElementNS(null, "match");
83 var text = doc.createTextNode(match ? match : '');
84 elem.appendChild(text);
85 docFrag.appendChild(elem);
86 nodeset.add(elem);
87 }
88 }
89
90 return nodeset;
91 },
92
replace
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
93 replace: function(str, regex, flags, replace) {
94 var re = new RegExp(regex, flags);
95
96 return str.replace(re, replace);
97 },
98
test
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
99 test: function(str, regex, flags) {
100 var re = new RegExp(regex, flags);
101
102 return re.test(str);
103 }
104 }
105
106 var SingletonInstance = null;
107
108 var txEXSLTRegExModule = {
registerSelf
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
109 registerSelf: function(compMgr, fileSpec, location, type) {
110 compMgr = compMgr.QueryInterface(Ci.nsIComponentRegistrar);
111 compMgr.registerFactoryLocation(EXSLT_REGEXP_CID, EXSLT_REGEXP_DESC,
112 EXSLT_REGEXP_CONTRACTID, fileSpec,
113 location, type);
114
115 var catman = Components.classes[CATMAN_CONTRACTID]
116 .getService(Ci.nsICategoryManager);
117 catman.addCategoryEntry(XSLT_EXTENSIONS_CAT, EXSLT_REGEXP_NS,
118 EXSLT_REGEXP_CONTRACTID, true, true);
119 },
120
unregisterSelf
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
121 unregisterSelf: function(compMgr, location, loaderStr) {
122 compMgr = compMgr.QueryInterface(Ci.nsIComponentRegistrar);
123 compMgr.unregisterFactoryLocation(EXSLT_REGEXP_CID, location);
124
125 var catman = Components.classes[CATMAN_CONTRACTID]
126 .getService(Ci.nsICategoryManager);
127 catman.deleteCategoryEntry(XSLT_EXTENSIONS_CAT, EXSLT_REGEXP_NS, true);
128 },
129
getClassObject
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
130 getClassObject: function(compMgr, cid, iid) {
131 if (!cid.equals(EXSLT_REGEXP_CID))
132 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
133
134 if (!iid.equals(Ci.nsIFactory) &&
135 !iid.equals(Ci.nsIClassInfo))
136 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
137
138 return this.factory;
139 },
140
141 factory: {
QueryInterface
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
142 QueryInterface: function(iid) {
143 if (iid.equals(Ci.nsISupports) ||
144 iid.equals(Ci.nsIFactory) ||
145 iid.equals(Ci.nsIClassInfo))
146 return this;
147
148 throw Components.results.NS_ERROR_NO_INTERFACE;
149 },
150
createInstance
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
151 createInstance: function(outer, iid) {
152 if (outer != null)
153 throw Components.results.NS_ERROR_NO_AGGREGATION;
154
155 if (SingletonInstance == null)
156 SingletonInstance = new txEXSLTRegExFunctions();
157
158 return SingletonInstance.QueryInterface(iid);
159 },
160
getInterfaces
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
161 getInterfaces: function(countRef) {
162 var interfaces = [
163 Ci.txIEXSLTRegExFunctions
164 ];
165 countRef.value = interfaces.length;
166
167 return interfaces;
168 },
169
getHelperForLanguage
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
170 getHelperForLanguage: function(language) {
171 return null;
172 },
173
174 contractID: EXSLT_REGEXP_CONTRACTID,
175 classDescription: EXSLT_REGEXP_DESC,
176 classID: EXSLT_REGEXP_CID,
177 implementationLanguage: Ci.nsIProgrammingLanguage.JAVASCRIPT,
178 flags: Ci.nsIClassInfo.SINGLETON
179 },
180
canUnload
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
181 canUnload: function(compMgr) {
182 return true;
183 }
184 };
185
NSGetModule
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
186 function NSGetModule(compMgr, fileSpec) {
187 return txEXSLTRegExModule;
188 }