node-utilities.cpp revision 535b1596de71acb960a629b0f34f0d2171a34348
493N/A/**
0N/A * Whiteboard session manager
1130N/A * XML node manipulation / retrieval utilities
0N/A *
0N/A * Authors:
919N/A * David Yip <yipdw@rose-hulman.edu>
919N/A *
919N/A * Copyright (c) 2005 Authors
919N/A *
919N/A * Released under GNU GPL, read the file 'COPYING' for more information
0N/A */
919N/A
919N/A#include "util/shared-c-string-ptr.h"
919N/A#include "util/list.h"
0N/A
919N/A#include "xml/node-observer.h"
919N/A#include "xml/attribute-record.h"
919N/A#include "xml/repr.h"
919N/A
919N/A#include "jabber_whiteboard/defines.h"
919N/A#include "jabber_whiteboard/typedefs.h"
919N/A#include "jabber_whiteboard/node-utilities.h"
0N/A#include "jabber_whiteboard/node-tracker.h"
0N/A//#include "jabber_whiteboard/node-observer.h"
0N/A
0N/Anamespace Inkscape {
0N/A
0N/Anamespace Whiteboard {
970N/A
970N/A/*
970N/AInkscape::XML::Node*
0N/ANodeUtilities::lookupReprByValue(Inkscape::XML::Node* root, gchar const* key, Glib::ustring const* value)
0N/A{
0N/A GQuark const quark = g_quark_from_string(key);
0N/A if (root == NULL) {
970N/A return NULL;
493N/A }
970N/A
0N/A Inkscape::Util::List<Inkscape::XML::AttributeRecord const> attrlist = root->attributeList();
1003N/A for( ; attrlist ; attrlist++) {
1003N/A if ((attrlist->key == quark) && (strcmp(attrlist->value, value->data()) == 0)) {
1003N/A return root;
1003N/A }
1003N/A }
1003N/A Inkscape::XML::Node* result;
1003N/A for ( Inkscape::XML::Node* child = root->firstChild() ; child != NULL ; child = child->next() ) {
970N/A result = NodeUtilities::lookupReprByValue(child, key, value);
970N/A if(result != NULL) {
0N/A return result;
970N/A }
970N/A }
731N/A
970N/A return NULL;
970N/A}
970N/A*/
970N/A
561N/AGlib::ustring
493N/ANodeUtilities::nodeTypeToString(XML::Node const& node)
970N/A{
970N/A switch(node.type()) {
970N/A case XML::DOCUMENT_NODE:
970N/A return NODETYPE_DOCUMENT_STR;
970N/A case XML::ELEMENT_NODE:
0N/A return NODETYPE_ELEMENT_STR;
0N/A case XML::TEXT_NODE:
0N/A return NODETYPE_TEXT_STR;
970N/A case XML::COMMENT_NODE:
970N/A default:
970N/A return NODETYPE_COMMENT_STR;
0N/A }
1219N/A}
1219N/A
1219N/AXML::NodeType
0N/ANodeUtilities::stringToNodeType(Glib::ustring const& type)
1219N/A{
1219N/A if (type == NODETYPE_DOCUMENT_STR) {
29N/A return XML::DOCUMENT_NODE;
0N/A } else if (type == NODETYPE_ELEMENT_STR) {
1219N/A return XML::ELEMENT_NODE;
970N/A } else if (type == NODETYPE_TEXT_STR) {
970N/A return XML::TEXT_NODE;
970N/A } else {
970N/A return XML::COMMENT_NODE;
970N/A }
970N/A}
970N/A
970N/AGlib::ustring
970N/ANodeUtilities::findNodeID(XML::Node const& node,
970N/A XMLNodeTracker* tracker,
1219N/A KeyNodeTable const& newnodes)
970N/A{
970N/A //g_log(NULL, G_LOG_LEVEL_DEBUG, "Attempting to locate id for %p", &node);
1130N/A Glib::ustring key = newnodes.get((XML::Node *)&node);
1219N/A if (key.size()>0)
1130N/A return key;
1130N/A
970N/A if (tracker->isTracking(node)) {
970N/A //g_log(NULL, G_LOG_LEVEL_DEBUG, "Located id for %p (in tracker): %s", &node, tracker->get(node).c_str());
493N/A return tracker->get(node);
} else {
//g_log(NULL, G_LOG_LEVEL_DEBUG, "Failed to locate id");
return "";
}
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :