1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_OOX_HELPER_ATTRIBUTELIST_HXX
21 #define INCLUDED_OOX_HELPER_ATTRIBUTELIST_HXX
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>
30 namespace sax_fastparser
{
31 class FastAttributeList
;
38 /** Static helpers for conversion of strings to attribute values of various
41 class OOX_DLLPUBLIC AttributeConversion
44 /** Returns the XML token identifier from the passed string. */
45 static sal_Int32
decodeToken( const OUString
& rValue
);
47 /** Returns the decoded string value. All characters in the format
48 '_xHHHH_' (H being a hexadecimal digit), will be decoded. */
49 static OUString
decodeXString( const OUString
& rValue
);
51 /** Returns the 32-bit signed integer value from the passed string (decimal). */
52 static sal_Int32
decodeInteger( const OUString
& rValue
);
54 /** Returns the 32-bit unsigned integer value from the passed string (decimal). */
55 static sal_uInt32
decodeUnsigned( const OUString
& rValue
);
57 /** Returns the 64-bit signed integer value from the passed string (decimal). */
58 static sal_Int64
decodeHyper( const OUString
& rValue
);
60 /** Returns the 32-bit signed integer value from the passed string (hexadecimal). */
61 static sal_Int32
decodeIntegerHex( const OUString
& rValue
);
66 /** Provides access to attribute values of an element.
68 Wraps a com.sun.star.xml.sax.XFastAttributeList object. Provides
69 convenience functions that convert the string value of an attribute to
70 various other data types.
72 class OOX_DLLPUBLIC AttributeList
75 explicit AttributeList(
76 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XFastAttributeList
>& rxAttribs
);
78 /** Returns the wrapped com.sun.star.xml.sax.XFastAttributeList object. */
79 ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XFastAttributeList
>
80 getFastAttributeList() const { return mxAttribs
; }
82 /** Returns true, if the specified attribute is present. */
83 bool hasAttribute( sal_Int32 nAttrToken
) const;
85 // optional return values -------------------------------------------------
87 /** Returns the token identifier of the value of the specified attribute. */
88 OptValue
< sal_Int32
> getToken( sal_Int32 nAttrToken
) const;
90 /** Returns the string value of the specified attribute. */
91 OptValue
< OUString
> getString( sal_Int32 nAttrToken
) const;
93 /** Returns the string value of the specified attribute. All characters in
94 the format '_xHHHH_' (H being a hexadecimal digit), will be decoded. */
95 OptValue
< OUString
> getXString( sal_Int32 nAttrToken
) const;
97 /** Returns the double value of the specified attribute. */
98 OptValue
< double > getDouble( sal_Int32 nAttrToken
) const;
100 /** Returns the 32-bit signed integer value of the specified attribute (decimal). */
101 OptValue
< sal_Int32
> getInteger( sal_Int32 nAttrToken
) const;
103 /** Returns the 32-bit unsigned integer value of the specified attribute (decimal). */
104 OptValue
< sal_uInt32
> getUnsigned( sal_Int32 nAttrToken
) const;
106 /** Returns the 64-bit signed integer value of the specified attribute (decimal). */
107 OptValue
< sal_Int64
> getHyper( sal_Int32 nAttrToken
) const;
109 /** Returns the 32-bit signed integer value of the specified attribute (hexadecimal). */
110 OptValue
< sal_Int32
> getIntegerHex( sal_Int32 nAttrToken
) const;
112 /** Returns the boolean value of the specified attribute. */
113 OptValue
< bool > getBool( sal_Int32 nAttrToken
) const;
115 /** Returns the date/time value of the specified attribute. */
116 OptValue
< ::com::sun::star::util::DateTime
> getDateTime( sal_Int32 nAttrToken
) const;
118 // defaulted return values ------------------------------------------------
120 /** Returns the token identifier of the value of the specified attribute,
121 or the passed default identifier if the attribute is missing. */
122 sal_Int32
getToken( sal_Int32 nAttrToken
, sal_Int32 nDefault
) const;
124 /** Returns the string value of the specified attribute, or the passed
125 default string if the attribute is missing. */
126 OUString
getString( sal_Int32 nAttrToken
, const OUString
& rDefault
) const;
128 /** Returns the decoded string value of the specified attribute, or the
129 passed default string if the attribute is missing. */
130 OUString
getXString( sal_Int32 nAttrToken
, const OUString
& rDefault
) const;
132 const char* getChar( sal_Int32 nAttrToken
) const;
135 /** Returns the double value of the specified attribute, or the passed
136 default value if the attribute is missing or not convertible to a double. */
137 double getDouble( sal_Int32 nAttrToken
, double fDefault
) const;
139 /** Returns the 32-bit signed integer value of the specified attribute, or the
140 passed default value if the attribute is missing or not convertible to integer. */
141 sal_Int32
getInteger( sal_Int32 nAttrToken
, sal_Int32 nDefault
) const;
143 /** Returns the 32-bit unsigned integer value of the specified attribute, or the
144 passed default value if the attribute is missing or not convertible to unsigned. */
145 sal_uInt32
getUnsigned( sal_Int32 nAttrToken
, sal_uInt32 nDefault
) const;
147 /** Returns the 64-bit signed integer value of the specified attribute, or the
148 passed default value if the attribute is missing or not convertible to integer. */
149 sal_Int64
getHyper( sal_Int32 nAttrToken
, sal_Int64 nDefault
) const;
151 /** Returns the 32-bit signed integer value of the specified attribute (hexadecimal),
152 or the passed default value if the attribute is missing or not convertible. */
153 sal_Int32
getIntegerHex( sal_Int32 nAttrToken
, sal_Int32 nDefault
) const;
155 sal_uInt32
getUnsignedHex( sal_Int32 nAttrToken
, sal_uInt32 nDefault
) const;
157 /** Returns the boolean value of the specified attribute, or the passed
158 default value if the attribute is missing or not convertible to bool. */
159 bool getBool( sal_Int32 nAttrToken
, bool bDefault
) const;
161 /** Returns the date/time value of the specified attribute, or the default
162 value if the attribute is missing or not convertible to a date/time value. */
163 ::com::sun::star::util::DateTime
getDateTime( sal_Int32 nAttrToken
, const ::com::sun::star::util::DateTime
& rDefault
) const;
166 ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XFastAttributeList
>
168 mutable sax_fastparser::FastAttributeList
*mpAttribList
;
169 sax_fastparser::FastAttributeList
*getAttribList() const;
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */