Line data Source code
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 :
22 : using namespace com::sun::star;
23 : using namespace com::sun::star::uno;
24 :
25 : namespace xmlscript
26 : {
27 :
28 0 : void XMLElement::addAttribute( OUString const & rAttrName, OUString const & rValue )
29 : SAL_THROW(())
30 : {
31 0 : _attrNames.push_back( rAttrName );
32 0 : _attrValues.push_back( rValue );
33 0 : }
34 :
35 0 : void XMLElement::addSubElement( Reference< xml::sax::XAttributeList > const & xElem )
36 : SAL_THROW(())
37 : {
38 0 : _subElems.push_back( xElem );
39 0 : }
40 :
41 0 : Reference< xml::sax::XAttributeList > XMLElement::getSubElement( sal_Int32 nIndex )
42 : SAL_THROW(())
43 : {
44 0 : return _subElems[ (size_t)nIndex ];
45 : }
46 :
47 0 : void XMLElement::dumpSubElements( Reference< xml::sax::XDocumentHandler > const & xOut )
48 : {
49 0 : for ( size_t nPos = 0; nPos < _subElems.size(); ++nPos )
50 : {
51 0 : XMLElement * pElem = static_cast< XMLElement * >( _subElems[ nPos ].get() );
52 0 : pElem->dump( xOut );
53 : }
54 0 : }
55 :
56 0 : void XMLElement::dump( Reference< xml::sax::XDocumentHandler > const & xOut )
57 : {
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 0 : sal_Int16 XMLElement::getLength()
68 : throw (RuntimeException, std::exception)
69 : {
70 0 : return static_cast<sal_Int16>(_attrNames.size());
71 : }
72 :
73 0 : OUString XMLElement::getNameByIndex( sal_Int16 nPos )
74 : throw (RuntimeException, std::exception)
75 : {
76 : OSL_ASSERT( (size_t)nPos < _attrNames.size() );
77 0 : return _attrNames[ nPos ];
78 : }
79 :
80 0 : OUString XMLElement::getTypeByIndex( sal_Int16 nPos )
81 : throw (RuntimeException, std::exception)
82 : {
83 : OSL_ASSERT( (size_t)nPos < _attrNames.size() );
84 : static_cast<void>(nPos);
85 : // xxx todo
86 0 : return OUString();
87 : }
88 :
89 0 : OUString XMLElement::getTypeByName( OUString const & /*rName*/ )
90 : throw (RuntimeException, std::exception)
91 : {
92 : // xxx todo
93 0 : return OUString();
94 : }
95 :
96 0 : OUString XMLElement::getValueByIndex( sal_Int16 nPos )
97 : throw (RuntimeException, std::exception)
98 : {
99 : OSL_ASSERT( (size_t)nPos < _attrNames.size() );
100 0 : return _attrValues[ nPos ];
101 : }
102 :
103 0 : OUString XMLElement::getValueByName( OUString const & rName )
104 : throw (RuntimeException, std::exception)
105 : {
106 0 : for ( size_t nPos = 0; nPos < _attrNames.size(); ++nPos )
107 : {
108 0 : if (_attrNames[ nPos ] == rName)
109 : {
110 0 : return _attrValues[ nPos ];
111 : }
112 : }
113 0 : return OUString();
114 : }
115 :
116 : }
117 :
118 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|