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_FRAMEWORK_INC_QUERIES_H
21 #define INCLUDED_FRAMEWORK_INC_QUERIES_H
25 #include <com/sun/star/uno/Sequence.hxx>
26 #include <rtl/ustring.hxx>
27 #include <rtl/ustrbuf.hxx>
31 /*-************************************************************************************************************
32 @short These values describe our supported queries for type, filter ... properties.
33 They are used by our FilterFactory or our TypeDetection to return
34 subsets of our cached configuration.
35 *//*-*************************************************************************************************************/
36 #define BASE_QUERY_ALL DECLARE_ASCII("_query_all" )
37 #define BASE_QUERY_WRITER DECLARE_ASCII("_query_Writer" )
38 #define BASE_QUERY_WEB DECLARE_ASCII("_query_web" )
39 #define BASE_QUERY_GLOBAL DECLARE_ASCII("_query_global" )
40 #define BASE_QUERY_CHART DECLARE_ASCII("_query_chart" )
41 #define BASE_QUERY_CALC DECLARE_ASCII("_query_calc" )
42 #define BASE_QUERY_IMPRESS DECLARE_ASCII("_query_impress" )
43 #define BASE_QUERY_DRAW DECLARE_ASCII("_query_draw" )
44 #define BASE_QUERY_MATH DECLARE_ASCII("_query_math" )
45 #define BASE_QUERY_GRAPHICS DECLARE_ASCII("_query_graphics")
47 /*-************************************************************************************************************
48 @short These parameters can be used in combination with BASE_QUERY_... defines to
50 use follow syntax to do so: "<query>[:<param>[=<value>]]"
51 e.g.: "_query_writer:default_first:use_order:sort_prop=uiname"
53 argument description default
54 -----------------------------------------------------------------------------------------------
55 iflags=<mask> include filters by given mask 0
56 eflags=<mask> exclude filters by given mask 0
57 sort_prop=<[name,uiname]> sort by internal name or uiname name
58 descending sort descending false
59 use_order use order flag of filters for sorting false
60 default_first set default filter on top of return list false
61 case_sensitive compare "sort_prop" case sensitive false
62 *//*-*************************************************************************************************************/
63 #define SEPARATOR_QUERYPARAM ((sal_Unicode)':')
64 #define SEPARATOR_QUERYPARAMVALUE ((sal_Unicode)'=')
66 #define QUERYPARAM_IFLAGS DECLARE_ASCII("iflags" )
67 #define QUERYPARAM_EFLAGS DECLARE_ASCII("eflags" )
68 #define QUERYPARAM_SORT_PROP DECLARE_ASCII("sort_prop" )
70 #define QUERYPARAM_DESCENDING DECLARE_ASCII("descending" )
71 #define QUERYPARAM_USE_ORDER DECLARE_ASCII("use_order" )
72 #define QUERYPARAM_DEFAULT_FIRST DECLARE_ASCII("default_first" )
73 #define QUERYPARAM_CASE_SENSITIVE DECLARE_ASCII("case_sensitive" )
75 #define QUERYPARAMVALUE_SORT_PROP_NAME DECLARE_ASCII("name" )
76 #define QUERYPARAMVALUE_SORT_PROP_UINAME DECLARE_ASCII("uiname" )
78 /*-************************************************************************************************************
79 @short Helper class to support easy building of a query statements.
80 *//*-*************************************************************************************************************/
85 // start with empty query
92 // returns full query as copy of internal set values
96 OUStringBuffer
sCopy( m_sParams
);
97 sCopy
.insert( 0, m_sBase
);
98 return sCopy
.makeStringAndClear();
101 // set new or change existing base query part
103 void setBase( const OUString
& sBase
)
108 // add new parameter (with optional value) to param list
110 void addParam( const OUString
& sParam
, const OUString
& sValue
= OUString() )
112 m_sParams
.append( SEPARATOR_QUERYPARAM
);
113 m_sParams
.append( sParam
);
114 if( sValue
.getLength() > 0 )
116 m_sParams
.append( SEPARATOR_QUERYPARAMVALUE
);
117 m_sParams
.append( sValue
);
121 // forget all setted params and start with empty ones
122 // Attention: base of query isn't changed!
126 m_sParams
.makeStringAndClear();
127 m_sParams
.ensureCapacity( 256 );
130 // start with new empty query
140 OUStringBuffer m_sParams
;
142 }; // class QueryBuilder
144 /*-************************************************************************************************************
145 @short Helper class to analyze queries and split into his different parts (base, params and values).
146 *//*-*************************************************************************************************************/
151 // it's will not perform to compare strings as query type ...
152 // so we convert it into these enum values.
169 // these are valid values for param "sort_prop".
170 // other ones are not supported!
179 // analyze given query and split it into his different parts; <base>:<param1>:<param2=value>...
181 QueryAnalyzer(const OUString
& sQuery
)
182 // Don't forget to set default values for non given params!
183 : m_eQuery ( E_ALL
) // return ALL filter ...
184 , m_nIFlags ( 0 ) // which has set ANY flag ... (we remove all entries which match with these mask .. => 0!)
185 , m_nEFlags ( 0 ) // (only used, if nIFlags==0 and himself!=0!)
186 , m_eSortProp ( E_NAME
) // sort it by internal name ...
187 , m_bDescending ( sal_False
) // in ascending order ...
188 , m_bCaseSensitive( sal_False
) // ignore case ...
189 , m_bUseOrder ( sal_False
) // don't use order flag ...
190 , m_bDefaultFirst ( sal_False
) // and don't handle default entries in special case!
192 // Translate old query format to new one first!
193 OUString
sNewQuery( sQuery
);
194 if (sQuery
== "_filterquery_textdocument_withdefault")
195 sNewQuery
= "_query_writer:default_first:use_order:sort_prop=uiname";
196 else if (sQuery
== "_filterquery_webdocument_withdefault")
197 sNewQuery
= "_query_web:default_first:use_order:sort_prop=uiname";
198 else if (sQuery
== "_filterquery_globaldocument_withdefault")
199 sNewQuery
= "_query_global:default_first:use_order:sort_prop=uiname";
200 else if (sQuery
== "_filterquery_chartdocument_withdefault")
201 sNewQuery
= "_query_chart:default_first:use_order:sort_prop=uiname";
202 else if (sQuery
== "_filterquery_spreadsheetdocument_withdefault")
203 sNewQuery
= "_query_calc:default_first:use_order:sort_prop=uiname";
204 else if (sQuery
== "_filterquery_presentationdocument_withdefault")
205 sNewQuery
= "_query_impress:default_first:use_order:sort_prop=uiname";
206 else if (sQuery
== "_filterquery_drawingdocument_withdefault")
207 sNewQuery
= "_query_draw:default_first:use_order:sort_prop=uiname";
208 else if (sQuery
== "_filterquery_formulaproperties_withdefault")
209 sNewQuery
= "_query_math:default_first:use_order:sort_prop=uiname";
210 else if (sQuery
== "_filterquery_textdocument")
211 sNewQuery
= "_query_writer:use_order:sort_prop=uiname";
212 else if (sQuery
== "_filterquery_webdocument")
213 sNewQuery
= "_query_web:use_order:sort_prop=uiname";
214 else if (sQuery
== "_filterquery_globaldocument")
215 sNewQuery
= "_query_global:use_order:sort_prop=uiname";
216 else if (sQuery
== "_filterquery_chartdocument")
217 sNewQuery
= "_query_chart:use_order:sort_prop=uiname";
218 else if (sQuery
== "_filterquery_spreadsheetdocument")
219 sNewQuery
= "_query_calc:use_order:sort_prop=uiname";
220 else if (sQuery
== "_filterquery_presentationdocument")
221 sNewQuery
= "_query_impress:use_order:sort_prop=uiname";
222 else if (sQuery
== "_filterquery_drawingdocument")
223 sNewQuery
= "_query_draw:use_order:sort_prop=uiname";
224 else if (sQuery
== "_filterquery_formulaproperties")
225 sNewQuery
= "_query_math:use_order:sort_prop=uiname";
228 // Try to find base of it and safe it for faster access as enum value!
229 sal_Int32 nToken
= 0;
231 OUString sBase
= sNewQuery
.getToken( 0, SEPARATOR_QUERYPARAM
, nToken
);
233 if (sBase
.equalsIgnoreAsciiCase(BASE_QUERY_ALL
))
235 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_WRITER
))
237 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_WEB
))
239 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_GLOBAL
))
241 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_CHART
))
243 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_CALC
))
245 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_IMPRESS
))
246 m_eQuery
= E_IMPRESS
;
247 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_DRAW
))
249 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_MATH
))
251 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_GRAPHICS
))
252 m_eQuery
= E_GRAPHICS
;
254 // Try to get additional parameters ...
257 sParam
= sNewQuery
.getToken( 0, SEPARATOR_QUERYPARAM
, nToken
);
259 if( sParam
.startsWith( QUERYPARAM_DEFAULT_FIRST
) )
261 m_bDefaultFirst
= sal_True
;
264 else if( sParam
.startsWith( QUERYPARAM_USE_ORDER
) )
266 m_bUseOrder
= sal_True
;
269 else if( sParam
.startsWith( QUERYPARAM_DESCENDING
) )
271 m_bDescending
= sal_True
;
274 else if( sParam
.startsWith( QUERYPARAM_CASE_SENSITIVE
) )
276 m_bCaseSensitive
= sal_True
;
279 else if( sParam
.startsWith( QUERYPARAM_IFLAGS
) )
281 sal_Int32 nSubToken
= 0;
282 sParam
.getToken( 0, SEPARATOR_QUERYPARAMVALUE
, nSubToken
);
285 m_nIFlags
= sParam
.getToken( 0, SEPARATOR_QUERYPARAMVALUE
, nSubToken
).toInt32();
289 else if( sParam
.startsWith( QUERYPARAM_EFLAGS
) )
291 sal_Int32 nSubToken
= 0;
292 sParam
.getToken( 0, SEPARATOR_QUERYPARAMVALUE
, nSubToken
);
295 m_nEFlags
= sParam
.getToken( 0, SEPARATOR_QUERYPARAMVALUE
, nSubToken
).toInt32();
298 // "sort_prop=<[name,uiname]>"
299 else if( sParam
.startsWith( QUERYPARAM_SORT_PROP
) )
301 sal_Int32 nSubToken
= 0;
302 sParam
.getToken( 0, SEPARATOR_QUERYPARAMVALUE
, nSubToken
);
305 OUString sParamValue
= sParam
.getToken( 0, SEPARATOR_QUERYPARAMVALUE
, nSubToken
);
306 if( sParamValue
.startsWith( QUERYPARAMVALUE_SORT_PROP_NAME
) )
307 m_eSortProp
= E_NAME
;
308 else if( sParamValue
.startsWith( QUERYPARAMVALUE_SORT_PROP_UINAME
) )
309 m_eSortProp
= E_UINAME
;
315 // return type of query. User can decide then, which action should be started.
316 // For faster work we converted query string into corresponding enum value!
318 EQuery
getQueryType() const { return m_eQuery
; }
320 // access to additional parameter values
321 // Methods return default of really set values!
323 sal_uInt32
getIFlags () const { return m_nIFlags
; }
324 sal_uInt32
getEFlags () const { return m_nEFlags
; }
325 ESortProp
getSortProp () const { return m_eSortProp
; }
326 bool getDescending () const { return m_bDescending
; }
327 bool getCaseSensitive() const { return m_bCaseSensitive
; }
328 bool getUseOrder () const { return m_bUseOrder
; }
329 bool getDefaultFirst () const { return m_bDefaultFirst
; }
331 // this method checks if given string match any supported query.
332 // (ignore additional parameters!)
334 static bool isQuery( const OUString
& sQuery
)
337 sQuery
.startsWith("_query_") || // new style
338 sQuery
.startsWith("_filterquery_") // old style!
344 sal_uInt32 m_nIFlags
;
345 sal_uInt32 m_nEFlags
;
346 ESortProp m_eSortProp
;
348 bool m_bCaseSensitive
;
350 bool m_bDefaultFirst
;
352 }; // class QueryAnalyzer
354 } // namespace framework
356 #endif // INCLUDED_FRAMEWORK_INC_QUERIES_H
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */