1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: attributesmap.cxx,v $
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"
36 CAttributesMap::CAttributesMap(const CElement
* aElement
)
37 : m_pElement(aElement
)
42 The number of nodes in this map.
44 sal_Int32 SAL_CALL
CAttributesMap::getLength() throw (RuntimeException
)
47 xmlNodePtr pNode
= m_pElement
->m_aNodePtr
;
50 xmlAttrPtr cur
= pNode
->properties
;
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
;
70 OString o1
= OUStringToOString(name
, RTL_TEXTENCODING_UTF8
);
71 xmlChar
* xName
= (xmlChar
*)o1
.getStr();
72 xmlAttrPtr cur
= pNode
->properties
;
75 if( strcmp((char*)xName
, (char*)cur
->name
) == 0)
77 aNode
= Reference
< XNode
>(static_cast<CNode
*>(CNode::get((xmlNodePtr
)cur
)));
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
;
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 &&
106 aNode
= Reference
< XNode
>(static_cast< CNode
* >(CNode::get((xmlNodePtr
)cur
)));
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
;
124 xmlAttrPtr cur
= pNode
->properties
;
130 aNode
= Reference
< XNode
>(static_cast< CNode
* >(CNode::get((xmlNodePtr
)cur
)));
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
;
150 OString o1
= OUStringToOString(name
, RTL_TEXTENCODING_UTF8
);
151 xmlChar
* xName
= (xmlChar
*)o1
.getStr();
152 xmlAttrPtr cur
= pNode
->properties
;
155 if( strcmp((char*)xName
, (char*)cur
->name
) == 0)
157 aNode
= Reference
< XNode
>(static_cast< CNode
* >(CNode::get((xmlNodePtr
)cur
)));
158 xmlUnlinkNode((xmlNodePtr
)cur
);
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
;
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 &&
187 aNode
= Reference
< XNode
>(static_cast< CNode
* >(CNode::get((xmlNodePtr
)cur
)));
188 xmlUnlinkNode((xmlNodePtr
)cur
);
198 // Adds a node using its nodeName attribute.
200 Reference
< XNode
> SAL_CALL
CAttributesMap::setNamedItem(const Reference
< XNode
>& arg
) throw (RuntimeException
)
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
)
212 // return Reference< XNode >();