|
|
1.1 parser 1: /** @node
2: Parser: @b dnode parser type.
3:
4: Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com)
5: Author: Alexander Petrosyan <paf@design.ru>(http://design.ru/paf)
6:
1.5 ! parser 7: $Id: pa_vxnode.C,v 1.4 2001/10/15 14:13:22 parser Exp $
1.1 parser 8: */
9: #include "pa_config_includes.h"
10: #ifdef XML
11:
12: #include "pa_vxnode.h"
13: #include "pa_vxdoc.h"
14: #include "pa_vstring.h"
15: #include "pa_vbool.h"
16: #include "pa_vhash.h"
17:
18: #include <util/XMLString.hpp>
19: #include <util/PlatformUtils.hpp>
20: #include <util/TransService.hpp>
21: #include <XalanDOM/XalanNamedNodeMap.hpp>
22: #include <XalanDOM/XalanAttr.hpp>
23: #include <XalanDOM/XalanProcessingInstruction.hpp>
1.2 parser 24: #include <XalanDOM/XalanNodeList.hpp>
1.3 parser 25: #include <XalanDOM/XalanElement.hpp>
1.4 parser 26: #include <XalanDOM/XalanDocumentType.hpp>
27: #include <XalanDOM/XalanNotation.hpp>
1.1 parser 28:
29: /*
30: void VXnode_cleanup(void *vxnode) {
31: //_asm int 3;
32: static_cast<VXnode *>(vxnode)->cleanup();
33: }
34: */
35:
1.3 parser 36: Value *VXnode::get_element(const String& name) {
37: try {
38: // $CLASS,$method
39: if(Value *result=VStateless_object::get_element(name))
40: return result;
41:
42: // fields
43:
44: XalanNode& node=get_node(pool(), &name);
45:
46: if(name=="nodeName") {
47: return NEW VString(transcode(node.getNodeName()));
48: } else if(name=="nodeValue") {
49: return NEW VString(transcode(node.getNodeValue()));
50: } else if(name=="nodeType") {
51: return NEW VInt(pool(), node.getNodeType());
52: } else if(name=="parentNode") {
53: if(XalanNode *result_node=node.getParentNode())
54: return NEW VXnode(pool(), result_node);
55: } else if(name=="childNodes") {
56: if(const XalanNodeList *nodes=node.getChildNodes()) {
57: VHash *result=NEW VHash(pool());
58: for(int i=0; i<nodes->getLength(); i++) {
59: String& skey=*NEW String(pool());
60: {
61: char *buf=(char *)malloc(MAX_NUMBER);
62: snprintf(buf, MAX_NUMBER, "%d", i);
63: skey << buf;
64: }
65:
66: result->hash().put(skey, NEW VXnode(pool(), nodes->item(i)));
1.2 parser 67: }
1.3 parser 68: return result;
1.2 parser 69: }
1.3 parser 70: } else if(name=="firstChild") {
71: if(XalanNode *result_node=node.getFirstChild())
72: return NEW VXnode(pool(), result_node);
73: } else if(name=="lastChild") {
74: if(XalanNode *result_node=node.getLastChild())
75: return NEW VXnode(pool(), result_node);
76: } else if(name=="previousSibling") {
77: if(XalanNode *result_node=node.getPreviousSibling())
78: return NEW VXnode(pool(), result_node);
79: } else if(name=="nextSibling") {
80: if(XalanNode *result_node=node.getNextSibling())
81: return NEW VXnode(pool(), result_node);
82: } else if(name=="ownerDocument") {
83: if(XalanDocument *document=node.getOwnerDocument())
1.5 ! parser 84: return NEW VXdoc(pool(), document, false/*owns not*/);
1.3 parser 85: } else switch(node.getNodeType()) {
86: case XalanNode::ELEMENT_NODE:
87: if(name=="attributes") {
88: if(const XalanNamedNodeMap *attributes=node.getAttributes()) {
89: VHash *result=NEW VHash(pool());
90: for(int i=0; i<attributes->getLength(); i++) {
91: XalanNode *attr_node=attributes->item(i);
92: result->hash().put(
93: transcode(attr_node->getNodeName()),
94: NEW VXnode(pool(), attr_node));
95: }
96: return result;
1.1 parser 97: }
1.3 parser 98: } else if(name=="tagName") {
99: return NEW VString(transcode(static_cast<XalanElement *>(&node)->getTagName()));
1.1 parser 100: }
1.3 parser 101: break;
102: case XalanNode::ATTRIBUTE_NODE:
103: if(name=="specified")
104: return NEW VBool(pool(), static_cast<XalanAttr *>(&node)->getSpecified());
105: break;
106: /*
107: case XalanNode::COMMENT_NODE:
108: substringData(unsigned int offset, unsigned int count)
109: */
110: case XalanNode::PROCESSING_INSTRUCTION_NODE:
111: if(name=="target")
112: return NEW VString(transcode(static_cast<XalanProcessingInstruction *>(&node)->getTarget()));
113: break;
114: case XalanNode::DOCUMENT_TYPE_NODE:
1.4 parser 115: {
116: XalanDocumentType& doctype=*static_cast<XalanDocumentType *>(&node);
117: if(name=="name") {
118: // readonly attribute DOMString name;
119: // The name of DTD; i.e., the name immediately following
120: // the DOCTYPE keyword in an XML source document.
121: return NEW VString(transcode(doctype.getName()));
122: }
123: /*
124: readonly attribute NamedNodeMap entities;
125: readonly attribute NamedNodeMap notations;
126: virtual const XalanNamedNodeMap* getEntities () const = 0
127: This function returns a NamedNodeMap containing the general entities, both external and internal, declared in the DTD. More...
128: virtual const XalanNamedNodeMap* getNotations () const = 0
129: This function returns a named node map containing an entry for each notation declared in a document's DTD. More...
130: */
131: }
132: break;
133: case XalanNode::NOTATION_NODE:
134: {
135: XalanNotation& notation=*static_cast<XalanNotation *>(&node);
136: if(name=="publicId") {
137: // readonly attribute DOMString publicId;
138: return NEW VString(transcode(notation.getPublicId()));
139: } else if(name=="systemId") {
140: // readonly attribute DOMString systemId;
141: return NEW VString(transcode(notation.getSystemId()));
142: }
143: }
144: break;
1.3 parser 145: }
146:
147: } catch(const XalanDOMException& e) {
148: exception()._throw(pool(), &name, e);
1.1 parser 149: }
150:
151: return 0;
152: }
153:
154: #endif