Annotation of parser3/src/types/pa_vxnode.C, revision 1.3
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.3 ! parser 7: $Id: pa_vxnode.C,v 1.2 2001/09/26 15:43:59 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.1 parser 26:
27: /*
28: void VXnode_cleanup(void *vxnode) {
29: //_asm int 3;
30: static_cast<VXnode *>(vxnode)->cleanup();
31: }
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())
! 52: return NEW VXnode(pool(), result_node);
! 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:
! 64: result->hash().put(skey, NEW VXnode(pool(), nodes->item(i)));
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())
! 70: return NEW VXnode(pool(), result_node);
! 71: } else if(name=="lastChild") {
! 72: if(XalanNode *result_node=node.getLastChild())
! 73: return NEW VXnode(pool(), result_node);
! 74: } else if(name=="previousSibling") {
! 75: if(XalanNode *result_node=node.getPreviousSibling())
! 76: return NEW VXnode(pool(), result_node);
! 77: } else if(name=="nextSibling") {
! 78: if(XalanNode *result_node=node.getNextSibling())
! 79: return NEW VXnode(pool(), result_node);
! 80: } else if(name=="ownerDocument") {
! 81: if(XalanDocument *document=node.getOwnerDocument())
! 82: return NEW VXdoc(pool(), document);
! 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()),
! 92: NEW VXnode(pool(), attr_node));
! 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: /*
! 113: case XalanNode::DOCUMENT_TYPE_NODE:
! 114: readonly attribute DOMString name;
! 115: readonly attribute NamedNodeMap entities;
! 116: readonly attribute NamedNodeMap notations;
! 117: virtual const XalanDOMString& getName () const = 0
! 118: The name of DTD; i.e., the name immediately following the DOCTYPE keyword in an XML source document.
! 119: virtual const XalanNamedNodeMap* getEntities () const = 0
! 120: This function returns a NamedNodeMap containing the general entities, both external and internal, declared in the DTD. More...
! 121: virtual const XalanNamedNodeMap* getNotations () const = 0
! 122: This function returns a named node map containing an entry for each notation declared in a document's DTD. More...*/
1.1 parser 123: /*
1.3 ! parser 124: case XalanNode::NOTATION_NODE;
! 125: readonly attribute DOMString publicId;
! 126: readonly attribute DOMString systemId;
1.1 parser 127: */
1.3 ! parser 128: }
! 129:
! 130: } catch(const XalanDOMException& e) {
! 131: exception()._throw(pool(), &name, e);
1.1 parser 132: }
133:
134: return 0;
135: }
136:
137: #endif
E-mail: