Annotation of parser3/src/types/pa_vdnode.C, revision 1.3
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.3 ! parser 8: $Id: pa_vdnode.C,v 1.2 2001/09/18 13:31:56 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"
1.3 ! parser 19: #include "pa_vbool.h"
1.1 parser 20:
21: #include <util/XMLString.hpp>
22: #include <util/PlatformUtils.hpp>
23: #include <util/TransService.hpp>
1.2 parser 24: #include <XalanDOM/XalanNamedNodeMap.hpp>
1.3 ! parser 25: #include <XalanDOM/XalanAttr.hpp>
! 26: #include <XalanDOM/XalanProcessingInstruction.hpp>
! 27:
1.1 parser 28: /*
29: void VDnode_cleanup(void *vnode) {
30: //_asm int 3;
31: static_cast<VDDom *>(vnode)->cleanup();
32: }
33: */
34:
35: /// @test pool maxBytes
36: static const char *strX(const XalanDOMString& s) {
37: // return XMLString::transcode(s.c_str());
38: XMLTransService::Codes resValue;
39: XMLTranscoder& transcoder=*XMLPlatformUtils::fgTransService->makeNewTranscoderFor(
40: "windows-1251", resValue, 0x400);
41: const unsigned int maxBytes=0x100;
42: XMLByte* toFill=(XMLByte *)malloc(maxBytes*sizeof(XMLByte));
43: unsigned int charsEaten;
44: unsigned int size=transcoder.transcodeTo(
45: s.c_str(), s.length(),
46: toFill,
47: maxBytes,
48: charsEaten,
49: XMLTranscoder::UnRep_RepChar /*UnRep_Throw*/
50: );
51: toFill[size]=0;
52: return (const char *)toFill;
53: }
54:
55: void _throw(Pool& pool, const String *source, const XSLException& e) {
56: if(e.getURI().empty())
57: PTHROW(0, 0,
58: source,
59: "%s (%s)",
60: strX(e.getMessage()), // message for exception
61: strX(e.getType()) // type of exception
62: );
63: else
64: PTHROW(0, 0,
65: source,
66: "%s (%s) %s(%d:%d)'",
67: strX(e.getMessage()), // message for exception
68: strX(e.getType()), // type of exception
69:
70: strX(e.getURI()), // URI for the associated document, if any
71: e.getLineNumber(), // line number, or -1 if unknown
72: e.getColumnNumber() // column number, or -1 if unknown
73: );
74: }
75:
76: /// VDnode: $CLASS,$method
77: Value *VDnode::get_element(const String& aname) {
78: // $CLASS,$method
79: if(Value *result=VStateless_object::get_element(aname))
80: return result;
81:
82: // fields
83:
1.3 ! parser 84: XalanNode *self=&get_node(pool(), &aname);
1.2 parser 85:
1.1 parser 86: if(aname=="name") {
1.3 ! parser 87: const char *name_cstr=strX(self->getNodeName());
1.1 parser 88: String& name=*NEW String(pool(), name_cstr);
89: return NEW VString(name);
1.2 parser 90: } else if(aname=="value") {
1.3 ! parser 91: const char *value_cstr=strX(self->getNodeValue());
1.1 parser 92: String& value=*NEW String(pool(), value_cstr);
93: return NEW VString(value);
1.2 parser 94: } else if(aname=="type") {
95: static const char *type_names[]={
96: "unknown",
97: "element",
98: "attribute",
99: "text",
100: "cdata",
101: "entityref",
102: "entity",
103: "pi",
104: "comment",
105: "document",
106: "doctype",
107: "docfragment",
108: "notation"
109: };
1.3 ! parser 110: XalanNode::NodeType node_type=self->getNodeType();
1.2 parser 111: if(node_type > sizeof(type_names)/sizeof(type_names[0]))
112: node_type=XalanNode::UNKNOWN_NODE;
113: return NEW VString(*NEW String(pool(), type_names[node_type]));
114: } else if(aname=="parent") {
1.3 ! parser 115: if(XalanNode *result_node=self->getParentNode())
1.2 parser 116: return NEW VDnode(pool(), result_node);
117: } else if(aname=="first-child") {
1.3 ! parser 118: if(XalanNode *result_node=self->getFirstChild())
1.2 parser 119: return NEW VDnode(pool(), result_node);
120: } else if(aname=="last-child") {
1.3 ! parser 121: if(XalanNode *result_node=self->getLastChild())
1.2 parser 122: return NEW VDnode(pool(), result_node);
123: } else if(aname=="previous-sibling") {
1.3 ! parser 124: if(XalanNode *result_node=self->getPreviousSibling())
1.2 parser 125: return NEW VDnode(pool(), result_node);
126: } else if(aname=="next-sibling") {
1.3 ! parser 127: if(XalanNode *result_node=self->getNextSibling())
1.2 parser 128: return NEW VDnode(pool(), result_node);
129: } else if(aname=="owner") {
1.3 ! parser 130: if(XalanDocument *document=self->getOwnerDocument())
1.2 parser 131: return NEW VDom(pool(), document);
1.3 ! parser 132: } else switch(self->getNodeType()) {
! 133: case XalanNode::ELEMENT_NODE:
! 134: if(aname=="attributes") {
! 135: if(const XalanNamedNodeMap *attributes=self->getAttributes()) {
! 136: VHash *result=NEW VHash(pool());
! 137: for(int i=0; i<attributes->getLength(); i++) {
! 138: XalanNode *attr_node=attributes->item(i);
! 139: result->hash().put(
! 140: *NEW String(pool(), strX(attr_node->getNodeName())),
! 141: NEW VDnode(pool(), attr_node));
! 142: }
! 143: return result;
! 144: }
! 145: }
! 146: break;
! 147: case XalanNode::ATTRIBUTE_NODE:
! 148: if(aname=="specified")
! 149: return NEW VBool(pool(), static_cast<XalanAttr *>(self)->getSpecified());
! 150: break;
! 151: /*
! 152: case XalanNode::TEXT_NODE:
! 153: case XalanNode::CDATA_SECTION_NODE:
! 154: case XalanNode::COMMENT_NODE:
! 155: substringData(unsigned int offset, unsigned int count)
! 156: */
! 157: //case XalanNode::ENTITY_REFERENCE_NODE:
! 158: //case XalanNode::ENTITY_NODE:
! 159: case XalanNode::PROCESSING_INSTRUCTION_NODE:
! 160: if(aname=="target")
! 161: return NEW VString(*NEW String(pool(),
! 162: strX(static_cast<XalanProcessingInstruction *>(self)->getTarget())));
! 163: break;
! 164: /*
! 165: case XalanNode::DOCUMENT_NODE:
! 166: virtual XalanDocumentType* getDoctype () const = 0
! 167: Get Document Type Declaration (see DocumentType) associated with this document. More...
! 168: virtual XalanDOMImplementation* getImplementation () const = 0
! 169: Return the DOMImplementation object that handles this document.
! 170: virtual XalanElement* getDocumentElement () const = 0
! 171: Return a reference to the root element of the document.
! 172: virtual XalanNodeList* getElementsByTagName (const XalanDOMString& tagname) const = 0
! 173: Returns a NodeList of all the elements with a given tag name. More...
! 174: */
! 175: /*
! 176: case XalanNode::DOCUMENT_TYPE_NODE:
! 177: virtual const XalanDOMString& getName () const = 0
! 178: The name of DTD; i.e., the name immediately following the DOCTYPE keyword in an XML source document.
! 179: virtual const XalanNamedNodeMap* getEntities () const = 0
! 180: This function returns a NamedNodeMap containing the general entities, both external and internal, declared in the DTD. More...
! 181: virtual const XalanNamedNodeMap* getNotations () const = 0
! 182: This function returns a named node map containing an entry for each notation declared in a document's DTD. More...*/
! 183: // case XalanNode::DOCUMENT_FRAGMENT_NODE:
! 184: // case XalanNode::NOTATION_NODE;
! 185: }
1.1 parser 186:
1.2 parser 187:
1.1 parser 188: return 0;
189: }
E-mail: