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: xml_element.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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlscript.hxx"
33 #include <xmlscript/xml_helper.hxx>
37 using namespace com::sun::star
;
38 using namespace com::sun::star::uno
;
44 //__________________________________________________________________________________________________
45 void XMLElement::addAttribute( OUString
const & rAttrName
, OUString
const & rValue
)
48 _attrNames
.push_back( rAttrName
);
49 _attrValues
.push_back( rValue
);
51 //__________________________________________________________________________________________________
52 void XMLElement::addSubElement( Reference
< xml::sax::XAttributeList
> const & xElem
)
55 _subElems
.push_back( xElem
);
57 //__________________________________________________________________________________________________
58 Reference
< xml::sax::XAttributeList
> XMLElement::getSubElement( sal_Int32 nIndex
)
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() );
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 ) );
78 dumpSubElements( xOut
);
80 xOut
->ignorableWhitespace( OUString() );
81 xOut
->endElement( _name
);
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
);
107 //__________________________________________________________________________________________________
108 OUString
XMLElement::getTypeByName( OUString
const & /*rName*/ )
109 throw (RuntimeException
)
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
];