Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef OOX_HELPER_ATTRIBUTELIST_HXX
21 : #define OOX_HELPER_ATTRIBUTELIST_HXX
22 :
23 : #include <com/sun/star/util/DateTime.hpp>
24 : #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
25 : #include "oox/helper/helper.hxx"
26 : #include "oox/token/namespaces.hxx"
27 : #include "oox/token/tokens.hxx"
28 : #include "oox/dllapi.h"
29 :
30 : namespace oox {
31 :
32 : // ============================================================================
33 :
34 : /** Static helpers for conversion of strings to attribute values of various
35 : different data types.
36 : */
37 : class OOX_DLLPUBLIC AttributeConversion
38 : {
39 : public:
40 : /** Returns the XML token identifier from the passed string. */
41 : static sal_Int32 decodeToken( const ::rtl::OUString& rValue );
42 :
43 : /** Returns the decoded string value. All characters in the format
44 : '_xHHHH_' (H being a hexadecimal digit), will be decoded. */
45 : static ::rtl::OUString decodeXString( const ::rtl::OUString& rValue );
46 :
47 : /** Returns the double value from the passed string. */
48 : static double decodeDouble( const ::rtl::OUString& rValue );
49 :
50 : /** Returns the 32-bit signed integer value from the passed string (decimal). */
51 : static sal_Int32 decodeInteger( const ::rtl::OUString& rValue );
52 :
53 : /** Returns the 32-bit unsigned integer value from the passed string (decimal). */
54 : static sal_uInt32 decodeUnsigned( const ::rtl::OUString& rValue );
55 :
56 : /** Returns the 64-bit signed integer value from the passed string (decimal). */
57 : static sal_Int64 decodeHyper( const ::rtl::OUString& rValue );
58 :
59 : /** Returns the 32-bit signed integer value from the passed string (hexadecimal). */
60 : static sal_Int32 decodeIntegerHex( const ::rtl::OUString& rValue );
61 : };
62 :
63 : // ============================================================================
64 :
65 : /** Provides access to attribute values of an element.
66 :
67 : Wraps a com.sun.star.xml.sax.XFastAttributeList object. Provides
68 : convenience functions that convert the string value of an attribute to
69 : various other data types.
70 : */
71 12452 : class OOX_DLLPUBLIC AttributeList
72 : {
73 : public:
74 : explicit AttributeList(
75 : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& rxAttribs );
76 :
77 : /** Returns the wrapped com.sun.star.xml.sax.XFastAttributeList object. */
78 : inline ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >
79 25 : getFastAttributeList() const { return mxAttribs; }
80 :
81 : /** Returns true, if the specified attribute is present. */
82 : bool hasAttribute( sal_Int32 nAttrToken ) const;
83 :
84 : // optional return values -------------------------------------------------
85 :
86 : /** Returns the token identifier of the value of the specified attribute. */
87 : OptValue< sal_Int32 > getToken( sal_Int32 nAttrToken ) const;
88 :
89 : /** Returns the string value of the specified attribute. */
90 : OptValue< ::rtl::OUString > getString( sal_Int32 nAttrToken ) const;
91 :
92 : /** Returns the string value of the specified attribute. All characters in
93 : the format '_xHHHH_' (H being a hexadecimal digit), will be decoded. */
94 : OptValue< ::rtl::OUString > getXString( sal_Int32 nAttrToken ) const;
95 :
96 : /** Returns the double value of the specified attribute. */
97 : OptValue< double > getDouble( sal_Int32 nAttrToken ) const;
98 :
99 : /** Returns the 32-bit signed integer value of the specified attribute (decimal). */
100 : OptValue< sal_Int32 > getInteger( sal_Int32 nAttrToken ) const;
101 :
102 : /** Returns the 32-bit unsigned integer value of the specified attribute (decimal). */
103 : OptValue< sal_uInt32 > getUnsigned( sal_Int32 nAttrToken ) const;
104 :
105 : /** Returns the 64-bit signed integer value of the specified attribute (decimal). */
106 : OptValue< sal_Int64 > getHyper( sal_Int32 nAttrToken ) const;
107 :
108 : /** Returns the 32-bit signed integer value of the specified attribute (hexadecimal). */
109 : OptValue< sal_Int32 > getIntegerHex( sal_Int32 nAttrToken ) const;
110 :
111 : /** Returns the boolean value of the specified attribute. */
112 : OptValue< bool > getBool( sal_Int32 nAttrToken ) const;
113 :
114 : /** Returns the date/time value of the specified attribute. */
115 : OptValue< ::com::sun::star::util::DateTime > getDateTime( sal_Int32 nAttrToken ) const;
116 :
117 : // defaulted return values ------------------------------------------------
118 :
119 : /** Returns the token identifier of the value of the specified attribute,
120 : or the passed default identifier if the attribute is missing. */
121 : sal_Int32 getToken( sal_Int32 nAttrToken, sal_Int32 nDefault ) const;
122 :
123 : /** Returns the string value of the specified attribute, or the passed
124 : default string if the attribute is missing. */
125 : ::rtl::OUString getString( sal_Int32 nAttrToken, const ::rtl::OUString& rDefault ) const;
126 :
127 : /** Returns the decoded string value of the specified attribute, or the
128 : passed default string if the attribute is missing. */
129 : ::rtl::OUString getXString( sal_Int32 nAttrToken, const ::rtl::OUString& rDefault ) const;
130 :
131 : /** Returns the double value of the specified attribute, or the passed
132 : default value if the attribute is missing or not convertible to a double. */
133 : double getDouble( sal_Int32 nAttrToken, double fDefault ) const;
134 :
135 : /** Returns the 32-bit signed integer value of the specified attribute, or the
136 : passed default value if the attribute is missing or not convertible to integer. */
137 : sal_Int32 getInteger( sal_Int32 nAttrToken, sal_Int32 nDefault ) const;
138 :
139 : /** Returns the 32-bit unsigned integer value of the specified attribute, or the
140 : passed default value if the attribute is missing or not convertible to unsigned. */
141 : sal_uInt32 getUnsigned( sal_Int32 nAttrToken, sal_uInt32 nDefault ) const;
142 :
143 : /** Returns the 64-bit signed integer value of the specified attribute, or the
144 : passed default value if the attribute is missing or not convertible to integer. */
145 : sal_Int64 getHyper( sal_Int32 nAttrToken, sal_Int64 nDefault ) const;
146 :
147 : /** Returns the 32-bit signed integer value of the specified attribute (hexadecimal),
148 : or the passed default value if the attribute is missing or not convertible. */
149 : sal_Int32 getIntegerHex( sal_Int32 nAttrToken, sal_Int32 nDefault ) const;
150 :
151 : /** Returns the boolean value of the specified attribute, or the passed
152 : default value if the attribute is missing or not convertible to bool. */
153 : bool getBool( sal_Int32 nAttrToken, bool bDefault ) const;
154 :
155 : /** Returns the date/time value of the specified attribute, or the default
156 : value if the attribute is missing or not convertible to a date/time value. */
157 : ::com::sun::star::util::DateTime getDateTime( sal_Int32 nAttrToken, const ::com::sun::star::util::DateTime& rDefault ) const;
158 :
159 : private:
160 : ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >
161 : mxAttribs;
162 : };
163 :
164 : // ============================================================================
165 :
166 : } // namespace oox
167 :
168 : #endif
169 :
170 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|