Annotation of parser3/src/classes/xdoc.C, revision 1.138
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.138 ! paf 12: static const char * const IDENT_XDOC_C="$Date: 2004/02/17 15:08:51 $";
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,
! 601: xsltStylesheetPtr style) {
1.133 paf 602: const xmlChar *encoding;
603: int base;
604: const xmlChar *method;
605: int indent;
606:
1.138 ! paf 607: if ((buf == NULL) || (result == NULL) || (style == NULL))
! 608: return(-1);
1.133 paf 609: if ((result->children == NULL) ||
610: ((result->children->type == XML_DTD_NODE) &&
611: (result->children->next == NULL)))
1.138 ! paf 612: return(0);
1.133 paf 613:
614: if ((style->methodURI != NULL) &&
615: ((style->method == NULL) ||
616: (!xmlStrEqual(style->method, (const xmlChar *) "xhtml")))) {
617: xsltGenericError(xsltGenericErrorContext,
618: "xsltSaveResultTo : unknown ouput method\n");
1.138 ! paf 619: return(-1);
1.133 paf 620: }
621:
1.138 ! paf 622: base = buf->written;
! 623:
1.133 paf 624: XSLT_GET_IMPORT_PTR(method, style, method)
625: XSLT_GET_IMPORT_PTR(encoding, style, encoding)
626: XSLT_GET_IMPORT_INT(indent, style, indent);
627:
628: if ((method == NULL) && (result->type == XML_HTML_DOCUMENT_NODE))
1.138 ! paf 629: method = BAD_CAST "html";
1.133 paf 630:
631: if ((method != NULL) &&
1.138 ! paf 632: (xmlStrEqual(method, (const xmlChar *) "html"))) {
1.133 paf 633: if (indent == -1)
634: indent = 1;
1.138 ! paf 635:
! 636: int is_xhtml = 0;
! 637: xmlDtdPtr dtd = xmlGetIntSubset(result);
! 638: if (dtd != NULL) {
! 639: is_xhtml = xmlIsXHTML(dtd->SystemID, dtd->ExternalID);
! 640: if (is_xhtml < 0)
! 641: is_xhtml = 0;
! 642: }
! 643: xmlNodePtr cur=result->last;
! 644: if(!cur) {
! 645: is_xhtml=0;
! 646: }
! 647:
! 648: if(is_xhtml) {
! 649: // xhtmlNodeDumpOutput is static :(
! 650: if((cur->parent == (xmlNodePtr) result) &&
! 651: (cur->type == XML_ELEMENT_NODE) &&
! 652: (xmlStrEqual(cur->name, BAD_CAST "html"))) {
! 653: //cur->name=BAD_CAST "html ";
! 654: }
! 655:
! 656: method = BAD_CAST "xml";
! 657: } else {
! 658: htmlDocContentDumpFormatOutput(buf, result, (const char *) encoding,
1.133 paf 659: indent);
1.138 ! paf 660: xmlOutputBufferFlush(buf);
! 661: goto finish;
! 662: }
! 663: }
! 664:
! 665: if ((method != NULL) &&
1.133 paf 666: (xmlStrEqual(method, (const xmlChar *) "text"))) {
667: xmlNodePtr cur;
668:
669: cur = result->children;
670: while (cur != NULL) {
671: if (cur->type == XML_TEXT_NODE)
672: xmlOutputBufferWriteString(buf, (const char *) cur->content);
673:
674: /*
675: * Skip to next node
676: */
677: if (cur->children != NULL) {
678: if ((cur->children->type != XML_ENTITY_DECL) &&
679: (cur->children->type != XML_ENTITY_REF_NODE) &&
680: (cur->children->type != XML_ENTITY_NODE)) {
681: cur = cur->children;
682: continue;
683: }
684: }
685: if (cur->next != NULL) {
686: cur = cur->next;
687: continue;
688: }
689:
690: do {
691: cur = cur->parent;
692: if (cur == NULL)
693: break;
694: if (cur == (xmlNodePtr) style->doc) {
695: cur = NULL;
696: break;
697: }
698: if (cur->next != NULL) {
699: cur = cur->next;
700: break;
701: }
702: } while (cur != NULL);
703: }
1.138 ! paf 704: xmlOutputBufferFlush(buf);
1.133 paf 705: } else {
706: int omitXmlDecl;
707: int standalone;
708:
709: XSLT_GET_IMPORT_INT(omitXmlDecl, style, omitXmlDeclaration);
710: XSLT_GET_IMPORT_INT(standalone, style, standalone);
711:
712: if (omitXmlDecl != 1) {
713: xmlOutputBufferWriteString(buf, "<?xml version=");
714: if (result->version != NULL)
715: xmlBufferWriteQuotedString(buf->buffer, result->version);
716: else
717: xmlOutputBufferWriteString(buf, "\"1.0\"");
718: if (encoding == NULL) {
719: if (result->encoding != NULL)
720: encoding = result->encoding;
721: else if (result->charset != XML_CHAR_ENCODING_UTF8)
722: encoding = (const xmlChar *)
723: xmlGetCharEncodingName((xmlCharEncoding)
724: result->charset);
725: }
726: if (encoding != NULL) {
727: xmlOutputBufferWriteString(buf, " encoding=");
728: xmlBufferWriteQuotedString(buf->buffer, (xmlChar *) encoding);
729: }
730: switch (standalone) {
731: case 0:
732: xmlOutputBufferWriteString(buf, " standalone=\"no\"");
733: break;
734: case 1:
735: xmlOutputBufferWriteString(buf, " standalone=\"yes\"");
736: break;
737: default:
738: break;
739: }
740: xmlOutputBufferWriteString(buf, "?>\n");
741: }
742: if (result->children != NULL) {
743: xmlNodePtr child = result->children;
744:
745: while (child != NULL) {
746: xmlNodeDumpOutput(buf, result, child, 0, (indent == 1),
747: (const char *) encoding);
748: if (child->type == XML_DTD_NODE)
749: xmlOutputBufferWriteString(buf, "\n");
750: child = child->next;
751: }
752: xmlOutputBufferWriteString(buf, "\n");
753: }
1.138 ! paf 754: xmlOutputBufferFlush(buf);
1.133 paf 755: }
1.138 ! paf 756: finish:
! 757: return(buf->written - base);
! 758: }
1.134 paf 759:
1.133 paf 760:
1.111 paf 761: struct Xdoc2buf_result {
762: char* str;
763: size_t length;
764: };
765: static Xdoc2buf_result xdoc2buf(Request& r, VXdoc& vdoc,
766: MethodParams& params, int index,
1.63 paf 767: VXdoc::Output_options& oo,
1.111 paf 768: const String* file_spec) {
769: Xdoc2buf_result result;
770: prepare_output_options(r, params, index,
1.61 paf 771: oo);
772:
1.111 paf 773: const char* encoding_cstr=oo.encoding->cstr();
1.63 paf 774: xmlCharEncodingHandler *encoder=xmlFindCharEncodingHandler(encoding_cstr);
775: if(!encoder)
1.87 paf 776: throw Exception("parser.runtime",
1.111 paf 777: 0,
1.63 paf 778: "encoding '%s' not supported", encoding_cstr);
1.61 paf 779: // UTF-8 encoder contains empty input/output converters,
780: // which is wrong for xmlOutputBufferCreateIO
781: // while zero encoder goes perfectly
1.130 paf 782: const char* encoder_name=encoder->name;
783: if(strcmp(encoder_name, "UTF-8")==0)
1.61 paf 784: encoder=0;
785:
1.138 ! paf 786: xmlOutputBuffer_auto_ptr outputBuffer(xmlAllocOutputBuffer(encoder));
! 787:
1.65 paf 788: xsltStylesheet_auto_ptr stylesheet(xsltNewStylesheet());
789: if(!stylesheet.get())
1.87 paf 790: throw Exception(0,
1.111 paf 791: 0,
1.61 paf 792: "xsltNewStylesheet failed");
793:
1.62 paf 794: #define OOS2STYLE(name) \
1.111 paf 795: stylesheet->name=oo.name?BAD_CAST xmlMemStrdup(r.transcode(*oo.name)->str):0
1.62 paf 796: #define OOE2STYLE(name) \
797: stylesheet->name=oo.name
1.61 paf 798:
1.62 paf 799: OOS2STYLE(method);
800: OOS2STYLE(encoding);
801: OOS2STYLE(mediaType);
1.124 paf 802: // OOS2STYLE(doctypeSystem);
1.130 paf 803: // OOS2STYLE(doctypePublic);
1.62 paf 804: OOE2STYLE(indent);
805: OOS2STYLE(version);
806: OOE2STYLE(standalone);
807: OOE2STYLE(omitXmlDeclaration);
1.61 paf 808:
1.111 paf 809: xmlDoc *document=gdome_xml_doc_get_xmlDoc(vdoc.get_document());
1.130 paf 810: document->encoding=BAD_CAST xmlMemStrdup(encoder_name);
1.138 ! paf 811: if(pa_xsltSaveResultTo(outputBuffer.get(), document, stylesheet.get())<0) {
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.111 paf 879: 0/*not to file, to memory*/);
1.63 paf 880: // write out result
1.111 paf 881: r.write_no_lang(String(buf.str, buf.length));
1.1 parser 882: }
1.58 paf 883:
1.111 paf 884: #ifndef DOXYGEN
885: struct Add_xslt_param_info {
886: Request* r;
887: Array<GdomeDOMString_auto_ptr>* strings;
888: const char** current_transform_param;
889: };
890: #endif
891: static void add_xslt_param(
892: HashStringValue::key_type attribute,
893: HashStringValue::value_type meaning,
894: Add_xslt_param_info* info) {
895: GdomeDOMString_auto_ptr s;
896: *info->current_transform_param++=(s=info->r->transcode(attribute))->str; *info->strings+=s;
897: *info->current_transform_param++=(s=info->r->transcode(meaning->as_string()))->str; *info->strings+=s;
898: }
1.132 paf 899:
1.111 paf 900: static VXdoc& _transform(Request& r, const String* stylesheet_source,
1.132 paf 901: VXdoc& vdoc, xsltStylesheetPtr stylesheet, const char** transform_params)
902: {
1.111 paf 903: xmlDoc *document=gdome_xml_doc_get_xmlDoc(vdoc.get_document());
1.65 paf 904: xsltTransformContext_auto_ptr transformContext(
905: xsltNewTransformContext(stylesheet, document));
1.90 paf 906: // make params literal
1.111 paf 907: if (transformContext->globalVars == NULL) // strangly not initialized by xsltNewTransformContext
1.90 paf 908: transformContext->globalVars = xmlHashCreate(20);
909: xsltQuoteUserParams(transformContext.get(), transform_params);
910: // do transform
1.59 paf 911: xmlDoc *transformed=xsltApplyStylesheetUser(
912: stylesheet,
913: document,
1.90 paf 914: 0/*already quoted-inserted transform_params*/,
1.111 paf 915: 0/*const char* output*/,
1.59 paf 916: 0/*FILE *profile*/,
1.65 paf 917: transformContext.get());
1.66 paf 918: if(!transformed || xmlHaveGenericErrors()) {
919: GdomeException exc=0;
1.116 paf 920: throw XmlException(stylesheet_source, exc);
1.66 paf 921: }
1.42 paf 922:
1.61 paf 923: //gdome_xml_doc_mkref dislikes XML_HTML_DOCUMENT_NODE type, fixing
924: transformed->type=XML_DOCUMENT_NODE;
1.59 paf 925: // constructing result
926: GdomeDocument *gdomeDocument=gdome_xml_doc_mkref(transformed);
927: if(!gdomeDocument)
1.87 paf 928: throw Exception(0,
1.111 paf 929: 0,
1.59 paf 930: "gdome_xml_doc_mkref failed");
1.111 paf 931: VXdoc& result=*new VXdoc(&r.charsets, gdomeDocument);
1.61 paf 932: /* grabbing options
933:
934: <xsl:output
935: !method = "xml" | "html" | "text"
936: X| qname-but-not-ncname
937: !version = nmtoken
938: !encoding = string
939: !omit-xml-declaration = "yes" | "no"
940: !standalone = "yes" | "no"
941: !doctype-public = string
942: !doctype-system = string
943: Xcdata-section-elements = qnames
944: !indent = "yes" | "no"
945: !media-type = string />
1.59 paf 946: */
947: VXdoc::Output_options& oo=result.output_options;
948:
1.111 paf 949: oo.method=stylesheet->method?&r.transcode(stylesheet->method):0;
950: oo.encoding=stylesheet->encoding?&r.transcode(stylesheet->encoding):0;
951: oo.mediaType=stylesheet->mediaType?&r.transcode(stylesheet->mediaType):0;
1.59 paf 952: oo.indent=stylesheet->indent!=0;
1.111 paf 953: oo.version=stylesheet->version?&r.transcode(stylesheet->version):0;
1.59 paf 954: oo.standalone=stylesheet->standalone!=0;
955: oo.omitXmlDeclaration=stylesheet->omitXmlDeclaration!=0;
956:
1.93 paf 957: // return
958: return result;
959: }
1.111 paf 960: static void _transform(Request& r, MethodParams& params) {
961: VXdoc& vdoc=GET_SELF(r, VXdoc);
1.93 paf 962:
963: // params
1.111 paf 964: Array<GdomeDOMString_auto_ptr> transform_strings;
965: const char** transform_params=0;
966: if(params.count()>1) {
967: Value& vparams=params.as_no_junction(1, "transform parameters must be hash");
1.106 paf 968: if(!vparams.is_string())
1.111 paf 969: if(HashStringValue* hash=vparams.get_hash()) {
970: transform_params=new(UseGC) const char*[hash->count()*2+1];
971: Add_xslt_param_info info={
972: &r,
973: &transform_strings,
974: transform_params
975: };
976: hash->for_each(add_xslt_param, &info);
977: transform_params[hash->count()*2]=0;
1.93 paf 978: } else
979: throw Exception("parser.runtime",
1.111 paf 980: 0,
1.93 paf 981: "transform parameters parameter must be hash");
982: }
983:
1.111 paf 984: VXdoc* result;
985: if(Value *vxdoc=params[0].as(VXDOC_TYPE, false)) { // stylesheet (xdoc)
1.93 paf 986: xmlDoc *document=gdome_xml_doc_get_xmlDoc(
1.111 paf 987: static_cast<VXdoc *>(vxdoc)->get_document());
1.93 paf 988: // compile xdoc stylesheet
1.94 paf 989: xsltStylesheet_auto_ptr stylesheet_ptr(xsltParseStylesheetDoc(document));
1.93 paf 990: if(xmlHaveGenericErrors()) {
991: GdomeException exc=0;
1.116 paf 992: throw XmlException(0, exc);
1.93 paf 993: }
994: if(!stylesheet_ptr.get())
995: throw Exception("xml",
1.111 paf 996: 0,
1.93 paf 997: "stylesheet failed to compile");
1.128 paf 998: // strange thing - xsltParseStylesheetDoc records document and destroys it in stylesheet destructor
999: // we don't need that
1000: stylesheet_ptr->doc=0;
1.93 paf 1001:
1002: // transform!
1.111 paf 1003: result=&_transform(r, 0,
1.93 paf 1004: vdoc, stylesheet_ptr.get(),
1005: transform_params);
1006: } else { // stylesheet (file name)
1007: // extablish stylesheet connection
1008: const String& stylesheet_filespec=
1.111 paf 1009: r.absolute(params.as_string(0, "stylesheet must be file name (string) or DOM document (xdoc)"));
1.125 paf 1010: Stylesheet_connection_ptr connection=stylesheet_manager->get_connection(stylesheet_filespec);
1.93 paf 1011:
1012: // load and compile file to stylesheet [or get cached if any]
1013: // transform!
1.122 paf 1014: result=&_transform(r, &stylesheet_filespec, vdoc, connection->stylesheet(),
1.93 paf 1015: transform_params);
1016: }
1017:
1.59 paf 1018: // write out result
1.93 paf 1019: r.write_no_lang(*result);
1.1 parser 1020: }
1021:
1.16 parser 1022: // constructor
1.2 parser 1023:
1.92 paf 1024: /// @test how to create empty type html?
1.111 paf 1025: MXdoc::MXdoc(): MXnode(XDOC_CLASS_NAME, xnode_class) {
1.16 parser 1026: /// DOM1
1.2 parser 1027:
1.16 parser 1028: // Element createElement(in DOMString tagName) raises(DOMException);
1029: add_native_method("createElement", Method::CT_DYNAMIC, _createElement, 1, 1);
1030: // DocumentFragment createDocumentFragment();
1031: add_native_method("createDocumentFragment", Method::CT_DYNAMIC, _createDocumentFragment, 0, 0);
1032: // Text createTextNode(in DOMString data);
1033: add_native_method("createTextNode", Method::CT_DYNAMIC, _createTextNode, 1, 1);
1034: // Comment createComment(in DOMString data);
1035: add_native_method("createComment", Method::CT_DYNAMIC, _createComment, 1, 1);
1036: // CDATASection createCDATASection(in DOMString data) raises(DOMException);
1037: add_native_method("createCDATASection", Method::CT_DYNAMIC, _createCDATASection, 1, 1);
1038: // ProcessingInstruction createProcessingInstruction(in DOMString target, in DOMString data) raises(DOMException);
1039: add_native_method("createProcessingInstruction", Method::CT_DYNAMIC, _createProcessingInstruction, 2, 2);
1040: // Attr createAttribute(in DOMString name) raises(DOMException);
1041: add_native_method("createAttribute", Method::CT_DYNAMIC, _createAttribute, 1, 1);
1042: // EntityReference createEntityReference(in DOMString name) raises(DOMException);
1043: add_native_method("createEntityReference", Method::CT_DYNAMIC, _createEntityReference, 1, 1);
1.99 paf 1044: // NodeList getElementsByTagName(in DOMString name);
1045: add_native_method("getElementsByTagName", Method::CT_DYNAMIC, _getElementsByTagName, 1, 1);
1.2 parser 1046:
1.79 paf 1047: /// DOM2
1.2 parser 1048:
1.16 parser 1049: // ^xdoc.getElementById[elementId]
1050: add_native_method("getElementById", Method::CT_DYNAMIC, _getElementById, 1, 1);
1.79 paf 1051:
1052: // Node (in Node importedNode, in boolean deep) raises(DOMException)
1053: add_native_method("importNode", Method::CT_DYNAMIC, _importNode, 2, 2);
1.112 paf 1054:
1.113 paf 1055: // Attr createAttributeNS(in DOMString namespaceURI, in DOMString qualifiedName) raises(DOMException);
1.112 paf 1056: add_native_method("createAttributeNS", Method::CT_DYNAMIC, _createAttributeNS, 2, 2);
1057:
1.113 paf 1058: // Element createElementNS(in DOMString namespaceURI, in DOMString qualifiedName) raises(DOMException);
1.112 paf 1059: add_native_method("createElementNS", Method::CT_DYNAMIC, _createElementNS, 2, 2);
1.99 paf 1060:
1061: // NodeList getElementsByTagNameNS(in DOMString namespaceURI, in DOMString localName);
1062: add_native_method("getElementsByTagNameNS", Method::CT_DYNAMIC, _getElementsByTagNameNS, 2, 2);
1.1 parser 1063:
1.16 parser 1064: /// parser
1065:
1.54 paf 1066: // ^xdoc::create{qualifiedName}
1.95 paf 1067: // ^xdoc::create[<some>xml</some>]
1068: // ^xdoc::create[URI][<some>xml</some>]
1069: add_native_method("create", Method::CT_DYNAMIC, _create, 1, 2);
1.83 paf 1070: // for backward compatibility with <=v 1.82 2002/01/31 11:51:46 paf
1071: add_native_method("set", Method::CT_DYNAMIC, _create, 1, 1);
1.54 paf 1072:
1073: // ^xdoc::load[some.xml]
1.122 paf 1074: add_native_method("load", Method::CT_DYNAMIC, _load, 1, 1);
1.54 paf 1075:
1.2 parser 1076: // ^xdoc.save[some.xml]
1077: // ^xdoc.save[some.xml;options hash]
1.1 parser 1078: add_native_method("save", Method::CT_DYNAMIC, _save, 1, 2);
1079:
1.2 parser 1080: // ^xdoc.string[] <doc/>
1081: // ^xdoc.string[options hash] <doc/>
1.1 parser 1082: add_native_method("string", Method::CT_DYNAMIC, _string, 0, 1);
1083:
1.2 parser 1084: // ^xdoc.file[] file with "<doc/>"
1085: // ^xdoc.file[options hash] file with "<doc/>"
1.58 paf 1086: add_native_method("file", Method::CT_DYNAMIC, _file, 0, 1);
1.1 parser 1087:
1.98 paf 1088: // ^xdoc.transform[stylesheet file_name/xdoc]
1089: // ^xdoc.transform[stylesheet file_name/xdoc;params hash]
1.59 paf 1090: add_native_method("transform", Method::CT_DYNAMIC, _transform, 1, 2);
1.2 parser 1091:
1.5 parser 1092: }
1093:
1.111 paf 1094: # else
1095:
1096: #include "classes.h"
1097:
1.1 parser 1098: // global variable
1099:
1.111 paf 1100: DECLARE_CLASS_VAR(xdoc, 0, 0); // fictive
1.1 parser 1101:
1102: #endif
E-mail: