xref: /trunk/main/oox/inc/oox/helper/attributelist.hxx (revision e3508121)
1*e3508121SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*e3508121SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*e3508121SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*e3508121SAndrew Rist  * distributed with this work for additional information
6*e3508121SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*e3508121SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*e3508121SAndrew Rist  * "License"); you may not use this file except in compliance
9*e3508121SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*e3508121SAndrew Rist  *
11*e3508121SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*e3508121SAndrew Rist  *
13*e3508121SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*e3508121SAndrew Rist  * software distributed under the License is distributed on an
15*e3508121SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*e3508121SAndrew Rist  * KIND, either express or implied.  See the License for the
17*e3508121SAndrew Rist  * specific language governing permissions and limitations
18*e3508121SAndrew Rist  * under the License.
19*e3508121SAndrew Rist  *
20*e3508121SAndrew Rist  *************************************************************/
21*e3508121SAndrew Rist 
22*e3508121SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef OOX_HELPER_ATTRIBUTELIST_HXX
25cdf0e10cSrcweir #define OOX_HELPER_ATTRIBUTELIST_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp>
28cdf0e10cSrcweir #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
29cdf0e10cSrcweir #include "oox/helper/helper.hxx"
30cdf0e10cSrcweir #include "oox/token/namespaces.hxx"
31cdf0e10cSrcweir #include "oox/token/tokens.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir namespace oox {
34cdf0e10cSrcweir 
35cdf0e10cSrcweir // ============================================================================
36cdf0e10cSrcweir 
37cdf0e10cSrcweir /** Static helpers for conversion of strings to attribute values of various
38cdf0e10cSrcweir     different data types.
39cdf0e10cSrcweir  */
40cdf0e10cSrcweir class AttributeConversion
41cdf0e10cSrcweir {
42cdf0e10cSrcweir public:
43cdf0e10cSrcweir     /** Returns the XML token identifier from the passed string. */
44cdf0e10cSrcweir     static sal_Int32    decodeToken( const ::rtl::OUString& rValue );
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     /** Returns the decoded string value. All characters in the format
47cdf0e10cSrcweir         '_xHHHH_' (H being a hexadecimal digit), will be decoded. */
48cdf0e10cSrcweir     static ::rtl::OUString decodeXString( const ::rtl::OUString& rValue );
49cdf0e10cSrcweir 
50cdf0e10cSrcweir     /** Returns the double value from the passed string. */
51cdf0e10cSrcweir     static double       decodeDouble( const ::rtl::OUString& rValue );
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     /** Returns the 32-bit signed integer value from the passed string (decimal). */
54cdf0e10cSrcweir     static sal_Int32    decodeInteger( const ::rtl::OUString& rValue );
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     /** Returns the 32-bit unsigned integer value from the passed string (decimal). */
57cdf0e10cSrcweir     static sal_uInt32   decodeUnsigned( const ::rtl::OUString& rValue );
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     /** Returns the 64-bit signed integer value from the passed string (decimal). */
60cdf0e10cSrcweir     static sal_Int64    decodeHyper( const ::rtl::OUString& rValue );
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     /** Returns the 32-bit signed integer value from the passed string (hexadecimal). */
63cdf0e10cSrcweir     static sal_Int32    decodeIntegerHex( const ::rtl::OUString& rValue );
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     /** Returns the 32-bit unsigned integer value from the passed string (hexadecimal). */
66cdf0e10cSrcweir     static sal_uInt32   decodeUnsignedHex( const ::rtl::OUString& rValue );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     /** Returns the 64-bit signed integer value from the passed string (hexadecimal). */
69cdf0e10cSrcweir     static sal_Int64    decodeHyperHex( const ::rtl::OUString& rValue );
70cdf0e10cSrcweir };
71cdf0e10cSrcweir 
72cdf0e10cSrcweir // ============================================================================
73cdf0e10cSrcweir 
74cdf0e10cSrcweir /** Provides access to attribute values of an element.
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     Wraps a com.sun.star.xml.sax.XFastAttributeList object. Provides
77cdf0e10cSrcweir     convenience functions that convert the string value of an attribute to
78cdf0e10cSrcweir     various other data types.
79cdf0e10cSrcweir  */
80cdf0e10cSrcweir class AttributeList
81cdf0e10cSrcweir {
82cdf0e10cSrcweir public:
83cdf0e10cSrcweir     explicit            AttributeList(
84cdf0e10cSrcweir                             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& rxAttribs );
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     /** Returns the wrapped com.sun.star.xml.sax.XFastAttributeList object. */
87cdf0e10cSrcweir     inline ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >
getFastAttributeList() const88cdf0e10cSrcweir                         getFastAttributeList() const { return mxAttribs; }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     /** Returns true, if the specified attribute is present. */
91cdf0e10cSrcweir     bool                hasAttribute( sal_Int32 nAttrToken ) const;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     // optional return values -------------------------------------------------
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     /** Returns the token identifier of the value of the specified attribute. */
96cdf0e10cSrcweir     OptValue< sal_Int32 > getToken( sal_Int32 nAttrToken ) const;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     /** Returns the string value of the specified attribute. */
99cdf0e10cSrcweir     OptValue< ::rtl::OUString > getString( sal_Int32 nAttrToken ) const;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     /** Returns the string value of the specified attribute. All characters in
102cdf0e10cSrcweir         the format '_xHHHH_' (H being a hexadecimal digit), will be decoded. */
103cdf0e10cSrcweir     OptValue< ::rtl::OUString > getXString( sal_Int32 nAttrToken ) const;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     /** Returns the double value of the specified attribute. */
106cdf0e10cSrcweir     OptValue< double >  getDouble( sal_Int32 nAttrToken ) const;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     /** Returns the 32-bit signed integer value of the specified attribute (decimal). */
109cdf0e10cSrcweir     OptValue< sal_Int32 > getInteger( sal_Int32 nAttrToken ) const;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     /** Returns the 32-bit unsigned integer value of the specified attribute (decimal). */
112cdf0e10cSrcweir     OptValue< sal_uInt32 > getUnsigned( sal_Int32 nAttrToken ) const;
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     /** Returns the 64-bit signed integer value of the specified attribute (decimal). */
115cdf0e10cSrcweir     OptValue< sal_Int64 > getHyper( sal_Int32 nAttrToken ) const;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     /** Returns the 32-bit signed integer value of the specified attribute (hexadecimal). */
118cdf0e10cSrcweir     OptValue< sal_Int32 > getIntegerHex( sal_Int32 nAttrToken ) const;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     /** Returns the 32-bit unsigned integer value of the specified attribute (hexadecimal). */
121cdf0e10cSrcweir     OptValue< sal_uInt32 > getUnsignedHex( sal_Int32 nAttrToken ) const;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     /** Returns the 64-bit signed integer value of the specified attribute (hexadecimal). */
124cdf0e10cSrcweir     OptValue< sal_Int64 > getHyperHex( sal_Int32 nAttrToken ) const;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     /** Returns the boolean value of the specified attribute. */
127cdf0e10cSrcweir     OptValue< bool >    getBool( sal_Int32 nAttrToken ) const;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     /** Returns the date/time value of the specified attribute. */
130cdf0e10cSrcweir     OptValue< ::com::sun::star::util::DateTime > getDateTime( sal_Int32 nAttrToken ) const;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     // defaulted return values ------------------------------------------------
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     /** Returns the token identifier of the value of the specified attribute,
135cdf0e10cSrcweir         or the passed default identifier if the attribute is missing. */
136cdf0e10cSrcweir     sal_Int32           getToken( sal_Int32 nAttrToken, sal_Int32 nDefault ) const;
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     /** Returns the string value of the specified attribute, or the passed
139cdf0e10cSrcweir         default string if the attribute is missing. */
140cdf0e10cSrcweir     ::rtl::OUString     getString( sal_Int32 nAttrToken, const ::rtl::OUString& rDefault ) const;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     /** Returns the decoded string value of the specified attribute, or the
143cdf0e10cSrcweir         passed default string if the attribute is missing. */
144cdf0e10cSrcweir     ::rtl::OUString     getXString( sal_Int32 nAttrToken, const ::rtl::OUString& rDefault ) const;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     /** Returns the double value of the specified attribute, or the passed
147cdf0e10cSrcweir         default value if the attribute is missing or not convertible to a double. */
148cdf0e10cSrcweir     double              getDouble( sal_Int32 nAttrToken, double fDefault ) const;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     /** Returns the 32-bit signed integer value of the specified attribute, or the
151cdf0e10cSrcweir         passed default value if the attribute is missing or not convertible to integer. */
152cdf0e10cSrcweir     sal_Int32           getInteger( sal_Int32 nAttrToken, sal_Int32 nDefault ) const;
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     /** Returns the 32-bit unsigned integer value of the specified attribute, or the
155cdf0e10cSrcweir         passed default value if the attribute is missing or not convertible to unsigned. */
156cdf0e10cSrcweir     sal_uInt32          getUnsigned( sal_Int32 nAttrToken, sal_uInt32 nDefault ) const;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     /** Returns the 64-bit signed integer value of the specified attribute, or the
159cdf0e10cSrcweir         passed default value if the attribute is missing or not convertible to integer. */
160cdf0e10cSrcweir     sal_Int64           getHyper( sal_Int32 nAttrToken, sal_Int64 nDefault ) const;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     /** Returns the 32-bit signed integer value of the specified attribute (hexadecimal),
163cdf0e10cSrcweir         or the passed default value if the attribute is missing or not convertible. */
164cdf0e10cSrcweir     sal_Int32           getIntegerHex( sal_Int32 nAttrToken, sal_Int32 nDefault ) const;
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     /** Returns the 32-bit unsigned integer value of the specified attribute (hexadecimal),
167cdf0e10cSrcweir         or the passed default value if the attribute is missing or not convertible. */
168cdf0e10cSrcweir     sal_uInt32          getUnsignedHex( sal_Int32 nAttrToken, sal_uInt32 nDefault ) const;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     /** Returns the 64-bit signed integer value of the specified attribute (hexadecimal),
171cdf0e10cSrcweir         or the passed default value if the attribute is missing or not convertible. */
172cdf0e10cSrcweir     sal_Int64           getHyperHex( sal_Int32 nAttrToken, sal_Int64 nDefault ) const;
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     /** Returns the boolean value of the specified attribute, or the passed
175cdf0e10cSrcweir         default value if the attribute is missing or not convertible to bool. */
176cdf0e10cSrcweir     bool                getBool( sal_Int32 nAttrToken, bool bDefault ) const;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     /** Returns the date/time value of the specified attribute, or the default
179cdf0e10cSrcweir         value if the attribute is missing or not convertible to a date/time value. */
180cdf0e10cSrcweir     ::com::sun::star::util::DateTime getDateTime( sal_Int32 nAttrToken, const ::com::sun::star::util::DateTime& rDefault ) const;
181cdf0e10cSrcweir 
182cdf0e10cSrcweir private:
183cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >
184cdf0e10cSrcweir                         mxAttribs;
185cdf0e10cSrcweir };
186cdf0e10cSrcweir 
187cdf0e10cSrcweir // ============================================================================
188cdf0e10cSrcweir 
189cdf0e10cSrcweir } // namespace oox
190cdf0e10cSrcweir 
191cdf0e10cSrcweir #endif
192