update dev300-m58
[ooovba.git] / unoxml / source / dom / attributesmap.cxx
blobf185450b990bef3f34a2b2823baa21d8d6957370
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: attributesmap.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "attributesmap.hxx"
32 #include <string.h>
34 namespace DOM
36 CAttributesMap::CAttributesMap(const CElement* aElement)
37 : m_pElement(aElement)
41 /**
42 The number of nodes in this map.
44 sal_Int32 SAL_CALL CAttributesMap::getLength() throw (RuntimeException)
46 sal_Int32 count = 0;
47 xmlNodePtr pNode = m_pElement->m_aNodePtr;
48 if (pNode != NULL)
50 xmlAttrPtr cur = pNode->properties;
51 while (cur != NULL)
53 count++;
54 cur = cur->next;
57 return count;
61 /**
62 Retrieves a node specified by local name
64 Reference< XNode > SAL_CALL CAttributesMap::getNamedItem(const OUString& name) throw (RuntimeException)
66 Reference< XNode > aNode;
67 xmlNodePtr pNode = m_pElement->m_aNodePtr;
68 if (pNode != NULL)
70 OString o1 = OUStringToOString(name, RTL_TEXTENCODING_UTF8);
71 xmlChar* xName = (xmlChar*)o1.getStr();
72 xmlAttrPtr cur = pNode->properties;
73 while (cur != NULL)
75 if( strcmp((char*)xName, (char*)cur->name) == 0)
77 aNode = Reference< XNode >(static_cast<CNode*>(CNode::get((xmlNodePtr)cur)));
78 break;
80 cur = cur->next;
83 return aNode;
86 /**
87 Retrieves a node specified by local name and namespace URI.
89 Reference< XNode > SAL_CALL CAttributesMap::getNamedItemNS(const OUString& namespaceURI,const OUString& localName) throw (RuntimeException)
91 Reference< XNode > aNode;
92 xmlNodePtr pNode = m_pElement->m_aNodePtr;
93 if (pNode != NULL)
95 OString o1 = OUStringToOString(localName, RTL_TEXTENCODING_UTF8);
96 xmlChar* xName = (xmlChar*)o1.getStr();
97 OString o2 = OUStringToOString(namespaceURI, RTL_TEXTENCODING_UTF8);
98 xmlChar* xNs = (xmlChar*)o1.getStr();
99 xmlNsPtr pNs = xmlSearchNs(pNode->doc, pNode, xNs);
100 xmlAttrPtr cur = pNode->properties;
101 while (cur != NULL && pNs != NULL)
103 if( strcmp((char*)xName, (char*)cur->name) == 0 &&
104 cur->ns == pNs)
106 aNode = Reference< XNode >(static_cast< CNode* >(CNode::get((xmlNodePtr)cur)));
107 break;
109 cur = cur->next;
112 return aNode;
116 Returns the indexth item in the map.
118 Reference< XNode > SAL_CALL CAttributesMap::item(sal_Int32 index) throw (RuntimeException)
120 Reference< XNode > aNode;
121 xmlNodePtr pNode = m_pElement->m_aNodePtr;
122 if (pNode != NULL)
124 xmlAttrPtr cur = pNode->properties;
125 sal_Int32 count = 0;
126 while (cur != NULL)
128 if (count == index)
130 aNode = Reference< XNode >(static_cast< CNode* >(CNode::get((xmlNodePtr)cur)));
131 break;
133 count++;
134 cur = cur->next;
137 return aNode;
142 Removes a node specified by name.
144 Reference< XNode > SAL_CALL CAttributesMap::removeNamedItem(const OUString& name) throw (RuntimeException)
146 Reference< XNode > aNode;
147 xmlNodePtr pNode = m_pElement->m_aNodePtr;
148 if (pNode != NULL)
150 OString o1 = OUStringToOString(name, RTL_TEXTENCODING_UTF8);
151 xmlChar* xName = (xmlChar*)o1.getStr();
152 xmlAttrPtr cur = pNode->properties;
153 while (cur != NULL)
155 if( strcmp((char*)xName, (char*)cur->name) == 0)
157 aNode = Reference< XNode >(static_cast< CNode* >(CNode::get((xmlNodePtr)cur)));
158 xmlUnlinkNode((xmlNodePtr)cur);
159 break;
161 cur = cur->next;
164 return aNode;
168 // Removes a node specified by local name and namespace URI.
170 Reference< XNode > SAL_CALL CAttributesMap::removeNamedItemNS(const OUString& namespaceURI, const OUString& localName) throw (RuntimeException)
172 Reference< XNode > aNode;
173 xmlNodePtr pNode = m_pElement->m_aNodePtr;
174 if (pNode != NULL)
176 OString o1 = OUStringToOString(localName, RTL_TEXTENCODING_UTF8);
177 xmlChar* xName = (xmlChar*)o1.getStr();
178 OString o2 = OUStringToOString(namespaceURI, RTL_TEXTENCODING_UTF8);
179 xmlChar* xNs = (xmlChar*)o1.getStr();
180 xmlNsPtr pNs = xmlSearchNs(pNode->doc, pNode, xNs);
181 xmlAttrPtr cur = pNode->properties;
182 while (cur != NULL && pNs != NULL)
184 if( strcmp((char*)xName, (char*)cur->name) == 0 &&
185 cur->ns == pNs)
187 aNode = Reference< XNode >(static_cast< CNode* >(CNode::get((xmlNodePtr)cur)));
188 xmlUnlinkNode((xmlNodePtr)cur);
189 break;
191 cur = cur->next;
194 return aNode;
198 // Adds a node using its nodeName attribute.
200 Reference< XNode > SAL_CALL CAttributesMap::setNamedItem(const Reference< XNode >& arg) throw (RuntimeException)
202 return arg;
203 // return Reference< XNode >();
207 Adds a node using its namespaceURI and localName.
209 Reference< XNode > SAL_CALL CAttributesMap::setNamedItemNS(const Reference< XNode >& arg) throw (RuntimeException)
211 return arg;
212 // return Reference< XNode >();