Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / xmlscript / source / xml_helper / xml_element.cxx
blob5bcb109cd044fd46374eca5d28e6eaf18f16ff38
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 <osl/diagnose.h>
22 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
24 using namespace com::sun::star;
25 using namespace com::sun::star::uno;
27 namespace xmlscript
30 void XMLElement::addAttribute( OUString const & rAttrName, OUString const & rValue )
32 _attrNames.push_back( rAttrName );
33 _attrValues.push_back( rValue );
36 void XMLElement::addSubElement( Reference< xml::sax::XAttributeList > const & xElem )
38 _subElems.push_back( xElem );
41 Reference< xml::sax::XAttributeList > const & XMLElement::getSubElement( sal_Int32 nIndex )
43 return _subElems[ static_cast<size_t>(nIndex) ];
46 void XMLElement::dumpSubElements( Reference< xml::sax::XDocumentHandler > const & xOut )
48 for (const Reference<XAttributeList> & _subElem : _subElems)
50 XMLElement * pElem = static_cast< XMLElement * >( _subElem.get() );
51 pElem->dump( xOut );
55 void XMLElement::dump( Reference< xml::sax::XDocumentHandler > const & xOut )
57 xOut->ignorableWhitespace( OUString() );
58 xOut->startElement( _name, static_cast< xml::sax::XAttributeList * >( this ) );
59 // write sub elements
60 dumpSubElements( xOut );
61 xOut->ignorableWhitespace( OUString() );
62 xOut->endElement( _name );
65 // XAttributeList
66 sal_Int16 XMLElement::getLength()
68 return static_cast<sal_Int16>(_attrNames.size());
71 OUString XMLElement::getNameByIndex( sal_Int16 nPos )
73 OSL_ASSERT( static_cast<size_t>(nPos) < _attrNames.size() );
74 return _attrNames[ nPos ];
77 OUString XMLElement::getTypeByIndex( sal_Int16 nPos )
79 OSL_ASSERT( static_cast<size_t>(nPos) < _attrNames.size() );
80 // xxx todo
81 return OUString();
84 OUString XMLElement::getTypeByName( OUString const & /*rName*/ )
86 // xxx todo
87 return OUString();
90 OUString XMLElement::getValueByIndex( sal_Int16 nPos )
92 OSL_ASSERT( static_cast<size_t>(nPos) < _attrNames.size() );
93 return _attrValues[ nPos ];
96 OUString XMLElement::getValueByName( OUString const & rName )
98 for ( size_t nPos = 0; nPos < _attrNames.size(); ++nPos )
100 if (_attrNames[ nPos ] == rName)
102 return _attrValues[ nPos ];
105 return OUString();
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */