tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / xmlscript / source / xml_helper / xml_element.cxx
blob2c7c71c58e31520626e0ebd6f881ba203612af4a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
28 namespace xmlscript
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() );
52 pElem->dump( xOut );
56 void XMLElement::dump( Reference< xml::sax::XDocumentHandler > const & xOut )
58 xOut->ignorableWhitespace( OUString() );
59 xOut->startElement( _name, static_cast< xml::sax::XAttributeList * >( this ) );
60 // write sub elements
61 dumpSubElements( xOut );
62 xOut->ignorableWhitespace( OUString() );
63 xOut->endElement( _name );
66 // XAttributeList
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() );
81 // xxx todo
82 return OUString();
85 OUString XMLElement::getTypeByName( OUString const & /*rName*/ )
87 // xxx todo
88 return OUString();
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 ];
106 return OUString();
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */