Annotation of parser3/src/classes/dom.C, revision 1.3
1.2 parser 1: /** @file
2: Parser: @b dom parser class.
3:
4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
5:
6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
7: */
1.3 ! parser 8: static const char *RCSId="$Id: dom.C,v 1.2 2001/09/07 12:46:19 parser Exp $";
1.2 parser 9:
10: #if _MSC_VER
11: # pragma warning(disable:4291) // disable warning
12: // "no matching operator delete found; memory will not be freed if initialization throws an exception
13: #endif
14:
15: #include "classes.h"
16: #include "pa_request.h"
17: #include "pa_vdom.h"
18:
19: #include <Include/PlatformDefinitions.hpp>
20: #include <util/PlatformUtils.hpp>
21: #include <XalanTransformer/XalanTransformer.hpp>
22:
23: // defines
24:
25: #define Dom_CLASS_NAME "dom"
26:
27: // class
28:
29: class MDom : public Methoded {
30: public: // VStateless_class
31: Value *create_new_value(Pool& pool) { return new(pool) VDOM(pool, 0); }
32:
33: public:
34: MDom(Pool& pool);
35:
36: public: // Methoded
37: bool used_directly() { return true; }
38: };
39:
40: // methods
41:
42: static void _load(Request& r, const String& method_name, MethodParams *params) {
43: Pool& pool=r.pool();
44: VDOM& vDOM=*static_cast<VDOM *>(r.self);
45:
46: // filename
47: const String& filename=params->as_string(0, "file name must not be code");
48:
49: // filespec
50: const char *filespec=r.absolute(filename).cstr(String::UL_FILE_NAME);
51:
52: // XSLTInputSource::XSLTInputSource ( std::istream * stream )
53: // XalanNode *node=inputSource.getNode();
54: XSLTInputSource inputSource(filespec);
55: XalanParsedSource* parsedSource;
56: int error=vDOM.getXalanTransformer().parseSource(inputSource, parsedSource);
57:
58: if(error)
59: PTHROW(0, 0,
60: &filename,
61: vDOM.getXalanTransformer().getLastError());
62:
63: // replace any previous node value
64: vDOM.setParsedSource(parsedSource);
65: }
66:
1.3 ! parser 67: static void _save(Request& r, const String& method_name, MethodParams *params) {
! 68: Pool& pool=r.pool();
! 69: VDOM& vDOM=*static_cast<VDOM *>(r.self);
! 70:
! 71: // filename
! 72: const String& filename=params->as_string(0, "file name must not be code");
! 73:
! 74: // filespec
! 75: const char *filespec=r.absolute(filename).cstr(String::UL_FILE_NAME);
! 76:
! 77: XSLTInputSource inputSource(filespec);
! 78: XalanParsedSource* parsedSource;
! 79: int error=vDOM.getXalanTransformer().parseSource(inputSource, parsedSource);
! 80:
! 81: if(error)
! 82: PTHROW(0, 0,
! 83: &filename,
! 84: vDOM.getXalanTransformer().getLastError());
! 85:
! 86: // replace any previous node value
! 87: vDOM.setParsedSource(parsedSource);
! 88: }
! 89:
1.2 parser 90: // constructor
91:
92: MDom::MDom(Pool& apool) : Methoded(apool) {
93: set_name(*NEW String(pool(), Dom_CLASS_NAME));
94:
1.3 ! parser 95: // ^dom::load[some.xml]
1.2 parser 96: add_native_method("load", Method::CT_DYNAMIC, _load, 1, 1);
1.3 ! parser 97:
! 98: // ^dom.save[some.xml]
! 99: add_native_method("save", Method::CT_DYNAMIC, _save, 1, 1);
1.2 parser 100:
101: }
102: // global variable
103:
104: Methoded *Dom_class;
105:
106: // creator
107:
108: Methoded *MDom_create(Pool& pool) {
109: // Use the static initializers to initialize the Xalan-C++ and Xerces-C++ platforms.
110: // You must initialize Xerces-C++ once per process
111: XMLPlatformUtils::Initialize();
112: XalanTransformer::initialize();
113:
114:
115: return Dom_class=new(pool) MDom(pool);
116: }
E-mail: