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

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.48    ! misha      10: static const char * const IDENT_VXNODE_C="$Date: 2005/12/19 12:55:09 $";
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        
        !            26: Value& VXnode::as_expr_result(bool /*return_string_as_is=false*/) { return *new VBool(as_bool()); }
        !            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.21      paf        99:                        } else if(aname=="tagName") {
1.44      paf       100:                                return new VString(charsets().source().transcode(selfNode.name));
1.2       parser    101:                        }
1.12      paf       102:                        break;
1.44      paf       103:                case XML_ATTRIBUTE_NODE: 
1.21      paf       104:                        if(aname=="specified")
1.44      paf       105:                                return new VBool(true); // were not working in gdome, leaving out
1.27      paf       106:                        else if(aname=="name")
1.44      paf       107:                                return new VString(charsets().source().transcode(selfNode.name));
1.21      paf       108:                        else if(aname=="value")
1.44      paf       109:                                return new VString(charsets().source().transcode(xmlNodeGetContent(&selfNode)));
1.12      paf       110:                        break;
                    111: /*
1.44      paf       112:                case XML_COMMENT_NODE: 
1.12      paf       113:                        substringData(unsigned int offset, unsigned int count)
                    114: */
1.44      paf       115:                case XML_PI_NODE: 
1.21      paf       116:                        if(aname=="target")
1.44      paf       117:                                return new VString(charsets().source().transcode(selfNode.name));
1.21      paf       118:                        else if(aname=="data")
1.44      paf       119:                                return new VString(charsets().source().transcode(xmlNodeGetContent(&selfNode)));
1.12      paf       120:                        break;
1.44      paf       121:                case XML_DTD_NODE: 
1.12      paf       122:                        {
1.26      paf       123:                                if(aname=="name") {
1.21      paf       124:                                        // readonly attribute DOMString aname;
                    125:                                        // The aname of DTD; i.e., the aname immediately following 
1.12      paf       126:                                        // the DOCTYPE keyword in an XML source document.
1.44      paf       127:                                        return new VString(charsets().source().transcode(selfNode.name));
1.1       parser    128:                                }
1.12      paf       129:                                /*
                    130:                                readonly attribute NamedNodeMap entities;
                    131:                                readonly attribute NamedNodeMap notations;
                    132:                                virtual const XalanNamedNodeMap* getEntities () const = 0 
                    133:                                This function returns a NamedNodeMap containing the general entities, both external and internal, declared in the DTD. More...
                    134:                                virtual const XalanNamedNodeMap* getNotations () const = 0 
                    135:                                This function returns a named selfNode map containing an entry for each notation declared in a document's DTD. More...
                    136:                                */
                    137:                        }
                    138:                        break;
1.44      paf       139:                        /* someday
                    140:                case XML_NOTATION_NODE:
1.12      paf       141:                        {
1.44      paf       142:                                GdomeNotation *notation=XML_NOT(selfNode);
1.21      paf       143:                                if(aname=="publicId") {
1.12      paf       144:                                        // readonly attribute DOMString publicId;
1.44      paf       145:                                        return new VString(charsets().source().transcode(gdome_not_publicId(notation, &exc)));
1.21      paf       146:                                } else if(aname=="systemId") {
1.12      paf       147:                                        // readonly attribute DOMString systemId;
1.44      paf       148:                                        return new VString(charsets().source().transcode(gdome_not_systemId(notation, &exc)));
1.4       parser    149:                                }
1.12      paf       150:                        }
                    151:                        break;
1.44      paf       152:                        */
1.47      paf       153:                default:
                    154:                        // calm compiler on unhandled cases
                    155:                        break;
1.12      paf       156:        }
1.3       parser    157:                
1.32      paf       158:        return bark("%s field not found", &aname);
1.1       parser    159: }
                    160: 
1.42      paf       161: const VJunction* VXnode::put_element(Value& /*aself*/, const String& aname, Value* avalue, bool /*replace*/)
1.36      paf       162: { 
1.44      paf       163:        xmlNode& selfNode=get_xmlnode();
1.36      paf       164: 
                    165:        if(aname=="nodeValue") {
1.44      paf       166:                xmlNodeSetContent(&selfNode, 
                    167:                        charsets().source().transcode(avalue->as_string()));
1.36      paf       168: 
1.39      paf       169:                return PUT_ELEMENT_REPLACED_ELEMENT;
1.36      paf       170:        }
                    171: 
1.38      paf       172:        bark("element can not be stored to %s", &aname);
1.39      paf       173:        return 0;
1.36      paf       174: }
1.1       parser    175: #endif

E-mail: