|
|
1.1 root 1: /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2: *
3: * ***** BEGIN LICENSE BLOCK *****
4: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5: *
6: * The contents of this file are subject to the Mozilla Public License Version
7: * 1.1 (the "License"); you may not use this file except in compliance with
8: * the License. You may obtain a copy of the License at
9: * http://www.mozilla.org/MPL/
10: *
11: * Software distributed under the License is distributed on an "AS IS" basis,
12: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13: * for the specific language governing rights and limitations under the
14: * License.
15: *
16: * The Original Code is SpiderMonkey E4X code, released August, 2004.
17: *
18: * The Initial Developer of the Original Code is
19: * Netscape Communications Corporation.
20: * Portions created by the Initial Developer are Copyright (C) 1998
21: * the Initial Developer. All Rights Reserved.
22: *
23: * Contributor(s):
24: *
25: * Alternatively, the contents of this file may be used under the terms of
26: * either of the GNU General Public License Version 2 or later (the "GPL"),
27: * or 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.
36: *
37: * ***** END LICENSE BLOCK ***** */
38:
39: #ifndef jsxml_h___
40: #define jsxml_h___
41:
42: #include "jsstddef.h"
43: #include "jspubtd.h"
44:
45: extern const char js_AnyName_str[];
46: extern const char js_AttributeName_str[];
47: extern const char js_isXMLName_str[];
48: extern const char js_Namespace_str[];
49: extern const char js_QName_str[];
50: extern const char js_XML_str[];
51: extern const char js_XMLList_str[];
52:
53: extern const char js_amp_entity_str[];
54: extern const char js_gt_entity_str[];
55: extern const char js_lt_entity_str[];
56: extern const char js_quot_entity_str[];
57:
58: struct JSXMLNamespace {
59: JSObject *object;
60: JSString *prefix;
61: JSString *uri;
62: JSBool declared; /* true if declared in its XML tag */
63: };
64:
65: extern JSXMLNamespace *
66: js_NewXMLNamespace(JSContext *cx, JSString *prefix, JSString *uri,
67: JSBool declared);
68:
69: extern void
70: js_MarkXMLNamespace(JSContext *cx, JSXMLNamespace *ns, void *arg);
71:
72: extern void
73: js_FinalizeXMLNamespace(JSContext *cx, JSXMLNamespace *ns);
74:
75: extern JSObject *
76: js_NewXMLNamespaceObject(JSContext *cx, JSString *prefix, JSString *uri,
77: JSBool declared);
78:
79: extern JSObject *
80: js_GetXMLNamespaceObject(JSContext *cx, JSXMLNamespace *ns);
81:
82: struct JSXMLQName {
83: JSObject *object;
84: JSString *uri;
85: JSString *prefix;
86: JSString *localName;
87: };
88:
89: extern JSXMLQName *
90: js_NewXMLQName(JSContext *cx, JSString *uri, JSString *prefix,
91: JSString *localName);
92:
93: extern void
94: js_MarkXMLQName(JSContext *cx, JSXMLQName *qn, void *arg);
95:
96: extern void
97: js_FinalizeXMLQName(JSContext *cx, JSXMLQName *qn);
98:
99: extern JSObject *
100: js_NewXMLQNameObject(JSContext *cx, JSString *uri, JSString *prefix,
101: JSString *localName);
102:
103: extern JSObject *
104: js_GetXMLQNameObject(JSContext *cx, JSXMLQName *qn);
105:
106: extern JSObject *
107: js_GetAttributeNameObject(JSContext *cx, JSXMLQName *qn);
108:
109: extern JSObject *
110: js_ConstructXMLQNameObject(JSContext *cx, jsval nsval, jsval lnval);
111:
112: typedef JSBool
113: (* JS_DLL_CALLBACK JSIdentityOp)(const void *a, const void *b);
114:
115: struct JSXMLArray {
116: uint32 length;
117: uint32 capacity;
118: void **vector;
119: JSXMLArrayCursor *cursors;
120: };
121:
122: struct JSXMLArrayCursor {
123: JSXMLArray *array;
124: uint32 index;
125: JSXMLArrayCursor *next;
126: JSXMLArrayCursor **prevp;
127: };
128:
129: /*
130: * NB: don't reorder this enum without changing all array initializers that
131: * depend on it in jsxml.c.
132: */
133: typedef enum JSXMLClass {
134: JSXML_CLASS_LIST,
135: JSXML_CLASS_ELEMENT,
136: JSXML_CLASS_ATTRIBUTE,
137: JSXML_CLASS_PROCESSING_INSTRUCTION,
138: JSXML_CLASS_TEXT,
139: JSXML_CLASS_COMMENT,
140: JSXML_CLASS_LIMIT
141: } JSXMLClass;
142:
143: #define JSXML_CLASS_HAS_KIDS(class_) ((class_) < JSXML_CLASS_ATTRIBUTE)
144: #define JSXML_CLASS_HAS_VALUE(class_) ((class_) >= JSXML_CLASS_ATTRIBUTE)
145: #define JSXML_CLASS_HAS_NAME(class_) \
146: ((uintN)((class_) - JSXML_CLASS_ELEMENT) <= \
147: (uintN)(JSXML_CLASS_PROCESSING_INSTRUCTION - JSXML_CLASS_ELEMENT))
148:
149: #ifdef DEBUG_notme
150: #include "jsclist.h"
151: #endif
152:
153: struct JSXML {
154: #ifdef DEBUG_notme
155: JSCList links;
156: uint32 serial;
157: #endif
158: JSObject *object;
159: void *domnode; /* DOM node if mapped info item */
160: JSXML *parent;
161: JSXMLQName *name;
162: uint16 xml_class; /* discriminates u, below */
163: uint16 xml_flags; /* flags, see below */
164: union {
165: struct JSXMLListVar {
166: JSXMLArray kids; /* NB: must come first */
167: JSXML *target;
168: JSXMLQName *targetprop;
169: } list;
170: struct JSXMLVar {
171: JSXMLArray kids; /* NB: must come first */
172: JSXMLArray namespaces;
173: JSXMLArray attrs;
174: } elem;
175: JSString *value;
176: } u;
177:
178: /* Don't add anything after u -- see js_NewXML for why. */
179: };
180:
181: /* union member shorthands */
182: #define xml_kids u.list.kids
183: #define xml_target u.list.target
184: #define xml_targetprop u.list.targetprop
185: #define xml_namespaces u.elem.namespaces
186: #define xml_attrs u.elem.attrs
187: #define xml_value u.value
188:
189: /* xml_flags values */
190: #define XMLF_WHITESPACE_TEXT 0x1
191:
192: /* xml_class-testing macros */
193: #define JSXML_HAS_KIDS(xml) JSXML_CLASS_HAS_KIDS((xml)->xml_class)
194: #define JSXML_HAS_VALUE(xml) JSXML_CLASS_HAS_VALUE((xml)->xml_class)
195: #define JSXML_HAS_NAME(xml) JSXML_CLASS_HAS_NAME((xml)->xml_class)
196: #define JSXML_LENGTH(xml) (JSXML_CLASS_HAS_KIDS((xml)->xml_class) \
197: ? (xml)->xml_kids.length \
198: : 0)
199:
200: extern JSXML *
201: js_NewXML(JSContext *cx, JSXMLClass xml_class);
202:
203: extern void
204: js_MarkXML(JSContext *cx, JSXML *xml, void *arg);
205:
206: extern void
207: js_FinalizeXML(JSContext *cx, JSXML *xml);
208:
209: extern JSObject *
210: js_ParseNodeToXMLObject(JSContext *cx, JSParseNode *pn);
211:
212: extern JSObject *
213: js_NewXMLObject(JSContext *cx, JSXMLClass xml_class);
214:
215: extern JSObject *
216: js_GetXMLObject(JSContext *cx, JSXML *xml);
217:
218: extern JS_FRIEND_DATA(JSXMLObjectOps) js_XMLObjectOps;
219: extern JS_FRIEND_DATA(JSClass) js_XMLClass;
220: extern JS_FRIEND_DATA(JSExtendedClass) js_QNameClass;
221: extern JS_FRIEND_DATA(JSClass) js_AttributeNameClass;
222: extern JS_FRIEND_DATA(JSClass) js_AnyNameClass;
223: extern JS_FRIEND_DATA(JSExtendedClass) js_NamespaceClass;
224:
225: /*
226: * Macros to test whether an object or a value is of type "xml" (per typeof).
227: * NB: jsapi.h must be included before any call to VALUE_IS_XML.
228: */
229: #define OBJECT_IS_XML(cx,obj) ((obj)->map->ops == &js_XMLObjectOps.base)
230: #define VALUE_IS_XML(cx,v) (!JSVAL_IS_PRIMITIVE(v) && \
231: OBJECT_IS_XML(cx, JSVAL_TO_OBJECT(v)))
232:
233: extern JSObject *
234: js_InitNamespaceClass(JSContext *cx, JSObject *obj);
235:
236: extern JSObject *
237: js_InitQNameClass(JSContext *cx, JSObject *obj);
238:
239: extern JSObject *
240: js_InitXMLClass(JSContext *cx, JSObject *obj);
241:
242: extern JSObject *
243: js_InitXMLClasses(JSContext *cx, JSObject *obj);
244:
245: extern JSBool
246: js_GetFunctionNamespace(JSContext *cx, jsval *vp);
247:
248: extern JSBool
249: js_GetDefaultXMLNamespace(JSContext *cx, jsval *vp);
250:
251: extern JSBool
252: js_SetDefaultXMLNamespace(JSContext *cx, jsval v);
253:
254: /*
255: * Return true if v is a XML QName object, or if it converts to a string that
256: * contains a valid XML qualified name (one containing no :), false otherwise.
257: * NB: This function is an infallible predicate, it hides exceptions.
258: */
259: extern JSBool
260: js_IsXMLName(JSContext *cx, jsval v);
261:
262: extern JSBool
263: js_ToAttributeName(JSContext *cx, jsval *vp);
264:
265: extern JSString *
266: js_EscapeAttributeValue(JSContext *cx, JSString *str);
267:
268: extern JSString *
269: js_AddAttributePart(JSContext *cx, JSBool isName, JSString *str,
270: JSString *str2);
271:
272: extern JSString *
273: js_EscapeElementValue(JSContext *cx, JSString *str);
274:
275: extern JSString *
276: js_ValueToXMLString(JSContext *cx, jsval v);
277:
278: extern JSBool
279: js_GetAnyName(JSContext *cx, jsval *vp);
280:
281: extern JSBool
282: js_FindXMLProperty(JSContext *cx, jsval name, JSObject **objp, jsval *namep);
283:
284: extern JSBool
285: js_GetXMLProperty(JSContext *cx, JSObject *obj, jsval name, jsval *vp);
286:
287: extern JSBool
288: js_SetXMLProperty(JSContext *cx, JSObject *obj, jsval name, jsval *vp);
289:
290: extern JSBool
291: js_GetXMLDescendants(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
292:
293: extern JSBool
294: js_DeleteXMLListElements(JSContext *cx, JSObject *listobj);
295:
296: extern JSBool
297: js_FilterXMLList(JSContext *cx, JSObject *obj, jsbytecode *pc, jsval *vp);
298:
299: extern JSObject *
300: js_ValueToXMLObject(JSContext *cx, jsval v);
301:
302: extern JSObject *
303: js_ValueToXMLListObject(JSContext *cx, jsval v);
304:
305: extern JSObject *
306: js_CloneXMLObject(JSContext *cx, JSObject *obj);
307:
308: extern JSObject *
309: js_NewXMLSpecialObject(JSContext *cx, JSXMLClass xml_class, JSString *name,
310: JSString *value);
311:
312: #endif /* jsxml_h___ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.