Annotation of parser3/src/types/pa_vdnode.C, revision 1.2

1.1       parser      1: /** @node
                      2:        Parser: @b dnode parser type.
                      3: 
                      4:        Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com)
                      5: 
                      6:        Author: Alexander Petrosyan <paf@design.ru>(http://design.ru/paf)
                      7: 
1.2     ! parser      8:        $Id: pa_vdnode.C,v 1.1 2001/09/18 12:25:06 parser Exp $
1.1       parser      9: */
                     10: 
                     11: #if _MSC_VER
                     12: #      pragma warning(disable:4291)   // disable warning 
                     13: //     "no matching operator delete found; memory will not be freed if initialization throws an exception
                     14: #endif
                     15: 
                     16: #include "pa_vdnode.h"
1.2     ! parser     17: #include "pa_vdom.h"
1.1       parser     18: #include "pa_vstring.h"
                     19: 
                     20: #include <util/XMLString.hpp>
                     21: #include <util/PlatformUtils.hpp>
                     22: #include <util/TransService.hpp>
1.2     ! parser     23: #include <XalanDOM/XalanNamedNodeMap.hpp>
1.1       parser     24: /*
                     25: void VDnode_cleanup(void *vnode) {
                     26:        //_asm int 3;
                     27:        static_cast<VDDom *>(vnode)->cleanup();
                     28: }
                     29: */
                     30: 
                     31: /// @test pool maxBytes
                     32: static const char *strX(const XalanDOMString& s) {
                     33: //     return XMLString::transcode(s.c_str());
                     34:        XMLTransService::Codes resValue;
                     35:        XMLTranscoder& transcoder=*XMLPlatformUtils::fgTransService->makeNewTranscoderFor(
                     36:                "windows-1251", resValue, 0x400);
                     37:        const unsigned int maxBytes=0x100;
                     38:        XMLByte* toFill=(XMLByte *)malloc(maxBytes*sizeof(XMLByte));
                     39:        unsigned int charsEaten;
                     40:        unsigned int size=transcoder.transcodeTo(
                     41:         s.c_str(), s.length(),
                     42:         toFill,
                     43:         maxBytes,
                     44:         charsEaten,
                     45:                XMLTranscoder::UnRep_RepChar /*UnRep_Throw*/
                     46:     );
                     47:        toFill[size]=0;
                     48:        return (const char *)toFill;
                     49: }
                     50: 
                     51: void _throw(Pool& pool, const String *source, const XSLException& e) {
                     52:        if(e.getURI().empty())
                     53:                PTHROW(0, 0,
                     54:                        source,
                     55:                        "%s (%s)",
                     56:                                strX(e.getMessage()),  // message for exception
                     57:                                strX(e.getType()) // type of exception
                     58:                );
                     59:        else
                     60:                PTHROW(0, 0,
                     61:                        source,
                     62:                        "%s (%s) %s(%d:%d)'", 
                     63:                                strX(e.getMessage()),  // message for exception
                     64:                                strX(e.getType()), // type of exception
                     65:                                
                     66:                                strX(e.getURI()),  // URI for the associated document, if any
                     67:                                e.getLineNumber(),  // line number, or -1 if unknown
                     68:                                e.getColumnNumber() // column number, or -1 if unknown
                     69:                );
                     70: }
                     71: 
                     72: /// VDnode: $CLASS,$method
                     73: Value *VDnode::get_element(const String& aname) { 
                     74:        // $CLASS,$method
                     75:        if(Value *result=VStateless_object::get_element(aname))
                     76:                return result;
                     77: 
                     78:        // fields
                     79: 
1.2     ! parser     80:        XalanNode& self=get_node(pool(), &aname);
        !            81: 
1.1       parser     82:        if(aname=="name") {
1.2     ! parser     83:                const char *name_cstr=strX(self.getNodeName());
1.1       parser     84:                String& name=*NEW String(pool(), name_cstr);
                     85:                return NEW VString(name);
1.2     ! parser     86:        } else if(aname=="value") {
        !            87:                const char *value_cstr=strX(self.getNodeValue());
1.1       parser     88:                String& value=*NEW String(pool(), value_cstr);
                     89:                return NEW VString(value);
1.2     ! parser     90:        } else if(aname=="type") {
        !            91:                static const char *type_names[]={
        !            92:                        "unknown",
        !            93:                        "element",    
        !            94:                        "attribute",    
        !            95:                        "text",    
        !            96:                        "cdata",    
        !            97:                        "entityref",    
        !            98:                        "entity",    
        !            99:                        "pi",    
        !           100:                        "comment",    
        !           101:                        "document",    
        !           102:                        "doctype",    
        !           103:                        "docfragment",    
        !           104:                        "notation"
        !           105:                };
        !           106:                XalanNode::NodeType node_type=self.getNodeType();
        !           107:                if(node_type > sizeof(type_names)/sizeof(type_names[0]))
        !           108:                        node_type=XalanNode::UNKNOWN_NODE;
        !           109:                return NEW VString(*NEW String(pool(), type_names[node_type]));
        !           110:        } else if(aname=="parent") {
        !           111:                if(XalanNode *result_node=self.getParentNode())
        !           112:                        return NEW VDnode(pool(), result_node);
        !           113:        } else if(aname=="first-child") {
        !           114:                if(XalanNode *result_node=self.getFirstChild())
        !           115:                        return NEW VDnode(pool(), result_node);
        !           116:        } else if(aname=="last-child") {
        !           117:                if(XalanNode *result_node=self.getLastChild())
        !           118:                        return NEW VDnode(pool(), result_node);
        !           119:        } else if(aname=="previous-sibling") {
        !           120:                if(XalanNode *result_node=self.getPreviousSibling())
        !           121:                        return NEW VDnode(pool(), result_node);
        !           122:        } else if(aname=="next-sibling") {
        !           123:                if(XalanNode *result_node=self.getNextSibling())
        !           124:                        return NEW VDnode(pool(), result_node);
        !           125:        } else if(aname=="attributes") {
        !           126:                if(const XalanNamedNodeMap *attributes=self.getAttributes()) {
        !           127:                        VHash *result=NEW VHash(pool());
        !           128:                        for(int i=0; i<attributes->getLength(); i++) {
        !           129:                                XalanNode *attr_node=attributes->item(i);
        !           130:                                result->hash().put(
        !           131:                                        *NEW String(pool(), strX(attr_node->getNodeName())), 
        !           132:                                        NEW VDnode(pool(), attr_node));
        !           133:                        }
        !           134:                        return result;
        !           135:                }
        !           136:        } else if(aname=="owner") {
        !           137:                if(XalanDocument *document=self.getOwnerDocument())
        !           138:                        return NEW VDom(pool(), document);
        !           139:        } 
1.1       parser    140:        
1.2     ! parser    141: 
1.1       parser    142:        return 0;
                    143: }

E-mail: