Update ooo320-m1
[ooovba.git] / xmlscript / source / xml_helper / xml_element.cxx
blob26fd9c30d360fecd5e8690326431884b33514aa7
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: xml_element.cxx,v $
10 * $Revision: 1.7 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlscript.hxx"
33 #include <xmlscript/xml_helper.hxx>
36 using namespace rtl;
37 using namespace com::sun::star;
38 using namespace com::sun::star::uno;
41 namespace xmlscript
44 //__________________________________________________________________________________________________
45 void XMLElement::addAttribute( OUString const & rAttrName, OUString const & rValue )
46 SAL_THROW( () )
48 _attrNames.push_back( rAttrName );
49 _attrValues.push_back( rValue );
51 //__________________________________________________________________________________________________
52 void XMLElement::addSubElement( Reference< xml::sax::XAttributeList > const & xElem )
53 SAL_THROW( () )
55 _subElems.push_back( xElem );
57 //__________________________________________________________________________________________________
58 Reference< xml::sax::XAttributeList > XMLElement::getSubElement( sal_Int32 nIndex )
59 SAL_THROW( () )
61 return _subElems[ (size_t)nIndex ];
63 //__________________________________________________________________________________________________
64 void XMLElement::dumpSubElements( Reference< xml::sax::XDocumentHandler > const & xOut )
66 for ( size_t nPos = 0; nPos < _subElems.size(); ++nPos )
68 XMLElement * pElem = static_cast< XMLElement * >( _subElems[ nPos ].get() );
69 pElem->dump( xOut );
72 //__________________________________________________________________________________________________
73 void XMLElement::dump( Reference< xml::sax::XDocumentHandler > const & xOut )
75 xOut->ignorableWhitespace( OUString() );
76 xOut->startElement( _name, static_cast< xml::sax::XAttributeList * >( this ) );
77 // write sub elements
78 dumpSubElements( xOut );
80 xOut->ignorableWhitespace( OUString() );
81 xOut->endElement( _name );
84 // XAttributeList
85 //__________________________________________________________________________________________________
86 sal_Int16 XMLElement::getLength()
87 throw (RuntimeException)
89 return static_cast<sal_Int16>(_attrNames.size());
91 //__________________________________________________________________________________________________
92 OUString XMLElement::getNameByIndex( sal_Int16 nPos )
93 throw (RuntimeException)
95 OSL_ASSERT( (size_t)nPos < _attrNames.size() );
96 return _attrNames[ nPos ];
98 //__________________________________________________________________________________________________
99 OUString XMLElement::getTypeByIndex( sal_Int16 nPos )
100 throw (RuntimeException)
102 OSL_ASSERT( (size_t)nPos < _attrNames.size() );
103 static_cast<void>(nPos);
104 // xxx todo
105 return OUString();
107 //__________________________________________________________________________________________________
108 OUString XMLElement::getTypeByName( OUString const & /*rName*/ )
109 throw (RuntimeException)
111 // xxx todo
112 return OUString();
114 //__________________________________________________________________________________________________
115 OUString XMLElement::getValueByIndex( sal_Int16 nPos )
116 throw (RuntimeException)
118 OSL_ASSERT( (size_t)nPos < _attrNames.size() );
119 return _attrValues[ nPos ];
121 //__________________________________________________________________________________________________
122 OUString XMLElement::getValueByName( OUString const & rName )
123 throw (RuntimeException)
125 for ( size_t nPos = 0; nPos < _attrNames.size(); ++nPos )
127 if (_attrNames[ nPos ] == rName)
129 return _attrValues[ nPos ];
132 return OUString();