xref: /trunk/main/xmloff/inc/xmloff/attrlist.hxx (revision cc61290d)
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 #ifndef _XMLOFF_ATTRLIST_HXX
25 #define _XMLOFF_ATTRLIST_HXX
26 
27 #include "sal/config.h"
28 #include "xmloff/dllapi.h"
29 #include <com/sun/star/util/XCloneable.hpp>
30 #include <com/sun/star/xml/sax/SAXParseException.hpp>
31 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
32 #include <com/sun/star/xml/sax/SAXException.hpp>
33 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
34 #include <com/sun/star/xml/sax/XAttributeList.hpp>
35 #include <com/sun/star/xml/sax/XLocator.hpp>
36 #include <com/sun/star/lang/XUnoTunnel.hpp>
37 
38 #include <cppuhelper/implbase3.hxx>
39 
40 /** Implementation of the XML attribute list.
41  *
42  * It is based on std::vector.
43  */
44 struct SvXMLAttributeList_Impl;
45 
46 /** Container for XML tag attributes. */
47 class XMLOFF_DLLPUBLIC SvXMLAttributeList : public ::cppu::WeakImplHelper3<
48 		::com::sun::star::xml::sax::XAttributeList,
49 		::com::sun::star::util::XCloneable,
50 		::com::sun::star::lang::XUnoTunnel>
51 {
52 	SvXMLAttributeList_Impl *m_pImpl;
53 
54 public:
55 	SvXMLAttributeList();
56 	SvXMLAttributeList( const SvXMLAttributeList& );
57 	SvXMLAttributeList( const ::com::sun::star::uno::Reference<
58 		::com::sun::star::xml::sax::XAttributeList> & rAttrList );
59 	~SvXMLAttributeList();
60 
61 	static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId() throw();
62 	static SvXMLAttributeList* getImplementation( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > ) throw();
63 
64 	// XUnoTunnel
65     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
66 
67     /** Return the number of attributes.
68      *
69      * Required by ::com::sun::star::xml::sax::XAttributeList
70      */
71 	virtual sal_Int16 SAL_CALL getLength(void) throw( ::com::sun::star::uno::RuntimeException );
72     /** Return the name of the i-th attribute.
73      *
74      * @param i index starting from zero.
75      *
76      * @return the name of the i-th attribute, or empty string if i is
77      * not a valid index.
78      */
79 	virtual ::rtl::OUString SAL_CALL getNameByIndex(sal_Int16 i) throw( ::com::sun::star::uno::RuntimeException );
80     /** Returns the type of the i-th attribute.
81      *
82      * @param i index starting from zero.
83      *
84      * @return CDATA for any value of i.
85      */
86 	virtual ::rtl::OUString SAL_CALL getTypeByIndex(sal_Int16 i) throw( ::com::sun::star::uno::RuntimeException );
87     /** Returns the type of an attribute.
88      *
89      * @param aName name of the attribute to look for.
90      *
91      * @return CDATA for any value of aName.
92      */
93 	virtual ::rtl::OUString SAL_CALL getTypeByName(const ::rtl::OUString& aName) throw( ::com::sun::star::uno::RuntimeException );
94     /** Return the value of the i-th attribute.
95      *
96      * @param i index starting from zero.
97      *
98      * @return the value of the i-th attribute, or empty string if i is
99      * not a valid index.
100      */
101 	virtual ::rtl::OUString SAL_CALL getValueByIndex(sal_Int16 i) throw( ::com::sun::star::uno::RuntimeException );
102     /** Return the value of an attribute.
103      *
104      * @param aName name of the attribute to look for.
105      *
106      * @return the value of the attribute named aName, or empty string
107      * if no attributes are named aName.
108      */
109 	virtual ::rtl::OUString SAL_CALL getValueByName(const ::rtl::OUString& aName) throw( ::com::sun::star::uno::RuntimeException );
110 
111 	/** Make a clone of this object.
112      *
113      * Required by ::com::sun::star::util::XCloneable
114      *
115      * @return a clone of the current object.
116      */
117 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone()	throw( ::com::sun::star::uno::RuntimeException );
118 
119 	// methods that are not contained in any interface
120 
121     /** Add an attribute.
122      *
123      * @param sName name of the attribute.
124      * @param sValue value of the attribute.
125      *
126      * @exception com::sun::star::uno::RuntimeException thrown if the
127      * attribute already exists.
128      */
129 	void AddAttribute( const ::rtl::OUString &sName , const ::rtl::OUString &sValue );
130     /** Clear the attributes list. */
131 	void Clear();
132     /** Remove an attribute from the list.
133      *
134      * @param sName name of the attribute to remove.
135      *
136      * If no attribute named sName is found, this method does not do anything.
137      */
138 	void RemoveAttribute( const ::rtl::OUString sName );
139     /** Reset the attributes list.
140      *
141      * @param r list to read the attributes from.
142      *
143      * The internal list is cleared and reset from r.
144      */
145 	void SetAttributeList( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &r );
146     /** Add attributes.
147      *
148      * @param r attributes to add.
149      *
150      * @exception com::sun::star::uno::RuntimeException thrown if any
151      * of the attributes in r already exists. Previous attributes may
152      * have been added.
153      */
154 	void AppendAttributeList( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &r );
155     /** Set the value of the i-th attribute.
156      *
157      * @param i index starting from zero.
158      * @param rValue value to set.
159      *
160      * If i is out of range, this method does nothing.
161      */
162 	void SetValueByIndex( sal_Int16 i, const ::rtl::OUString& rValue );
163     /** Remove the i-th attribute.
164      *
165      * @param i index starting from zero.
166      *
167      * If i is out of range, this method does nothing.
168      */
169 	void RemoveAttributeByIndex( sal_Int16 i );
170     /** Rename the i-th attribute.
171      *
172      * @param i index starting from zero.
173      * @param rNewName new name to set.
174      *
175      * If i is out of range, this method does nothing.
176      */
177 	void RenameAttributeByIndex( sal_Int16 i, const ::rtl::OUString& rNewName );
178     /** Find an attribute from its name.
179      *
180      * @param rName attribute name to look for.
181      *
182      * @return the index of attribute named rName (starting from
183      * zero), or -1 if no attributes were found.
184      */
185 	sal_Int16 GetIndexByName( const ::rtl::OUString& rName ) const;
186 
187  private:
188     /** "CDATA" string */
189     const ::rtl::OUString sType;
190 };
191 
192 
193 #endif	//  _XMLOFF_ATTRLIST_HXX
194