/src/libreoffice/xmlscript/source/xml_helper/xml_element.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
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> |
24 | | |
25 | | using namespace com::sun::star; |
26 | | using namespace com::sun::star::uno; |
27 | | |
28 | | namespace xmlscript |
29 | | { |
30 | | |
31 | | void XMLElement::addAttribute( OUString const & rAttrName, OUString const & rValue ) |
32 | 48 | { |
33 | 48 | _attrNames.push_back( rAttrName ); |
34 | 48 | _attrValues.push_back( rValue ); |
35 | 48 | } |
36 | | |
37 | | void XMLElement::addSubElement( Reference< xml::sax::XAttributeList > const & xElem ) |
38 | 0 | { |
39 | 0 | _subElems.push_back( xElem ); |
40 | 0 | } |
41 | | |
42 | | Reference< xml::sax::XAttributeList > const & XMLElement::getSubElement( sal_Int32 nIndex ) |
43 | 0 | { |
44 | 0 | return _subElems[ static_cast<size_t>(nIndex) ]; |
45 | 0 | } |
46 | | |
47 | | void XMLElement::dumpSubElements( Reference< xml::sax::XDocumentHandler > const & xOut ) |
48 | 0 | { |
49 | 0 | for (const Reference<XAttributeList> & _subElem : _subElems) |
50 | 0 | { |
51 | 0 | XMLElement * pElem = static_cast< XMLElement * >( _subElem.get() ); |
52 | 0 | pElem->dump( xOut ); |
53 | 0 | } |
54 | 0 | } |
55 | | |
56 | | void XMLElement::dump( Reference< xml::sax::XDocumentHandler > const & xOut ) |
57 | 0 | { |
58 | 0 | xOut->ignorableWhitespace( OUString() ); |
59 | 0 | xOut->startElement( _name, static_cast< xml::sax::XAttributeList * >( this ) ); |
60 | | // write sub elements |
61 | 0 | dumpSubElements( xOut ); |
62 | 0 | xOut->ignorableWhitespace( OUString() ); |
63 | 0 | xOut->endElement( _name ); |
64 | 0 | } |
65 | | |
66 | | // XAttributeList |
67 | | sal_Int16 XMLElement::getLength() |
68 | 24 | { |
69 | 24 | return static_cast<sal_Int16>(_attrNames.size()); |
70 | 24 | } |
71 | | |
72 | | OUString XMLElement::getNameByIndex( sal_Int16 nPos ) |
73 | 48 | { |
74 | 48 | OSL_ASSERT( nPos >= 0 && o3tl::make_unsigned(nPos) < _attrNames.size() ); |
75 | 48 | return _attrNames[ nPos ]; |
76 | 48 | } |
77 | | |
78 | | OUString XMLElement::getTypeByIndex( sal_Int16 nPos ) |
79 | 0 | { |
80 | 0 | OSL_ASSERT( nPos >= 0 && o3tl::make_unsigned(nPos) < _attrNames.size() ); |
81 | | // xxx todo |
82 | 0 | return OUString(); |
83 | 0 | } |
84 | | |
85 | | OUString XMLElement::getTypeByName( OUString const & /*rName*/ ) |
86 | 0 | { |
87 | | // xxx todo |
88 | 0 | return OUString(); |
89 | 0 | } |
90 | | |
91 | | OUString XMLElement::getValueByIndex( sal_Int16 nPos ) |
92 | 48 | { |
93 | 48 | OSL_ASSERT( nPos >= 0 && o3tl::make_unsigned(nPos) < _attrNames.size() ); |
94 | 48 | return _attrValues[ nPos ]; |
95 | 48 | } |
96 | | |
97 | | OUString XMLElement::getValueByName( OUString const & rName ) |
98 | 0 | { |
99 | 0 | for ( size_t nPos = 0; nPos < _attrNames.size(); ++nPos ) |
100 | 0 | { |
101 | 0 | if (_attrNames[ nPos ] == rName) |
102 | 0 | { |
103 | 0 | return _attrValues[ nPos ]; |
104 | 0 | } |
105 | 0 | } |
106 | 0 | return OUString(); |
107 | 0 | } |
108 | | |
109 | | } |
110 | | |
111 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |