Back to index

lightning-sunbird  0.9+nobinonly
jsxml.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is SpiderMonkey E4X code, released August, 2004.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or 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 #ifndef jsxml_h___
00040 #define jsxml_h___
00041 
00042 #include "jsstddef.h"
00043 #include "jspubtd.h"
00044 
00045 extern const char js_AnyName_str[];
00046 extern const char js_AttributeName_str[];
00047 extern const char js_isXMLName_str[];
00048 extern const char js_XMLList_str[];
00049 
00050 extern const char js_amp_entity_str[];
00051 extern const char js_gt_entity_str[];
00052 extern const char js_lt_entity_str[];
00053 extern const char js_quot_entity_str[];
00054 
00055 struct JSXMLNamespace {
00056     JSObject            *object;
00057     JSString            *prefix;
00058     JSString            *uri;
00059     JSBool              declared;       /* true if declared in its XML tag */
00060 };
00061 
00062 extern JSXMLNamespace *
00063 js_NewXMLNamespace(JSContext *cx, JSString *prefix, JSString *uri,
00064                    JSBool declared);
00065 
00066 extern void
00067 js_MarkXMLNamespace(JSContext *cx, JSXMLNamespace *ns);
00068 
00069 extern void
00070 js_FinalizeXMLNamespace(JSContext *cx, JSXMLNamespace *ns);
00071 
00072 extern JSObject *
00073 js_NewXMLNamespaceObject(JSContext *cx, JSString *prefix, JSString *uri,
00074                          JSBool declared);
00075 
00076 extern JSObject *
00077 js_GetXMLNamespaceObject(JSContext *cx, JSXMLNamespace *ns);
00078 
00079 struct JSXMLQName {
00080     JSObject            *object;
00081     JSString            *uri;
00082     JSString            *prefix;
00083     JSString            *localName;
00084 };
00085 
00086 extern JSXMLQName *
00087 js_NewXMLQName(JSContext *cx, JSString *uri, JSString *prefix,
00088                JSString *localName);
00089 
00090 extern void
00091 js_MarkXMLQName(JSContext *cx, JSXMLQName *qn);
00092 
00093 extern void
00094 js_FinalizeXMLQName(JSContext *cx, JSXMLQName *qn);
00095 
00096 extern JSObject *
00097 js_NewXMLQNameObject(JSContext *cx, JSString *uri, JSString *prefix,
00098                      JSString *localName);
00099 
00100 extern JSObject *
00101 js_GetXMLQNameObject(JSContext *cx, JSXMLQName *qn);
00102 
00103 extern JSObject *
00104 js_GetAttributeNameObject(JSContext *cx, JSXMLQName *qn);
00105 
00106 extern JSObject *
00107 js_ConstructXMLQNameObject(JSContext *cx, jsval nsval, jsval lnval);
00108 
00109 typedef JSBool
00110 (* JS_DLL_CALLBACK JSIdentityOp)(const void *a, const void *b);
00111 
00112 struct JSXMLArray {
00113     uint32              length;
00114     uint32              capacity;
00115     void                **vector;
00116     JSXMLArrayCursor    *cursors;
00117 };
00118 
00119 #define JSXML_PRESET_CAPACITY   JS_BIT(31)
00120 #define JSXML_CAPACITY_MASK     JS_BITMASK(31)
00121 #define JSXML_CAPACITY(array)   ((array)->capacity & JSXML_CAPACITY_MASK)
00122 
00123 struct JSXMLArrayCursor {
00124     JSXMLArray          *array;
00125     uint32              index;
00126     JSXMLArrayCursor    *next;
00127     JSXMLArrayCursor    **prevp;
00128     void                *root;
00129 };
00130 
00131 /*
00132  * NB: don't reorder this enum without changing all array initializers that
00133  * depend on it in jsxml.c.
00134  */
00135 typedef enum JSXMLClass {
00136     JSXML_CLASS_LIST,
00137     JSXML_CLASS_ELEMENT,
00138     JSXML_CLASS_ATTRIBUTE,
00139     JSXML_CLASS_PROCESSING_INSTRUCTION,
00140     JSXML_CLASS_TEXT,
00141     JSXML_CLASS_COMMENT,
00142     JSXML_CLASS_LIMIT
00143 } JSXMLClass;
00144 
00145 #define JSXML_CLASS_HAS_KIDS(class_)    ((class_) < JSXML_CLASS_ATTRIBUTE)
00146 #define JSXML_CLASS_HAS_VALUE(class_)   ((class_) >= JSXML_CLASS_ATTRIBUTE)
00147 #define JSXML_CLASS_HAS_NAME(class_)                                          \
00148     ((uintN)((class_) - JSXML_CLASS_ELEMENT) <=                               \
00149      (uintN)(JSXML_CLASS_PROCESSING_INSTRUCTION - JSXML_CLASS_ELEMENT))
00150 
00151 #ifdef DEBUG_notme
00152 #include "jsclist.h"
00153 #endif
00154 
00155 struct JSXML {
00156 #ifdef DEBUG_notme
00157     JSCList             links;
00158     uint32              serial;
00159 #endif
00160     JSObject            *object;
00161     void                *domnode;       /* DOM node if mapped info item */
00162     JSXML               *parent;
00163     JSXMLQName          *name;
00164     uint16              xml_class;      /* discriminates u, below */
00165     uint16              xml_flags;      /* flags, see below */
00166     union {
00167         struct JSXMLListVar {
00168             JSXMLArray  kids;           /* NB: must come first */
00169             JSXML       *target;
00170             JSXMLQName  *targetprop;
00171         } list;
00172         struct JSXMLVar {
00173             JSXMLArray  kids;           /* NB: must come first */
00174             JSXMLArray  namespaces;
00175             JSXMLArray  attrs;
00176         } elem;
00177         JSString        *value;
00178     } u;
00179 
00180     /* Don't add anything after u -- see js_NewXML for why. */
00181 };
00182 
00183 /* union member shorthands */
00184 #define xml_kids        u.list.kids
00185 #define xml_target      u.list.target
00186 #define xml_targetprop  u.list.targetprop
00187 #define xml_namespaces  u.elem.namespaces
00188 #define xml_attrs       u.elem.attrs
00189 #define xml_value       u.value
00190 
00191 /* xml_flags values */
00192 #define XMLF_WHITESPACE_TEXT    0x1
00193 
00194 /* xml_class-testing macros */
00195 #define JSXML_HAS_KIDS(xml)     JSXML_CLASS_HAS_KIDS((xml)->xml_class)
00196 #define JSXML_HAS_VALUE(xml)    JSXML_CLASS_HAS_VALUE((xml)->xml_class)
00197 #define JSXML_HAS_NAME(xml)     JSXML_CLASS_HAS_NAME((xml)->xml_class)
00198 #define JSXML_LENGTH(xml)       (JSXML_CLASS_HAS_KIDS((xml)->xml_class)       \
00199                                  ? (xml)->xml_kids.length                     \
00200                                  : 0)
00201 
00202 extern JSXML *
00203 js_NewXML(JSContext *cx, JSXMLClass xml_class);
00204 
00205 extern void
00206 js_MarkXML(JSContext *cx, JSXML *xml);
00207 
00208 extern void
00209 js_FinalizeXML(JSContext *cx, JSXML *xml);
00210 
00211 extern JSObject *
00212 js_ParseNodeToXMLObject(JSContext *cx, JSParseNode *pn);
00213 
00214 extern JSObject *
00215 js_NewXMLObject(JSContext *cx, JSXMLClass xml_class);
00216 
00217 extern JSObject *
00218 js_GetXMLObject(JSContext *cx, JSXML *xml);
00219 
00220 extern JS_FRIEND_DATA(JSXMLObjectOps)   js_XMLObjectOps;
00221 extern JS_FRIEND_DATA(JSClass)          js_XMLClass;
00222 extern JS_FRIEND_DATA(JSExtendedClass)  js_NamespaceClass;
00223 extern JS_FRIEND_DATA(JSExtendedClass)  js_QNameClass;
00224 extern JS_FRIEND_DATA(JSClass)          js_AttributeNameClass;
00225 extern JS_FRIEND_DATA(JSClass)          js_AnyNameClass;
00226 
00227 /*
00228  * Macros to test whether an object or a value is of type "xml" (per typeof).
00229  * NB: jsapi.h must be included before any call to VALUE_IS_XML.
00230  */
00231 #define OBJECT_IS_XML(cx,obj)   ((obj)->map->ops == &js_XMLObjectOps.base)
00232 #define VALUE_IS_XML(cx,v)      (!JSVAL_IS_PRIMITIVE(v) &&                    \
00233                                  OBJECT_IS_XML(cx, JSVAL_TO_OBJECT(v)))
00234 
00235 extern JSObject *
00236 js_InitNamespaceClass(JSContext *cx, JSObject *obj);
00237 
00238 extern JSObject *
00239 js_InitQNameClass(JSContext *cx, JSObject *obj);
00240 
00241 extern JSObject *
00242 js_InitAttributeNameClass(JSContext *cx, JSObject *obj);
00243 
00244 extern JSObject *
00245 js_InitAnyNameClass(JSContext *cx, JSObject *obj);
00246 
00247 extern JSObject *
00248 js_InitXMLClass(JSContext *cx, JSObject *obj);
00249 
00250 extern JSObject *
00251 js_InitXMLClasses(JSContext *cx, JSObject *obj);
00252 
00253 extern JSBool
00254 js_GetFunctionNamespace(JSContext *cx, jsval *vp);
00255 
00256 extern JSBool
00257 js_GetDefaultXMLNamespace(JSContext *cx, jsval *vp);
00258 
00259 extern JSBool
00260 js_SetDefaultXMLNamespace(JSContext *cx, jsval v);
00261 
00262 /*
00263  * Return true if v is a XML QName object, or if it converts to a string that
00264  * contains a valid XML qualified name (one containing no :), false otherwise.
00265  * NB: This function is an infallible predicate, it hides exceptions.
00266  */
00267 extern JSBool
00268 js_IsXMLName(JSContext *cx, jsval v);
00269 
00270 extern JSBool
00271 js_ToAttributeName(JSContext *cx, jsval *vp);
00272 
00273 extern JSString *
00274 js_EscapeAttributeValue(JSContext *cx, JSString *str);
00275 
00276 extern JSString *
00277 js_AddAttributePart(JSContext *cx, JSBool isName, JSString *str,
00278                     JSString *str2);
00279 
00280 extern JSString *
00281 js_EscapeElementValue(JSContext *cx, JSString *str);
00282 
00283 extern JSString *
00284 js_ValueToXMLString(JSContext *cx, jsval v);
00285 
00286 extern JSBool
00287 js_GetAnyName(JSContext *cx, jsval *vp);
00288 
00289 extern JSBool
00290 js_FindXMLProperty(JSContext *cx, jsval name, JSObject **objp, jsval *namep);
00291 
00292 extern JSBool
00293 js_GetXMLProperty(JSContext *cx, JSObject *obj, jsval name, jsval *vp);
00294 
00295 extern JSBool
00296 js_GetXMLFunction(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
00297 
00298 extern JSBool
00299 js_SetXMLProperty(JSContext *cx, JSObject *obj, jsval name, jsval *vp);
00300 
00301 extern JSBool
00302 js_GetXMLDescendants(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
00303 
00304 extern JSBool
00305 js_DeleteXMLListElements(JSContext *cx, JSObject *listobj);
00306 
00307 extern JSBool
00308 js_FilterXMLList(JSContext *cx, JSObject *obj, jsbytecode *pc, jsval *vp);
00309 
00310 extern JSObject *
00311 js_ValueToXMLObject(JSContext *cx, jsval v);
00312 
00313 extern JSObject *
00314 js_ValueToXMLListObject(JSContext *cx, jsval v);
00315 
00316 extern JSObject *
00317 js_CloneXMLObject(JSContext *cx, JSObject *obj);
00318 
00319 extern JSObject *
00320 js_NewXMLSpecialObject(JSContext *cx, JSXMLClass xml_class, JSString *name,
00321                        JSString *value);
00322 
00323 extern JSString *
00324 js_MakeXMLCDATAString(JSContext *cx, JSString *str);
00325 
00326 extern JSString *
00327 js_MakeXMLCommentString(JSContext *cx, JSString *str);
00328 
00329 extern JSString *
00330 js_MakeXMLPIString(JSContext *cx, JSString *name, JSString *str);
00331 
00332 #endif /* jsxml_h___ */