xref: /AOO41X/main/xmlscript/source/xml_helper/xml_element.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmlscript.hxx"
30 #include <xmlscript/xml_helper.hxx>
31 
32 
33 using namespace rtl;
34 using namespace com::sun::star;
35 using namespace com::sun::star::uno;
36 
37 
38 namespace xmlscript
39 {
40 
41 //__________________________________________________________________________________________________
42 void XMLElement::addAttribute( OUString const & rAttrName, OUString const & rValue )
43 	SAL_THROW( () )
44 {
45 	_attrNames.push_back( rAttrName );
46 	_attrValues.push_back( rValue );
47 }
48 //__________________________________________________________________________________________________
49 void XMLElement::addSubElement( Reference< xml::sax::XAttributeList > const & xElem )
50 	SAL_THROW( () )
51 {
52 	_subElems.push_back( xElem );
53 }
54 //__________________________________________________________________________________________________
55 Reference< xml::sax::XAttributeList > XMLElement::getSubElement( sal_Int32 nIndex )
56 	SAL_THROW( () )
57 {
58 	return _subElems[ (size_t)nIndex ];
59 }
60 //__________________________________________________________________________________________________
61 void XMLElement::dumpSubElements( Reference< xml::sax::XDocumentHandler > const & xOut )
62 {
63 	for ( size_t nPos = 0; nPos < _subElems.size(); ++nPos )
64 	{
65 		XMLElement * pElem = static_cast< XMLElement * >( _subElems[ nPos ].get() );
66 		pElem->dump( xOut );
67 	}
68 }
69 //__________________________________________________________________________________________________
70 void XMLElement::dump( Reference< xml::sax::XDocumentHandler > const & xOut )
71 {
72 	xOut->ignorableWhitespace( OUString() );
73 	xOut->startElement( _name, static_cast< xml::sax::XAttributeList * >( this ) );
74 	// write sub elements
75     dumpSubElements( xOut );
76 	//
77 	xOut->ignorableWhitespace( OUString() );
78 	xOut->endElement( _name );
79 }
80 
81 // XAttributeList
82 //__________________________________________________________________________________________________
83 sal_Int16 XMLElement::getLength()
84 	throw (RuntimeException)
85 {
86 	return static_cast<sal_Int16>(_attrNames.size());
87 }
88 //__________________________________________________________________________________________________
89 OUString XMLElement::getNameByIndex( sal_Int16 nPos )
90 	throw (RuntimeException)
91 {
92 	OSL_ASSERT( (size_t)nPos < _attrNames.size() );
93 	return _attrNames[ nPos ];
94 }
95 //__________________________________________________________________________________________________
96 OUString XMLElement::getTypeByIndex( sal_Int16 nPos )
97 	throw (RuntimeException)
98 {
99 	OSL_ASSERT( (size_t)nPos < _attrNames.size() );
100     static_cast<void>(nPos);
101 	// xxx todo
102 	return OUString();
103 }
104 //__________________________________________________________________________________________________
105 OUString XMLElement::getTypeByName( OUString const & /*rName*/ )
106 	throw (RuntimeException)
107 {
108 	// xxx todo
109 	return OUString();
110 }
111 //__________________________________________________________________________________________________
112 OUString XMLElement::getValueByIndex( sal_Int16 nPos )
113 	throw (RuntimeException)
114 {
115 	OSL_ASSERT( (size_t)nPos < _attrNames.size() );
116 	return _attrValues[ nPos ];
117 }
118 //__________________________________________________________________________________________________
119 OUString XMLElement::getValueByName( OUString const & rName )
120 	throw (RuntimeException)
121 {
122 	for ( size_t nPos = 0; nPos < _attrNames.size(); ++nPos )
123 	{
124 		if (_attrNames[ nPos ] == rName)
125 		{
126 			return _attrValues[ nPos ];
127 		}
128 	}
129 	return OUString();
130 }
131 
132 }
133