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 <osl/diagnose.h>
23 using namespace com::sun::star
;
24 using namespace com::sun::star::uno
;
29 void XMLElement::addAttribute( OUString
const & rAttrName
, OUString
const & rValue
)
31 _attrNames
.push_back( rAttrName
);
32 _attrValues
.push_back( rValue
);
35 void XMLElement::addSubElement( Reference
< xml::sax::XAttributeList
> const & xElem
)
37 _subElems
.push_back( xElem
);
40 Reference
< xml::sax::XAttributeList
> XMLElement::getSubElement( sal_Int32 nIndex
)
42 return _subElems
[ (size_t)nIndex
];
45 void XMLElement::dumpSubElements( Reference
< xml::sax::XDocumentHandler
> const & xOut
)
47 for ( size_t nPos
= 0; nPos
< _subElems
.size(); ++nPos
)
49 XMLElement
* pElem
= static_cast< XMLElement
* >( _subElems
[ nPos
].get() );
54 void XMLElement::dump( Reference
< xml::sax::XDocumentHandler
> const & xOut
)
56 xOut
->ignorableWhitespace( OUString() );
57 xOut
->startElement( _name
, static_cast< xml::sax::XAttributeList
* >( this ) );
59 dumpSubElements( xOut
);
60 xOut
->ignorableWhitespace( OUString() );
61 xOut
->endElement( _name
);
65 sal_Int16
XMLElement::getLength()
66 throw (RuntimeException
, std::exception
)
68 return static_cast<sal_Int16
>(_attrNames
.size());
71 OUString
XMLElement::getNameByIndex( sal_Int16 nPos
)
72 throw (RuntimeException
, std::exception
)
74 OSL_ASSERT( (size_t)nPos
< _attrNames
.size() );
75 return _attrNames
[ nPos
];
78 OUString
XMLElement::getTypeByIndex( sal_Int16 nPos
)
79 throw (RuntimeException
, std::exception
)
81 OSL_ASSERT( (size_t)nPos
< _attrNames
.size() );
82 static_cast<void>(nPos
);
87 OUString
XMLElement::getTypeByName( OUString
const & /*rName*/ )
88 throw (RuntimeException
, std::exception
)
94 OUString
XMLElement::getValueByIndex( sal_Int16 nPos
)
95 throw (RuntimeException
, std::exception
)
97 OSL_ASSERT( (size_t)nPos
< _attrNames
.size() );
98 return _attrValues
[ nPos
];
101 OUString
XMLElement::getValueByName( OUString
const & rName
)
102 throw (RuntimeException
, std::exception
)
104 for ( size_t nPos
= 0; nPos
< _attrNames
.size(); ++nPos
)
106 if (_attrNames
[ nPos
] == rName
)
108 return _attrValues
[ nPos
];
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */