xref: /trunk/main/scripting/source/storage/XMLElement.cxx (revision 9d37da743abb7db0a497688391f6e55a19f27c44)
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 //*************************************************************************
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 //*************************************************************************
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 //*************************************************************************
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 //*************************************************************************
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 //*************************************************************************
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
101 sal_Int16 XMLElement::getLength()
102 {
103     OSL_TRACE( "XMLElement::getLength\n" );
104 
105     return _attrNames.size();
106 }
107 
108 //*************************************************************************
109 OUString XMLElement::getNameByIndex( sal_Int16 nPos )
110 {
111     OSL_TRACE( "XMLElement::getNameByIndex\n" );
112     OSL_ASSERT( ( size_t )nPos < _attrNames.size() );
113 
114     return _attrNames[ nPos ];
115 }
116 
117 //*************************************************************************
118 OUString XMLElement::getTypeByIndex( sal_Int16 nPos )
119 {
120     OSL_TRACE( "XMLElement::getTypeByIndex\n" );
121     OSL_ASSERT( (size_t)nPos < _attrNames.size() );
122 
123     // xxx todo
124     return OUString();
125 }
126 
127 //*************************************************************************
128 OUString XMLElement::getTypeByName( OUString const & rName )
129 {
130     OSL_TRACE( "XMLElement::getTypeByName\n" );
131     // xxx todo
132     return OUString();
133 }
134 
135 //*************************************************************************
136 OUString XMLElement::getValueByIndex( sal_Int16 nPos )
137 {
138     OSL_TRACE( "XMLElement::getValueByIndex\n" );
139     OSL_ASSERT( ( size_t )nPos < _attrNames.size() );
140 
141     return _attrValues[ nPos ];
142 }
143 
144 //*************************************************************************
145 OUString XMLElement::getValueByName( OUString const & rName )
146 {
147     OSL_TRACE( "XMLElement::getValueByName\n" );
148 
149     for ( size_t nPos = 0; nPos < _attrNames.size(); ++nPos )
150     {
151         if (_attrNames[ nPos ] == rName)
152         {
153             return _attrValues[ nPos ];
154         }
155     }
156     return OUString();
157 }
158 
159 }
160