1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <xmlscript/xml_helper.hxx>
32 using namespace com::sun::star
;
33 using namespace com::sun::star::uno
;
35 using ::rtl::OUString
;
39 //__________________________________________________________________________________________________
40 void XMLElement::addAttribute( OUString
const & rAttrName
, OUString
const & rValue
)
43 _attrNames
.push_back( rAttrName
);
44 _attrValues
.push_back( rValue
);
46 //__________________________________________________________________________________________________
47 void XMLElement::addSubElement( Reference
< xml::sax::XAttributeList
> const & xElem
)
50 _subElems
.push_back( xElem
);
52 //__________________________________________________________________________________________________
53 Reference
< xml::sax::XAttributeList
> XMLElement::getSubElement( sal_Int32 nIndex
)
56 return _subElems
[ (size_t)nIndex
];
58 //__________________________________________________________________________________________________
59 void XMLElement::dumpSubElements( Reference
< xml::sax::XDocumentHandler
> const & xOut
)
61 for ( size_t nPos
= 0; nPos
< _subElems
.size(); ++nPos
)
63 XMLElement
* pElem
= static_cast< XMLElement
* >( _subElems
[ nPos
].get() );
67 //__________________________________________________________________________________________________
68 void XMLElement::dump( Reference
< xml::sax::XDocumentHandler
> const & xOut
)
70 xOut
->ignorableWhitespace( OUString() );
71 xOut
->startElement( _name
, static_cast< xml::sax::XAttributeList
* >( this ) );
73 dumpSubElements( xOut
);
74 xOut
->ignorableWhitespace( OUString() );
75 xOut
->endElement( _name
);
79 //__________________________________________________________________________________________________
80 sal_Int16
XMLElement::getLength()
81 throw (RuntimeException
)
83 return static_cast<sal_Int16
>(_attrNames
.size());
85 //__________________________________________________________________________________________________
86 OUString
XMLElement::getNameByIndex( sal_Int16 nPos
)
87 throw (RuntimeException
)
89 OSL_ASSERT( (size_t)nPos
< _attrNames
.size() );
90 return _attrNames
[ nPos
];
92 //__________________________________________________________________________________________________
93 OUString
XMLElement::getTypeByIndex( sal_Int16 nPos
)
94 throw (RuntimeException
)
96 OSL_ASSERT( (size_t)nPos
< _attrNames
.size() );
97 static_cast<void>(nPos
);
101 //__________________________________________________________________________________________________
102 OUString
XMLElement::getTypeByName( OUString
const & /*rName*/ )
103 throw (RuntimeException
)
108 //__________________________________________________________________________________________________
109 OUString
XMLElement::getValueByIndex( sal_Int16 nPos
)
110 throw (RuntimeException
)
112 OSL_ASSERT( (size_t)nPos
< _attrNames
.size() );
113 return _attrValues
[ nPos
];
115 //__________________________________________________________________________________________________
116 OUString
XMLElement::getValueByName( OUString
const & rName
)
117 throw (RuntimeException
)
119 for ( size_t nPos
= 0; nPos
< _attrNames
.size(); ++nPos
)
121 if (_attrNames
[ nPos
] == rName
)
123 return _attrValues
[ nPos
];
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */