1 /**
2 * Whiteboard session manager
3 * XML node manipulation / retrieval utilities
4 *
5 * Authors:
6 * David Yip <yipdw@rose-hulman.edu>
7 *
8 * Copyright (c) 2005 Authors
9 *
10 * Released under GNU GPL, read the file 'COPYING' for more information
11 */
13 #include "util/share.h"
14 #include "util/list.h"
16 #include "xml/node-observer.h"
17 #include "xml/attribute-record.h"
18 #include "xml/repr.h"
20 #include "jabber_whiteboard/defines.h"
21 #include "jabber_whiteboard/typedefs.h"
22 #include "jabber_whiteboard/node-utilities.h"
23 #include "jabber_whiteboard/node-tracker.h"
24 //#include "jabber_whiteboard/node-observer.h"
26 namespace Inkscape {
28 namespace Whiteboard {
30 /*
31 Inkscape::XML::Node*
32 NodeUtilities::lookupReprByValue(Inkscape::XML::Node* root, gchar const* key, Glib::ustring const* value)
33 {
34 GQuark const quark = g_quark_from_string(key);
35 if (root == NULL) {
36 return NULL;
37 }
39 Inkscape::Util::List<Inkscape::XML::AttributeRecord const> attrlist = root->attributeList();
40 for( ; attrlist ; attrlist++) {
41 if ((attrlist->key == quark) && (strcmp(attrlist->value, value->data()) == 0)) {
42 return root;
43 }
44 }
45 Inkscape::XML::Node* result;
46 for ( Inkscape::XML::Node* child = root->firstChild() ; child != NULL ; child = child->next() ) {
47 result = NodeUtilities::lookupReprByValue(child, key, value);
48 if(result != NULL) {
49 return result;
50 }
51 }
53 return NULL;
54 }
55 */
57 Glib::ustring const
58 NodeUtilities::nodeTypeToString(XML::Node const& node)
59 {
60 switch(node.type()) {
61 case XML::DOCUMENT_NODE:
62 return NODETYPE_DOCUMENT_STR;
63 case XML::ELEMENT_NODE:
64 return NODETYPE_ELEMENT_STR;
65 case XML::TEXT_NODE:
66 return NODETYPE_TEXT_STR;
67 case XML::COMMENT_NODE:
68 default:
69 return NODETYPE_COMMENT_STR;
70 }
71 }
73 XML::NodeType
74 NodeUtilities::stringToNodeType(Glib::ustring const& type)
75 {
76 if (type == NODETYPE_DOCUMENT_STR) {
77 return XML::DOCUMENT_NODE;
78 } else if (type == NODETYPE_ELEMENT_STR) {
79 return XML::ELEMENT_NODE;
80 } else if (type == NODETYPE_TEXT_STR) {
81 return XML::TEXT_NODE;
82 } else {
83 return XML::COMMENT_NODE;
84 }
85 }
87 std::string const
88 NodeUtilities::findNodeID(XML::Node const& node, XMLNodeTracker* tracker, NodeToKeyMap const& newnodes)
89 {
90 // g_log(NULL, G_LOG_LEVEL_DEBUG, "Attempting to locate id for %p", &node);
91 NodeToKeyMap::const_iterator result = newnodes.find(&node);
92 if (result != newnodes.end()) {
93 // g_log(NULL, G_LOG_LEVEL_DEBUG, "Located id for %p: %s", &node, (*result).second.c_str());
94 return (*result).second;
95 }
97 if (tracker->isTracking(node)) {
98 // g_log(NULL, G_LOG_LEVEL_DEBUG, "Located id for %p (in tracker): %s", &node, tracker->get(node).c_str());
99 return tracker->get(node);
100 } else {
101 // g_log(NULL, G_LOG_LEVEL_DEBUG, "Failed to locate id");
102 return "";
103 }
104 }
106 }
108 }
110 /*
111 Local Variables:
112 mode:c++
113 c-file-style:"stroustrup"
114 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
115 indent-tabs-mode:nil
116 fill-column:99
117 End:
118 */
119 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :