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_xmlscript.hxx" 26 #include <xmlscript/xml_helper.hxx> 27 28 29 using namespace rtl; 30 using namespace com::sun::star; 31 using namespace com::sun::star::uno; 32 33 34 namespace xmlscript 35 { 36 37 //__________________________________________________________________________________________________ addAttribute(OUString const & rAttrName,OUString const & rValue)38void XMLElement::addAttribute( OUString const & rAttrName, OUString const & rValue ) 39 SAL_THROW( () ) 40 { 41 _attrNames.push_back( rAttrName ); 42 _attrValues.push_back( rValue ); 43 } 44 //__________________________________________________________________________________________________ addSubElement(Reference<xml::sax::XAttributeList> const & xElem)45void XMLElement::addSubElement( Reference< xml::sax::XAttributeList > const & xElem ) 46 SAL_THROW( () ) 47 { 48 _subElems.push_back( xElem ); 49 } 50 //__________________________________________________________________________________________________ getSubElement(sal_Int32 nIndex)51Reference< xml::sax::XAttributeList > XMLElement::getSubElement( sal_Int32 nIndex ) 52 SAL_THROW( () ) 53 { 54 return _subElems[ (size_t)nIndex ]; 55 } 56 //__________________________________________________________________________________________________ dumpSubElements(Reference<xml::sax::XDocumentHandler> const & xOut)57void XMLElement::dumpSubElements( Reference< xml::sax::XDocumentHandler > const & xOut ) 58 { 59 for ( size_t nPos = 0; nPos < _subElems.size(); ++nPos ) 60 { 61 XMLElement * pElem = static_cast< XMLElement * >( _subElems[ nPos ].get() ); 62 pElem->dump( xOut ); 63 } 64 } 65 //__________________________________________________________________________________________________ dump(Reference<xml::sax::XDocumentHandler> const & xOut)66void XMLElement::dump( Reference< xml::sax::XDocumentHandler > const & xOut ) 67 { 68 xOut->ignorableWhitespace( OUString() ); 69 xOut->startElement( _name, static_cast< xml::sax::XAttributeList * >( this ) ); 70 // write sub elements 71 dumpSubElements( xOut ); 72 // 73 xOut->ignorableWhitespace( OUString() ); 74 xOut->endElement( _name ); 75 } 76 77 // XAttributeList 78 //__________________________________________________________________________________________________ getLength()79sal_Int16 XMLElement::getLength() 80 { 81 return static_cast<sal_Int16>(_attrNames.size()); 82 } 83 //__________________________________________________________________________________________________ getNameByIndex(sal_Int16 nPos)84OUString XMLElement::getNameByIndex( sal_Int16 nPos ) 85 { 86 OSL_ASSERT( (size_t)nPos < _attrNames.size() ); 87 return _attrNames[ nPos ]; 88 } 89 //__________________________________________________________________________________________________ getTypeByIndex(sal_Int16 nPos)90OUString XMLElement::getTypeByIndex( sal_Int16 nPos ) 91 { 92 OSL_ASSERT( (size_t)nPos < _attrNames.size() ); 93 static_cast<void>(nPos); 94 // xxx todo 95 return OUString(); 96 } 97 //__________________________________________________________________________________________________ getTypeByName(OUString const &)98OUString XMLElement::getTypeByName( OUString const & /*rName*/ ) 99 { 100 // xxx todo 101 return OUString(); 102 } 103 //__________________________________________________________________________________________________ getValueByIndex(sal_Int16 nPos)104OUString XMLElement::getValueByIndex( sal_Int16 nPos ) 105 { 106 OSL_ASSERT( (size_t)nPos < _attrNames.size() ); 107 return _attrValues[ nPos ]; 108 } 109 //__________________________________________________________________________________________________ getValueByName(OUString const & rName)110OUString XMLElement::getValueByName( OUString const & rName ) 111 { 112 for ( size_t nPos = 0; nPos < _attrNames.size(); ++nPos ) 113 { 114 if (_attrNames[ nPos ] == rName) 115 { 116 return _attrValues[ nPos ]; 117 } 118 } 119 return OUString(); 120 } 121 122 } 123