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