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