Annotation of parser3/src/classes/xdoc.C, revision 1.140
1.1 parser 1: /** @file
1.2 parser 2: Parser: @b xdoc parser class.
1.1 parser 3:
1.131 paf 4: Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com)
1.85 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.96 paf 6: */
1.1 parser 7:
1.111 paf 8: #include "pa_config_includes.h"
9:
1.1 parser 10: #ifdef XML
1.96 paf 11:
1.140 ! paf 12: static const char * const IDENT_XDOC_C="$Date: 2004/02/18 11:54:08 $";
1.82 paf 13:
1.69 paf 14: #include "gdome.h"
15: #include "libxml/tree.h"
1.133 paf 16: #include "libxml/HTMLtree.h"
1.69 paf 17: #include "libxslt/xsltInternals.h"
18: #include "libxslt/transform.h"
19: #include "libxslt/xsltutils.h"
1.90 paf 20: #include "libxslt/variables.h"
1.132 paf 21: #include "libxslt/imports.h"
1.111 paf 22:
23: #include "pa_vmethod_frame.h"
24:
25: #include "pa_stylesheet_manager.h"
26: #include "pa_request.h"
27: #include "pa_vxdoc.h"
28: #include "pa_charset.h"
29: #include "pa_vfile.h"
1.115 paf 30: #include "pa_xml_exception.h"
1.111 paf 31: #include "xnode.h"
32:
1.1 parser 33: // defines
34:
35: #define XDOC_CLASS_NAME "xdoc"
36:
37: #define XDOC_OUTPUT_METHOD_OPTION_NAME "method"
38: #define XDOC_OUTPUT_METHOD_OPTION_VALUE_XML "xml"
39: #define XDOC_OUTPUT_METHOD_OPTION_VALUE_HTML "html"
40: #define XDOC_OUTPUT_METHOD_OPTION_VALUE_TEXT "text"
41:
42: // class
43:
1.111 paf 44: class MXdoc: public MXnode {
1.1 parser 45: public: // VStateless_class
1.118 paf 46: Value* create_new_value(Pool&) { return new VXdoc(0, 0); }
1.1 parser 47:
48: public:
1.111 paf 49: MXdoc();
1.1 parser 50:
51: };
52:
1.111 paf 53: // global variable
54:
55: DECLARE_CLASS_VAR(xdoc, new MXdoc, 0);
1.61 paf 56:
1.138 paf 57: // helper classes
58:
59: class xmlOutputBuffer_auto_ptr {
60: public:
61: explicit xmlOutputBuffer_auto_ptr(xmlOutputBuffer *_APtr = 0)
62: : _Owns(_APtr != 0), _Ptr(_APtr) {}
63: xmlOutputBuffer_auto_ptr(const xmlOutputBuffer_auto_ptr& _Y)
64: : _Owns(_Y._Owns), _Ptr(_Y.release()) {}
65: xmlOutputBuffer_auto_ptr& operator=(const xmlOutputBuffer_auto_ptr& _Y)
66: {if (this != &_Y)
67: {if (_Ptr != _Y.get())
68: {if (_Owns && _Ptr)
69: xmlOutputBufferClose(_Ptr);
70: _Owns = _Y._Owns; }
71: else if (_Y._Owns)
72: _Owns = true;
73: _Ptr = _Y.release(); }
74: return (*this); }
75: ~xmlOutputBuffer_auto_ptr()
76: {if (_Owns && _Ptr)
77: xmlOutputBufferClose(_Ptr); }
78: xmlOutputBuffer& operator*() const
79: {return (*get()); }
80: xmlOutputBuffer *operator->() const
81: {return (get()); }
82: xmlOutputBuffer *get() const
83: {return (_Ptr); }
84: xmlOutputBuffer *release() const
85: {((xmlOutputBuffer_auto_ptr *)this)->_Owns = false;
86: return (_Ptr); }
87: private:
88: bool _Owns;
89: xmlOutputBuffer *_Ptr;
90: };
91:
1.65 paf 92: class xsltTransformContext_auto_ptr {
93: public:
1.67 paf 94: explicit xsltTransformContext_auto_ptr(xsltTransformContext *_APtr = 0)
95: : _Owns(_APtr != 0), _Ptr(_APtr) {}
1.65 paf 96: xsltTransformContext_auto_ptr(const xsltTransformContext_auto_ptr& _Y)
97: : _Owns(_Y._Owns), _Ptr(_Y.release()) {}
98: xsltTransformContext_auto_ptr& operator=(const xsltTransformContext_auto_ptr& _Y)
99: {if (this != &_Y)
100: {if (_Ptr != _Y.get())
101: {if (_Owns && _Ptr)
102: xsltFreeTransformContext(_Ptr);
103: _Owns = _Y._Owns; }
104: else if (_Y._Owns)
105: _Owns = true;
106: _Ptr = _Y.release(); }
107: return (*this); }
108: ~xsltTransformContext_auto_ptr()
109: {if (_Owns && _Ptr)
110: xsltFreeTransformContext(_Ptr); }
111: xsltTransformContext& operator*() const
112: {return (*get()); }
113: xsltTransformContext *operator->() const
114: {return (get()); }
115: xsltTransformContext *get() const
116: {return (_Ptr); }
117: xsltTransformContext *release() const
118: {((xsltTransformContext_auto_ptr *)this)->_Owns = false;
119: return (_Ptr); }
120: private:
121: bool _Owns;
122: xsltTransformContext *_Ptr;
123: };
1.61 paf 124:
1.65 paf 125: class xsltStylesheet_auto_ptr {
126: public:
1.67 paf 127: explicit xsltStylesheet_auto_ptr(xsltStylesheet *_APtr = 0)
128: : _Owns(_APtr != 0), _Ptr(_APtr) {}
1.65 paf 129: xsltStylesheet_auto_ptr(const xsltStylesheet_auto_ptr& _Y)
130: : _Owns(_Y._Owns), _Ptr(_Y.release()) {}
131: xsltStylesheet_auto_ptr& operator=(const xsltStylesheet_auto_ptr& _Y)
132: {if (this != &_Y)
133: {if (_Ptr != _Y.get())
134: {if (_Owns && _Ptr)
135: xsltFreeStylesheet(_Ptr);
136: _Owns = _Y._Owns; }
137: else if (_Y._Owns)
138: _Owns = true;
139: _Ptr = _Y.release(); }
140: return (*this); }
141: ~xsltStylesheet_auto_ptr()
142: {if (_Owns && _Ptr)
143: xsltFreeStylesheet(_Ptr); }
144: xsltStylesheet& operator*() const
145: {return (*get()); }
146: xsltStylesheet *operator->() const
147: {return (get()); }
148: xsltStylesheet *get() const
149: {return (_Ptr); }
150: xsltStylesheet *release() const
151: {((xsltStylesheet_auto_ptr *)this)->_Owns = false;
152: return (_Ptr); }
153: private:
154: bool _Owns;
155: xsltStylesheet *_Ptr;
156: };
1.61 paf 157:
1.1 parser 158: // methods
159:
1.111 paf 160: static void writeNode(Request& r, GdomeNode *node,
1.54 paf 161: GdomeException exc) {
162: if(!node || exc)
1.115 paf 163: throw XmlException(0, exc);
1.54 paf 164:
165: // write out result
1.111 paf 166: r.write_no_lang(*new VXnode(&r.charsets, node));
1.54 paf 167: }
168:
1.16 parser 169: // Element createElement(in DOMString tagName) raises(DOMException);
1.111 paf 170: static void _createElement(Request& r, MethodParams& params) {
171: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.16 parser 172:
1.111 paf 173: const String& tagName=params.as_string(0, "tagName must be string");
1.16 parser 174:
1.54 paf 175: GdomeException exc;
176: GdomeNode *node=
1.111 paf 177: (GdomeNode *)gdome_doc_createElement(vdoc.get_document(),
178: r.transcode(tagName).use(),
1.54 paf 179: &exc);
1.111 paf 180: writeNode(r, node, exc);
1.16 parser 181: }
182:
1.113 paf 183: // Element createElementNS(in DOMString namespaceURI, in DOMString qualifiedName) raises(DOMException);
1.112 paf 184: static void _createElementNS(Request& r, MethodParams& params) {
185: VXdoc& vdoc=GET_SELF(r, VXdoc);
186:
187: // namespaceURI;localName
188: const String& namespaceURI=params.as_string(0, "namespaceURI must be string");
1.113 paf 189: const String& qualifiedName=params.as_string(1, "qualifiedName must be string");
1.112 paf 190:
191: GdomeException exc;
192: GdomeNode *node=
193: (GdomeNode *)gdome_doc_createElementNS(vdoc.get_document(),
194: r.transcode(namespaceURI).use(),
1.113 paf 195: r.transcode(qualifiedName).use(),
1.112 paf 196: &exc);
197: writeNode(r, node, exc);
198: }
199:
1.16 parser 200: // DocumentFragment createDocumentFragment()
1.111 paf 201: static void _createDocumentFragment(Request& r, MethodParams&) {
202: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.16 parser 203:
1.54 paf 204: GdomeException exc;
205: GdomeNode *node=
206: (GdomeNode *)gdome_doc_createDocumentFragment(
1.111 paf 207: vdoc.get_document(),
1.54 paf 208: &exc);
1.111 paf 209: writeNode(r, node, exc);
1.16 parser 210: }
211:
212: // Text createTextNode(in DOMString data);
1.111 paf 213: static void _createTextNode(Request& r, MethodParams& params) {
214: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.16 parser 215:
1.111 paf 216: const String& data=params.as_string(0, "data must be string");
1.16 parser 217:
1.54 paf 218: GdomeException exc;
219: GdomeNode *node=(GdomeNode *)gdome_doc_createTextNode(
1.111 paf 220: vdoc.get_document(),
221: r.transcode(data).use(),
1.54 paf 222: &exc);
1.111 paf 223: writeNode(r, node, exc);
1.16 parser 224: }
225:
226: // Comment createComment(in DOMString data)
1.111 paf 227: static void _createComment(Request& r, MethodParams& params) {
228: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.16 parser 229:
1.111 paf 230: const String& data=params.as_string(0, "data must be string");
1.16 parser 231:
1.54 paf 232: GdomeException exc;
233: GdomeNode *node=(GdomeNode *)gdome_doc_createComment(
1.111 paf 234: vdoc.get_document(),
235: r.transcode(data).use(),
1.54 paf 236: &exc);
1.111 paf 237: writeNode(r, node, exc);
1.16 parser 238: }
239:
240: // CDATASection createCDATASection(in DOMString data) raises(DOMException);
1.111 paf 241: static void _createCDATASection(Request& r, MethodParams& params) {
242: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.16 parser 243:
1.111 paf 244: const String& data=params.as_string(0, "data must be string");
1.16 parser 245:
1.54 paf 246: GdomeException exc;
247: GdomeNode *node=(GdomeNode *)gdome_doc_createCDATASection(
1.111 paf 248: vdoc.get_document(),
249: r.transcode(data).use(),
1.54 paf 250: &exc);
1.111 paf 251: writeNode(r, node, exc);
1.16 parser 252: }
253:
254: // ProcessingInstruction createProcessingInstruction(in DOMString target,in DOMString data) raises(DOMException);
1.111 paf 255: static void _createProcessingInstruction(Request& r, MethodParams& params) {
256: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.16 parser 257:
1.111 paf 258: const String& target=params.as_string(0, "data must be string");
259: const String& data=params.as_string(1, "data must be string");
1.16 parser 260:
1.54 paf 261: GdomeException exc;
262: GdomeNode *node=(GdomeNode *)gdome_doc_createProcessingInstruction(
1.111 paf 263: vdoc.get_document(),
264: r.transcode(target).use(),
265: r.transcode(data).use(),
1.54 paf 266: &exc);
1.111 paf 267: writeNode(r, node, exc);
1.16 parser 268: }
269:
270: // Attr createAttribute(in DOMString name) raises(DOMException);
1.111 paf 271: static void _createAttribute(Request& r, MethodParams& params) {
272: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.16 parser 273:
1.111 paf 274: const String& name=params.as_string(0, "name must be string");
1.16 parser 275:
1.54 paf 276: GdomeException exc;
277: GdomeNode *node=(GdomeNode *)gdome_doc_createAttribute(
1.111 paf 278: vdoc.get_document(),
279: r.transcode(name).use(),
1.54 paf 280: &exc);
1.111 paf 281: writeNode(r, node, exc);
1.16 parser 282: }
1.112 paf 283:
1.113 paf 284: // Attr createAttributeNS(in DOMString namespaceURI, in DOMString qualifiedName) raises(DOMException);
1.112 paf 285: static void _createAttributeNS(Request& r, MethodParams& params) {
286: VXdoc& vdoc=GET_SELF(r, VXdoc);
287:
288: // namespaceURI;qualifiedName
289: const String& namespaceURI=params.as_string(0, "namespaceURI must be string");
290: const String& qualifiedName=params.as_string(1, "name must be string");
291:
292: GdomeException exc;
293: GdomeNode *node=(GdomeNode *)gdome_doc_createAttributeNS(
294: vdoc.get_document(),
295: r.transcode(namespaceURI).use(),
296: r.transcode(qualifiedName).use(),
297: &exc);
298: writeNode(r, node, exc);
299: }
300:
1.16 parser 301: // EntityReference createEntityReference(in DOMString name) raises(DOMException);
1.111 paf 302: static void _createEntityReference(Request& r, MethodParams& params) {
303: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.16 parser 304:
1.111 paf 305: const String& name=params.as_string(0, "name must be string");
1.16 parser 306:
1.54 paf 307: GdomeException exc;
308: GdomeNode *node=(GdomeNode *)gdome_doc_createEntityReference(
1.111 paf 309: vdoc.get_document(),
310: r.transcode(name).use(),
1.54 paf 311: &exc);
1.111 paf 312: writeNode(r, node, exc);
1.16 parser 313: }
314:
1.99 paf 315: // NodeList getElementsByTagName(in DOMString name);
1.111 paf 316: static void _getElementsByTagName(Request& r, MethodParams& params) {
317: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.99 paf 318:
1.111 paf 319: const String& name=params.as_string(0, "name must be string");
1.99 paf 320:
1.111 paf 321: VHash& result=*new VHash;
1.99 paf 322: GdomeException exc;
323: if(GdomeNodeList *nodes=
324: gdome_doc_getElementsByTagName(
1.111 paf 325: vdoc.get_document(),
326: r.transcode(name).use(),
1.99 paf 327: &exc)) {
328: gulong length=gdome_nl_length(nodes, &exc);
1.111 paf 329: for(gulong i=0; i<length; i++)
330: result.hash().put(
1.114 paf 331: String::Body::Format(i),
1.111 paf 332: new VXnode(&r.charsets, gdome_nl_item(nodes, i, &exc)));
1.99 paf 333: } else if(exc)
1.116 paf 334: throw XmlException(0, exc);
1.99 paf 335:
336: // write out result
337: r.write_no_lang(result);
338: }
339:
1.111 paf 340: static void _getElementsByTagNameNS(Request& r, MethodParams& params) {
341: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.99 paf 342:
343: // namespaceURI;localName
1.111 paf 344: const String& namespaceURI=params.as_string(0, "namespaceURI must be string");
345: const String& localName=params.as_string(1, "localName must be string");
1.99 paf 346:
347: GdomeException exc;
1.111 paf 348: VHash& result=*new VHash;
1.99 paf 349: if(GdomeNodeList *nodes=
350: gdome_doc_getElementsByTagNameNS(
1.111 paf 351: vdoc.get_document(),
352: r.transcode(namespaceURI).use(),
353: r.transcode(localName).use(),
1.99 paf 354: &exc)) {
355: gulong length=gdome_nl_length(nodes, &exc);
1.111 paf 356: for(gulong i=0; i<length; i++)
357: result.hash().put(
1.114 paf 358: String::Body::Format(i),
1.111 paf 359: new VXnode(&r.charsets, gdome_nl_item(nodes, i, &exc)));
1.99 paf 360: }
361:
362: // write out result
363: r.write_no_lang(result);
364: }
365:
1.111 paf 366: static void _getElementById(Request& r, MethodParams& params) {
367: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.16 parser 368:
1.54 paf 369: // elementId
1.111 paf 370: const String& elementId=params.as_string(0, "elementID must be string");
1.1 parser 371:
1.54 paf 372: GdomeException exc;
373: if(GdomeNode *node=(GdomeNode *)gdome_doc_getElementById(
1.111 paf 374: vdoc.get_document(),
375: r.transcode(elementId).use(),
1.54 paf 376: &exc)) {
377: // write out result
1.111 paf 378: r.write_no_lang(*new VXnode(&r.charsets, node));
1.66 paf 379: } else if(exc || xmlHaveGenericErrors())
1.116 paf 380: throw XmlException(&elementId, exc);
1.54 paf 381: }
1.79 paf 382:
1.111 paf 383: static void _importNode(Request& r, MethodParams& params) {
384: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.79 paf 385:
386: GdomeNode *importedNode=
1.111 paf 387: as_node(params, 0, "importedNode must be node");
1.79 paf 388: bool deep=
1.111 paf 389: params.as_bool(1, "deep must be bool", r);
1.79 paf 390:
391: GdomeException exc;
1.111 paf 392: GdomeNode *outputNode=gdome_doc_importNode(vdoc.get_document(),
1.79 paf 393: importedNode,
394: deep, &exc);
395: if(exc)
1.116 paf 396: throw XmlException(0, exc);
1.79 paf 397:
398: // write out result
1.111 paf 399: r.write_no_lang(*new VXnode(&r.charsets, outputNode));
1.79 paf 400: }
1.54 paf 401: /*
402: GdomeElement *gdome_doc_createElementNS (GdomeDocument *self, GdomeDOMString *namespaceURI, GdomeDOMString *qualifiedName, GdomeException *exc);
403: GdomeAttr *gdome_doc_createAttributeNS (GdomeDocument *self, GdomeDOMString *namespaceURI, GdomeDOMString *qualifiedName, GdomeException *exc);
404: */
1.1 parser 405:
1.111 paf 406: static void _create(Request& r, MethodParams& params) {
407: Charset& source_charset=r.charsets.source();
408: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.1 parser 409:
1.111 paf 410: Value& param=params[params.count()-1];
1.83 paf 411: GdomeDocument *document;
1.111 paf 412: bool set_encoding=false;
1.95 paf 413: if(param.get_junction()) { // {<?xml?>...}
1.111 paf 414: Temp_lang temp_lang(r, String::L_XML);
1.91 paf 415: const String& xml=r.process_to_string(param);
1.83 paf 416:
1.127 paf 417: const char* cstr=xml.cstr(String::L_UNSPECIFIED, 0, &r.charsets);
1.83 paf 418: document=(GdomeDocument *)
419: gdome_xml_n_mkref((xmlNode *)xmlParseMemory(
420: cstr, strlen(cstr)
421: ));
1.111 paf 422: //printf("document=0x%p\n", document);
1.83 paf 423: if(!document || xmlHaveGenericErrors()) {
424: GdomeException exc=0;
1.116 paf 425: throw XmlException(0, exc);
1.83 paf 426: }
1.111 paf 427:
428: // must be last action in if, see after if}
1.83 paf 429: } else { // [name]
430: const String& qualifiedName=param.as_string();
1.1 parser 431:
1.83 paf 432: GdomeException exc;
1.120 paf 433: #if 0
1.83 paf 434: GdomeDocumentType *documentType=gdome_di_createDocumentType (
435: docimpl,
1.111 paf 436: r.transcode(qualifiedName),
1.120 paf 437: 0/*publicId*/,
438: 0/*systemId*/,
1.83 paf 439: &exc);
440: if(!documentType || exc || xmlHaveGenericErrors())
1.87 paf 441: throw Exception(
1.111 paf 442: method_name,
1.83 paf 443: exc);
1.111 paf 444: /// +xalan createXMLDecl ?
1.120 paf 445: #endif
446: document=gdome_di_createDocument(domimpl,
1.83 paf 447: 0/*namespaceURI*/,
1.111 paf 448: r.transcode(qualifiedName).use(),
1.83 paf 449: 0/*doctype*/,
450: &exc);
451: if(!document || exc || xmlHaveGenericErrors())
1.116 paf 452: throw XmlException(0, exc);
1.103 paf 453:
1.111 paf 454: set_encoding=true;
455: // must be last action in if, see after if}
456: }
457: // must be first action after if}
458: // replace any previous parsed source
459: {
460: vdoc.set_document(&r.charsets, document);
461: GdomeException exc;
462: gdome_doc_unref(document, &exc);
1.73 paf 463: }
1.95 paf 464:
465: // URI
1.111 paf 466: const char* URI_cstr;
467: const char* URI_cstr_ptr;
468: if(params.count()>1) { // absolute(param)
469: const String& URI=params.as_string(0, "URI must be string");
470: URI_cstr=URI_cstr_ptr=r.absolute(URI).cstr();
1.95 paf 471: } else // default = disk path to requested document
1.111 paf 472: URI_cstr=r.request_info.path_translated;
1.95 paf 473: xmlDoc *doc=gdome_xml_doc_get_xmlDoc(document);
474: if(URI_cstr)
1.111 paf 475: doc->URL=source_charset.transcode_buf2xchar(URI_cstr, strlen(URI_cstr));
1.95 paf 476:
1.111 paf 477: if(set_encoding) {
478: const char* source_charset_name=source_charset.NAME().cstr();
479: doc->encoding=source_charset.transcode_buf2xchar(source_charset_name, strlen(source_charset_name));
480: }
1.9 parser 481: }
482:
1.111 paf 483: static void _load(Request& r, MethodParams& params) {
484: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.9 parser 485:
1.54 paf 486: // filespec
1.122 paf 487: const String* uri=¶ms.as_string(0, "uri must be string");
488: const char* uri_cstr;
489: if(uri->pos("://")==STRING_NOT_FOUND) // disk path
490: uri_cstr=r.absolute(*uri).cstr(String::L_FILE_SPEC);
491: else // xxx://
492: uri_cstr=uri->cstr(String::L_AS_IS); // leave as-is for xmlParseFile to handle
1.105 paf 493:
1.122 paf 494: /// todo!! add SAFE MODE!!
1.73 paf 495: GdomeDocument *document=(GdomeDocument *)
1.123 paf 496: gdome_xml_n_mkref((xmlNode *)xmlParseFile(uri_cstr));
1.73 paf 497: if(!document || xmlHaveGenericErrors()) {
498: GdomeException exc=0;
1.122 paf 499: throw XmlException(uri, exc);
1.111 paf 500: }
501: // must be first action after if}
502: // replace any previous parsed source
503: {
504: vdoc.set_document(&r.charsets, document);
505: GdomeException exc;
506: gdome_doc_unref(document, &exc);
1.73 paf 507: }
1.122 paf 508: /* xmlParseFile does that itself. old peace for xmlParseMemory
509: const char* URI_cstr=uri->cstr();
1.107 paf 510: xmlDoc *doc=gdome_xml_doc_get_xmlDoc(document);
511: if(URI_cstr)
1.111 paf 512: doc->URL=r.charsets.source().transcode_buf2xchar(URI_cstr, strlen(URI_cstr));
1.122 paf 513: */
1.9 parser 514: }
515:
1.111 paf 516: static void param_option_over_output_option(
517: HashStringValue& param_options, const char* option_name,
518: const String*& output_option) {
1.114 paf 519: if(Value* value=param_options.get(String::Body(option_name)))
1.61 paf 520: output_option=&value->as_string();
1.46 paf 521: }
1.111 paf 522: static void param_option_over_output_option(
523: HashStringValue& param_options, const char* option_name,
524: bool& output_option) {
1.114 paf 525: if(Value* value=param_options.get(String::Body(option_name))) {
1.46 paf 526: const String& s=value->as_string();
527: if(s=="yes")
528: output_option=true;
529: else if(s=="no")
530: output_option=false;
531: else
1.87 paf 532: throw Exception("parser.runtime",
1.46 paf 533: &s,
534: "%s must be either 'yes' or 'no'", option_name);
535: }
536: }
537:
1.100 paf 538: /// @test valid_options check
1.111 paf 539: static void prepare_output_options(Request& r,
540: MethodParams& params, size_t index,
541: VXdoc::Output_options& oo) {
1.46 paf 542: /*
543: <xsl:output
544: !method = "xml" | "html" | "text" | qname-but-not-ncname
545: !version = nmtoken
546: !encoding = string
547: !omit-xml-declaration = "yes" | "no"
548: !standalone = "yes" | "no"
549: !doctype-public = string
550: !doctype-system = string
551: cdata-section-elements = qnames
552: !indent = "yes" | "no"
553: !media-type = string />
1.61 paf 554: */
1.1 parser 555:
1.46 paf 556: // configuring with options from parameter...
1.111 paf 557: if(params.count()>index) {
558: Value& voptions=params.as_no_junction(index, "options must be string");
1.1 parser 559: if(voptions.is_defined()) {
1.111 paf 560: if(HashStringValue *options=voptions.get_hash()) {
1.1 parser 561: // $.method[xml|html|text]
1.114 paf 562: if(Value* vmethod=options->get(String::Body(XDOC_OUTPUT_METHOD_OPTION_NAME)))
1.61 paf 563: oo.method=&vmethod->as_string();
1.1 parser 564:
1.46 paf 565: // $.version[1.0]
1.111 paf 566: param_option_over_output_option(*options, "version", oo.version);
1.1 parser 567: // $.encoding[windows-1251|...]
1.111 paf 568: param_option_over_output_option(*options, "encoding", oo.encoding);
1.46 paf 569: // $.omit-xml-declaration[yes|no]
1.111 paf 570: param_option_over_output_option(*options, "omit-xml-declaration", oo.omitXmlDeclaration);
1.46 paf 571: // $.standalone[yes|no]
1.111 paf 572: param_option_over_output_option(*options, "standalone", oo.standalone);
1.46 paf 573: // $.indent[yes|no]
1.111 paf 574: param_option_over_output_option(*options, "indent", oo.indent);
1.46 paf 575: // $.media-type[text/{html|xml|plain}]
1.111 paf 576: param_option_over_output_option(*options, "media-type", oo.mediaType);
1.19 parser 577: }
1.1 parser 578: }
579: }
580:
1.46 paf 581: // default encoding from pool
1.61 paf 582: if(!oo.encoding)
1.111 paf 583: oo.encoding=new String(r.charsets.source().NAME(), String::L_TAINTED);
1.46 paf 584: // default method=xml
585: if(!oo.method)
1.111 paf 586: oo.method=new String(XDOC_OUTPUT_METHOD_OPTION_VALUE_XML);
1.61 paf 587: // default mediaType = depending on method
588: if(!oo.mediaType) {
589: if(*oo.method==XDOC_OUTPUT_METHOD_OPTION_VALUE_XML)
1.111 paf 590: oo.mediaType=new String("text/xml");
1.61 paf 591: else if(*oo.method==XDOC_OUTPUT_METHOD_OPTION_VALUE_HTML)
1.111 paf 592: oo.mediaType=new String("text/html");
1.61 paf 593: else // XDOC_OUTPUT_METHOD_OPTION_VALUE_TEXT & all others
1.111 paf 594: oo.mediaType=new String("text/plain");
1.61 paf 595: }
596: }
1.46 paf 597:
1.138 paf 598: /// patching piecees from libxslt and libxml not to set meta encoding
599: static int
600: pa_xsltSaveResultTo(xmlOutputBufferPtr buf, xmlDocPtr result,
1.140 ! paf 601: xsltStylesheetPtr style,
! 602: const xmlChar *header_encoding) {
1.133 paf 603: const xmlChar *encoding;
604: int base;
605: const xmlChar *method;
606: int indent;
607:
1.138 paf 608: if ((buf == NULL) || (result == NULL) || (style == NULL))
609: return(-1);
1.133 paf 610: if ((result->children == NULL) ||
611: ((result->children->type == XML_DTD_NODE) &&
612: (result->children->next == NULL)))
1.138 paf 613: return(0);
1.133 paf 614:
615: if ((style->methodURI != NULL) &&
616: ((style->method == NULL) ||
617: (!xmlStrEqual(style->method, (const xmlChar *) "xhtml")))) {
618: xsltGenericError(xsltGenericErrorContext,
619: "xsltSaveResultTo : unknown ouput method\n");
1.138 paf 620: return(-1);
1.133 paf 621: }
622:
1.138 paf 623: base = buf->written;
624:
1.133 paf 625: XSLT_GET_IMPORT_PTR(method, style, method)
626: XSLT_GET_IMPORT_PTR(encoding, style, encoding)
1.140 ! paf 627: if(header_encoding)
! 628: encoding=header_encoding;
1.133 paf 629: XSLT_GET_IMPORT_INT(indent, style, indent);
630:
631: if ((method == NULL) && (result->type == XML_HTML_DOCUMENT_NODE))
1.139 paf 632: method = BAD_CAST "html";
633:
634: int omitXmlDecl;
635: XSLT_GET_IMPORT_INT(omitXmlDecl, style, omitXmlDeclaration);
1.133 paf 636:
637: if ((method != NULL) &&
1.138 paf 638: (xmlStrEqual(method, (const xmlChar *) "html"))) {
1.133 paf 639: if (indent == -1)
640: indent = 1;
1.138 paf 641:
642: int is_xhtml = 0;
643: xmlDtdPtr dtd = xmlGetIntSubset(result);
644: if (dtd != NULL) {
645: is_xhtml = xmlIsXHTML(dtd->SystemID, dtd->ExternalID);
646: if (is_xhtml < 0)
647: is_xhtml = 0;
648: }
649: if(is_xhtml) {
650: method = BAD_CAST "xml";
1.139 paf 651: omitXmlDecl = 0;
1.138 paf 652: } else {
653: htmlDocContentDumpFormatOutput(buf, result, (const char *) encoding,
1.133 paf 654: indent);
1.138 paf 655: xmlOutputBufferFlush(buf);
656: goto finish;
657: }
658: }
1.139 paf 659:
1.138 paf 660: if ((method != NULL) &&
1.133 paf 661: (xmlStrEqual(method, (const xmlChar *) "text"))) {
662: xmlNodePtr cur;
663:
664: cur = result->children;
665: while (cur != NULL) {
666: if (cur->type == XML_TEXT_NODE)
667: xmlOutputBufferWriteString(buf, (const char *) cur->content);
668:
669: /*
670: * Skip to next node
671: */
672: if (cur->children != NULL) {
673: if ((cur->children->type != XML_ENTITY_DECL) &&
674: (cur->children->type != XML_ENTITY_REF_NODE) &&
675: (cur->children->type != XML_ENTITY_NODE)) {
676: cur = cur->children;
677: continue;
678: }
679: }
680: if (cur->next != NULL) {
681: cur = cur->next;
682: continue;
683: }
684:
685: do {
686: cur = cur->parent;
687: if (cur == NULL)
688: break;
689: if (cur == (xmlNodePtr) style->doc) {
690: cur = NULL;
691: break;
692: }
693: if (cur->next != NULL) {
694: cur = cur->next;
695: break;
696: }
697: } while (cur != NULL);
698: }
1.138 paf 699: xmlOutputBufferFlush(buf);
1.133 paf 700: } else {
701: int standalone;
702:
703: XSLT_GET_IMPORT_INT(standalone, style, standalone);
704:
705: if (omitXmlDecl != 1) {
706: xmlOutputBufferWriteString(buf, "<?xml version=");
707: if (result->version != NULL)
1.140 ! paf 708: xmlBufferWriteQuotedString(buf->buffer, result->version);
! 709: else
! 710: xmlOutputBufferWriteString(buf, "\"1.0\"");
1.133 paf 711: if (encoding == NULL) {
712: if (result->encoding != NULL)
713: encoding = result->encoding;
714: else if (result->charset != XML_CHAR_ENCODING_UTF8)
1.140 ! paf 715: encoding = BAD_CAST xmlGetCharEncodingName((xmlCharEncoding)result->charset);
1.133 paf 716: }
717: if (encoding != NULL) {
718: xmlOutputBufferWriteString(buf, " encoding=");
719: xmlBufferWriteQuotedString(buf->buffer, (xmlChar *) encoding);
720: }
721: switch (standalone) {
722: case 0:
723: xmlOutputBufferWriteString(buf, " standalone=\"no\"");
724: break;
725: case 1:
726: xmlOutputBufferWriteString(buf, " standalone=\"yes\"");
727: break;
728: default:
729: break;
730: }
731: xmlOutputBufferWriteString(buf, "?>\n");
732: }
733: if (result->children != NULL) {
734: xmlNodePtr child = result->children;
735:
736: while (child != NULL) {
737: xmlNodeDumpOutput(buf, result, child, 0, (indent == 1),
738: (const char *) encoding);
739: if (child->type == XML_DTD_NODE)
740: xmlOutputBufferWriteString(buf, "\n");
741: child = child->next;
742: }
743: xmlOutputBufferWriteString(buf, "\n");
744: }
1.138 paf 745: xmlOutputBufferFlush(buf);
1.133 paf 746: }
1.138 paf 747: finish:
748: return(buf->written - base);
749: }
1.134 paf 750:
1.133 paf 751:
1.111 paf 752: struct Xdoc2buf_result {
753: char* str;
754: size_t length;
755: };
756: static Xdoc2buf_result xdoc2buf(Request& r, VXdoc& vdoc,
757: MethodParams& params, int index,
1.63 paf 758: VXdoc::Output_options& oo,
1.140 ! paf 759: const String* file_spec,
! 760: bool use_source_charset_to_render_and_client_charset_to_write_to_header=false) {
1.111 paf 761: Xdoc2buf_result result;
762: prepare_output_options(r, params, index,
1.61 paf 763: oo);
764:
1.140 ! paf 765: const char* render_encoding;
! 766: const char* header_encoding;
! 767: if(use_source_charset_to_render_and_client_charset_to_write_to_header) {
! 768: render_encoding=r.charsets.source().NAME_CSTR();
! 769: header_encoding=r.charsets.client().NAME_CSTR();
! 770: } else {
! 771: header_encoding=render_encoding=oo.encoding->cstr();
! 772: }
! 773:
! 774: xmlCharEncodingHandler *renderer=xmlFindCharEncodingHandler(render_encoding);
! 775: if(!renderer)
1.87 paf 776: throw Exception("parser.runtime",
1.111 paf 777: 0,
1.140 ! paf 778: "encoding '%s' not supported", render_encoding);
! 779: // UTF-8 renderer contains empty input/output converters,
1.61 paf 780: // which is wrong for xmlOutputBufferCreateIO
1.140 ! paf 781: // while zero renderer goes perfectly
! 782: if(strcmp(render_encoding, "UTF-8")==0)
! 783: renderer=0;
1.61 paf 784:
1.140 ! paf 785: xmlOutputBuffer_auto_ptr outputBuffer(xmlAllocOutputBuffer(renderer));
1.138 paf 786:
1.65 paf 787: xsltStylesheet_auto_ptr stylesheet(xsltNewStylesheet());
788: if(!stylesheet.get())
1.87 paf 789: throw Exception(0,
1.111 paf 790: 0,
1.61 paf 791: "xsltNewStylesheet failed");
792:
1.62 paf 793: #define OOS2STYLE(name) \
1.111 paf 794: stylesheet->name=oo.name?BAD_CAST xmlMemStrdup(r.transcode(*oo.name)->str):0
1.62 paf 795: #define OOE2STYLE(name) \
796: stylesheet->name=oo.name
1.61 paf 797:
1.62 paf 798: OOS2STYLE(method);
799: OOS2STYLE(encoding);
800: OOS2STYLE(mediaType);
1.124 paf 801: // OOS2STYLE(doctypeSystem);
1.130 paf 802: // OOS2STYLE(doctypePublic);
1.62 paf 803: OOE2STYLE(indent);
804: OOS2STYLE(version);
805: OOE2STYLE(standalone);
806: OOE2STYLE(omitXmlDeclaration);
1.61 paf 807:
1.111 paf 808: xmlDoc *document=gdome_xml_doc_get_xmlDoc(vdoc.get_document());
1.140 ! paf 809: //document->encoding=BAD_CAST xmlMemStrdup(encoder_name);
! 810: if(pa_xsltSaveResultTo(outputBuffer.get(), document, stylesheet.get(), BAD_CAST header_encoding)<0
! 811: || xmlHaveGenericErrors()) {
1.75 paf 812: GdomeException exc=0;
1.116 paf 813: throw XmlException(0, exc);
1.75 paf 814: }
1.61 paf 815:
1.138 paf 816: // write out result
817: char *gnome_str; size_t gnome_length;
818: if(outputBuffer->conv) {
819: gnome_length=outputBuffer->conv->use;
820: gnome_str=(char *)outputBuffer->conv->content;
821: } else {
822: gnome_length=outputBuffer->buffer->use;
823: gnome_str=(char *)outputBuffer->buffer->content;
824: }
825:
826: if((result.length=gnome_length)) {
827: result.str=pa_strdup(gnome_str, gnome_length);
828: } else
829: result.str=0;
1.118 paf 830:
1.63 paf 831: if(file_spec)
1.111 paf 832: file_write(*file_spec,
1.138 paf 833: gnome_str, gnome_length,
1.111 paf 834: true/*as_text*/);
835:
836: return result;
1.1 parser 837: }
838:
1.111 paf 839: static void _file(Request& r, MethodParams& params) {
840: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.63 paf 841: VXdoc::Output_options oo(vdoc.output_options);
1.111 paf 842: Xdoc2buf_result buf=xdoc2buf(r, vdoc, params, 0,
1.63 paf 843: oo,
1.111 paf 844: 0/*not to file, to memory*/);
1.63 paf 845: // write out result
1.111 paf 846: r.write_no_lang(String(buf.str, buf.length));
1.1 parser 847:
1.58 paf 848: // write out result
1.111 paf 849: VFile& vfile=*new VFile;
850: VHash& vhcontent_type=*new VHash;
851: vhcontent_type.hash().put(
852: value_name,
853: new VString(*oo.mediaType));
854: vhcontent_type.hash().put(
1.126 paf 855: String::Body("charset"),
1.111 paf 856: new VString(*oo.encoding));
857:
858: vfile.set(false/*tainted*/, buf.str?buf.str:""/*to distinguish from stat-ed file*/, buf.length,
859: 0/*file_name*/, &vhcontent_type);
1.58 paf 860: r.write_no_lang(vfile);
1.63 paf 861: }
862:
1.111 paf 863: static void _save(Request& r, MethodParams& params) {
864: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.63 paf 865:
1.111 paf 866: const String& file_spec=r.absolute(params.as_string(0, "file name must be string"));
1.63 paf 867:
868: VXdoc::Output_options oo(vdoc.output_options);
1.111 paf 869: xdoc2buf(r, vdoc, params, 1,
1.63 paf 870: oo,
1.111 paf 871: &file_spec);
1.63 paf 872: }
873:
1.111 paf 874: static void _string(Request& r, MethodParams& params) {
875: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.63 paf 876: VXdoc::Output_options oo(vdoc.output_options);
1.111 paf 877: Xdoc2buf_result buf=xdoc2buf(r, vdoc, params, 0,
1.63 paf 878: oo,
1.140 ! paf 879: 0/*not to file, to memory*/,
! 880: true/*use source charset to render, client charset to put to header*/);
1.63 paf 881: // write out result
1.111 paf 882: r.write_no_lang(String(buf.str, buf.length));
1.1 parser 883: }
1.58 paf 884:
1.111 paf 885: #ifndef DOXYGEN
886: struct Add_xslt_param_info {
887: Request* r;
888: Array<GdomeDOMString_auto_ptr>* strings;
889: const char** current_transform_param;
890: };
891: #endif
892: static void add_xslt_param(
893: HashStringValue::key_type attribute,
894: HashStringValue::value_type meaning,
895: Add_xslt_param_info* info) {
896: GdomeDOMString_auto_ptr s;
897: *info->current_transform_param++=(s=info->r->transcode(attribute))->str; *info->strings+=s;
898: *info->current_transform_param++=(s=info->r->transcode(meaning->as_string()))->str; *info->strings+=s;
899: }
1.132 paf 900:
1.111 paf 901: static VXdoc& _transform(Request& r, const String* stylesheet_source,
1.132 paf 902: VXdoc& vdoc, xsltStylesheetPtr stylesheet, const char** transform_params)
903: {
1.111 paf 904: xmlDoc *document=gdome_xml_doc_get_xmlDoc(vdoc.get_document());
1.65 paf 905: xsltTransformContext_auto_ptr transformContext(
906: xsltNewTransformContext(stylesheet, document));
1.90 paf 907: // make params literal
1.111 paf 908: if (transformContext->globalVars == NULL) // strangly not initialized by xsltNewTransformContext
1.90 paf 909: transformContext->globalVars = xmlHashCreate(20);
910: xsltQuoteUserParams(transformContext.get(), transform_params);
911: // do transform
1.59 paf 912: xmlDoc *transformed=xsltApplyStylesheetUser(
913: stylesheet,
914: document,
1.90 paf 915: 0/*already quoted-inserted transform_params*/,
1.111 paf 916: 0/*const char* output*/,
1.59 paf 917: 0/*FILE *profile*/,
1.65 paf 918: transformContext.get());
1.66 paf 919: if(!transformed || xmlHaveGenericErrors()) {
920: GdomeException exc=0;
1.116 paf 921: throw XmlException(stylesheet_source, exc);
1.66 paf 922: }
1.42 paf 923:
1.61 paf 924: //gdome_xml_doc_mkref dislikes XML_HTML_DOCUMENT_NODE type, fixing
925: transformed->type=XML_DOCUMENT_NODE;
1.59 paf 926: // constructing result
927: GdomeDocument *gdomeDocument=gdome_xml_doc_mkref(transformed);
928: if(!gdomeDocument)
1.87 paf 929: throw Exception(0,
1.111 paf 930: 0,
1.59 paf 931: "gdome_xml_doc_mkref failed");
1.111 paf 932: VXdoc& result=*new VXdoc(&r.charsets, gdomeDocument);
1.61 paf 933: /* grabbing options
934:
935: <xsl:output
936: !method = "xml" | "html" | "text"
937: X| qname-but-not-ncname
938: !version = nmtoken
939: !encoding = string
940: !omit-xml-declaration = "yes" | "no"
941: !standalone = "yes" | "no"
942: !doctype-public = string
943: !doctype-system = string
944: Xcdata-section-elements = qnames
945: !indent = "yes" | "no"
946: !media-type = string />
1.59 paf 947: */
948: VXdoc::Output_options& oo=result.output_options;
949:
1.111 paf 950: oo.method=stylesheet->method?&r.transcode(stylesheet->method):0;
951: oo.encoding=stylesheet->encoding?&r.transcode(stylesheet->encoding):0;
952: oo.mediaType=stylesheet->mediaType?&r.transcode(stylesheet->mediaType):0;
1.59 paf 953: oo.indent=stylesheet->indent!=0;
1.111 paf 954: oo.version=stylesheet->version?&r.transcode(stylesheet->version):0;
1.59 paf 955: oo.standalone=stylesheet->standalone!=0;
956: oo.omitXmlDeclaration=stylesheet->omitXmlDeclaration!=0;
957:
1.93 paf 958: // return
959: return result;
960: }
1.111 paf 961: static void _transform(Request& r, MethodParams& params) {
962: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.93 paf 963:
964: // params
1.111 paf 965: Array<GdomeDOMString_auto_ptr> transform_strings;
966: const char** transform_params=0;
967: if(params.count()>1) {
968: Value& vparams=params.as_no_junction(1, "transform parameters must be hash");
1.106 paf 969: if(!vparams.is_string())
1.111 paf 970: if(HashStringValue* hash=vparams.get_hash()) {
971: transform_params=new(UseGC) const char*[hash->count()*2+1];
972: Add_xslt_param_info info={
973: &r,
974: &transform_strings,
975: transform_params
976: };
977: hash->for_each(add_xslt_param, &info);
978: transform_params[hash->count()*2]=0;
1.93 paf 979: } else
980: throw Exception("parser.runtime",
1.111 paf 981: 0,
1.93 paf 982: "transform parameters parameter must be hash");
983: }
984:
1.111 paf 985: VXdoc* result;
986: if(Value *vxdoc=params[0].as(VXDOC_TYPE, false)) { // stylesheet (xdoc)
1.93 paf 987: xmlDoc *document=gdome_xml_doc_get_xmlDoc(
1.111 paf 988: static_cast<VXdoc *>(vxdoc)->get_document());
1.93 paf 989: // compile xdoc stylesheet
1.94 paf 990: xsltStylesheet_auto_ptr stylesheet_ptr(xsltParseStylesheetDoc(document));
1.93 paf 991: if(xmlHaveGenericErrors()) {
992: GdomeException exc=0;
1.116 paf 993: throw XmlException(0, exc);
1.93 paf 994: }
995: if(!stylesheet_ptr.get())
996: throw Exception("xml",
1.111 paf 997: 0,
1.93 paf 998: "stylesheet failed to compile");
1.128 paf 999: // strange thing - xsltParseStylesheetDoc records document and destroys it in stylesheet destructor
1000: // we don't need that
1001: stylesheet_ptr->doc=0;
1.93 paf 1002:
1003: // transform!
1.111 paf 1004: result=&_transform(r, 0,
1.93 paf 1005: vdoc, stylesheet_ptr.get(),
1006: transform_params);
1007: } else { // stylesheet (file name)
1008: // extablish stylesheet connection
1009: const String& stylesheet_filespec=
1.111 paf 1010: r.absolute(params.as_string(0, "stylesheet must be file name (string) or DOM document (xdoc)"));
1.125 paf 1011: Stylesheet_connection_ptr connection=stylesheet_manager->get_connection(stylesheet_filespec);
1.93 paf 1012:
1013: // load and compile file to stylesheet [or get cached if any]
1014: // transform!
1.122 paf 1015: result=&_transform(r, &stylesheet_filespec, vdoc, connection->stylesheet(),
1.93 paf 1016: transform_params);
1017: }
1018:
1.59 paf 1019: // write out result
1.93 paf 1020: r.write_no_lang(*result);
1.1 parser 1021: }
1022:
1.16 parser 1023: // constructor
1.2 parser 1024:
1.92 paf 1025: /// @test how to create empty type html?
1.111 paf 1026: MXdoc::MXdoc(): MXnode(XDOC_CLASS_NAME, xnode_class) {
1.16 parser 1027: /// DOM1
1.2 parser 1028:
1.16 parser 1029: // Element createElement(in DOMString tagName) raises(DOMException);
1030: add_native_method("createElement", Method::CT_DYNAMIC, _createElement, 1, 1);
1031: // DocumentFragment createDocumentFragment();
1032: add_native_method("createDocumentFragment", Method::CT_DYNAMIC, _createDocumentFragment, 0, 0);
1033: // Text createTextNode(in DOMString data);
1034: add_native_method("createTextNode", Method::CT_DYNAMIC, _createTextNode, 1, 1);
1035: // Comment createComment(in DOMString data);
1036: add_native_method("createComment", Method::CT_DYNAMIC, _createComment, 1, 1);
1037: // CDATASection createCDATASection(in DOMString data) raises(DOMException);
1038: add_native_method("createCDATASection", Method::CT_DYNAMIC, _createCDATASection, 1, 1);
1039: // ProcessingInstruction createProcessingInstruction(in DOMString target, in DOMString data) raises(DOMException);
1040: add_native_method("createProcessingInstruction", Method::CT_DYNAMIC, _createProcessingInstruction, 2, 2);
1041: // Attr createAttribute(in DOMString name) raises(DOMException);
1042: add_native_method("createAttribute", Method::CT_DYNAMIC, _createAttribute, 1, 1);
1043: // EntityReference createEntityReference(in DOMString name) raises(DOMException);
1044: add_native_method("createEntityReference", Method::CT_DYNAMIC, _createEntityReference, 1, 1);
1.99 paf 1045: // NodeList getElementsByTagName(in DOMString name);
1046: add_native_method("getElementsByTagName", Method::CT_DYNAMIC, _getElementsByTagName, 1, 1);
1.2 parser 1047:
1.79 paf 1048: /// DOM2
1.2 parser 1049:
1.16 parser 1050: // ^xdoc.getElementById[elementId]
1051: add_native_method("getElementById", Method::CT_DYNAMIC, _getElementById, 1, 1);
1.79 paf 1052:
1053: // Node (in Node importedNode, in boolean deep) raises(DOMException)
1054: add_native_method("importNode", Method::CT_DYNAMIC, _importNode, 2, 2);
1.112 paf 1055:
1.113 paf 1056: // Attr createAttributeNS(in DOMString namespaceURI, in DOMString qualifiedName) raises(DOMException);
1.112 paf 1057: add_native_method("createAttributeNS", Method::CT_DYNAMIC, _createAttributeNS, 2, 2);
1058:
1.113 paf 1059: // Element createElementNS(in DOMString namespaceURI, in DOMString qualifiedName) raises(DOMException);
1.112 paf 1060: add_native_method("createElementNS", Method::CT_DYNAMIC, _createElementNS, 2, 2);
1.99 paf 1061:
1062: // NodeList getElementsByTagNameNS(in DOMString namespaceURI, in DOMString localName);
1063: add_native_method("getElementsByTagNameNS", Method::CT_DYNAMIC, _getElementsByTagNameNS, 2, 2);
1.1 parser 1064:
1.16 parser 1065: /// parser
1066:
1.54 paf 1067: // ^xdoc::create{qualifiedName}
1.95 paf 1068: // ^xdoc::create[<some>xml</some>]
1069: // ^xdoc::create[URI][<some>xml</some>]
1070: add_native_method("create", Method::CT_DYNAMIC, _create, 1, 2);
1.83 paf 1071: // for backward compatibility with <=v 1.82 2002/01/31 11:51:46 paf
1072: add_native_method("set", Method::CT_DYNAMIC, _create, 1, 1);
1.54 paf 1073:
1074: // ^xdoc::load[some.xml]
1.122 paf 1075: add_native_method("load", Method::CT_DYNAMIC, _load, 1, 1);
1.54 paf 1076:
1.2 parser 1077: // ^xdoc.save[some.xml]
1078: // ^xdoc.save[some.xml;options hash]
1.1 parser 1079: add_native_method("save", Method::CT_DYNAMIC, _save, 1, 2);
1080:
1.2 parser 1081: // ^xdoc.string[] <doc/>
1082: // ^xdoc.string[options hash] <doc/>
1.1 parser 1083: add_native_method("string", Method::CT_DYNAMIC, _string, 0, 1);
1084:
1.2 parser 1085: // ^xdoc.file[] file with "<doc/>"
1086: // ^xdoc.file[options hash] file with "<doc/>"
1.58 paf 1087: add_native_method("file", Method::CT_DYNAMIC, _file, 0, 1);
1.1 parser 1088:
1.98 paf 1089: // ^xdoc.transform[stylesheet file_name/xdoc]
1090: // ^xdoc.transform[stylesheet file_name/xdoc;params hash]
1.59 paf 1091: add_native_method("transform", Method::CT_DYNAMIC, _transform, 1, 2);
1.2 parser 1092:
1.5 parser 1093: }
1094:
1.111 paf 1095: # else
1096:
1097: #include "classes.h"
1098:
1.1 parser 1099: // global variable
1100:
1.111 paf 1101: DECLARE_CLASS_VAR(xdoc, 0, 0); // fictive
1.1 parser 1102:
1103: #endif
E-mail: