1*e1d5bd03SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*e1d5bd03SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*e1d5bd03SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*e1d5bd03SAndrew Rist  * distributed with this work for additional information
6*e1d5bd03SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*e1d5bd03SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*e1d5bd03SAndrew Rist  * "License"); you may not use this file except in compliance
9*e1d5bd03SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*e1d5bd03SAndrew Rist  *
11*e1d5bd03SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*e1d5bd03SAndrew Rist  *
13*e1d5bd03SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*e1d5bd03SAndrew Rist  * software distributed under the License is distributed on an
15*e1d5bd03SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*e1d5bd03SAndrew Rist  * KIND, either express or implied.  See the License for the
17*e1d5bd03SAndrew Rist  * specific language governing permissions and limitations
18*e1d5bd03SAndrew Rist  * under the License.
19*e1d5bd03SAndrew Rist  *
20*e1d5bd03SAndrew Rist  *************************************************************/
21*e1d5bd03SAndrew Rist 
22*e1d5bd03SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmlscript.hxx"
26cdf0e10cSrcweir #include <xmlscript/xml_helper.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir using namespace rtl;
30cdf0e10cSrcweir using namespace com::sun::star;
31cdf0e10cSrcweir using namespace com::sun::star::uno;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace xmlscript
35cdf0e10cSrcweir {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //__________________________________________________________________________________________________
addAttribute(OUString const & rAttrName,OUString const & rValue)38cdf0e10cSrcweir void XMLElement::addAttribute( OUString const & rAttrName, OUString const & rValue )
39cdf0e10cSrcweir 	SAL_THROW( () )
40cdf0e10cSrcweir {
41cdf0e10cSrcweir 	_attrNames.push_back( rAttrName );
42cdf0e10cSrcweir 	_attrValues.push_back( rValue );
43cdf0e10cSrcweir }
44cdf0e10cSrcweir //__________________________________________________________________________________________________
addSubElement(Reference<xml::sax::XAttributeList> const & xElem)45cdf0e10cSrcweir void XMLElement::addSubElement( Reference< xml::sax::XAttributeList > const & xElem )
46cdf0e10cSrcweir 	SAL_THROW( () )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir 	_subElems.push_back( xElem );
49cdf0e10cSrcweir }
50cdf0e10cSrcweir //__________________________________________________________________________________________________
getSubElement(sal_Int32 nIndex)51cdf0e10cSrcweir Reference< xml::sax::XAttributeList > XMLElement::getSubElement( sal_Int32 nIndex )
52cdf0e10cSrcweir 	SAL_THROW( () )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir 	return _subElems[ (size_t)nIndex ];
55cdf0e10cSrcweir }
56cdf0e10cSrcweir //__________________________________________________________________________________________________
dumpSubElements(Reference<xml::sax::XDocumentHandler> const & xOut)57cdf0e10cSrcweir void XMLElement::dumpSubElements( Reference< xml::sax::XDocumentHandler > const & xOut )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir 	for ( size_t nPos = 0; nPos < _subElems.size(); ++nPos )
60cdf0e10cSrcweir 	{
61cdf0e10cSrcweir 		XMLElement * pElem = static_cast< XMLElement * >( _subElems[ nPos ].get() );
62cdf0e10cSrcweir 		pElem->dump( xOut );
63cdf0e10cSrcweir 	}
64cdf0e10cSrcweir }
65cdf0e10cSrcweir //__________________________________________________________________________________________________
dump(Reference<xml::sax::XDocumentHandler> const & xOut)66cdf0e10cSrcweir void XMLElement::dump( Reference< xml::sax::XDocumentHandler > const & xOut )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir 	xOut->ignorableWhitespace( OUString() );
69cdf0e10cSrcweir 	xOut->startElement( _name, static_cast< xml::sax::XAttributeList * >( this ) );
70cdf0e10cSrcweir 	// write sub elements
71cdf0e10cSrcweir     dumpSubElements( xOut );
72cdf0e10cSrcweir 	//
73cdf0e10cSrcweir 	xOut->ignorableWhitespace( OUString() );
74cdf0e10cSrcweir 	xOut->endElement( _name );
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir // XAttributeList
78cdf0e10cSrcweir //__________________________________________________________________________________________________
getLength()79cdf0e10cSrcweir sal_Int16 XMLElement::getLength()
80cdf0e10cSrcweir 	throw (RuntimeException)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir 	return static_cast<sal_Int16>(_attrNames.size());
83cdf0e10cSrcweir }
84cdf0e10cSrcweir //__________________________________________________________________________________________________
getNameByIndex(sal_Int16 nPos)85cdf0e10cSrcweir OUString XMLElement::getNameByIndex( sal_Int16 nPos )
86cdf0e10cSrcweir 	throw (RuntimeException)
87cdf0e10cSrcweir {
88cdf0e10cSrcweir 	OSL_ASSERT( (size_t)nPos < _attrNames.size() );
89cdf0e10cSrcweir 	return _attrNames[ nPos ];
90cdf0e10cSrcweir }
91cdf0e10cSrcweir //__________________________________________________________________________________________________
getTypeByIndex(sal_Int16 nPos)92cdf0e10cSrcweir OUString XMLElement::getTypeByIndex( sal_Int16 nPos )
93cdf0e10cSrcweir 	throw (RuntimeException)
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 	OSL_ASSERT( (size_t)nPos < _attrNames.size() );
96cdf0e10cSrcweir     static_cast<void>(nPos);
97cdf0e10cSrcweir 	// xxx todo
98cdf0e10cSrcweir 	return OUString();
99cdf0e10cSrcweir }
100cdf0e10cSrcweir //__________________________________________________________________________________________________
getTypeByName(OUString const &)101cdf0e10cSrcweir OUString XMLElement::getTypeByName( OUString const & /*rName*/ )
102cdf0e10cSrcweir 	throw (RuntimeException)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	// xxx todo
105cdf0e10cSrcweir 	return OUString();
106cdf0e10cSrcweir }
107cdf0e10cSrcweir //__________________________________________________________________________________________________
getValueByIndex(sal_Int16 nPos)108cdf0e10cSrcweir OUString XMLElement::getValueByIndex( sal_Int16 nPos )
109cdf0e10cSrcweir 	throw (RuntimeException)
110cdf0e10cSrcweir {
111cdf0e10cSrcweir 	OSL_ASSERT( (size_t)nPos < _attrNames.size() );
112cdf0e10cSrcweir 	return _attrValues[ nPos ];
113cdf0e10cSrcweir }
114cdf0e10cSrcweir //__________________________________________________________________________________________________
getValueByName(OUString const & rName)115cdf0e10cSrcweir OUString XMLElement::getValueByName( OUString const & rName )
116cdf0e10cSrcweir 	throw (RuntimeException)
117cdf0e10cSrcweir {
118cdf0e10cSrcweir 	for ( size_t nPos = 0; nPos < _attrNames.size(); ++nPos )
119cdf0e10cSrcweir 	{
120cdf0e10cSrcweir 		if (_attrNames[ nPos ] == rName)
121cdf0e10cSrcweir 		{
122cdf0e10cSrcweir 			return _attrValues[ nPos ];
123cdf0e10cSrcweir 		}
124cdf0e10cSrcweir 	}
125cdf0e10cSrcweir 	return OUString();
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir }
129