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