1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <xmlscript/xml_helper.hxx>
21 #include <o3tl/safeint.hxx>
22 #include <osl/diagnose.h>
23 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
25 using namespace com::sun::star
;
26 using namespace com::sun::star::uno
;
31 void XMLElement::addAttribute( OUString
const & rAttrName
, OUString
const & rValue
)
33 _attrNames
.push_back( rAttrName
);
34 _attrValues
.push_back( rValue
);
37 void XMLElement::addSubElement( Reference
< xml::sax::XAttributeList
> const & xElem
)
39 _subElems
.push_back( xElem
);
42 Reference
< xml::sax::XAttributeList
> const & XMLElement::getSubElement( sal_Int32 nIndex
)
44 return _subElems
[ static_cast<size_t>(nIndex
) ];
47 void XMLElement::dumpSubElements( Reference
< xml::sax::XDocumentHandler
> const & xOut
)
49 for (const Reference
<XAttributeList
> & _subElem
: _subElems
)
51 XMLElement
* pElem
= static_cast< XMLElement
* >( _subElem
.get() );
56 void XMLElement::dump( Reference
< xml::sax::XDocumentHandler
> const & xOut
)
58 xOut
->ignorableWhitespace( OUString() );
59 xOut
->startElement( _name
, static_cast< xml::sax::XAttributeList
* >( this ) );
61 dumpSubElements( xOut
);
62 xOut
->ignorableWhitespace( OUString() );
63 xOut
->endElement( _name
);
67 sal_Int16
XMLElement::getLength()
69 return static_cast<sal_Int16
>(_attrNames
.size());
72 OUString
XMLElement::getNameByIndex( sal_Int16 nPos
)
74 OSL_ASSERT( nPos
>= 0 && o3tl::make_unsigned(nPos
) < _attrNames
.size() );
75 return _attrNames
[ nPos
];
78 OUString
XMLElement::getTypeByIndex( sal_Int16 nPos
)
80 OSL_ASSERT( nPos
>= 0 && o3tl::make_unsigned(nPos
) < _attrNames
.size() );
85 OUString
XMLElement::getTypeByName( OUString
const & /*rName*/ )
91 OUString
XMLElement::getValueByIndex( sal_Int16 nPos
)
93 OSL_ASSERT( nPos
>= 0 && o3tl::make_unsigned(nPos
) < _attrNames
.size() );
94 return _attrValues
[ nPos
];
97 OUString
XMLElement::getValueByName( OUString
const & rName
)
99 for ( size_t nPos
= 0; nPos
< _attrNames
.size(); ++nPos
)
101 if (_attrNames
[ nPos
] == rName
)
103 return _attrValues
[ nPos
];
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */