1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_scripting.hxx" 30 #include "XMLElement.hxx" 31 #include <osl/diagnose.h> 32 33 using namespace rtl; 34 using namespace com::sun::star; 35 using namespace com::sun::star::uno; 36 37 namespace scripting_impl 38 { 39 40 //************************************************************************* 41 void XMLElement::addAttribute( OUString const & rAttrName, OUString const & rValue ) 42 SAL_THROW( () ) 43 { 44 OSL_TRACE( "XMLElement::addAttribute\n" ); 45 46 _attrNames.push_back( rAttrName ); 47 _attrValues.push_back( rValue ); 48 } 49 50 //************************************************************************* 51 void XMLElement::addSubElement( Reference< xml::sax::XAttributeList > const & xElem ) 52 SAL_THROW( () ) 53 { 54 OSL_TRACE( "XMLElement::addSubElement\n" ); 55 56 _subElems.push_back( xElem ); 57 } 58 59 //************************************************************************* 60 Reference< xml::sax::XAttributeList > XMLElement::getSubElement( sal_Int32 nIndex ) 61 SAL_THROW( () ) 62 { 63 OSL_TRACE( "XMLElement::getSubElement\n" ); 64 65 return _subElems[ ( size_t )nIndex ]; 66 } 67 68 //************************************************************************* 69 void XMLElement::dumpSubElements( Reference< xml::sax::XExtendedDocumentHandler > const & xOut ) 70 { 71 OSL_TRACE( "+++++ XMLElement::dumpSubElement\n" ); 72 73 for ( size_t nPos = 0; nPos < _subElems.size(); ++nPos ) 74 { 75 XMLElement * pElem = static_cast< XMLElement * >( _subElems[ nPos ].get() ); 76 pElem->dump( xOut ); 77 } 78 } 79 80 //************************************************************************* 81 void XMLElement::dump( Reference< xml::sax::XExtendedDocumentHandler > const & xOut ) 82 { 83 OSL_TRACE( "XMLElement::dump" ); 84 85 xOut->ignorableWhitespace( OUString() ); 86 OSL_TRACE( "XMLElement::dump starting %s",::rtl::OUStringToOString( 87 _name, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); 88 xOut->startElement( _name, static_cast< xml::sax::XAttributeList * >( this ) ); 89 // Write out CDATA 90 if( _chars.getLength() > 0 ) 91 { 92 xOut->ignorableWhitespace( OUString() ); 93 xOut->characters( _chars ); 94 } 95 // write sub elements 96 dumpSubElements( xOut ); 97 xOut->ignorableWhitespace( OUString() ); 98 xOut->endElement( _name ); 99 OSL_TRACE( "XMLElement::dump ending %s",::rtl::OUStringToOString( 100 _name, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); 101 } 102 103 //************************************************************************* 104 // XAttributeList 105 sal_Int16 XMLElement::getLength() 106 throw ( RuntimeException ) 107 { 108 OSL_TRACE( "XMLElement::getLength\n" ); 109 110 return _attrNames.size(); 111 } 112 113 //************************************************************************* 114 OUString XMLElement::getNameByIndex( sal_Int16 nPos ) 115 throw ( RuntimeException ) 116 { 117 OSL_TRACE( "XMLElement::getNameByIndex\n" ); 118 OSL_ASSERT( ( size_t )nPos < _attrNames.size() ); 119 120 return _attrNames[ nPos ]; 121 } 122 123 //************************************************************************* 124 OUString XMLElement::getTypeByIndex( sal_Int16 nPos ) 125 throw ( RuntimeException ) 126 { 127 OSL_TRACE( "XMLElement::getTypeByIndex\n" ); 128 OSL_ASSERT( (size_t)nPos < _attrNames.size() ); 129 130 // xxx todo 131 return OUString(); 132 } 133 134 //************************************************************************* 135 OUString XMLElement::getTypeByName( OUString const & rName ) 136 throw ( RuntimeException ) 137 { 138 OSL_TRACE( "XMLElement::getTypeByName\n" ); 139 // xxx todo 140 return OUString(); 141 } 142 143 //************************************************************************* 144 OUString XMLElement::getValueByIndex( sal_Int16 nPos ) 145 throw ( RuntimeException ) 146 { 147 OSL_TRACE( "XMLElement::getValueByIndex\n" ); 148 OSL_ASSERT( ( size_t )nPos < _attrNames.size() ); 149 150 return _attrValues[ nPos ]; 151 } 152 153 //************************************************************************* 154 OUString XMLElement::getValueByName( OUString const & rName ) 155 throw ( RuntimeException ) 156 { 157 OSL_TRACE( "XMLElement::getValueByName\n" ); 158 159 for ( size_t nPos = 0; nPos < _attrNames.size(); ++nPos ) 160 { 161 if (_attrNames[ nPos ] == rName) 162 { 163 return _attrValues[ nPos ]; 164 } 165 } 166 return OUString(); 167 } 168 169 } 170