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