Annotation of parser3/src/types/pa_vxnode.C, revision 1.46
1.1 parser 1: /** @node
2: Parser: @b dnode parser type.
3:
1.43 paf 4: Copyright(c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com)
1.15 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1 parser 6: */
7: #include "pa_config_includes.h"
8: #ifdef XML
1.18 paf 9:
1.46 ! paf 10: static const char * const IDENT_VXNODE_C="$Date: 2005/12/16 14:48:22 $";
1.1 parser 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"
1.31 paf 17: #include "pa_request_charsets.h"
18: #include "pa_charset.h"
1.36 paf 19: #include "pa_xml_exception.h"
1.1 parser 20:
1.44 paf 21: Request_charsets& VXnode::charsets() {
1.45 paf 22: return get_vxdoc().charsets();
1.44 paf 23: }
24:
1.31 paf 25: Value* VXnode::get_element(const String& aname, Value& aself, bool looking_up) {
1.12 paf 26: // $CLASS,$method
1.31 paf 27: if(Value* result=VStateless_object::get_element(aname, aself, looking_up))
1.12 paf 28: return result;
29:
30: // fields
1.44 paf 31: xmlNode& selfNode=get_xmlnode();
1.12 paf 32:
1.21 paf 33: if(aname=="nodeName") {
1.44 paf 34: return new VString(charsets().source().transcode(selfNode.name));
1.21 paf 35: } else if(aname=="nodeValue") {
1.46 ! paf 36: switch(selfNode.type) {
! 37: case XML_ATTRIBUTE_NODE:
! 38: case XML_PI_NODE:
! 39: case XML_CDATA_SECTION_NODE:
! 40: case XML_COMMENT_NODE:
! 41: case XML_TEXT_NODE:
! 42: return new VString(charsets().source().transcode(xmlNodeGetContent(&selfNode)));
! 43: }
! 44:
! 45: return 0;
1.21 paf 46: } else if(aname=="nodeType") {
1.44 paf 47: return new VInt(selfNode.type);
1.21 paf 48: } else if(aname=="parentNode") {
1.44 paf 49: if(xmlNode* result_node=selfNode.parent)
50: return &get_vxdoc().wrap(*result_node);
1.25 paf 51: return 0;
1.21 paf 52: } else if(aname=="childNodes") {
1.44 paf 53: if(xmlNode* currentNode=selfNode.children) {
1.31 paf 54: VHash* result=new VHash;
1.12 paf 55: int i=0;
56: do {
1.31 paf 57: result->hash().put(
1.33 paf 58: String::Body::Format(i++),
1.44 paf 59: &get_vxdoc().wrap(*currentNode));
60: } while((currentNode=currentNode->next));
1.3 parser 61: return result;
1.12 paf 62: }
1.25 paf 63: return 0;
1.21 paf 64: } else if(aname=="firstChild") {
1.44 paf 65: if(xmlNode* result_node=selfNode.children)
66: return &get_vxdoc().wrap(*result_node);
1.25 paf 67: return 0;
1.21 paf 68: } else if(aname=="lastChild") {
1.44 paf 69: if(xmlNode* result_node=selfNode.last)
70: return &get_vxdoc().wrap(*result_node);
1.25 paf 71: return 0;
1.21 paf 72: } else if(aname=="previousSibling") {
1.44 paf 73: if(xmlNode* result_node=selfNode.prev)
74: return &get_vxdoc().wrap(*result_node);
1.25 paf 75: return 0;
1.21 paf 76: } else if(aname=="nextSibling") {
1.44 paf 77: if(xmlNode* result_node=selfNode.next)
78: return &get_vxdoc().wrap(*result_node);
1.25 paf 79: return 0;
1.21 paf 80: } else if(aname=="ownerDocument") {
1.44 paf 81: return &get_vxdoc();
82: } else switch(selfNode.type) {
83: case XML_ELEMENT_NODE:
1.21 paf 84: if(aname=="attributes") {
1.44 paf 85: if(xmlNode* currentNode=(xmlNode*)selfNode.properties) {
1.31 paf 86: VHash* result=new VHash;
1.44 paf 87: do {
1.31 paf 88: result->hash().put(
1.44 paf 89: charsets().source().transcode(currentNode->name),
90: &get_vxdoc().wrap(*currentNode));
91: } while((currentNode=currentNode->next));
1.12 paf 92: return result;
93: }
1.25 paf 94: return 0;
1.21 paf 95: } else if(aname=="tagName") {
1.44 paf 96: return new VString(charsets().source().transcode(selfNode.name));
1.2 parser 97: }
1.12 paf 98: break;
1.44 paf 99: case XML_ATTRIBUTE_NODE:
1.21 paf 100: if(aname=="specified")
1.44 paf 101: return new VBool(true); // were not working in gdome, leaving out
1.27 paf 102: else if(aname=="name")
1.44 paf 103: return new VString(charsets().source().transcode(selfNode.name));
1.21 paf 104: else if(aname=="value")
1.44 paf 105: return new VString(charsets().source().transcode(xmlNodeGetContent(&selfNode)));
1.12 paf 106: break;
107: /*
1.44 paf 108: case XML_COMMENT_NODE:
1.12 paf 109: substringData(unsigned int offset, unsigned int count)
110: */
1.44 paf 111: case XML_PI_NODE:
1.21 paf 112: if(aname=="target")
1.44 paf 113: return new VString(charsets().source().transcode(selfNode.name));
1.21 paf 114: else if(aname=="data")
1.44 paf 115: return new VString(charsets().source().transcode(xmlNodeGetContent(&selfNode)));
1.12 paf 116: break;
1.44 paf 117: case XML_DTD_NODE:
1.12 paf 118: {
1.26 paf 119: if(aname=="name") {
1.21 paf 120: // readonly attribute DOMString aname;
121: // The aname of DTD; i.e., the aname immediately following
1.12 paf 122: // the DOCTYPE keyword in an XML source document.
1.44 paf 123: return new VString(charsets().source().transcode(selfNode.name));
1.1 parser 124: }
1.12 paf 125: /*
126: readonly attribute NamedNodeMap entities;
127: readonly attribute NamedNodeMap notations;
128: virtual const XalanNamedNodeMap* getEntities () const = 0
129: This function returns a NamedNodeMap containing the general entities, both external and internal, declared in the DTD. More...
130: virtual const XalanNamedNodeMap* getNotations () const = 0
131: This function returns a named selfNode map containing an entry for each notation declared in a document's DTD. More...
132: */
133: }
134: break;
1.44 paf 135: /* someday
136: case XML_NOTATION_NODE:
1.12 paf 137: {
1.44 paf 138: GdomeNotation *notation=XML_NOT(selfNode);
1.21 paf 139: if(aname=="publicId") {
1.12 paf 140: // readonly attribute DOMString publicId;
1.44 paf 141: return new VString(charsets().source().transcode(gdome_not_publicId(notation, &exc)));
1.21 paf 142: } else if(aname=="systemId") {
1.12 paf 143: // readonly attribute DOMString systemId;
1.44 paf 144: return new VString(charsets().source().transcode(gdome_not_systemId(notation, &exc)));
1.4 parser 145: }
1.12 paf 146: }
147: break;
1.44 paf 148: */
1.12 paf 149: }
1.3 parser 150:
1.32 paf 151: return bark("%s field not found", &aname);
1.1 parser 152: }
153:
1.42 paf 154: const VJunction* VXnode::put_element(Value& /*aself*/, const String& aname, Value* avalue, bool /*replace*/)
1.36 paf 155: {
1.44 paf 156: xmlNode& selfNode=get_xmlnode();
1.36 paf 157:
158: if(aname=="nodeValue") {
1.44 paf 159: xmlNodeSetContent(&selfNode,
160: charsets().source().transcode(avalue->as_string()));
1.36 paf 161:
1.39 paf 162: return PUT_ELEMENT_REPLACED_ELEMENT;
1.36 paf 163: }
164:
1.38 paf 165: bark("element can not be stored to %s", &aname);
1.39 paf 166: return 0;
1.36 paf 167: }
1.1 parser 168: #endif
E-mail: