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 __FRAMEWORK_QUERIES_H_
21 #define __FRAMEWORK_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 ouer 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 *//*-*************************************************************************************************************/
84 //---------------------------------------------------------------------------------------------------------
85 // start with empty query
86 //---------------------------------------------------------------------------------------------------------
92 //---------------------------------------------------------------------------------------------------------
93 // returns full query as copy of internal set values
94 //---------------------------------------------------------------------------------------------------------
97 OUStringBuffer
sCopy( m_sParams
);
98 sCopy
.insert( 0, m_sBase
);
99 return sCopy
.makeStringAndClear();
102 //---------------------------------------------------------------------------------------------------------
103 // set new or change existing base query part
104 //---------------------------------------------------------------------------------------------------------
105 void setBase( const OUString
& sBase
)
110 //---------------------------------------------------------------------------------------------------------
111 // add new parameter (with optional value) to param list
112 //---------------------------------------------------------------------------------------------------------
113 void addParam( const OUString
& sParam
, const OUString
& sValue
= OUString() )
115 m_sParams
.append( SEPARATOR_QUERYPARAM
);
116 m_sParams
.append( sParam
);
117 if( sValue
.getLength() > 0 )
119 m_sParams
.append( SEPARATOR_QUERYPARAMVALUE
);
120 m_sParams
.append( sValue
);
124 //---------------------------------------------------------------------------------------------------------
125 // forget all setted params and start with empty ones
126 // Attention: base of query isn't changed!
127 //---------------------------------------------------------------------------------------------------------
130 m_sParams
.makeStringAndClear();
131 m_sParams
.ensureCapacity( 256 );
134 //---------------------------------------------------------------------------------------------------------
135 // start with new empty query
136 //---------------------------------------------------------------------------------------------------------
139 m_sBase
= OUString();
145 OUStringBuffer m_sParams
;
147 }; // class QueryBuilder
149 /*-************************************************************************************************************//**
150 @short Helper class to analyze queries and split into his different parts (base, params and values).
151 *//*-*************************************************************************************************************/
156 //---------------------------------------------------------------------------------------------------------
157 // it's will not perform to compare strings as query type ...
158 // so we convert it into these enum values.
160 //---------------------------------------------------------------------------------------------------------
175 //---------------------------------------------------------------------------------------------------------
176 // these are valid values for param "sort_prop".
177 // other ones are not supported!
179 //---------------------------------------------------------------------------------------------------------
186 //---------------------------------------------------------------------------------------------------------
187 // analyze given query and split it into his different parts; <base>:<param1>:<param2=value>...
188 //---------------------------------------------------------------------------------------------------------
189 QueryAnalyzer(const OUString
& sQuery
)
190 // Don't forget to set default values for non given params!
191 : m_eQuery ( E_ALL
) // return ALL filter ...
192 , m_nIFlags ( 0 ) // which has set ANY flag ... (we remove all entries which match with these mask .. => 0!)
193 , m_nEFlags ( 0 ) // (only used, if nIFlags==0 and himself!=0!)
194 , m_eSortProp ( E_NAME
) // sort it by internal name ...
195 , m_bDescending ( sal_False
) // in ascending order ...
196 , m_bCaseSensitive( sal_False
) // ignore case ...
197 , m_bUseOrder ( sal_False
) // don't use order flag ...
198 , m_bDefaultFirst ( sal_False
) // and don't handle default entries in special case!
200 // Translate old query format to new one first!
201 OUString
sNewQuery( sQuery
);
202 if (sQuery
== "_filterquery_textdocument_withdefault")
203 sNewQuery
= "_query_writer:default_first:use_order:sort_prop=uiname";
204 else if (sQuery
== "_filterquery_webdocument_withdefault")
205 sNewQuery
= "_query_web:default_first:use_order:sort_prop=uiname";
206 else if (sQuery
== "_filterquery_globaldocument_withdefault")
207 sNewQuery
= "_query_global:default_first:use_order:sort_prop=uiname";
208 else if (sQuery
== "_filterquery_chartdocument_withdefault")
209 sNewQuery
= "_query_chart:default_first:use_order:sort_prop=uiname";
210 else if (sQuery
== "_filterquery_spreadsheetdocument_withdefault")
211 sNewQuery
= "_query_calc:default_first:use_order:sort_prop=uiname";
212 else if (sQuery
== "_filterquery_presentationdocument_withdefault")
213 sNewQuery
= "_query_impress:default_first:use_order:sort_prop=uiname";
214 else if (sQuery
== "_filterquery_drawingdocument_withdefault")
215 sNewQuery
= "_query_draw:default_first:use_order:sort_prop=uiname";
216 else if (sQuery
== "_filterquery_formulaproperties_withdefault")
217 sNewQuery
= "_query_math:default_first:use_order:sort_prop=uiname";
218 else if (sQuery
== "_filterquery_textdocument")
219 sNewQuery
= "_query_writer:use_order:sort_prop=uiname";
220 else if (sQuery
== "_filterquery_webdocument")
221 sNewQuery
= "_query_web:use_order:sort_prop=uiname";
222 else if (sQuery
== "_filterquery_globaldocument")
223 sNewQuery
= "_query_global:use_order:sort_prop=uiname";
224 else if (sQuery
== "_filterquery_chartdocument")
225 sNewQuery
= "_query_chart:use_order:sort_prop=uiname";
226 else if (sQuery
== "_filterquery_spreadsheetdocument")
227 sNewQuery
= "_query_calc:use_order:sort_prop=uiname";
228 else if (sQuery
== "_filterquery_presentationdocument")
229 sNewQuery
= "_query_impress:use_order:sort_prop=uiname";
230 else if (sQuery
== "_filterquery_drawingdocument")
231 sNewQuery
= "_query_draw:use_order:sort_prop=uiname";
232 else if (sQuery
== "_filterquery_formulaproperties")
233 sNewQuery
= "_query_math:use_order:sort_prop=uiname";
236 // Try to find base of it and safe it for faster access as enum value!
237 sal_Int32 nToken
= 0;
239 OUString sBase
= sNewQuery
.getToken( 0, SEPARATOR_QUERYPARAM
, nToken
);
241 if (sBase
.equalsIgnoreAsciiCase(BASE_QUERY_ALL
))
243 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_WRITER
))
245 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_WEB
))
247 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_GLOBAL
))
249 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_CHART
))
251 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_CALC
))
253 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_IMPRESS
))
254 m_eQuery
= E_IMPRESS
;
255 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_DRAW
))
257 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_MATH
))
259 else if( sBase
.equalsIgnoreAsciiCase(BASE_QUERY_GRAPHICS
))
260 m_eQuery
= E_GRAPHICS
;
262 // Try to get additional parameters ...
265 sParam
= sNewQuery
.getToken( 0, SEPARATOR_QUERYPARAM
, nToken
);
267 if( sParam
.startsWith( QUERYPARAM_DEFAULT_FIRST
) )
269 m_bDefaultFirst
= sal_True
;
272 else if( sParam
.startsWith( QUERYPARAM_USE_ORDER
) )
274 m_bUseOrder
= sal_True
;
277 else if( sParam
.startsWith( QUERYPARAM_DESCENDING
) )
279 m_bDescending
= sal_True
;
282 else if( sParam
.startsWith( QUERYPARAM_CASE_SENSITIVE
) )
284 m_bCaseSensitive
= sal_True
;
287 else if( sParam
.startsWith( QUERYPARAM_IFLAGS
) )
289 sal_Int32 nSubToken
= 0;
290 sParam
.getToken( 0, SEPARATOR_QUERYPARAMVALUE
, nSubToken
);
293 m_nIFlags
= sParam
.getToken( 0, SEPARATOR_QUERYPARAMVALUE
, nSubToken
).toInt32();
297 else if( sParam
.startsWith( QUERYPARAM_EFLAGS
) )
299 sal_Int32 nSubToken
= 0;
300 sParam
.getToken( 0, SEPARATOR_QUERYPARAMVALUE
, nSubToken
);
303 m_nEFlags
= sParam
.getToken( 0, SEPARATOR_QUERYPARAMVALUE
, nSubToken
).toInt32();
306 // "sort_prop=<[name,uiname]>"
307 else if( sParam
.startsWith( QUERYPARAM_SORT_PROP
) )
309 sal_Int32 nSubToken
= 0;
310 sParam
.getToken( 0, SEPARATOR_QUERYPARAMVALUE
, nSubToken
);
313 OUString sParamValue
= sParam
.getToken( 0, SEPARATOR_QUERYPARAMVALUE
, nSubToken
);
314 if( sParamValue
.startsWith( QUERYPARAMVALUE_SORT_PROP_NAME
) )
315 m_eSortProp
= E_NAME
;
316 else if( sParamValue
.startsWith( QUERYPARAMVALUE_SORT_PROP_UINAME
) )
317 m_eSortProp
= E_UINAME
;
323 //---------------------------------------------------------------------------------------------------------
324 // return type of query. User can decide then, which action should be started.
325 // For faster work we converted query string into corresponding enum value!
326 //---------------------------------------------------------------------------------------------------------
327 EQuery
getQueryType() const { return m_eQuery
; }
329 //---------------------------------------------------------------------------------------------------------
330 // access to additional parameter values
331 // Methods return default of realy set values!
332 //---------------------------------------------------------------------------------------------------------
333 sal_uInt32
getIFlags () const { return m_nIFlags
; }
334 sal_uInt32
getEFlags () const { return m_nEFlags
; }
335 ESortProp
getSortProp () const { return m_eSortProp
; }
336 sal_Bool
getDescending () const { return m_bDescending
; }
337 sal_Bool
getCaseSensitive() const { return m_bCaseSensitive
; }
338 sal_Bool
getUseOrder () const { return m_bUseOrder
; }
339 sal_Bool
getDefaultFirst () const { return m_bDefaultFirst
; }
341 //---------------------------------------------------------------------------------------------------------
342 // this method checks if given string match any supported query.
343 // (ignore additional parameters!)
344 //---------------------------------------------------------------------------------------------------------
345 static sal_Bool
isQuery( const OUString
& sQuery
)
348 sQuery
.startsWith("_query_") || // new style
349 sQuery
.startsWith("_filterquery_") // old style!
355 sal_uInt32 m_nIFlags
;
356 sal_uInt32 m_nEFlags
;
357 ESortProp m_eSortProp
;
358 sal_Bool m_bDescending
;
359 sal_Bool m_bCaseSensitive
;
360 sal_Bool m_bUseOrder
;
361 sal_Bool m_bDefaultFirst
;
363 }; // class QueryAnalyzer
365 } // namespace framework
367 #endif // #ifndef __FRAMEWORK_QUERIES_H_
369 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */