CL_DomNode CL_DomNamedNodeMap::get_named_item(const std::string &name) const
{
	int size = impl->attributes.size();
	for (int i=0; i<size; i++)
	{
		if (impl->attributes[i].first == name)
		{
			return CL_DomNode(impl->attributes[i].second);
		}
	}
	return CL_DomNode();
}
Ejemplo n.º 2
0
CL_DomNode CL_DomNode::get_next_sibling() const
{
	if (impl)
	{
		const CL_DomTreeNode *tree_node = impl->get_tree_node();
		if (tree_node->next_sibling != cl_null_node_index)
		{
			CL_DomDocument_Generic *doc_impl = (CL_DomDocument_Generic *) impl->owner_document.lock().get();
			CL_DomNode_Generic *dom_node = doc_impl->allocate_dom_node();
			dom_node->node_index = tree_node->next_sibling;
			return CL_DomNode(CL_SharedPtr<CL_DomNode_Generic>(dom_node, CL_DomDocument_Generic::NodeDeleter(doc_impl)));
		}
	}
	return CL_DomNode();
}
Ejemplo n.º 3
0
CL_DomNode CL_DomNode::remove_child(CL_DomNode &old_child)
{
	if (impl && old_child.impl)
	{
		CL_DomDocument_Generic *doc_impl = (CL_DomDocument_Generic *) impl->owner_document.lock().get();
		CL_DomTreeNode *tree_node = impl->get_tree_node();
		CL_DomTreeNode *old_tree_node = old_child.impl->get_tree_node();
		unsigned int prev_index = old_tree_node->previous_sibling;
		unsigned int next_index = old_tree_node->next_sibling;
		CL_DomTreeNode *prev = old_tree_node->get_previous_sibling(doc_impl);
		CL_DomTreeNode *next = old_tree_node->get_next_sibling(doc_impl);
		if (next)
			next->previous_sibling = prev_index;
		if (prev)
			prev->next_sibling = next_index;
		if (tree_node->first_child == old_child.impl->node_index)
			tree_node->first_child = next_index;
		if (tree_node->last_child == old_child.impl->node_index)
			tree_node->last_child = prev_index;
		old_tree_node->previous_sibling = cl_null_node_index;
		old_tree_node->next_sibling = cl_null_node_index;
		old_tree_node->parent = cl_null_node_index;
	}
	return CL_DomNode();
}
Ejemplo n.º 4
0
CL_DomNode CL_DomNode::insert_before(CL_DomNode &new_child, CL_DomNode &ref_child)
{
	if (!ref_child.impl)
	{
		append_child(new_child);
		return new_child;
	}

	if (impl && new_child.impl && ref_child.impl)
	{
		CL_DomDocument_Generic *doc_impl = (CL_DomDocument_Generic *) impl->owner_document.lock().get();
		CL_DomTreeNode *tree_node = impl->get_tree_node();
		CL_DomTreeNode *new_tree_node = new_child.impl->get_tree_node();
		CL_DomTreeNode *ref_tree_node = ref_child.impl->get_tree_node();

		new_tree_node->previous_sibling = ref_tree_node->previous_sibling;
		new_tree_node->next_sibling = ref_child.impl->node_index;
		ref_tree_node->previous_sibling = new_child.impl->node_index;
		if (new_tree_node->previous_sibling != cl_null_node_index)
			new_tree_node->get_previous_sibling(doc_impl)->next_sibling = new_child.impl->node_index;
		if (tree_node->first_child == ref_child.impl->node_index)
			tree_node->first_child = new_child.impl->node_index;
		new_tree_node->parent = impl->node_index;

		return new_child;
	}
	return CL_DomNode();
}
Ejemplo n.º 5
0
CL_DomNode CL_DomNode::named_item(const CL_DomString &name) const
{
	CL_DomNode node = get_first_child();
	while (node.is_null() == false)
	{
		if (node.get_node_name() == name) return node;
		node = node.get_next_sibling();
	}
	return CL_DomNode();
}
Ejemplo n.º 6
0
CL_DomNode CL_DomNode::named_item_ns(
	const CL_DomString &namespace_uri,
	const CL_DomString &local_name) const
{
	CL_DomNode node = get_first_child();
	while (node.is_null() == false)
	{
		if (node.get_namespace_uri() == namespace_uri && node.get_local_name() == local_name)
			return node;
		node = node.get_next_sibling();
	}
	return CL_DomNode();
}
CL_DomNode CL_DomNamedNodeMap::set_named_item(const CL_DomNode &node)
{
	int size = impl->attributes.size();
	for (int i=0; i<size; i++)
	{
		if (impl->attributes[i].first == node.to_attr().get_name())
		{
			CL_DomNode oldnode(impl->attributes[i].second);
			impl->attributes[i].second = node;
			return oldnode;
		}
	}
	
	impl->attributes.push_back(std::pair<std::string, CL_DomNode>(node.to_attr().get_name(), node));

	return CL_DomNode();
}
Ejemplo n.º 8
0
CL_DomNode CL_DomNode::replace_child(CL_DomNode &new_child, CL_DomNode &old_child)
{
	if (impl && new_child.impl && old_child.impl)
	{
		CL_DomTreeNode *tree_node = impl->get_tree_node();
		CL_DomTreeNode *new_tree_node = new_child.impl->get_tree_node();
		CL_DomTreeNode *old_tree_node = old_child.impl->get_tree_node();

		new_tree_node->previous_sibling = old_tree_node->previous_sibling;
		new_tree_node->next_sibling = old_tree_node->next_sibling;
		new_tree_node->parent = impl->node_index;
		if (tree_node->first_child == old_child.impl->node_index)
			tree_node->first_child = new_child.impl->node_index;
		if (tree_node->last_child == old_child.impl->node_index)
			tree_node->last_child = new_child.impl->node_index;
		old_tree_node->previous_sibling = cl_null_node_index;
		old_tree_node->next_sibling = cl_null_node_index;
		old_tree_node->parent = cl_null_node_index;

		return new_child;
	}
	return CL_DomNode();
}
Ejemplo n.º 9
0
CL_DomNode CL_DomNode::append_child(CL_DomNode new_child)
{
	if (impl && new_child.impl)
	{
		CL_DomDocument_Generic *doc_impl = (CL_DomDocument_Generic *) impl->owner_document.lock().get();
		CL_DomTreeNode *tree_node = impl->get_tree_node();
		CL_DomTreeNode *new_tree_node = new_child.impl->get_tree_node();
		if (tree_node->last_child != cl_null_node_index)
		{
			CL_DomTreeNode *last_tree_node = tree_node->get_last_child(doc_impl);
			last_tree_node->next_sibling = new_child.impl->node_index;
			new_tree_node->previous_sibling = tree_node->last_child;
			tree_node->last_child = new_child.impl->node_index;
		}
		else
		{
			tree_node->first_child = new_child.impl->node_index;
			tree_node->last_child = new_child.impl->node_index;
		}
		new_tree_node->parent = impl->node_index;
		return new_child;
	}
	return CL_DomNode();
}
CL_DomNode CL_DomNamedNodeMap::remove_named_item(const std::string &name)
{
	// FIXME: Implement me
	return CL_DomNode();
}
CL_DomNode CL_DomNamedNodeMap::item(unsigned long index) const
{
	return CL_DomNode(impl->attributes[index].second);
}