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 throw (RuntimeException) 81 { 82 return static_cast<sal_Int16>(_attrNames.size()); 83 } 84 //__________________________________________________________________________________________________ getNameByIndex(sal_Int16 nPos)85OUString XMLElement::getNameByIndex( sal_Int16 nPos ) 86 throw (RuntimeException) 87 { 88 OSL_ASSERT( (size_t)nPos < _attrNames.size() ); 89 return _attrNames[ nPos ]; 90 } 91 //__________________________________________________________________________________________________ getTypeByIndex(sal_Int16 nPos)92OUString XMLElement::getTypeByIndex( sal_Int16 nPos ) 93 throw (RuntimeException) 94 { 95 OSL_ASSERT( (size_t)nPos < _attrNames.size() ); 96 static_cast<void>(nPos); 97 // xxx todo 98 return OUString(); 99 } 100 //__________________________________________________________________________________________________ getTypeByName(OUString const &)101OUString XMLElement::getTypeByName( OUString const & /*rName*/ ) 102 throw (RuntimeException) 103 { 104 // xxx todo 105 return OUString(); 106 } 107 //__________________________________________________________________________________________________ getValueByIndex(sal_Int16 nPos)108OUString XMLElement::getValueByIndex( sal_Int16 nPos ) 109 throw (RuntimeException) 110 { 111 OSL_ASSERT( (size_t)nPos < _attrNames.size() ); 112 return _attrValues[ nPos ]; 113 } 114 //__________________________________________________________________________________________________ getValueByName(OUString const & rName)115OUString XMLElement::getValueByName( OUString const & rName ) 116 throw (RuntimeException) 117 { 118 for ( size_t nPos = 0; nPos < _attrNames.size(); ++nPos ) 119 { 120 if (_attrNames[ nPos ] == rName) 121 { 122 return _attrValues[ nPos ]; 123 } 124 } 125 return OUString(); 126 } 127 128 } 129