Annotation of parser3/src/types/pa_vxnode.C, revision 1.50

1.1       parser      1: /** @node
                      2:        Parser: @b dnode parser type.
                      3: 
1.50    ! misha       4:        Copyright(c) 2001-2009 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.50    ! misha      10: static const char * const IDENT_VXNODE_C="$Date: 2007/10/23 13:56:46 $";
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.48      misha      25: /// VXnode: true        
1.50    ! misha      26: Value& VXnode::as_expr_result(bool /*return_string_as_is=false*/) { return VBool::get(as_bool()); }
1.48      misha      27: 
                     28: 
1.31      paf        29: Value* VXnode::get_element(const String& aname, Value& aself, bool looking_up) { 
1.12      paf        30:        // $CLASS,$method
1.31      paf        31:        if(Value* result=VStateless_object::get_element(aname, aself, looking_up))
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.21      paf        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.31      paf        61:                                result->hash().put(
1.33      paf        62:                                        String::Body::Format(i++), 
1.44      paf        63:                                        &get_vxdoc().wrap(*currentNode));
                     64:                        } while((currentNode=currentNode->next));
1.3       parser     65:                        return result;
1.12      paf        66:                }
1.25      paf        67:                return 0;
1.21      paf        68:        } else if(aname=="firstChild") {
1.44      paf        69:                if(xmlNode* result_node=selfNode.children)
                     70:                        return &get_vxdoc().wrap(*result_node);
1.25      paf        71:                return 0;
1.21      paf        72:        } else if(aname=="lastChild") {
1.44      paf        73:                if(xmlNode* result_node=selfNode.last)
                     74:                        return &get_vxdoc().wrap(*result_node);
1.25      paf        75:                return 0;
1.21      paf        76:        } else if(aname=="previousSibling") {
1.44      paf        77:                if(xmlNode* result_node=selfNode.prev)
                     78:                        return &get_vxdoc().wrap(*result_node);
1.25      paf        79:                return 0;
1.21      paf        80:        } else if(aname=="nextSibling") {
1.44      paf        81:                if(xmlNode* result_node=selfNode.next)
                     82:                        return &get_vxdoc().wrap(*result_node);
1.25      paf        83:                return 0;
1.21      paf        84:        } else if(aname=="ownerDocument") {
1.44      paf        85:                return &get_vxdoc();
                     86:        } else switch(selfNode.type) {
                     87:                case XML_ELEMENT_NODE: 
1.21      paf        88:                        if(aname=="attributes") {
1.44      paf        89:                                if(xmlNode* currentNode=(xmlNode*)selfNode.properties) {
1.31      paf        90:                                        VHash* result=new VHash;
1.44      paf        91:                                        do {
1.31      paf        92:                                                result->hash().put(
1.44      paf        93:                                                        charsets().source().transcode(currentNode->name),
                     94:                                                        &get_vxdoc().wrap(*currentNode));
                     95:                                        } while((currentNode=currentNode->next));
1.12      paf        96:                                        return result;
                     97:                                }
1.25      paf        98:                                return 0;
1.49      misha      99:                        } else if(aname=="tagName")
1.44      paf       100:                                return new VString(charsets().source().transcode(selfNode.name));
1.49      misha     101:                        else if(aname=="prefix")
                    102:                                return (selfNode.ns ? new VString(charsets().source().transcode(selfNode.ns->prefix)) : 0);
                    103:                        else if(aname=="namespaceURI")
                    104:                                return (selfNode.ns ? new VString(charsets().source().transcode(selfNode.ns->href)) : 0);
1.12      paf       105:                        break;
1.44      paf       106:                case XML_ATTRIBUTE_NODE: 
1.21      paf       107:                        if(aname=="specified")
1.50    ! misha     108:                                return &VBool::get(true); // were not working in gdome, leaving out
1.27      paf       109:                        else if(aname=="name")
1.44      paf       110:                                return new VString(charsets().source().transcode(selfNode.name));
1.21      paf       111:                        else if(aname=="value")
1.44      paf       112:                                return new VString(charsets().source().transcode(xmlNodeGetContent(&selfNode)));
1.49      misha     113:                        else if(aname=="prefix")
                    114:                                return (selfNode.ns ? new VString(charsets().source().transcode(selfNode.ns->prefix)) : 0);
                    115:                        else if(aname=="namespaceURI")
                    116:                                return (selfNode.ns ? new VString(charsets().source().transcode(selfNode.ns->href)) : 0);
1.12      paf       117:                        break;
                    118: /*
1.44      paf       119:                case XML_COMMENT_NODE: 
1.12      paf       120:                        substringData(unsigned int offset, unsigned int count)
                    121: */
1.44      paf       122:                case XML_PI_NODE: 
1.21      paf       123:                        if(aname=="target")
1.44      paf       124:                                return new VString(charsets().source().transcode(selfNode.name));
1.21      paf       125:                        else if(aname=="data")
1.44      paf       126:                                return new VString(charsets().source().transcode(xmlNodeGetContent(&selfNode)));
1.12      paf       127:                        break;
1.44      paf       128:                case XML_DTD_NODE: 
1.12      paf       129:                        {
1.26      paf       130:                                if(aname=="name") {
1.21      paf       131:                                        // readonly attribute DOMString aname;
                    132:                                        // The aname of DTD; i.e., the aname immediately following 
1.12      paf       133:                                        // the DOCTYPE keyword in an XML source document.
1.44      paf       134:                                        return new VString(charsets().source().transcode(selfNode.name));
1.1       parser    135:                                }
1.12      paf       136:                                /*
                    137:                                readonly attribute NamedNodeMap entities;
                    138:                                readonly attribute NamedNodeMap notations;
                    139:                                virtual const XalanNamedNodeMap* getEntities () const = 0 
                    140:                                This function returns a NamedNodeMap containing the general entities, both external and internal, declared in the DTD. More...
                    141:                                virtual const XalanNamedNodeMap* getNotations () const = 0 
                    142:                                This function returns a named selfNode map containing an entry for each notation declared in a document's DTD. More...
                    143:                                */
                    144:                        }
                    145:                        break;
1.44      paf       146:                        /* someday
                    147:                case XML_NOTATION_NODE:
1.12      paf       148:                        {
1.44      paf       149:                                GdomeNotation *notation=XML_NOT(selfNode);
1.21      paf       150:                                if(aname=="publicId") {
1.12      paf       151:                                        // readonly attribute DOMString publicId;
1.44      paf       152:                                        return new VString(charsets().source().transcode(gdome_not_publicId(notation, &exc)));
1.21      paf       153:                                } else if(aname=="systemId") {
1.12      paf       154:                                        // readonly attribute DOMString systemId;
1.44      paf       155:                                        return new VString(charsets().source().transcode(gdome_not_systemId(notation, &exc)));
1.4       parser    156:                                }
1.12      paf       157:                        }
                    158:                        break;
1.44      paf       159:                        */
1.47      paf       160:                default:
                    161:                        // calm compiler on unhandled cases
                    162:                        break;
1.12      paf       163:        }
1.3       parser    164:                
1.32      paf       165:        return bark("%s field not found", &aname);
1.1       parser    166: }
                    167: 
1.42      paf       168: const VJunction* VXnode::put_element(Value& /*aself*/, const String& aname, Value* avalue, bool /*replace*/)
1.36      paf       169: { 
1.44      paf       170:        xmlNode& selfNode=get_xmlnode();
1.36      paf       171: 
                    172:        if(aname=="nodeValue") {
1.44      paf       173:                xmlNodeSetContent(&selfNode, 
                    174:                        charsets().source().transcode(avalue->as_string()));
1.36      paf       175: 
1.39      paf       176:                return PUT_ELEMENT_REPLACED_ELEMENT;
1.36      paf       177:        }
                    178: 
1.38      paf       179:        bark("element can not be stored to %s", &aname);
1.39      paf       180:        return 0;
1.36      paf       181: }
1.1       parser    182: #endif

E-mail: