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 #ifndef _SCRIPTING_XML_ELEMENT_HXX_ 24 #define _SCRIPTING_XML_ELEMENT_HXX_ 25 26 #include <vector> 27 28 #include <cppuhelper/implbase1.hxx> 29 30 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> 31 32 namespace scripting_impl 33 { 34 // for simplification 35 #define css ::com::sun::star 36 #define dcsssf ::drafts::com::sun::star::script::framework 37 38 /*################################################################################################## 39 40 EXPORTING 41 42 ##################################################################################################*/ 43 44 //================================================================================================== 45 class XMLElement : public ::cppu::WeakImplHelper1< css::xml::sax::XAttributeList > 46 { 47 public: XMLElement(::rtl::OUString const & name,::rtl::OUString const & chars)48 inline XMLElement( ::rtl::OUString const & name, ::rtl::OUString const & chars ) 49 SAL_THROW( () ) 50 : _name( name ), _chars( chars ) 51 { 52 } 53 54 inline XMLElement( ::rtl::OUString const & name ) 55 SAL_THROW( () ) 56 : _name( name ) 57 { 58 } 59 60 /** Adds a sub element of element. 61 62 @param xElem element reference 63 */ 64 void SAL_CALL addSubElement( 65 css::uno::Reference< css::xml::sax::XAttributeList > const & xElem ) 66 SAL_THROW( () ); 67 68 /** Gets sub element of given index. The index follows order in which sub elements were added. 69 70 @param nIndex index of sub element 71 */ 72 css::uno::Reference< css::xml::sax::XAttributeList > SAL_CALL getSubElement( 73 sal_Int32 nIndex ) 74 SAL_THROW( () ); 75 76 /** Adds an attribute to elements. 77 78 @param rAttrName qname of attribute 79 @param rValue value string of element 80 */ 81 void SAL_CALL addAttribute( ::rtl::OUString const & rAttrName, 82 ::rtl::OUString const & rValue ) 83 SAL_THROW( () ); 84 85 /** Gets the tag name (qname) of element. 86 87 @return 88 qname of element 89 */ getName()90 inline ::rtl::OUString SAL_CALL getName() SAL_THROW( () ) 91 { 92 return _name; 93 } 94 95 /** Dumps out element (and all sub elements). 96 97 @param xOut document handler to be written to 98 */ 99 void SAL_CALL dump( 100 css::uno::Reference< css::xml::sax::XExtendedDocumentHandler > const & xOut ); 101 /** Dumps out sub elements (and all further sub elements). 102 103 @param xOut document handler to be written to 104 */ 105 void SAL_CALL dumpSubElements( 106 css::uno::Reference< css::xml::sax::XExtendedDocumentHandler > const & xOut ); 107 108 // XAttributeList 109 virtual sal_Int16 SAL_CALL getLength() 110 throw ( css::uno::RuntimeException ); 111 virtual ::rtl::OUString SAL_CALL getNameByIndex( sal_Int16 nPos ) 112 throw ( css::uno::RuntimeException ); 113 virtual ::rtl::OUString SAL_CALL getTypeByIndex( sal_Int16 nPos ) 114 throw ( css::uno::RuntimeException ); 115 virtual ::rtl::OUString SAL_CALL getTypeByName( ::rtl::OUString const & rName ) 116 throw ( css::uno::RuntimeException ); 117 virtual ::rtl::OUString SAL_CALL getValueByIndex( sal_Int16 nPos ) 118 throw ( css::uno::RuntimeException ); 119 virtual ::rtl::OUString SAL_CALL getValueByName( ::rtl::OUString const & rName ) 120 throw ( css::uno::RuntimeException ); 121 122 protected: 123 ::rtl::OUString _name; 124 125 ::rtl::OUString _chars; 126 127 ::std::vector< ::rtl::OUString > _attrNames; 128 ::std::vector< ::rtl::OUString > _attrValues; 129 130 ::std::vector< css::uno::Reference< 131 css::xml::sax::XAttributeList > > _subElems; 132 }; 133 134 } 135 136 #endif 137